I have an indicator in Pine Script whose buy signal is BuyCondition. I am trying to reference the lowest within 20 bars back of the last BuyCondition. In my head, I thought the following would work, however it gives the study error "Invalid value of the 'length' argument (0.0) in the "lowest" function. It must be > 0."
Pine script:
RRR = input.float(1.5, title='Risk Reward Ratio')
LookbackForLowest = input.int(20, title='Lowest Low LookBack')
SinceLastBought = ta.barssince(BuyCondition)
BuyClosePrice = ta.valuewhen(BuyCondition == 1, close, 1)
LookbackFromNow = (SinceLastBought + LookbackForLowest)
LowestLow = ta.lowest(low, LookbackFromNow)[1]
StopLoss = close<LowestLow
Exit = (BuyClosePrice - LowestLow) * RRR
//SELL CONDITIONS
//1. Stop loss at recent low
//2. RRR
SellCondition1 = close<LowestLow
SellCondition2 = close>Exit
SellCondition = SellCondition1 or SellCondition2
Is anyone able to help me please?