Lesson 1 - siiiimplest strategy
- Terranin
- Site Admin
- Posts: 833
- Joined: Sat Oct 21, 2006 4:39 pm
Lesson 1 - siiiimplest strategy
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
Let's create new project. Go to menu File -> New -> Other. You will see next dialog:
Select Delphi Projects -> Dll wizard and press Ok button. This will just create some code for your dll library as shown below:
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.
This is what you see when you start Turbo Delphi - Welcome page
Let's create new project. Go to menu File -> New -> Other. You will see next dialog:
Select Delphi Projects -> Dll wizard and press Ok button. This will just create some code for your dll library as shown below:
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
Mike
- Terranin
- Site Admin
- Posts: 833
- Joined: Sat Oct 21, 2006 4:39 pm
Editing text
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:
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:
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.
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).
Congratulations! You created your first strategy for ForexTester. It does nothing though and has no options but it is only first step.
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).
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
Mike
- Terranin
- Site Admin
- Posts: 833
- Joined: Sat Oct 21, 2006 4:39 pm
Now, let's make the same for Microsoft Visual C++ 2005 Express Edition.
Welcome page:
Go to File -> New project, Select "Win 32 Console Application", type name "DemoStrategy" and press Ok button:
Now we are in another wizard, select here "DLL" and check "Empty project", and press "Finish" button:
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:
Almost done. Now you can type the same code in *.cpp file like we do in Delphi:
And the last important thing you need to do, create small file DemoStrategy.def in the same directory with next lines inside:
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?
Save your project and build solution. You can find your dll file in \Release\ folder.
Welcome page:
Go to File -> New project, Select "Win 32 Console Application", type name "DemoStrategy" and press Ok button:
Now we are in another wizard, select here "DLL" and check "Empty project", and press "Finish" button:
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:
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?
Save your project and build solution. You can find your dll file in \Release\ folder.
Hasta la vista
Mike
Mike
-
- Posts: 2
- Joined: Thu Dec 06, 2012 10:03 pm
- Location: Dominican Republic
Scrip Problem
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
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
-
- Posts: 103
- Joined: Sun Jan 02, 2011 6:05 pm
Re: Scrip Problem
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
-
- Posts: 9
- Joined: Sat Apr 05, 2014 12:46 am
Re: Lesson 1 - siiiimplest strategy
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
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
-
- Posts: 1479
- Joined: Mon Apr 01, 2013 3:55 am
Re: Lesson 1 - siiiimplest strategy
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
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
-
- Posts: 9
- Joined: Sat Apr 05, 2014 12:46 am
Re: Lesson 1 - siiiimplest strategy
Got it! Thank you!!!
-
- Posts: 6
- Joined: Tue Oct 14, 2014 8:56 pm
Re: Lesson 1 - siiiimplest strategy
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.
I am not sure where it looks to get this. Please let me know what I am missing.
-
- Posts: 1479
- Joined: Mon Apr 01, 2013 3:55 am
Re: Lesson 1 - siiiimplest strategy
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.
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.
-
- Posts: 6
- Joined: Tue Oct 14, 2014 8:56 pm
Re: Lesson 1 - siiiimplest strategy
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.
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.
-
- Posts: 1479
- Joined: Mon Apr 01, 2013 3:55 am
Re: Lesson 1 - siiiimplest strategy
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.
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.
-
- Posts: 1
- Joined: Tue Sep 22, 2015 8:07 am
- Contact:
Re: Lesson 1 - siiiimplest strategy
very helpful post, thx for this
-
- Posts: 4
- Joined: Wed Nov 11, 2015 3:54 am
Re: Lesson 1 - siiiimplest strategy
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.
-
- Posts: 1479
- Joined: Mon Apr 01, 2013 3:55 am
Re: Lesson 1 - siiiimplest strategy
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.
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.
-
- Posts: 4
- Joined: Wed Nov 11, 2015 3:54 am
Re: Lesson 1 - siiiimplest strategy
Thanks, but I'd rather not risk installing an executable from a random share site as it might contain viruses/malware.
-
- Posts: 1
- Joined: Tue Nov 17, 2015 3:58 am
- Contact:
Re: Lesson 1 - siiiimplest strategy
Very helpful, thank you Terranin
-
- Posts: 5
- Joined: Wed Jan 20, 2016 9:58 am
Re: Lesson 1 Compiling Error C2447 missing function header
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.
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.
-
- Posts: 6
- Joined: Tue Aug 22, 2017 10:51 am
Re: Lesson 1 - siiiimplest strategy
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.
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.
-
- Posts: 1479
- Joined: Mon Apr 01, 2013 3:55 am
Re: Lesson 1 - siiiimplest strategy
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
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
-
- Posts: 4
- Joined: Tue Feb 13, 2018 7:46 pm
Re: Lesson 1 - siiiimplest strategy
To get lesson 1 working in an Empty Project on Visual Studio 2017, i had to do 2 things:
Edit Project Properties / Configuration Properties / C/C++ / Preprocessor / Preprocessor Definitions - Add _CRT_SECURE_NO_WARNINGS
Edit Project Properties / Configuration Properties / C/C++ / Command Line / Additional Options - Add /Zc:strictStrings-
Edit Project Properties / Configuration Properties / C/C++ / Preprocessor / Preprocessor Definitions - Add _CRT_SECURE_NO_WARNINGS
Edit Project Properties / Configuration Properties / C/C++ / Command Line / Additional Options - Add /Zc:strictStrings-
-
- Posts: 1
- Joined: Thu Dec 21, 2017 3:50 pm
Re: Lesson 1 - siiiimplest strategy
I'm using Visual c++ 2005 express but I got fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
What's the problem?
What's the problem?
-
- Posts: 1479
- Joined: Mon Apr 01, 2013 3:55 am
Re: Lesson 1 - siiiimplest strategy
Hello,
windows.h is a default header file, if your compiler doesn't have it then we can recommend you to download from the Internet.
windows.h is a default header file, if your compiler doesn't have it then we can recommend you to download from the Internet.
-
- Posts: 1
- Joined: Sun Sep 09, 2018 8:59 pm
Re: Lesson 1 - siiiimplest strategy
Hi,
I have TechnicalFunctions.h, but I don't have TechnicalFunctions.pas, Can you share it?
Thnks
I have TechnicalFunctions.h, but I don't have TechnicalFunctions.pas, Can you share it?
Thnks
Return to “Programming lessons”
Who is online
Users browsing this forum: No registered users and 40 guests