Forex Algo Trader
Sign In Register
Market Resources Tools Autotrading Algo Jobs
3 Inside Up: Your Ticket to Bullish Reversal Glory
Resource

3 Inside Up: Your Ticket to Bullish Reversal Glory

Hop into our fun, newbie-friendly guide to the 3 Inside Up MQL5 code! We’ll chop it into bits, explain each part like you’re five, and keep you laughing while learning to automate bullish reversals.
Allan Munene Mutiiria Verified
@allan_munene_mutiiria
1 year ago 508 views 0 comments 6 min read 2 files

Introduction

Yo, future forex legend! Picture a market sulking like it just got dumped. Then, the 3 Inside Up pattern rolls in, pumps up the bulls, and flips the vibe to “party mode.” This article is your golden ticket to automating that glow-up with MQL5 code on MetaTrader 5. We’ll carve the code into juicy chunks, explain it like you’re brand new (no judgment!), and toss in some humor to keep it lively. By the end, you’ll be ready to let this Expert Advisor (EA) chase bullish reversals for you. Let’s get it!

Strategy Blueprint

The 3 Inside Up is a three-candle drama that signals a bullish reversal. Here’s the storyline:

  1. Candle 1: A bearish candle, moping hard (opens high, closes low). The market’s in a serious funk.

  2. Candle 2: A bullish candle, small but spunky, fitting inside the first candle’s high-low range. It’s like a rebel with a plan.

  3. Candle 3: A big bullish candle that opens above the second’s open and closes above the first’s high, roaring, “Bulls, let’s roll!”

Our MQL5 code spots this saga, tags the chart with a green arrow, and says, “Buy now!” It’s like having a market scout who never sleeps. See below.

Code Implementation

Time to crack open this MQL5 code like a piñata and see what goodies spill out. We’re serving it in tasty, meaningful slices with explanations so clear even your dog could nod along (okay, maybe not). Variables like "open1" and functions like "get3insideUP()" will be quoted for clarity. Let’s build this EA like we’re stacking a burger—one layer at a time.

1. Kicking Things Off: Header and Properties

Every EA needs a slick intro, like a title screen for a blockbuster.

//+------------------------------------------------------------------+
//|                                                  3 INSIDE UP.mq5 |
//|                        Copyright 2025, Allan Munene Mutiiria      |
//|                            https://t.me/Forex_Algo_Trader         |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Allan Munene Mutiiria"
#property link      "https://t.me/Forex_Algo_Trader"
#property version   "1.00"

This chunk declares, “I’m the 3 Inside Up EA, crafted by Allan in 2025, version 1.00.” The "link" points to your Telegram channel for more trading juice. It’s like the EA’s business card, telling MetaTrader 5 who’s boss.

2. Warming Up: Initialization Functions

Next, we get the EA ready to roll and shut down cleanly, like a car with a smooth engine.

//+------------------------------------------------------------------+
//| Expert initialization function                                    |
//+------------------------------------------------------------------+
int OnInit()
{
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}

The "OnInit()" function is the EA’s morning coffee—it fires when you attach it to a chart and says, “Ready!” with INIT_SUCCEEDED. The "OnDeinit()" function is its bedtime routine, but it’s empty, like forgetting to lock the door. These are MQL5’s standard startup and shutdown gigs, and we’re keeping it chill.

3. The Pulse: OnTick Function

Now we hit the EA’s heartbeat, checking for market action.

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   get3insideUP();
}

The "OnTick()" function runs on every price tick, like a trader glued to their screen. It calls "get3insideUP()", the star player that hunts for our bullish pattern. Think of "OnTick()" as the coach yelling, “Go find me a buy signal!”

4. The Scout: get3insideUP Function (Part 1 - Gathering Data)

Here’s where the EA turns into a data nerd, collecting info on the last three candles.

