Strategy Install Error

How to create strategies and indicators
Message
Author
Gen
Posts: 14
Joined: Tue Sep 21, 2010 2:19 pm

Strategy Install Error

#1 Postby Gen » Tue Sep 21, 2010 2:44 pm

Hi,
I am having hard time to install my strategy onto FT2.

This is what I did.

I change Strategy Description in the default file, SMA Strategy.
Saved and Build on razarus.
Came back to FT2, and did "Install New Strategy".

Then, I got th following error.
After asking me for the overwriting and I clicked Yes, the error comes back by saying "Can not install strategy, file will be deleted"

Then the SMA Strategy is not in the Strategy list any more.

You know, All I did was just changing Strategy Description.
Did I do something wrong?

Is there any work around for this?
Any different way of installing the strategy?

I remember it used to be OK to move the dll file directly into Strategy folder on FT2.

Please help me out.
Attachments
Untitled.png
Untitled.png (131.64 KiB) Viewed 17628 times

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#2 Postby FT Support » Tue Sep 21, 2010 3:12 pm

Is it correct that your strategy is written in C++?

if yes then please check that you have .def file in your project and it has the following text:

Code: Select all

LIBRARY MYSTRATEGY

EXPORTS InitStrategy
   DoneStrategy
   ReplaceStr
   ResetStrategy
   GetSingleTick
   IntrfProcsRec
Check our other product here:
http://www.forexcopier.com

Gen
Posts: 14
Joined: Tue Sep 21, 2010 2:19 pm

#3 Postby Gen » Wed Sep 22, 2010 1:46 am

Hi,

It is delphi.
I got this from the /examples/Strategies/Delphi folder.
As you see below, I only changed "StrategyDescription"


//-------------------------------------------------------------------------
// Example of strategy based on 2 crossing SMA (c) Koshelev M.A.
//-------------------------------------------------------------------------
library SMAStrategy;

uses
SysUtils, Classes, StrategyInterfaceUnit;

var
// External parameters
Currency: PChar = nil;
TimeFrame: integer;
LotSize: double;
period1: integer;
period2: integer;

// custom variables
OrderHandle: integer;
OrderStyle: TTradePositionType;
OpenTime: TDateTime;


{-----Init strategy---------------------------------------------------------}
procedure InitStrategy; stdcall;
begin
StrategyShortName('SimpleSMA');
StrategyDescription('Trend Analysis');

// Register external parameters
RegOption('Currency', ot_Currency, Currency);
ReplaceStr(Currency, 'EURUSD');

RegOption('Timeframe', ot_Timeframe, TimeFrame);
TimeFrame := PERIOD_H1;

RegOption('LotSize', ot_Double, LotSize);
SetOptionDigits('LotSize', 1);
lotSize := 0.1;

RegOption('SMA1 period', ot_Integer, period1);
SetOptionRange('SMA1 period', 2, MaxInt);
period1 := 16;

RegOption('SMA2 period', ot_Integer, period2);
SetOptionRange('SMA2 period', 2, MaxInt);
period2 := 32;
end;

{-----Done strategy---------------------------------------------------------}
procedure DoneStrategy; stdcall;
begin
FreeMem(Currency);
end;

{-----Reset strategy--------------------------------------------------------}
procedure ResetStrategy; stdcall;
begin
OrderHandle := -1;
end;

{-----Calculate SMA---------------------------------------------------------}
function GetSMA(period: integer): double;
var
i: integer;
sum: double;
begin
sum := 0;
for i:=0 to period - 1 do
sum := sum + Close(i);
result := sum/period;
end;

{-----Process single tick---------------------------------------------------}
procedure GetSingleTick; stdcall;
var
sma1, sma2: double;
begin
// check our currency
if Symbol <> string(Currency) then exit;

// set currency and timeframe
SetCurrencyAndTimeframe(Symbol, TimeFrame);

// check number of bars and SMA period
if (Bars < period1) or (Bars < period2) then exit;

// calculate SMA
sma1 := GetSMA(period1);
sma2 := GetSMA(period2);

// if BUY order exists and fast SMA crosses slow SMA from top
// then close order
if (OrderHandle <> -1) and (OrderStyle = tp_Buy) and
(OpenTime <> Time(0)) and (sma1 < sma2) then
begin
CloseOrder(OrderHandle);
OrderHandle := -1;
end;

// if SELL order exists and fast SMA crosses slow SMA from bottom
// then close order
if (OrderHandle <> -1) and (OrderStyle = tp_Sell) and
(OpenTime <> Time(0)) and (sma1 > sma2) then
begin
CloseOrder(OrderHandle);
OrderHandle := -1;
end;

// if there is no order and fast SMA crosses slow SMA from top
// then open SELL order
if (OrderHandle = -1) and (sma1 < sma2) then
begin
SendInstantOrder(Symbol, op_Sell, LotSize, 0, 0, '', 0, OrderHandle);
OrderStyle := tp_Sell;
OpenTime := Time(0);
end;

