Lesson 1 - siiiimplest strategy

Examples step by step how to make your own automated strategy or user indicator
Message
Author
User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

Lesson 1 - siiiimplest strategy

#1 Postby Terranin » Fri Jul 11, 2008 9:56 am

Soooo, I assume that you already installed Turbo Delphi on your computer, it could be also any other Delphi, for example Borland Delphi 6, 7 or 2006/2007. But I will make screen shots from Turbo Delphi Explorer. Good news - all versions of Delphi are compatible and you do not need to do any changes in source codes.

This is what you see when you start Turbo Delphi - Welcome page

Image

Let's create new project. Go to menu File -> New -> Other. You will see next dialog:

Image

Select Delphi Projects -> Dll wizard and press Ok button. This will just create some code for your dll library as shown below:

Image

Save your project with Ctrl+S and define its name, this will be your *.dll file name. By default it will save project to "My documents\Borland Studio Projects". I changed name to DemoStrategy. To compile your project press Ctrl+F9. Voala - we have DemoStrategy.dll in our directory where we saved our project. This is all you need to do to create dll library in Delphi, that's why I love this fantastic tool.
Last edited by Terranin on Mon Jan 26, 2009 3:57 pm, edited 5 times in total.
Hasta la vista
Mike

User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

Editing text

#2 Postby Terranin » Fri Jul 11, 2008 10:27 am

After all these steps we will only work with text inside the main window, so I will post here only listings. First step, let's delete all unnecessary strings from text:

Code: Select all

library DemoStrategy;

uses
  SysUtils;

begin

end.


After installation of ForexTester you can find API files for strategies in folder <FT>\Examples\Strategies\Delphi\ . There are 2 files StrategyInterfaceUnit.pas and TechnicalFunctions.pas. Copy these files to the same folder where you saved your project. And add their names to uses section of your code:

Code: Select all

library DemoStrategy;

uses
  SysUtils, StrategyInterfaceUnit, TechnicalFunctions;

begin

end.


Now you can use all functions from these two files, and we can create simple strategy. To make ForexTester recognize our dll as a strategy that can be executed, our module should contain at least 4 procedures:

- InitStrategy - this procedure is called only once, when strategy is initialized after it was loaded by ForexTester when it starts.

- DoneStrategy - this procedure is called only once, when you close ForexTester to release some resources that you possible allocated in InitStrategy.

- ResetStrategy - this procedure is called every time when you start new testing. I will explain it later in details.

- GetSingleTick - this procedure is called every time when price changes during testing. It does not matter what currency changes, strategy can work with every currency and receives every changes from all currencies.

Code: Select all

library DemoStrategy;

uses
  SysUtils, StrategyInterfaceUnit, TechnicalFunctions;

procedure InitStrategy; stdcall;
begin
  StrategyShortName('DemoStrategy');
  StrategyDescription('Demo strategy that does nothing');
end;

procedure DoneStrategy; stdcall;
begin

end;

procedure ResetStrategy; stdcall;
begin

end;

procedure GetSingleTick; stdcall;
begin

end;

exports
  InitStrategy,
  DoneStrategy,
  ResetStrategy,
  GetSingleTick;

end.


As you can see, I added 2 string in InitStrategy procedure. First string defines short name of strategy and second defines some longer description. You will be able to see these string in "Strategies list" dialog in ForexTester.

Press Ctrl+F9 and compile our project.

You will have DemoStrategy.dll file at the same folder where you saved the project. Now we need to import this file into ForexTester. All you need to do - just close ForexTester (if it was started), copy DemoStrategy.dll to <ForexTester>\Strategies\ folder, and start ForexTester again. If everything was correct you will see our strategy in Strategies List (menu Tools -> Strategies List).

Image

Congratulations! You created your first strategy for ForexTester. It does nothing though and has no options :) but it is only first step.
Hasta la vista

Mike

User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

#3 Postby Terranin » Sat Jul 12, 2008 4:07 am

Now, let's make the same for Microsoft Visual C++ 2005 Express Edition.

Welcome page:

Image

Go to File -> New project, Select "Win 32 Console Application", type name "DemoStrategy" and press Ok button:

Image

Now we are in another wizard, select here "DLL" and check "Empty project", and press "Finish" button:

