SetStopLoss(Percentage)

This procedure is used to set an automatic stop loss in your systems. If the price go below the selected percentage, it will sell automatically at the next close price.

 

This procedure has one parameter:
Percentage   The percentage level if you go below system will sell. 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()
  SetStopLoss(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