Im looking for some help - currently im learning delphi and I throught it try code up something simple like when an indicator hits a certain level the script places a buy order, and if an indicator hits another level it places a sell order.
This code compiles ok - but it doesnt place buy and sell orders.
Can some kind member of this community point out where I have gone wrong =)
Thanks in advance,
Pete.
Code: Select all
library CCITRY;
uses
SysUtils, Classes, StrategyInterfaceUnit, TechnicalFunctions;
var
Currency: PChar = nil;
TimeFrame: integer;
LotSize: double;
CCI1: integer;
CCIUPPER: integer;
CCILOWER: integer;
OrderHandle: integer;
OrderStyle: TTradePositionType;
OpenTime: TDateTime;
procedure InitStrategy; stdcall;
begin
StrategyShortName('CCITRY');
StrategyDescription('CCI level strategy');
RegOption('Currency', ot_Currency, Currency);
ReplaceStr(Currency, 'EURUSD');
RegOption('Timeframe', ot_Timeframe, TimeFrame);
TimeFrame := PERIOD_M1;
RegOption('LotSize', ot_Double, LotSize);
SetOptionDigits('LotSize', 1);
lotSize := 0.1;
RegOption('CCI1', ot_Integer, CCI1);
CCI1 := 30;
RegOption('CCIUPPER', ot_Integer, CCIUPPER);
CCIUPPER := 250;
RegOption('CCILOWER', ot_Integer, CCILOWER);
CCIUPPER := -250;
end;
procedure DoneStrategy; stdcall;
begin
FreeMem(Currency)
end;
procedure ResetStrategy; stdcall;
begin
OrderHandle := -1
end;
procedure GetSingleTick; stdcall;
var
CCI: Double;
begin
if Symbol <> string(Currency) then exit;
SetCurrencyAndTimeframe(Symbol, TimeFrame);
CCI := GetIndicatorValue(CCI1, 1,0);
if (OrderHandle = 0) and (CCI > CCIUPPER) then
begin
SendInstantOrder(Symbol, op_Buy, LotSize, Ask - 20*Point, Ask + 50*Point, '',0, OrderHandle);
OrderStyle := tp_Buy;
OpenTime := Time(0)
end;
if (OrderHandle = 0) and (CCI < CCILOWER) then
begin
SendInstantOrder(Symbol, op_Sell, LotSize, Ask + 20*Point, Ask - 50*Point, '', 0, OrderHandle);
OrderStyle := tp_Sell;
OpenTime := Time(0)
end;
end;
exports
InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick,
ReplaceStr;
end.