дописать в uses:
Код: Выделить всё
Math
Код: Выделить всё
TrailingStop:integer;
TrailingStep:integer;
дописать в Initstrategy
Код: Выделить всё
RegOption('TrailingStop', ot_integer,TrailingStop);
SetOptionRange('TrailingStop',0,100);
TrailingStop:=20;
RegOption('TrailingStep', ot_integer,TrailingStep);
SetOptionRange('TrailingStep',0,100);
TrailingStep:=10;
Код: Выделить всё
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;