Page 1 of 1

Check if a buy order has been placed in de last X candles

Posted: Thu Apr 14, 2022 5:27 pm
by Anjimlio2
Hello,

I would like to know if a buy order has been placed in the last 20 candles
If so, no new buy order may be placed.
If not, a buy order may be placed.

Thank you very much

Re: Check if a buy order has been placed in de last X candles

Posted: Fri Apr 15, 2022 11:38 pm
by Shenpai
this should work if the order placed in the last 20 candles is still open. if it was opened 18 candles ago and closed 10 candles ago this will not detect the order. If it's important to know if there was ANY order, tell me and I try to help.

barsSinceLastEntry()=>
strategy.opentrades > 0 ? (bar_index - strategy.opentrades.entry_bar_index(strategy.opentrades-1)) : na

condition := not (barsSinceLastEntry() < 21)

if (condition)
strategy.entry()