Image

Huh, now you need to copy to the same folder files StrategyInterfaceUnit.h and TechnicalFunctions.h from <FT>\Examples\Strategies\C++\ folder and add those files to project, also create main file DemoStrategy.cpp and also attach to the project:

Image

Almost done. Now you can type the same code in *.cpp file like we do in Delphi:

Code: Select all

#include <windows.h>
#include "StrategyInterfaceUnit.h"
#include "TechnicalFunctions.h"


EXPORT void __stdcall InitStrategy()
{
  StrategyShortName("DemoStrategy");
  StrategyDescription("Demo strategy that does nothing");
}

EXPORT void __stdcall DoneStrategy()
{
 
}

EXPORT void __stdcall  ResetStrategy()
{

}

EXPORT void __stdcall GetSingleTick()
{

}


And the last important thing you need to do, create small file DemoStrategy.def in the same directory with next lines inside:

Code: Select all

LIBRARY DemoStrategy

EXPORTS InitStrategy
   DoneStrategy
   ResetStrategy
   GetSingleTick
   ReplaceStr
   IntrfProcsRec


And add it to Project -> Options -> Configuration Properties -> Linker -> Input -> Module Definition File ...
Set Release mode everywhere.
Huuuuh, this is Microsoft, what do you want? :)

Image

Save your project and build solution. You can find your dll file in \Release\ folder.
Hasta la vista

Mike

Erjagope
Posts: 2
Joined: Thu Dec 06, 2012 10:03 pm
Location: Dominican Republic

Scrip Problem

#4 Postby Erjagope » Thu Dec 06, 2012 10:09 pm

I have and error with the Scrip, I think there's something wrong in the script.

I'm using Visual c++ 2010 express, I'm new in programing

Error C2572: 'ObjectsDeleteAll' : redefinition of default parameter : parameter 2

And the script that i have from Forex Tester is:

//-----Delete all objects-----------------------------------------------------
void ObjectsDeleteAll(int window = 0, TObjectType ObjType = obj_AnyObject)
{
if (rec.pObjectsDeleteAll == NULL) return;
rec.ObjectsDeleteAll(rec.pObjectsDeleteAll, window, ObjType);
}

What can i do

KelvinHand
Posts: 103
Joined: Sun Jan 02, 2011 6:05 pm

Re: Scrip Problem

#5 Postby KelvinHand » Fri Dec 07, 2012 3:08 am

Erjagope wrote:I have and error with the Scrip, I think there's something wrong in the script.

I'm using Visual c++ 2010 express, I'm new in programing

Error C2572: 'ObjectsDeleteAll' : redefinition of default parameter : parameter 2

And the script that i have from Forex Tester is:

//-----Delete all objects-----------------------------------------------------
void ObjectsDeleteAll(int window = 0, TObjectType ObjType = obj_AnyObject)
{
if (rec.pObjectsDeleteAll == NULL) return;
rec.ObjectsDeleteAll(rec.pObjectsDeleteAll, window, ObjType);
}

What can i do


1. void ObjectsDeleteAll(int window = 0, TObjectType ObjType = obj_AnyObject)

Remove the hightlighted.
There should be a function declaration done for that.

2. Also fixed the following bug: add "="

//-----Get current time-------------------------------------------------------
TDateTime TimeCurrent()
{
if (IntrfProcsRec.TimeCurrent == NULL) return 0;
return IntrfProcsRec.TimeCurrent(IntrfProcsRec.pTimeCurrent);
}


3. Add the following for missing objects

// object types
enum TObjectType {
.....

obj_Rectangle = 13,
obj_Ellipse = 14,
obj_Triangle = 15,
obj_FiboChannel = 16,
obj_LRChannel = 17,
obj_FiboExtension = 18,
};


4. Add this for for placing obj_text to absolute coordinates

#define SVA_TOP 0
#define SVA_BOT 1

#define SHA_LEFT 0
#define SHA_RIGHT 1


5. For Transparent Color, add this to the group of colors

#define clNone 0x1FFFFFFF

6. Add the following missing OBJPROP
#define OBJPROP_FILLINSIDE 32
#define OBJPROP_FILLCOLOR 33

