Reputation: 35
What needs to be done so that buy/sell gets activated only when the candle is closed?
Sometimes, I have seen that buy/sell signal gets generated while candle is on (not closed). And by the time candle closes, depending on last trading price (ltp) the signal isn't there. How do I avoid generating buy-sell mid-way of the candle?
additional information - I am using higher time frame (HTF) to get macd value which is part of buy/sell strategy. Not sure whether that causes any issue. Function security is used to get the value from htf. and I am using Pine-script v4.
Upvotes: 0
Views: 1633
Reputation: 8789
You don't mention it but I'll assume you're using a study and not a strategy.
If you are generating alerts, the simplest way is to configure alerts to trigger "Once Per Bar Close".
If you are concerned about the signals plotted on the chart, then you will need to ensure your code does not produce repainting conditions. See:
How to avoid repainting when NOT using security().
How to avoid repainting when using security() - PineCoders FAQ.
Upvotes: 1