How to hold the first Buy/Sell Signal on the same candle till end

I have an AFL code which works fine with the Candle Completion but l would like to trade in RealTime without Delay.

I am planning to Buy/Sell at first signal of the candle but sometimes the signal is not getting confirmed (dis appearing) by end of the candle which makes me into some open positions left.

To avoid above issue , I would like to carry the First Buy/Sell signal till end of the candle even though that is not a confirmed signal by end of the candle to clear my open positions in the next candle with right reverse signals.

To achieve above , I need a logic to hold the First Buy/Sell signal till the end of the candle even though the signal is false or disappears by end of the candle.


It has been answered in the forum.

Thanks for sharing the information.

In my case i don't have a problem with algo as my algo supports to take only one order even if the afl generates multiple buy signals on the same candle.

My algo considering first signal on the bar and firing order and if it 's generates multiple signals on that candel the algo will not consider them as the lastbuy is true on that candle , but am facing a different issue here, if the signal get disappeared by end of the candle my buy order will not be squared off and my system left with one open buy position and i have to manually square off that position, to avoid that manual stuff i would like to carry my first buy signal till end of the candle even though it is false by the end of the candle, if i am able to carry that signal by end of the candle i will get sell signal on the next candle automatically so that my position will be cleared .

It is very simple but maybe you are not able to relate.
to "hold" the signals, the article and post suggest that you set a static variable.
Without that, you will not have a state in AFL so even if your algo takes care of multiple signals, you need to maintain same state in AFL, check the status and write some more code to exit if at the end of the bar the signal was cancelled.

If you are not using static variables, then the normal variables will get updated each time the formula runs whether its chart or analysis.

Thanks , I will try to use same logic for the state in AFL , if possible provide AFL code steps for exit if the signal lost.