int get3insideUP(){
   datetime time = iTime(_Symbol,PERIOD_CURRENT,1);
   double open1 = iOpen(_Symbol,PERIOD_CURRENT,1);
   double high1 = iHigh(_Symbol,PERIOD_CURRENT,1);
   double low1 = iLow(_Symbol,PERIOD_CURRENT,1);
   double close1 = iClose(_Symbol,PERIOD_CURRENT,1);

   double open2 = iOpen(_Symbol,PERIOD_CURRENT,2);
   double high2 = iHigh(_Symbol,PERIOD_CURRENT,2);
   double low2 = iLow(_Symbol,PERIOD_CURRENT,2);
   double close2 = iClose(_Symbol,PERIOD_CURRENT,2);

   double open3 = iOpen(_Symbol,PERIOD_CURRENT,3);
   double high3 = iHigh(_Symbol,PERIOD_CURRENT,3);
   double low3 = iLow(_Symbol,PERIOD_CURRENT,3);
   double close3 = iClose(_Symbol,PERIOD_CURRENT,3);

This chunk grabs the "open1", "high1", "low1", and "close1" (and so on) for the last three candles (1 is newest, 3 is oldest). The "_Symbol" is your chart’s pair (e.g., EURUSD), and "PERIOD_CURRENT" is the timeframe (e.g., H1). The "time" variable snags the latest candle’s timestamp for arrow placement later. It’s like the EA’s snapping a selfie of the market.

5. The Scout: get3insideUP Function (Part 2 - Pattern Check)

Now the EA plays detective, checking if the candles match the 3 Inside Up pattern.

if (open3 > close3){   // bearish bar
      if (open2 < close2){   // bullish bar
         if (open2 > low3 && close2 < high3){  // bar2 is within bar3 
            if (open1 < close1 && open1 > open2 && open1 < close2){
               if (close1 > high3){
                  Print("We found the 3 INSIDE UP PATTERN");
                  createARROW(time,low1);
                  return 1;   // buy 
               }
            }
         }
      }
   }
   return 0;
}

This is the EA’s “Aha!” moment, with nested if statements checking:

  • Candle 3: Bearish ("open3" > "close3"). The market’s all “Boo, downtrend!”

  • Candle 2: Bullish ("open2" < "close2") and inside Candle 3’s range ("open2" > "low3" && "close2" < "high3"). It’s like Candle 2’s sneaking in for a surprise.

  • Candle 1: Bullish ("open1" < "close1"), opens above Candle 2’s open ("open1" > "open2") but below its close ("open1" < "close2"), and closes above Candle 3’s high ("close1" > "high3"). This is the bullish victory lap.

If all boxes are checked, the EA logs “We found the 3 INSIDE UP PATTERN”, calls "createARROW()", and returns 1 for a buy signal. If not, it returns 0 and waits for the next tick.

6. The Painter: createARROW Function

Finally, the EA gets creative, dropping a green arrow to shout “Buy here!”

void createARROW(datetime time,double price){
   string name = "3 INSIDE UP";
   if (ObjectCreate(0,name,OBJ_ARROW,0,time,price)){
      ObjectSetInteger(0,name,OBJPROP_ARROWCODE,233);
      ObjectSetInteger(0,name,OBJPROP_COLOR,clrGreen);
      ObjectSetInteger(0,name,OBJPROP_WIDTH,5);
   }
}

The "createARROW()" function uses "ObjectCreate()" to place a green arrow at the given "time" and "price" (below Candle 1’s low). The arrow’s style ("OBJPROP_ARROWCODE", 233), color ("clrGreen"), and width (5) make it stand out like a lime in a fruit basket. If the arrow’s already there, it won’t redraw, keeping your chart neat.

Putting It All Together

To use this EA:

  1. Fire up MetaEditor in MetaTrader 5.

  2. Paste the code into a new Expert Advisor file.

  3. Compile (F5). If errors sneak in, check your copy-paste game.

  4. Drag the EA onto your chart, turn on AutoTrading, and watch for green arrows.

  5. Trade wisely—don’t bet your lunch money on one signal!

Conclusion

The 3 Inside Up EA is like a loyal dog sniffing out bullish reversals. We’ve sliced its MQL5 code into chunks, from setup to buy signals, so you can grasp every line. Now you’re set to automate your trading and let the bulls lead the charge. Want to see it live? Check our video tutorial on the website!

Disclaimer: Trading’s like riding a rollercoaster—thrilling but risky. Losses can exceed deposits. Test on a demo account before going live.

Attachments
3_INSIDE_UP.ex5 · 6.5 KB
Download
3_INSIDE_UP.mq5 · 2.8 KB
Download
508 views
Discussions 0

No discussions yet

Be the first to share your thoughts on this resource.

Sign in to take part
Sign in or register to comment and report.
0%
Uploading…
Please don’t close this page