Alright, trading warriors, grab your machetes and night-vision goggles, βcause weβre diving into the forex jungle to build an MQL5 Expert Advisor (EA) thatβs like a panther stalking breakout gold! This ainβt just codeβitβs a heart-pounding hunt weβre crafting together, and weβre gonna map it out with a flow so slick itβs like gliding down a river. Weβll keep it pro, stuffed with detail to make you a coding beast, and spiced with humor and examplesβlike picturing you as a jungle tracker snaring pipsβso you stay wide awake and grinning. Our mission? Build a bot that spots tight price ranges, marks them with a rectangle, and signals buy or sell breakouts when prices bust loose, all without trading logic yet (but ready for you to add the firepower). Letβs hack through the vines and unleash this breakout beast! πΉ
Step 1: Setting Up the Jungle CampβPrepping Our Hunt π΄
First, weβre pitching our jungle camp, the base where we sharpen our spears and prep our traps. This is like gearing up with a map, compass, and a trusty machete before stalking our prey.
#define RANGE "Range Rectangle"
int OnInit()
{
datetime
t1 = D'2023/09/05 06:00',
t2 = D'2023.09.11 02:00';
double
p1 = 0.64000,
p2 = 0.63650;
ObjectDelete(0,"REC");
ObjectCreate(0,"REC",OBJ_RECTANGLE,0,t1,p1,t2,p2);
ObjectSetInteger(0,"REC",OBJPROP_COLOR,clrLime);
ObjectSetInteger(0,"REC",OBJPROP_FILL,false);
ObjectSetInteger(0,"REC",OBJPROP_WIDTH,7);
return(INIT_SUCCEEDED);
}We start by rigging our camp with a test rectangleβthink of it as a practice snare to mark our territory. We define a rectangle named βRECβ with hardcoded dates (September 5 to 11, 2023) and prices (0.64000 to 0.63650), like sketching a mock trap on our map. We paint it lime green, unfilled, with a beefy 7-pixel width, like a glowing marker in the jungle. This rectangle is a one-time setup, drawn when we load the EA, to test our drawing skills before the real hunt. We clear any old βRECβ first, ensuring a clean slate, and return a success signal to confirm our campβs ready. Itβs like saying, βTraps set, letβs hunt!β with a practice run to boost our confidence.
Step 2: Scouting the ClearingβSpotting Tight Ranges π§
Camp set? Time to scout the jungle clearing, searching for a tight price range where the marketβs chilling like a panther before a leap. This is where we hunt for consolidation zones.
int totalBars = 0;
void OnTick()
{
double
Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits),
Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
int
indexHighestBar = iHighest(_Symbol,_Period,MODE_HIGH,50,1),
indexLowestBar = iLowest(_Symbol,_Period,MODE_LOW,50,1);
double
rangeHighPrice = iHigh(_Symbol,_Period,indexHighestBar),
rangeLowPrice = iLow(_Symbol,_Period,indexLowestBar);
datetime
RangeStartTime = iTime(_Symbol,_Period,30),
RangeEndTime = iTime(_Symbol,_Period,0);
double currentRangeHeight = NormalizeDouble(rangeHighPrice - rangeLowPrice,_Digits);
bool isInRange = currentRangeHeight <= 500*_Point;
if (isInRange){
drawRange(RangeStartTime,rangeHighPrice,RangeEndTime,rangeLowPrice);
}
}Every market tick is like a rustle in the bushes, so we grab the current ask and bid prices, like checking the wind direction. We scan the last 50 candles to find the highest and lowest prices, like spotting the tallest tree and deepest ditch in the clearing. If the range between them is 500 pips or less, weβve found our consolidation zoneβour pantherβs pacing cage. We mark this range with timestamps from 30 candles back to the current candle, like setting a trapβs boundaries. If the range is tight, we call our drawing function to paint a red rectangle on the chart, like a neon sign shouting, βHereβs the quiet zone!β This is our βAha!β moment, like a tracker spotting fresh paw prints. If the range is too wide, we hold off, waiting for a tighter clearing, like a patient hunter avoiding a noisy jungle.
Step 3: Springing the TrapβSignaling Breakouts π₯
Range spotted? Time to set the snare and pounce when the market breaks out, like a panther busting free from its cage.
void OnTick()
{
// ... (range detection code as above)
if (isInRange){
if (Ask > rangeHighPrice){
int bars = iBars(_Symbol,_Period);
if (totalBars == bars) return;
totalBars = bars;
Comment("BUY BREAKOUT");
Print("BUY BREAKOUT");
isInRange = false;
return;
}
else if (Bid < rangeLowPrice){
int bars = iBars(_Symbol,_Period);
if (totalBars == bars) return;
totalBars = bars;
Comment("SELL BREAKOUT");
Print("SELL BREAKOUT");
isInRange = false;
return;
}
return;
}
}If weβre in a tight range, we watch for the breakout. If the ask price surges above the rangeβs high, itβs like the panther leaping upward, triggering a βBUY BREAKOUTβ signal. If the bid crashes below the low, itβs like a dive into the shadows, cueing a βSELL BREAKOUT.β We only act on new candles, checking the bar count to avoid spamming like a trigger-happy hunter. When a breakout hits, we log and display it on the chart, like shouting βGotcha!β and waving a flag. We then reset our range flag, like pulling up the snare for the next hunt. This is pure adrenaline, like spotting the pantherβs leap and knowing itβs go-time!
Step 4: Painting the TrapβDrawing the Range Rectangle π¨
To make our hunt visual, we paint a red rectangle around the consolidation zone, like marking a trap with glowing paint.
void drawRange(datetime time1,double price1,datetime time2,double price2){
int found = ObjectFind(0,RANGE);
if (found < 0){
ObjectCreate(0,RANGE,OBJ_RECTANGLE,0,time1,price1,time2,price2);
}
else{
ObjectSetInteger(0,RANGE,OBJPROP_TIME,0,time1);
ObjectSetDouble(0,RANGE,OBJPROP_PRICE,0,price1);
ObjectSetInteger(0,RANGE,OBJPROP_TIME,1,time2);
ObjectSetDouble(0,RANGE,OBJPROP_PRICE,1,price2);
ObjectSetInteger(0,RANGE,OBJPROP_FILL,false);
ObjectSetInteger(0,RANGE,OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,RANGE,OBJPROP_WIDTH,3);
ObjectSetInteger(0,RANGE,OBJPROP_STYLE,STYLE_SOLID);
ObjectSetInteger(0,RANGE,OBJPROP_BACK,true);
}
}We define a rectangle named βRange Rectangleβ and check if it exists. If not, we create it, spanning from 30 candles back to the current candle, covering the rangeβs high to low. If itβs already there, we update its coordinates, painting it red, unfilled, with a 3-pixel width, like a bold outline in the jungle. This rectangle is our trapβs marker, making the consolidation zone pop on the chart like a glowing snare. Itβs like saying, βHereβs where the pantherβs hiding!β so we never miss the action. See below.

