_Merch_Man_
Active member
Morning all! Need some help here. I am building a strategy for use on /ES 1000 tick chart. I want my stop loss to be the swinglow at the time of entry. What I am trying to get is "If I went long on this bar then stoploss = swinglow else stoploss = stoploss[1]" but I can't figure out the if condition. I cant use getquantity() to check if I have a position because getQuantity() doesn't work on tick charts. Any ideas? TIA!
Code:
#SWING HIGH LOW CODE
input LookbackPeriod = 3;
def _lowInPeriod1 = Lowest(low, LookbackPeriod);
def marketLow1 = if _lowInPeriod1 < _lowInPeriod1[-LookbackPeriod] then _lowInPeriod1 else _lowInPeriod1[-LookbackPeriod];
def _markedLow1 = low == marketLow1;
rec _lastMarkedLow1 = CompoundValue(1, if IsNaN(_markedLow1) then _lastMarkedLow1[1] else if _markedLow1 then low else _lastMarkedLow1[1], low);
#END SWING HIGH LOW CODE
def swingLow = _lastMarkedLow1 ;
def buyTrigger = close >= close[2] + 1;
def stopLoss = if [WHAT CONDITION GOES HERE?] then swingLow else swingLow[1];
addOrder(OrderType.BUY_TO_OPEN, buyTrigger, open[-1], 1, name = "open");
addOrder(OrderType.SELL_TO_CLOSE, close <= stopLoss, close, 1, name = "close");