Странно но у меня в Delphi 7 не компилится в DLL стратегия приведенная в примерах, я добавил в нее только трал из соседней ветки. В чем проблема?
Код: Выделить всё
//-------------------------------------------------------------------------
// Example of strategy based on 2 crossing SMA (c) Koshelev M.A.
//-------------------------------------------------------------------------
library SMAStrategy;
uses
SysUtils, Classes, StrategyInterfaceUnit, Math;
var
// External parameters
Currency: PChar = nil;
TimeFrame: integer;
LotSize: double;
period1: integer;
period2: integer;
// custom variables
OrderHandle: integer;
OrderStyle: TTradePositionType;
OpenTime: TDateTime;
// TrailingStop
TrailingStop: integer;
TrailingStep: integer;
{-----Init strategy---------------------------------------------------------}
procedure InitStrategy; stdcall;
begin
StrategyShortName('SimpleSMA');
StrategyDescription('Strategy based on 2 SMA');
// 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;
RegOption('TrailingStop', ot_integer,TrailingStop);
SetOptionRange('TrailingStop',0,100);
TrailingStop:=20;
RegOption('TrailingStep', ot_integer,TrailingStep);
SetOptionRange('TrailingStep',0,100);
TrailingStep:=1;
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, 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, OrderHandle);
OrderStyle := tp_Buy;
OpenTime := Time(0);
end;
end;
Procedure TS;
var i:integer;
begin
if OrdersTotal>0 then
for i:=0 to OrdersTotal do
{1} begin
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderType=tp_Buy) then
begin
if (OrderStopLoss=0) and (Bid-OrderOpenPrice>TrailingStop*Point) then ModifyOrder(OrderTicket,OrderOpenPrice,Bid-TrailingStop*Point,0);
if (OrderStopLoss>0) and (RoundTo(Bid-TrailingStop*Point,-4)>RoundTo(OrderStopLoss,-4)) then
begin
if Bid-OrderStoploss>(TrailingStop+TrailingStep)*Point then ModifyOrder(OrderTicket,OrderOpenPrice,Bid-TrailingStop*Point,0);
end;
end;
if (OrderType=tp_Sell) then
begin
if (OrderStopLoss=0) and (OrderOpenPrice-Ask>Trailingstop*Point) then ModifyOrder(OrderTicket,OrderOpenPrice,Ask+TrailingStop*Point,0);
if (OrderStopLoss>0) and (RoundTo(Ask+TrailingStop*Point,-4)< RoundTo(OrderStopLoss,-4)) then
begin
if (OrderStopLoss-Ask)>(TrailingStop+TrailingStep)*Point then ModifyOrder(OrderTicket,OrderOpenPrice,Ask+TrailingStop*Point,0);
end;
end;
{1} end;
end;
exports
InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick;
end.
Выдает следующие
Компоновка
[Ошибка] SMAStrategy.dpr(123): Incompatible types: 'String' and 'Integer'
[Ошибка] SMAStrategy.dpr(132): Incompatible types: 'String' and 'Integer'
Вот в этом куске кода
Код: Выделить всё
if (OrderHandle = -1) and (sma1 < sma2) then
begin
[b]SendInstantOrder(Symbol, op_Sell, LotSize, 0, 0, OrderHandle);[/b]
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
[b]SendInstantOrder(Symbol, op_Buy, LotSize, 0, 0, OrderHandle);[/b]
OrderStyle := tp_Buy;
OpenTime := Time(0);
end;
Кстате и в предыдущих билдах тоже не компилилилась стратегия.
Может у меня что-то еще не доустановленно? Но помоему проблема не в этом.