"Can not install..." new strategy

How to create strategies and indicators
Message
Author
SquareMeal
Posts: 40
Joined: Wed Sep 15, 2010 6:52 am

"Can not install..." new strategy

#1 Postby SquareMeal » Sun Sep 19, 2010 12:02 pm

I'm using lazarus in a Delphi syntax mode. After days of self-teaching an old dog new programming tricks, I've completed my first clean compile of a strategy (woof!!) and tried to install the resulting .dll file into ForexTester2.

The error message I got was "Can not install..."

I looked this up in this forum and found that your previously suggested a review of the 4 required parts of the strategy source code. I looked at example strategies regarding those 4 major sections and mine looks identical... as best I can tell.

I also read the information on accessing indicators within strategies and was therefore careful to execute the CreateIndicator procedure within the Reset section.

I don't know what else to look for -- so I would appreciate your help at this point.

Regards,
SquareMeal

-------------My source code follows-----------:

library onyx;

uses
SysUtils, Classes, StrategyInterfaceUnit, IndicatorInterfaceUnit;

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

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

IndMo: integer;
IndEMA: integer;

Midline, HighTZ, LowTZ, TZPeriod: double;
MoPrevious, MoCurrent, MoChange, MinMo: double;

{-----Init strategy---------------------------------------------------------}
procedure InitStrategy; stdcall;
begin
StrategyShortName('Onyx');
StrategyDescription('Test Trading Engine');

// 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('Minimum Momentum %Chg', ot_Double, MinMO);
SetOptionRange('Minimum Momentum %Chg', 0, 0.50);
MinMO := 0.02;

RegOption('TradeZone Period', ot_Integer, TZPeriod);
SetOptionRange('TradeZone Period', 5, 15);
TZPeriod := 10;
end;

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

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

// Create the Momentum Indicator
IndMo := CreateIndicator('EURUSD', 30, 'Momentum', '5;Close');

{ SetIndicatorBuffStyle(IndMo, 0, 'psSolid', 1, clBlue); }

// Create the 3 EMA Indicators (1 indicator, 3 buffers)
IndEMA := CreateIndicator('EURUSD', 30, 'MovingAverage',
format ('%d;0;0;Exponential (EMA);High + Low + Close)/3',
[TZPeriod]));
IndEMA := CreateIndicator('EURUSD', 30, 'MovingAverage',
format ('%d;0;0;Exponential (EMA);High', [TZPeriod]));
IndEMA := CreateIndicator('EURUSD', 30, 'MovingAverage',
format ('%d;0;0;Exponential (EMA);Low', [TZPeriod]));

{ SetIndicatorBuffStyle(IndEMA, 0, 'psDot', 1, clYellow);
SetIndicatorBuffStyle(IndEMA, 1, 'psSolid', 1, clYellow);
SetIndicatorBuffStyle(IndEMA, 2, 'psSolid', 1, clYellow); }

end;

{-----Process single tick---------------------------------------------------}
procedure GetSingleTick; stdcall;

begin
// check our currency
if Symbol <> string(Currency) then exit;

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

// check number of bars and TZ period
if Bars < TZPeriod then exit;

// get the Momentum numbers

MoCurrent := GetIndicatorValue (IndMo, 0, 1);
MoPrevious := GetIndicatorValue (IndMo, 1, 1);
MOChange := MoCurrent / MoPrevious - 1;

// get the TradeZone (EMA) numbers

Midline := GetIndicatorValue (IndEMA, 0, 0);
HighTZ := GetIndicatorValue (IndEMA, 0, 1);
LowTZ := GetIndicatorValue (IndEMA, 0, 2);


// if Buy order exists and Close crosses Midline from beneath
// then close order
if (OrderHandle <> -1) and (OrderStyle = tp_Buy) and
(OpenTime <> Time(0)) and (Close(0) > Midline) then
begin
CloseOrder(OrderHandle);
OrderHandle := -1;
end;

// if SELL order exists and Close crosses Midline from above
// then close order
if (OrderHandle <> -1) and (OrderStyle = tp_Sell) and
(OpenTime <> Time(0)) and (Close(0) < Midline) then
begin
CloseOrder(OrderHandle);
OrderHandle := -1;
end;

// if there is no order and Body above TZ and good MO change
// then open SELL order
if (OrderHandle = -1) and (Open(0) > HighTZ) and (Close(0) > HighTZ)
and (MOChange < (MinMO * -1)) then
begin
SendInstantOrder(Symbol, op_Sell, LotSize, 0, 0, '', 0, OrderHandle);
OrderStyle := tp_Sell;
OpenTime := Time(0);
end;

// if there is no order and Body below TZ and good MO change
// then open BUY order
if (OrderHandle = -1) and (Open(0) < LowTZ) and (Close(0) < LowTZ)
and (MOChange > MinMO) 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.
creativity + willful purpose

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

Additional info on the problem

#2 Postby SquareMeal » Sun Sep 19, 2010 6:55 pm

Just to make sure I am doing everything correctly in Lazarus / compiling, etc... I brought the sample SMAStrategy into Lazarus, compiled it to a .dll file and installed it into ForexTester2. It worked (recognizing there was one there by that name already and did I want to overwrite?) I answered 'Yes' and the file was installed.

So, I conclude there must be something wrong with my CODE (above) vs. my OPERATIONAL METHODS.

Thanks again for any help,

SquareMeal
creativity + willful purpose

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

#3 Postby FT Support » Mon Sep 20, 2010 3:52 am

Hello,

Probably this is the reason of the error:

you have the following code:

Code: Select all

RegOption('TradeZone Period', ot_Integer, TZPeriod);

but note that "TZPeriod" variable is declired as double:

Code: Select all

TZPeriod: double;

so you probably need to declare TZPeriod as integer or change option type to ot_Double
Check our other product here:
http://www.forexcopier.com


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 33 guests