Multi-Timeframe Trend-Follower EA

with Pivot-Flip Recovery
Your complete strategy explained like you're 5 years old -- with pictures

What's Inside

1. The Big Picture - What Does This Bot Do?

🏊
Think of it like fishing

You check the weather (big timeframe) to see if it's a good day. Then you watch the waves (middle timeframe) to see where the fish are pulling back. Then you cast your rod (small timeframe) at the perfect moment. If the fish pulls the wrong way, you flip your rod to the other side instead of cutting the line.

This is a fully automated MT4 trading bot (Expert Advisor). You turn it on and it trades by itself. Here's what it does in plain English:

The Bot's Job in One Sentence
Watches the
Big Trend
→
Waits for a
Pullback
→
Enters at the
Perfect Moment
→
Manages with
Flip Recovery
→
Takes
Profit!

Key Features at a Glance

2. The 3 TVs (Timeframes)

📺
Imagine you have 3 TVs showing the same road from different distances

TV 1 (Helicopter view): Shows you which direction traffic is flowing on the highway.
TV 2 (Street camera): Shows you when a car briefly reverses into a parking spot.
TV 3 (Dashcam): Shows you the exact moment to hit the gas pedal.

The 3 Timeframes

🚀 Higher TF (Default: H1)

THE BIG PICTURE

What it does: Finds the trend direction
Uses: EMA 13 & EMA 62
Looking for: EMA crossover + touch
Analogy: Is traffic going North or South?

⏲ Pullback TF (Default: M5)

THE PULLBACK CHECK

What it does: Confirms price is pulling back
Uses: Supertrend indicator
Looking for: Counter-trend signal
Analogy: Did a car briefly reverse?

🎯 Entry TF (Default: M1)

THE TRIGGER

What it does: Fires the actual trade
Uses: Supertrend indicator
Looking for: Trend-direction signal
Analogy: Hit the gas pedal NOW!
Simple Explanation

The bot looks at 3 different "zoom levels" of the same chart. The big zoom (H1) tells it the direction. The medium zoom (M5) tells it when the price pulls back. The small zoom (M1) tells it the exact second to open a trade.

3. The Tools It Uses (Indicators)

3.1 EMA (Exponential Moving Average)

📈
EMA is like a smoothed-out path of where price has been

Imagine dragging your finger across a foggy window. The trail you leave behind is like an EMA -- it shows the average direction price has been moving. A fast EMA (13) reacts quickly like a sports car. A slow EMA (62) reacts slowly like a truck.

EMA Crossover = Trend Change Signal
BULLISH CROSSOVER
CROSS!

▬ Fast EMA (13) crosses ABOVE - - Slow EMA (62)
= Price is going UP = Look for BUY

BEARISH CROSSOVER
CROSS!

▬ Fast EMA (13) crosses BELOW - - Slow EMA (62)
= Price is going DOWN = Look for SELL

3.2 Supertrend Indicator

🚩
Supertrend is like a traffic light

It simply says GREEN (Buy) or RED (Sell). When it switches from green to red, that's a sell signal. When it switches from red to green, that's a buy signal. The bot doesn't care about the Supertrend line itself -- just when the light changes color.

Where Each Indicator Is Used
TimeframeIndicatorWhat We Read From It
Higher TF (H1)EMA 13 + EMA 62Crossover direction + price touching EMA 13
Pullback TF (M5)SupertrendCounter-signal (sell in buy setup, buy in sell setup)
Entry TF (M1)Supertrend + EMA 13Entry signal + flip monitoring at pivot line

4. The 4 Steps to Enter a Trade

🔓
Think of it like a 4-lock safe

The bot needs to unlock 4 locks in order before it opens a trade. If any lock doesn't unlock, or if lock 1 re-locks before all 4 are done, the whole thing resets. ALL 4 must be unlocked in sequence.

