Page 1 of 2

Lesson 1 - siiiimplest strategy

Posted: Fri Jul 11, 2008 9:56 am
by Terranin
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.

Editing text

Posted: Fri Jul 11, 2008 10:27 am
by Terranin
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.

Posted: Sat Jul 12, 2008 4:07 am
by Terranin
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.

Scrip Problem

Posted: Thu Dec 06, 2012 10:09 pm
by Erjagope
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

Re: Scrip Problem

Posted: Fri Dec 07, 2012 3:08 am
by KelvinHand
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

Posted: Mon Dec 10, 2012 6:43 am
by Erjagope
Thanks....KelvinHand

Re: Lesson 1 - siiiimplest strategy

Posted: Wed Oct 22, 2014 1:48 am
by krumpet
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

Re: Lesson 1 - siiiimplest strategy

Posted: Wed Oct 22, 2014 9:03 am
by FX Helper
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

Re: Lesson 1 - siiiimplest strategy

Posted: Wed Oct 22, 2014 7:53 pm
by krumpet
Got it! Thank you!!!

Re: Lesson 1 - siiiimplest strategy

Posted: Tue Feb 17, 2015 4:52 pm
by fredferrell
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.

Re: Lesson 1 - siiiimplest strategy

Posted: Wed Feb 18, 2015 8:17 am
by FX Helper
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.

Re: Lesson 1 - siiiimplest strategy

Posted: Wed Feb 18, 2015 5:09 pm
by fredferrell
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.

Re: Lesson 1 - siiiimplest strategy

Posted: Thu Feb 19, 2015 8:37 am
by FX Helper
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.

Re: Lesson 1 - siiiimplest strategy

Posted: Tue Sep 22, 2015 8:09 am
by zyddarek
very helpful post, thx for this

Re: Lesson 1 - siiiimplest strategy

Posted: Wed Nov 11, 2015 4:05 am
by zvolpe
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.

Re: Lesson 1 - siiiimplest strategy

Posted: Wed Nov 11, 2015 5:17 am
by FX Helper
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.

Re: Lesson 1 - siiiimplest strategy

Posted: Wed Nov 11, 2015 5:20 am
by zvolpe
Thanks, but I'd rather not risk installing an executable from a random share site as it might contain viruses/malware.

Re: Lesson 1 - siiiimplest strategy

Posted: Tue Nov 17, 2015 4:05 am
by Solids Control
Very helpful, thank you Terranin

Re: Lesson 1 Compiling Error C2447 missing function header

Posted: Wed Mar 16, 2016 10:08 am
by txquestor
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.

Re: Lesson 1 - siiiimplest strategy

Posted: Thu Sep 14, 2017 12:04 pm
by badasstrader
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. :-)

Re: Lesson 1 - siiiimplest strategy

Posted: Fri Sep 15, 2017 3:31 am
by FX Helper
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

Re: Lesson 1 - siiiimplest strategy

Posted: Tue Feb 13, 2018 9:24 pm
by beno
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-

Re: Lesson 1 - siiiimplest strategy

Posted: Thu Apr 05, 2018 2:24 pm
by James000
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?

Re: Lesson 1 - siiiimplest strategy

Posted: Fri Apr 06, 2018 3:16 am
by FX Helper
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.

Re: Lesson 1 - siiiimplest strategy

Posted: Sun Sep 09, 2018 9:07 pm
by artem56
Hi,

I have TechnicalFunctions.h, but I don't have TechnicalFunctions.pas, Can you share it?
Thnks