Hi Everyone,
I am trying to build an EMA crossover options strategy in FYERS Algo and need some guidance on the execution flow.
Requirement:
Enter a trade when an EMA crossover occurs.
Buy ATM CE when the fast EMA crosses above the slow EMA.
Buy ATM PE when the fast EMA crosses below the slow EMA.
On every new crossover, the algo should first check whether there is an active/open position.
If an active position already exists:
Exit the current position immediately.
Enter the new position based on the latest crossover signal.
If no active position exists:
Simply enter the trade according to the crossover signal.
Example:
EMA bullish crossover → Buy ATM CE.
Later, EMA bearish crossover occurs → Check if CE position is active → Exit CE → Buy ATM PE.
Again, EMA bullish crossover occurs → Check if PE position is active → Exit PE → Buy ATM CE.
Is there a way to implement this "position reversal" logic in FYERS Algo using Canvas blocks? Specifically, how can we check whether any position is currently active and then square it off before placing the new order?
If anyone has built a similar CE ↔ PE reversal strategy, please share the Canvas flow or the logic used.
Thanks in advance!