The 4 Confirmations (Buy Example)
STEP 1: H1 EMA Crossover
EMA 13 crosses ABOVE EMA 62 on the 1-hour chart
Must be confirmed on a CLOSED candle (not still forming)
↓
STEP 2: H1 Price Touches EMA 13
After the crossover, price must come back and touch the fast EMA
Wick touch or body touch -- both count
↓
STEP 3: M5 Supertrend SELL Signal
On the 5-minute chart, Supertrend flips to SELL (counter-trend pullback)
This proves price is actually pulling back
↓
STEP 4: M1 Supertrend BUY Signal
On the 1-minute chart, Supertrend flips to BUY
This is the ACTUAL trade trigger -- BUY is executed HERE
↓
TRADE OPENED!
Bot opens a BUY trade, sets TP, draws pivot line
Why 4 steps?

Each step acts as a filter. Step 1 says "the trend is up." Step 2 says "price confirmed the trend." Step 3 says "price pulled back." Step 4 says "the pullback is over, it's going back up." By the time all 4 are confirmed, you have a very high-quality entry point.

5. Buy Example - Full Walkthrough

The Story

Let's walk through a complete BUY trade from start to finish. Imagine it's Monday morning, EURUSD is trending up, and your bot is watching...

9:00 AM - H1 Candle Closes: EMA 13 crosses above EMA 62
The bot sees the fast line just went above the slow line on the 1-hour chart. It thinks: "OK, the trend is now bullish. Let me start watching for a trade setup." This is Step 1 confirmed.
10:00 AM - H1 Candle: Price wick touches EMA 13
Price drops a little and the candle's wick touches the EMA 13 line on H1. The bot thinks: "Good, price came back to test the fast EMA. The trend is confirmed." Step 2 confirmed.
10:15 AM - M5: Supertrend flips to SELL
On the 5-minute chart, Supertrend switches from buy to sell. The bot thinks: "Price is pulling back -- this is my counter-trend signal. The pullback is active." Step 3 confirmed.
10:23 AM - M1: Supertrend flips to BUY
On the 1-minute chart, Supertrend switches from sell to buy. The bot thinks: "The pullback is over, price is resuming upward. TIME TO BUY!" Step 4 confirmed.
10:23 AM - TRADE EXECUTED
The bot opens a BUY at 1.10500 with 0.01 lots. It sets TP at 1.10500 + 50 pips = 1.11000. It finds the lowest low between 10:15-10:23 on M1 (say, 1.10350) and draws a pivot line there. It assigns magic number 50001.
Visual: The Buy Entry Sequence on Chart
1. CROSS 2. TOUCH 3. PULLBACK 4. BUY! PIVOT LINE (lowest low) TP +50 pips EMA 13 EMA 62 Price

6. Sell Example - Full Walkthrough

Mirror Image

A sell setup is the exact opposite of a buy. Everything is reversed.

Sell Entry -- The 4 Steps (Reversed)
STEP 1: H1 EMA Crossover DOWN
EMA 13 crosses BELOW EMA 62 on H1 (trend is bearish)
↓
STEP 2: H1 Price Touches EMA 13
Price bounces up and touches EMA 13 from below
↓
STEP 3: M5 Supertrend BUY Signal
Counter-trend! Price pulling UP in a DOWN trend
↓
STEP 4: M1 Supertrend SELL Signal
Pullback over, price resuming downward -- SELL NOW
↓
SELL TRADE OPENED!
Pivot = highest high between M5 buy signal and M1 sell signal
TP = entry price MINUS 50 pips

7. When Things Get Cancelled (Invalidation)

❌
Think of it like waiting in line for a rollercoaster

You're waiting (Steps 1-3 done, waiting for Step 4). But then the ride breaks down (the EMAs cross back). The line gets cancelled and you have to go find a new ride (wait for a new crossover).

The Invalidation Rule

