VarSinceLastBuy as Number

VarSinceLastBuy function returns the variation in percent since the last buy action (not short! See VarSinceLastAction). To use it you must use CurrentBar variable for the loop process. (For CurrenBar = 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(VarSinceLastBuy)
      Sell(CurrentBar)
    End If
  Next
  If VarSinceLastBuy < -4 then Sell(CurrentBar);
End Sub