Erjagope
Posts: 2
Joined: Thu Dec 06, 2012 10:03 pm
Location: Dominican Republic

#6 Postby Erjagope » Mon Dec 10, 2012 6:43 am

Thanks....KelvinHand

krumpet
Posts: 9
Joined: Sat Apr 05, 2014 12:46 am

Re: Lesson 1 - siiiimplest strategy

#7 Postby krumpet » Wed Oct 22, 2014 1:48 am

I am new to coding and i am using 2013 VS express.

Any idea why i get the following msg when i try to build the example strategy?

Error 1 error LNK1104: cannot open file 'ObjectsTest.def'

I feel like i have followed all instructions.

I have spent over 4 hours on this and its doing my head in. Any help would be greatly appreciated.

Regards

FX Helper
Posts: 949
Joined: Mon Apr 01, 2013 3:55 am

Re: Lesson 1 - siiiimplest strategy

#8 Postby FX Helper » Wed Oct 22, 2014 9:03 am

Hello,

Please copy ObjectsTest.def file from C:\ForexTester2\Examples\Strategies\C++ folder to the root folder of your project. Also please set this file as the linker in project properties.

Please see more info here:
http://msdn.microsoft.com/EN-us/library/28d6s79h.aspx

krumpet
Posts: 9
Joined: Sat Apr 05, 2014 12:46 am

Re: Lesson 1 - siiiimplest strategy

#9 Postby krumpet » Wed Oct 22, 2014 7:53 pm

Got it! Thank you!!!

fredferrell
Posts: 6
Joined: Tue Oct 14, 2014 8:56 pm

Re: Lesson 1 - siiiimplest strategy

#10 Postby fredferrell » Tue Feb 17, 2015 4:52 pm

I am using Lazarus IDE v1.2.6 and have an issue running the strategy in FT2. It seems to compile fine when I am both LCL and LCLbase in the required packages along with StrategyInterfaceUnit, TechnicalFunctions, and IndicatorInterfaceUnit in the project folder. I did the copy/paste method first, but it never came up. Next I did the install through the application and it gives me the following error: Can not install strategy, file will be deleted. Have error: Can not get "ReplaceStr" proc address.

I am not sure where it looks to get this. Please let me know what I am missing.

FX Helper
Posts: 949
Joined: Mon Apr 01, 2013 3:55 am

Re: Lesson 1 - siiiimplest strategy

#11 Postby FX Helper » Wed Feb 18, 2015 8:17 am

Hello,

Do you have this issue when trying to compile this simplest strategy? Or you are trying to compile some another strategy? In this case can you send source code?

Also please try to use usual Delphi, everything should work in this case.

fredferrell
Posts: 6
Joined: Tue Oct 14, 2014 8:56 pm

Re: Lesson 1 - siiiimplest strategy

#12 Postby fredferrell » Wed Feb 18, 2015 5:09 pm

Yes, this is with the first strategy, but not during the compile. It does that fine. It is an issue when I try to run the .dll in FT2.

Below is the source code:

library DemoStrategy;

uses
SysUtils, StrategyInterfaceUnit, TechnicalFunctions;

procedure InitStrategy; stdcall;
begin
StrategyShortName('DemoStrategy');
StrategyDescription('Demo strategy that does nothing');
end;

procedure DoneStrategy; stdcall;
begin

end;

procedure ResetStrategy; stdcall;
begin

end;

procedure GetSingleTick; stdcall;
begin

end;

exports
InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick;

end.

FX Helper
Posts: 949
Joined: Mon Apr 01, 2013 3:55 am

Re: Lesson 1 - siiiimplest strategy

#13 Postby FX Helper » Thu Feb 19, 2015 8:37 am

Hello,

Probably this issue is associated with Lazarus. Sorry, but we haven't worked with Lazarus so we can't help you with this.

Can you install any Delphi version? For example, please google for Delphi7_Lite_Full_Setup_v7.3.3.0_Build_2009-6-22_.rar
This should work for you.

zyddarek
Posts: 1
Joined: Tue Sep 22, 2015 8:07 am
Contact:

Re: Lesson 1 - siiiimplest strategy

#14 Postby zyddarek » Tue Sep 22, 2015 8:09 am