// if there is no order and fast SMA crosses slow SMA from bottom
// then open BUY order
if (OrderHandle = -1) and (sma1 > sma2) then
begin
SendInstantOrder(Symbol, op_Buy, LotSize, 0, 0, '', 0, OrderHandle);
OrderStyle := tp_Buy;
OpenTime := Time(0);
end;
end;

exports

InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick;

end.

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#4 Postby FT Support » Wed Sep 22, 2010 6:11 am

Hello, this is quite strange...

I've just tried to build your strategy and install it into Forex Tester, it worked fine.
Btw, what compiler did you use to build it?

Where was the file located when you chose it from "Install Strategy" dialog?
Check our other product here:
http://www.forexcopier.com

Gen
Posts: 14
Joined: Tue Sep 21, 2010 2:19 pm

#5 Postby Gen » Wed Sep 22, 2010 2:37 pm

Hi,

I used razrus for the compiler.
I followed exactly what the video explained for ruzarus setup and for compiling.

The strategy dll file is located at razarus/strategy.
So, I am getting it directly from folder under razarus.

Do I need to move dll file to FT/Strategies folder first?

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#6 Postby FT Support » Wed Sep 22, 2010 3:36 pm

What Lazarus version do you use?
Did you set "Win XX" as a "Target OS" in Project -> "Compiler Options" -> "Code"?
Check our other product here:
http://www.forexcopier.com

Gen
Posts: 14
Joined: Tue Sep 21, 2010 2:19 pm

#7 Postby Gen » Thu Sep 23, 2010 2:21 pm

Hi,
I attached the razarus version information.

And yes, I set the target OS in Project to Win32.

My PC is Windows7 64bit.
It should be working 32bit application as well in the compatibility mode.[/img]
Attachments
version.png
version.png (94.34 KiB) Viewed 17590 times

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#8 Postby FT Support » Thu Sep 23, 2010 3:08 pm

Please try to set Win64 as target OS, maybe this will help
Check our other product here:
http://www.forexcopier.com

Gen
Posts: 14
Joined: Tue Sep 21, 2010 2:19 pm

#9 Postby Gen » Mon Sep 27, 2010 1:41 am

Hi,

I tried something different from what you suggested.

What I did was I installed the same version of Lazarus into my other Windows PC.

Then, I replicated the same problem in the other PC.
That means it does not matter if my PC is 32bit or 64bit.

So, I came to realize that this must be coming from the way I compile and install the strategy.

Can you please tell me how you compile and install the strategy in every single details?
(Please remember I am fine with the strategy installation for the first time, but never been successful from second time.)

BTW, this is what I do once it has been compiled and installed into FT2.

- Go back to Lazarus
- Change and modify "SMAStrategy.dpr" on Source Editor. (This file is already opened under "SMAStrategy.lpi" project file.)
- Press Save all button
- Run >> Build from Menu bar
- On Messages window, 'Project "SMAStrategy" successfully built. :)'
- Launch FT2
- File >> Install New Strategy

or

- Go back to Lazarus
- Change and modify "SMAStrategy.dpr" on Source Editor. (This file is already opened under "SMAStrategy.lpi" project file.)
- Press Save all button
- Run >> Build from Menu bar
- On Messages window, 'Project "SMAStrategy" successfully built. :)'
- Take SMAStrategy.dll from Lazarus folder to ForexTester2\Strategies
- Launch FT2

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#10 Postby FT Support » Mon Sep 27, 2010 2:16 pm

Ok, please try to do the following:

1) replace your StrategyInterfaceUnit with attached one

2) add ReplaceStr and IntrfProcsRec functions into "exports" section on your strategy, so it will look like this:

Code: Select all

exports

InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick,
ReplaceStr,
IntrfProcsRec;


Let me know if it does not help
Attachments
StrategyInterfaceUnit.zip
(8.87 KiB) Downloaded 651 times
Check our other product here:
http://www.forexcopier.com

SquareMeal
Posts: 40
Joined: Wed Sep 15, 2010 6:52 am

worked for me

#11 Postby SquareMeal » Mon Sep 27, 2010 11:25 pm

I have been watching this thread because I have had the same problem.
I use Lazarus with Windows Vista.
I have only been able to install a strategy after the first compile.
If I made any change and recompiled, it would not install.
I would have to do: Project / New... paste in the source code, add LCL, etc. (all of the steps on the video), then do a "Save As" with a new name and compile... THEN I could install the .dll into Forex Tester.

Of course this was too much work to be productive with changes.
Thank you for your suggested solution...

I started using the new StrategyInterfaceUnit and included the additional lines as Exports (suggested above) and it works fine now!!!
creativity + willful purpose

Gen
Posts: 14
Joined: Tue Sep 21, 2010 2:19 pm

#12 Postby Gen » Mon Sep 27, 2010 11:56 pm

It finally worked. :D
Thanks for your support.


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 11 guests