Trailing Stop

SetTrailingStop

 

The SetTrailingStop() method allows you to set and modify trailing stop on a position. In case the position already has a stop order, it will be replaced with trailing stop.

 

Constructor:

procedure SetTrailingStop(const Trade: TTrade; const TrailDistance: Integer; const OperationTag: String);

 

Trade — the open position on which the trailing stop should be placed or modified

TrailDistance — the trailing distance in pips.

OperationTag — the custom order tag. This is an optional parameter, it does not have to be the same as the position tag.

 

Example:

procedure OnTradeChange(const Action: TDataModificationType; const Trade: Ttrade);

begin

if Action = dmtInsert then

begin

   SetTrailingStop(Trade, 10, Trade.Tag);

...

 

 

Trailing Distance Value

If tailing stop is set on a position, you can find out the Trailing Distance Value. This value is held in TrailDistance property of a TOrder object.

The TrailDistance property is created for TOrder object (Stop order only) at calling the SetTrailingStop procedure.

Constructor:

property TrailDistance: Integer;

 

Example:

procedure OnCommand(const Command: String);

var

 i: Integer;

 Order: TOrder;

begin

for i := TradeList.Count - 1 downto 0 do

begin        

   Order := TradeList.Get(i).StopOrder;    

  if Order <> nil then

     Log('Trail Distance: ' + FloatToStr(Order.TrailDistance));

end;

...

 

Nore: If returned value of TrailDistance is '0' (zero), it means that Trailing Stop is not set for the position, but position has a Stop order.