very helpful post, thx for this

zvolpe
Posts: 4
Joined: Wed Nov 11, 2015 3:54 am

Re: Lesson 1 - siiiimplest strategy

#15 Postby zvolpe » Wed Nov 11, 2015 4:05 am

Can anyone recommend a free Delphi IDE? I haven't used Delphi for many years and it looks like Turbo Delphi (or it's successor) is no longer free.

FX Helper
Posts: 949
Joined: Mon Apr 01, 2013 3:55 am

Re: Lesson 1 - siiiimplest strategy

#16 Postby FX Helper » Wed Nov 11, 2015 5:17 am

Hello,

You cna try to search for Delphi7_Lite_Full_Setup_v7.3.3.0_Build_2009-6-22_.rar in Internet.
Does it work for you?
I don't know other free Delphi versions.

zvolpe
Posts: 4
Joined: Wed Nov 11, 2015 3:54 am

Re: Lesson 1 - siiiimplest strategy

#17 Postby zvolpe » Wed Nov 11, 2015 5:20 am

Thanks, but I'd rather not risk installing an executable from a random share site as it might contain viruses/malware.

Solids Control
Posts: 1
Joined: Tue Nov 17, 2015 3:58 am
Contact:

Re: Lesson 1 - siiiimplest strategy

#18 Postby Solids Control » Tue Nov 17, 2015 4:05 am

Very helpful, thank you Terranin

txquestor
Posts: 5
Joined: Wed Jan 20, 2016 9:58 am

Re: Lesson 1 Compiling Error C2447 missing function header

#19 Postby txquestor » Wed Mar 16, 2016 10:08 am

Compiling Error for Forextester2 DemoStrategy DLL

Hi Terranin,

2 issues:

1. without additional 'include' path for .h files the \strategyinterfaceunit.h won't load but,
2. add 'include' path, get this error.

strategyinterfaceunit.h(1738) : error C2447: '{' : missing function header (old-style formal list?)

What do I need to do to fix this error? I don't see anything in the wrong place.

Thanks,
txquestor

This is the code:

//-----Delete all objects-----------------------------------------------------
void ObjectsDeleteAll(int window, TObjectType ObjType)
{
if (rec.pObjectsDeleteAll == NULL) return;
rec.ObjectsDeleteAll(rec.pObjectsDeleteAll, window, ObjType);
}

I use Visual Studio 2008 Express to compile it.

badasstrader
Posts: 6
Joined: Tue Aug 22, 2017 10:51 am

Re: Lesson 1 - siiiimplest strategy

#20 Postby badasstrader » Thu Sep 14, 2017 12:04 pm

Hello,

I've compiled DemoStrategy.dll with Visual C++ 2010 Express and installed it. During the installation (Install New Strategy), I have the message "Can not get InitStrategy proc adress".

If I directly copy the file in the FT Strategy folder, I don't see it in Strategies List.

Thanks in advance.

AFTER EDIT

Well I did something that resolved my problem, I don't know whether it's a coincidence or not, maybe it could help someone struggling with the same problem. In the properties on the project I put the complete name of the .def file (which was in my project directory lol).

Also I verified that my project properties where set for everything (debug and release) by choosing the "All Configurations" option.

I noticed too that trying to build the project with the Debug option is a very bad idea because it display errors that are not there in the release building.

So Now when I put DemoStrategy.dll in the Forex Tester Strategies folder and restart FT I can see my strategy among the other ones. :-)
Last edited by badasstrader on Fri Sep 15, 2017 4:03 am, edited 1 time in total.

FX Helper
Posts: 949
Joined: Mon Apr 01, 2013 3:55 am

Re: Lesson 1 - siiiimplest strategy

#21 Postby FX Helper » Fri Sep 15, 2017 3:31 am

Hello,

You should make some procedures visible for Forex Tester defining them in EXPORTS section i.
For C++ you need to attach a file like this to a project (this is for strategy) see the message 3 from this topic:

LIBRARY DemoStrategy

EXPORTS InitStrategy
DoneStrategy
ResetStrategy
GetSingleTick
ReplaceStr
IntrfProcsRec


Return to “Programming lessons”

Who is online

Users browsing this forum: No registered users and 1 guest