A! The_Bipolar_Breakout
Detailed Breakdown of the Indicator's Logic
This is a pure price-action, alternating breakout indicator. Here is its step-by-step process inside the start() function.
Step 1: Initialization and Loop
The code begins by calculating limit, which tells it where to start processing bars. It loops from the most recent un-calculated bar backwards towards the oldest history.
Step 2: Finding the "Ceiling" and "Floor"
For every bar i in the loop, the first thing it does is establish the trading range.
This creates a dynamic support and resistance channel based on recent price history.
Step 3: The Breakout Event
It then checks if the current bar i represents a decisive break of that channel.
Bullish Breakout: (Close[i+1] < resistance_level && Close > resistance_level)
In plain English: "Did the previous bar close below the ceiling, AND did the current bar close above the ceiling?" This confirms a clean break.
Bearish Breakdown: (Close[i+1] > support_level && Close < support_level)
In plain English: "Did the previous bar close above the floor, AND did the current bar close below the floor?"
Step 4: The "Bipolar" State Check
This is the key to the alternating signals. Before plotting anything, it checks its memory (lastSignalState).
If a bullish breakout is found, it asks: "Was the last signal I drew a bearish one (or is this the first signal)?" (if(lastSignalState != 1)).
If YES, it proceeds to plot a signal.
If NO (the last signal was also bullish), it does nothing and ignores this new breakout.
The same logic applies in reverse for a bearish breakdown.
Step 5: Plotting the Signal and Updating the State
If all conditions are met, it performs two actions:
Plot the Signal: It calculates the signal_price using your InpSignalDistance input and places the Dot and Arrow in their respective buffers at bar i.
Update Its Memory: It immediately updates its state variable: lastSignalState = 1; (for bullish). Now, it will not plot another bullish signal until a bearish one appears first.
Step 6: Updating the On-Screen Label
After the loop is finished, it checks the final value of lastSignalState and updates the text and color of the on-screen display accordingly, providing you with a clear, real-time status.