Step 5: Packing Up CampβCleaning Up Loose Ends ποΈ
When the huntβs over, or weβre moving camp, we clean up to keep the jungle tidy.
void OnDeinit(const int reason)
{
}Our cleanup is minimalβno objects or indicators to clear, like a tracker leaving no trace. The test rectangle (βRECβ) is set once, and the dynamic range rectangle persists, but we could add cleanup later if we want a spotless chart, like sweeping away campfire ashes. For now, itβs a light pack-up, ready for the next stalk.
Why This EAβs a Jungle Legend (and Keeps You Hooked!) π€
This EA is a breakout-hunting beast, spotting tight ranges like a tracker eyeing paw prints and signaling breakouts like a pantherβs leap. Itβs pro-grade trading with a jungle swagger, keeping you awake with its simplicity and potential. Imagine stalking EURUSD, seeing a 400-pip range on H1, and catching a 300-pip breakout when it busts looseβthatβs this botβs vibe! Itβs ready for you to add trading logic, like arming your trap with cannons, and the red rectangle makes ranges pop like a neon sign. Tweak the range size (500 pips) or candle window (50) to match your style, like sharpening your machete for bigger prey.
Putting It All Together
To unleash this EA:
Fire up MetaEditor in MetaTrader 5 like youβre entering the jungle.
Paste the code, compile (F5), and fix typosβnobody wants a broken trap.
Drop the EA on your chart, enable AutoTrading, and watch for red rectangles and breakout signals.
Add trading logic (e.g., buy/sell orders) to pounce on signals, like arming your snare.
Stay sharpβtest on a demo first, βcause even trackers scout before a hunt!
Conclusion
Weβve built a breakout-hunting beast that spots consolidation ranges, paints them red, and signals explosive moves like a panther on the prowl. This MQL5 code is our jungle trap, explained with detail to make you a trading tracker, humor to keep you grinning, and flow to carry you like a river. Ready to stalk? Check our video guide on the website for a front-row seat to this jungle adventure. Now go snare those pips! π
Disclaimer: Tradingβs like hunting a jungle beastβthrilling but risky. Losses can exceed deposits. Test on a demo account before going live.