VarSinceLastAction as Number

VarSinceLastAction function returns the variation in percent since the last action (Buy or Short). To use it you must use CurrentBar variable in the loop process. (For CurrentBar = BeginBar to EndBar)

 

Example:

' This is a system
Sub Main()
  For CurrentBar = BeginBar to EndBar
    I1 = GetValue("SMA", CurrentBar)
    I2 = GetValue("SMA", CurrentBar - 1)
    J1 = GetValue("LMA", CurrentBar)
    J2 = GetValue("LMA", CurrentBar - 1)

    If (J1 < I1) and (J2 > I2) then Buy(CurrentBar)
    If (J1 > I1) and (J2 < I2) then
      AddText(VarSinceLastAction)
      Sell(CurrentBar)
    End If
  Next
  If VarSinceLastAction < -4 then Sell(CurrentBar);
End Sub