If the bot is waiting between Steps 1-3 (crossover happened, but the M1 entry signal hasn't fired yet), and the H1 EMAs cross back in the opposite direction, the ENTIRE setup is cancelled. The bot throws everything away and starts looking for a new crossover.

Example Scenarios

Scenario A: Successful Entry (No Invalidation)
H1 Cross ✅
→
Touch ✅
→
M5 Signal ✅
→
M1 Signal ✅
→
TRADE!
Scenario B: Invalidated -- EMAs Cross Back Before M1 Entry
H1 Cross ✅
→
Touch ✅
→
M5 Signal ✅
→
H1 CROSS BACK ❌
→
CANCELLED
Start over
Scenario C: Invalidated -- M5 Pullback Doesn't Touch EMA 13
H1 Cross ✅
→
No Touch ❌
→
STUCK
Waiting...

The bot keeps waiting for the touch. It won't move to Step 3 without it.

Important

Once a trade IS opened (all 4 steps complete), future H1 crossovers do NOT affect that trade. The trade lives on its own with its pivot line and TP. New crossovers just create new independent sequences.

8. The Pivot Line - Your Safety Net

📏
Think of the pivot line like a fence in your backyard

When the trade opens, the bot builds a permanent fence at the lowest point (for buys) or highest point (for sells) that price reached during the pullback. This fence NEVER moves. It's the line where the bot decides "if things go bad, I'll flip my trade direction."

How Is the Pivot Line Calculated?

Buy Example: Finding the Pivot Line
Search window for lowest low M5 Sell Signal M1 Buy Signal LOWEST LOW! PIVOT LINE (stays here FOREVER)
Key Rules About the Pivot Line
  • 📌 For BUY setups: Pivot = lowest low on M1 between M5 sell signal and M1 buy signal
  • 📌 For SELL setups: Pivot = highest high on M1 between M5 buy signal and M1 sell signal
  • 🔒 Once set, the pivot line NEVER moves for that sequence
  • 🔒 It stays until the sequence hits TP or is terminated
  • 🎨 Drawn as a visible horizontal line on the chart (color-coded per sequence)

9. The Flip Engine - No Stop Loss!

🔄
Think of it like a revolving door

Normal trading: You walk in, the door hits you, you fall down (stop loss).
YOUR strategy: You walk in, the door pushes you, you spin around and walk out the other side (flip). If the door pushes you again, you spin and walk back in. You keep spinning until you end up exactly where you want to be (TP hit).

Critical Concept - No Traditional Stop Loss

This bot does NOT use a normal stop loss that just closes the trade at a loss. Instead, when EMA 13 on the entry timeframe crosses the pivot line, the bot closes the current trade AND immediately opens the opposite trade. This is called a "flip."

How a Flip Works

Buy-to-Sell Flip
Current:
BUY open
→
M1 EMA 13 crosses
BELOW pivot line
(candle must CLOSE)
→
Close BUY
Open SELL
→
New TP set from
new entry price
FlipCount +1
Sell-to-Buy Flip
Current:
SELL open
→
M1 EMA 13 crosses
ABOVE pivot line
(candle must CLOSE)
→
Close SELL
Open BUY
→
New TP set from
new entry price
FlipCount +1
The Flip only triggers on candle close

The EMA 13 might dip below the pivot line temporarily during a candle. That does NOT trigger a flip. The bot waits for the M1 candle to fully close with EMA 13 on the other side of the pivot. This prevents false signals from price spikes (wicks).

10. Flip Examples - Every Possible Scenario

Example A: Perfect Trade -- No Flips Needed

Best Case: BUY goes straight to TP
1
🏁 BUY at 1.10500 0.01 lots TP: 1.11000 ✅ HIT!

Result: +50 pips profit on 0.01 lots. Sequence DONE!

Example B: 2 Flips, Then TP

Price bounces around the pivot line before trending
1
BUY at 1.10500 0.01 EMA crosses below pivot → FLIP
2
SELL at 1.10420 (flip #1) 0.01 EMA crosses above pivot → FLIP
3
BUY at 1.10380 (flip #2) 0.01 TP: 1.10880 ✅ HIT!

Trade 1: lost ~8 pips. Trade 2: lost ~4 pips. Trade 3: won 50 pips. Net profit!

Example C: Many Flips with Lot Progression

Choppy market -- lots of flips (StartAddingAfterFlips = 3)
1
BUY (initial entry)0.01flip #0
2
SELL (flip)0.01flip #1
3
BUY (flip)0.01flip #2
4
SELL (flip) 📈 LOT INCREASE STARTS0.02flip #3
5
BUY (flip)0.03flip #4
6
SELL (flip)0.04flip #5
7
BUY (flip) 🏁0.05TP HIT! ✅

By the time TP is hit, the lot size is bigger, so the win can cover the smaller earlier losses.

11. Take Profit - How You Win

Simple Rule

Every single trade (including flip trades) gets its own TP calculated from its own entry price.

  • BUY trade TP = Entry Price + 50 pips
  • SELL trade TP = Entry Price - 50 pips
TP is Independent Per Trade (Even Within Same Sequence)
TradeDirectionEntry PriceTP PriceStatus
Trade 1BUY1.105001.11000Flipped (closed)
Trade 2SELL1.104201.09920Flipped (closed)
Trade 3BUY1.103801.10880✅ TP HIT!
When TP is hit

The entire sequence ends. The flip logic stops. The pivot line gets cleaned up. That sequence is marked as completed. Any other sequences running in parallel are NOT affected.

12. Lot Sizes - Smart Money Growth

💰
Think of it like adding a penny to your bet

You start betting 1 penny (0.01 lots). After 3 losses (flips), you add another penny. So now you bet 2 pennies. Then 3, then 4. You're NOT doubling (that's martingale/gambling). You're just adding one more penny each time. When you finally win, the slightly bigger bet helps cover the small earlier losses.

NOT Martingale!

Martingale = 0.01, 0.02, 0.04, 0.08, 0.16... (doubles each time -- DANGEROUS)
Your Strategy = 0.01, 0.01, 0.01, 0.02, 0.03, 0.04... (adds a small fixed amount -- MUCH safer)

The Formula

Lot Calculation

If FlipCount < StartAddingAfterFlips: Lot = BaseLotSize

If FlipCount >= StartAddingAfterFlips: Lot = BaseLotSize + ((FlipCount - StartAddingAfterFlips) + 1) × LotIncrement

Full Example Table

Settings: BaseLot=0.01, LotIncrement=0.01, StartAfter=3 flips
Trade #Flip CountPast Threshold?Lot SizeCalculation
1 (initial)0❌ No (0 < 3)0.01Base lot
2 (1st flip)1❌ No (1 < 3)0.01Base lot
3 (2nd flip)2❌ No (2 < 3)0.01Base lot
4 (3rd flip)3✅ Yes (3 ≥ 3)0.020.01 + ((3-3)+1) × 0.01
5 (4th flip)4✅ Yes0.030.01 + ((4-3)+1) × 0.01
6 (5th flip)5✅ Yes0.040.01 + ((5-3)+1) × 0.01
7 (6th flip)6✅ Yes0.050.01 + ((6-3)+1) × 0.01

Alternative Settings Example

Settings: BaseLot=0.05, LotIncrement=0.02, StartAfter=2 flips
Trade #Flip CountLot Size
100.05
210.05
320.07
430.09
540.11

13. Sequences - Multiple Games at Once

🎲
Think of it like playing multiple board games at the same time

Each time a new H1 crossover happens, the bot starts a new board game. Each game has its own board (pivot line), its own dice (lot size), its own score (flip count), and its own winning condition (TP). Games run at the same time and NEVER interfere with each other.

3 Sequences Running in Parallel

Sequence A (Magic: 50001)

Started: Mon 9:00 AM
Origin: H1 Bullish Cross
Current Trade: BUY
Pivot: 1.10350
Flips: 4
Current Lot: 0.02
TP: 1.10880
Status: ACTIVE

Sequence B (Magic: 50002)

Started: Tue 2:00 PM
Origin: H1 Bearish Cross
Current Trade: SELL
Pivot: 1.11200
Flips: 1
Current Lot: 0.01
TP: 1.10600
Status: ACTIVE

Sequence C (Magic: 50003)

Started: Wed 10:00 AM
Origin: H1 Bullish Cross
Current Trade: --
Pivot: 1.10800
Flips: 6
Current Lot: --
TP: 1.11300
Status: COMPLETED (TP HIT!)
Key Rule

Each sequence is a completely independent universe. Sequence A flipping from buy to sell does NOTHING to Sequence B. They each have their own pivot line, their own flip counter, their own lot size, and their own TP.

14. Magic Numbers - Name Tags for Trades

🏷
Think of magic numbers like name tags at a party

Every guest (trade) at the party wears a name tag that says which family (sequence) they belong to. The bot can look at any trade and immediately know "this buy trade belongs to Sequence 1" or "this sell trade belongs to Sequence 3."

Magic Number Formula
MagicNumber = BaseMagicNumber + SequenceID
SequenceBase+ID=Magic NumberUsed By
Sequence 150000+1=50001All trades in Seq 1 (buy, sell flips, everything)
Sequence 250000+2=50002All trades in Seq 2
Sequence 350000+3=50003All trades in Seq 3

15. One Trade Per Crossover Rule

Rule

Each H1 crossover event can only create ONE sequence. Once the first valid entry is taken from that crossover, that crossover is "consumed." You can't get two sequences from the same crossover.

However, once a trade IS open, the flips within that sequence don't count as "new" sequences. And future crossovers create future independent sequences.

16. Crash Recovery - Saving Your Work

💾
Think of it like auto-save in a video game

Imagine you're playing a game and the power goes out. When the power comes back, you don't want to start from scratch -- you want to continue from where you were. This bot does the same thing. It constantly saves its "game state" so if MT4 crashes, restarts, or your computer reboots, it picks up right where it left off.

How Crash Recovery Works

1. SAVE (Continuous)

Every time something changes, the bot saves to MT4 Global Variables or a file:

  • Pivot Line price
  • Flip Count
  • Sequence ID
  • Current direction
  • Magic Number
  • Lot progression state
→

2. CRASH!

MT4 closes unexpectedly, computer restarts, internet drops, etc.

⚡

Bot stops running

→

3. RECOVER (On Restart)

When MT4 starts again, the bot:

  • Reads saved data
  • Finds open trades by magic number
  • Rebuilds pivot lines
  • Restores flip counts
  • Continues managing trades

What Gets Saved?

DataWhy It's SavedWhat Happens Without It
Pivot Line PriceThe pivot is the core of the flip logic. Without it, the bot doesn't know where to flip.Bot loses its "fence" -- trades would go unmanaged
Flip CountDetermines the lot size for the next tradeBot resets lot size to base -- incorrect lot progression
Sequence IDLinks trades to their sequence for independent managementBot can't tell which trade belongs to which sequence
DirectionKnows if the current sequence is in buy or sell modeBot might flip the wrong way
Current TicketThe MT4 order ticket of the currently open tradeBot needs to search for it (can recover from magic number)

Two Storage Methods

Method 1: Global Variables

MT4 has built-in "Global Variables" -- tiny pieces of data that survive restarts.

Pros: Fast, built-in, no file I/O

Cons: Limited to number values, can be lost if terminal data is cleared

Example variable name:
SEQ_50001_PIVOT = 1.10350
SEQ_50001_FLIPS = 4

Method 2: File Logging

The bot writes data to a CSV/text file on disk.

Pros: Survives even terminal data clearing, can store complex data

Cons: Slightly slower, requires file access

Example file content:
50001,BUY,1.10350,4,0.02,1234567

17. What You See on the Chart

Visual Aids

The bot draws things on your chart so you can visually verify what it's doing. This is especially useful during backtesting.

Chart Objects Drawn by the Bot
ObjectWhat It Looks LikePurpose
Pivot LineHorizontal line, color-coded per sequenceShows the exact price where flips happen
Sequence LabelText label near the pivot lineShows: Seq ID, direction, flip count, lot size, pivot price

Each sequence gets its own color. Example: Seq 1 = Green, Seq 2 = Orange, Seq 3 = Purple

18. ALL Settings - Complete Reference

Every Knob You Can Turn

Below is every single setting in the bot with its default value and a plain-English explanation.

Setting NameDefaultWhat It Does
INDICATOR SETTINGS
FastEMAPeriod 13 The "fast" moving average period on the higher timeframe. Lower number = reacts faster to price changes. This is the line that crosses the slow EMA to signal trend direction.
SlowEMAPeriod 62 The "slow" moving average period on the higher timeframe. Higher number = smoother, slower reaction. When fast crosses above slow = bullish. When fast crosses below slow = bearish.
SupertrendATRPeriod 10 How many candles the Supertrend indicator uses to calculate its Average True Range. Affects how sensitive the Supertrend signals are.
SupertrendMultiplier 3.0 A multiplier for the Supertrend bands. Higher = less sensitive (fewer signals). Lower = more sensitive (more signals, but more noise).
TIMEFRAME SETTINGS
HigherTF PERIOD_H1 The "big picture" timeframe used for EMA crossover and trend direction. You could change this to H4, D1, etc.
PullbackTF PERIOD_M5 The "pullback" timeframe used for Supertrend counter-signal. Must be smaller than HigherTF.
EntryTF PERIOD_M1 The "trigger" timeframe used for Supertrend entry signal and flip monitoring. Must be smallest of the three.
TRADE SETTINGS
BaseLotSize 0.01 Your starting trade size. This is the lot size used for the initial trade and all trades before the lot progression kicks in. 0.01 = micro lot.
TakeProfitPips 50 How many pips of profit each trade aims for. Every trade (including flip trades) uses this value from its own entry price. 50 pips = 500 points on 5-digit brokers.
Slippage 3 Maximum allowed price slippage when opening/closing trades. In points. If the price moves more than this during execution, the order might be rejected.
MaxSpreadFilter 0 (disabled) Optional. If set above 0, the bot won't open trades when the spread is wider than this value. Protects against trading during high-spread periods (news, low liquidity).
AllowBuy true Set to false to prevent the bot from opening any BUY sequences. Useful if you only want to trade sell setups.
AllowSell true Set to false to prevent the bot from opening any SELL sequences. Useful if you only want to trade buy setups.
LOT PROGRESSION SETTINGS
LotIncrement 0.01 How much lot size to ADD on each trade after the threshold is reached. This is pure addition, not multiplication. Example: if 0.01, lots go 0.01, 0.02, 0.03...
StartAddingAfterFlips 3 How many flips must happen before lot size starts increasing. If set to 3, the first 3 flips all use BaseLotSize. Starting from the 4th flip, lot increases begin.
SAFETY SETTINGS (all optional, disabled by default)
UseMaxFlips false Enable to set a maximum number of flips per sequence. If reached, the sequence closes and stops.
MaxFlips 0 Maximum number of flips allowed if UseMaxFlips is true. Example: 10 means the bot stops flipping after 10 flips and closes the trade.
UseMaxLotCap false Enable to set a ceiling on lot size. Even if the formula says the lot should be higher, it won't go above MaxLotCap.
MaxLotCap 0.00 Maximum lot size allowed per trade if UseMaxLotCap is true. Example: 0.50 means even after many flips, the lot won't go above 0.50.
UseMaxDrawdownPerSequence false Enable to set a max dollar loss per sequence. If total losses in one sequence exceed this amount, the sequence closes.
MaxDrawdownCurrency 0.00 Maximum money (in account currency, e.g. USD) that can be lost in one sequence before it's forcibly closed.
MAGIC NUMBER SETTINGS
BaseMagicNumber 50000 Starting number for magic number assignment. Sequence 1 = 50001, Sequence 2 = 50002, etc. Change this if running multiple instances of the bot on different charts.

19. How the Bot Thinks Every Second

On Every Tick

Every time price moves (every "tick"), the bot runs through this checklist:

Bot's Decision Tree on Every Tick
1. Check for NEW H1 crossovers
Has EMA 13 just crossed EMA 62? Create a new pending sequence.
↓
2. For each PENDING sequence:
Check: EMA touch? M5 pullback signal? M1 entry signal? Invalidation?
↓
3. For each ACTIVE sequence:
Monitor TP hit. Monitor pivot flip (EMA 13 vs pivot line). Execute flip if needed.
↓
4. For each COMPLETED sequence:
Clean up chart objects. Remove state data.
Important Execution Rules
  • Only execute entries on closed candles (not while a candle is still forming)
  • Only flip once per candle close (not on every tick)
  • Never open duplicate trades for the same sequence on the same candle
  • Once a trade is open, H1 crossovers do NOT affect it

20. Safety Features

Built-in Safety Controls
FeatureWhat It PreventsDefault
Max Flips LimitPrevents infinite flipping in a choppy marketOFF (unlimited)
Max Lot CapPrevents lot size from growing too largeOFF (unlimited)
Max Drawdown/SequencePrevents one sequence from losing too much moneyOFF (unlimited)
Max Spread FilterPrevents trading during high-spread conditionsOFF
AllowBuy / AllowSellLimits trading to one direction onlyBoth ON
Crash RecoveryPrevents losing track of trades after a restartALWAYS ON

21. Buy vs Sell - Side by Side Comparison

Complete Mirror Comparison
ElementBUY SetupSELL Setup
H1 CrossoverEMA 13 crosses ABOVE EMA 62EMA 13 crosses BELOW EMA 62
H1 EMA TouchPrice touches EMA 13 from abovePrice touches EMA 13 from below
M5 PullbackSupertrend SELL signalSupertrend BUY signal
M1 EntrySupertrend BUY signalSupertrend SELL signal
Pivot LineLOWEST low between M5 sell & M1 buyHIGHEST high between M5 buy & M1 sell
Flip TriggerM1 EMA 13 crosses BELOW pivotM1 EMA 13 crosses ABOVE pivot
Take ProfitEntry + 50 pipsEntry - 50 pips
Flip DirectionFlip to SELLFlip to BUY
InvalidationH1 EMA crosses back belowH1 EMA crosses back above

22. Technical Notes for Developers

Developer Checklist
  • Use closed candles only for crossover detection and signal confirmation
  • Avoid repeated re-entry from the same signal candle (track last processed bar time)
  • Normalize lot size to broker's minimum lot and lot step (use MarketInfo)
  • Normalize TP prices to the symbol's digit count (use NormalizeDouble)
  • Handle both 4-digit and 5-digit brokers: if Digits==5 or Digits==3, multiply pip values by 10
  • Sequence state must survive ticks reliably -- use static arrays or global scope
  • Implement Global Variable or file-based persistence for restart recovery
  • Supertrend must be called via iCustom() or embedded calculation -- ensure consistent signal reading
  • Use one OnTick() loop that processes: new crossovers → pending setups → active flips → cleanup

Internal State Per Sequence

FieldTypePurpose
SequenceIDintUnique identifier for this sequence
MagicNumberintBaseMagicNumber + SequenceID
DirectionintCurrent trade side (BUY/SELL)
IsActiveboolWhether this sequence has an open trade
IsCompletedboolWhether TP was hit (sequence finished)
HigherTFCrossoverTimedatetimeWhen the H1 crossover occurred
EMATouchConfirmedboolWhether Step 2 (touch) happened
PullbackSignalTimedatetimeWhen M5 counter-signal appeared
EntrySignalTimedatetimeWhen M1 entry signal appeared
PivotPricedoubleThe anchor price for the pivot line
FlipCountintHow many times this sequence has flipped
CurrentLotdoubleCurrent lot size based on progression
CurrentTicketintMT4 order ticket of the open trade
TakeProfitPricedoubleTP price for the current open trade

Strategy Document: Multi-Timeframe Trend-Follower with Pivot-Flip Recovery

Platform: MetaTrader 4 | Language: MQL4 | Type: Fully Automated Expert Advisor

Generated from EMA Strategy.pdf -- Full Understanding Review

Built by Gnourt · algorithmic trading systems