Internal vs Swing Structure in MQL5
Internal and swing structure are two different readings of the same chart. Internal structure uses a short pivot lookback and reacts quickly. Swing structure uses a long lookback and changes less often. Treating them as one state produces false CHoCH labels and unstable trend colouring.
1. Two engines, not two labels on one engine
Use one structure object for internal pivots and another for swing pivots. Both can share the price-series array, but they must own their own leg state, last/previous high and low, trend and last-event bar.
#define SWING_LENGTH 50
#define INTERNAL_LENGTH 5
struct StructureState
{
Pivot lastHigh, prevHigh;
Pivot lastLow, prevLow;
int trend;
int lastEventBar;
};
StructureState internalState;
StructureState swingState;
int internalLeg = LEG_NONE, internalPrevious = LEG_NONE;
int swingLeg = LEG_NONE, swingPrevious = LEG_NONE;
Update both engines with the same leg-change function from the previous article, but pass different lengths:
Pivot p;
if(UpdateLegPivot(rates, current, INTERNAL_LENGTH,
internalLeg, internalPrevious, p))
{
if(p.isHigh) { internalState.prevHigh = internalState.lastHigh;
internalState.lastHigh = p; }
else { internalState.prevLow = internalState.lastLow;
internalState.lastLow = p; }
}
if(UpdateLegPivot(rates, current, SWING_LENGTH,
swingLeg, swingPrevious, p))
{
if(p.isHigh) { swingState.prevHigh = swingState.lastHigh;
swingState.lastHigh = p; }
else { swingState.prevLow = swingState.lastLow;
swingState.lastLow = p; }
}
The canonical lengths are 5 for internal and 50 for swing. The same close can break an internal high without touching the swing high. That is not a contradiction: the two events describe different levels of structure.
2. A longer leg length is not automatically “stronger”
A swing pivot requires more bars on its right before it is known, so it appears later. That delay is the price of stability. A short internal pivot confirms sooner, but it also produces more noise. Neither is “more accurate” without a stated question.
- Internal trend: useful for early continuation and pullback timing.
- Swing trend: useful for the primary directional bias.
- Conflict: internal down while swing up is a pullback inside a larger uptrend, not a global reversal.
A common mistake is to overwrite the swing trend when an internal CHoCH occurs. That makes the indicator flip direction on minor pullbacks.
3. Event routing must be explicit
int internalEvent = StructureEvent(internalState, 1, bar);
int swingEvent = StructureEvent(swingState, 1, bar);
if(internalEvent == 2)
alertInternalBullishCHoCH = true;
if(swingEvent == 2)
alertSwingBullishCHoCH = true;
Do not route both states into the same alert flags. The user must be able to see which structure produced the event. The same rule applies to drawing: internal lines use a smaller style; swing lines use the primary style.
4. State, buffers and chart output
If the indicator exposes values to an EA, publish the two trends separately. A single “trend” buffer loses the distinction that caused the signal.
| Buffer | Meaning |
|---|---|
| Internal trend | 1 bullish, -1 bearish, 0 mixed for the short lookback |
| Swing trend | 1 bullish, -1 bearish, 0 mixed for the long lookback |
| Internal event | Last internal BOS or CHoCH code |
| Swing event | Last swing BOS or CHoCH code |
Store the last event on the closed bar, not on the current forming bar. The forming-bar preview can use a copy of the state, but it must not commit the trend or alert flags.
5. Test cases
- Internal pivot confirmed but swing pivot absent: internal event only.
- Internal leg unchanged: no new internal pivot or event.
- Internal bearish CHoCH while swing trend is bullish: swing trend must not change.
- A short pivot equals an older high: apply the documented equality rule in both engines.
- Missing bars in the lookback: no event until the confirmation window is complete.
- Forming bar breaks an internal level: preview only.
- Object cleanup: deleting an internal line must not delete the swing line.
Use the Object Parity Checker to verify style, time and price differences between the two exports. Use the SMC Code Map to keep the states separated.
6. FAQ
Which lookback should I use?
Choose based on timeframe and testing. The key is to keep internal and swing settings explicit and independently testable.
Can internal structure lead swing structure?
Yes. That is normal. It is not a reason to overwrite the swing trend.
Should both structures draw CHoCH?
Yes, but with separate labels and styles so the source is unambiguous.
Previous: BOS and CHoCHNext: Confluence filterSMC Lab
Educational content. Verify the lookback and equality rules against your own fixtures.