SetTrailingStop(Percentage)

This procedure is used to set an automatic trailing stop in your systems. If the price go below the selected percentage compared to the highest result since buy or short, it will sell automatically at the next close price. Always use ApplyAutoStops to process this action.

 

This procedure has one parameter:
Percentage   The percentage level of your trailing stop. Use a positive number!

 

Example:

' This system is based on Trend Detection Index indicator
' SetStopLoss is usually set before the loop process, but you can change dynamically
' this level based on previous results.
Sub Main()
  SetTrailingStop(5)
  For CurrentBar = BeginBar to EndBar
    ApplyAutoStops
    Value = GetValue("Trend Detection Index", CurrentBar)
    If (Value > 0) and (LastSignal <> 1) then
      If GetValue("Direction Indicator", CurrentBar) > 0 then Buy(CurrentDay)
    End If

    If Value < 0 then Sell(CurrentBar)

    If LastSignal = Signal then Neutral(CurrentBar)
    If VarSinceLastBuy < -4 then Sell(CurrentBar)
  Next
End Sub