Viewing the resource: 3 Inside Down: Your Ticket to Bearish Reversal Glory

3 Inside Down: Your Ticket to Bearish Reversal Glory

Allan Munene Mutiiria 2025-06-20 17:28:11 99 Views
Join us for a fun, newbie-friendly dive into the 3 Inside Down MQL5 code! We’ll break it into chun...

Introduction

Hey there, future forex rockstar! Imagine you’re at a market party where the bulls are dancing like nobody’s watching. Then, the 3 Inside Down pattern crashes in, flips the DJ table, and hands the mic to the bears. This article is your backstage pass to automating that drama with MQL5 code on MetaTrader 5. We’ll slice the code into tasty chunks, explain it like you’re new to this (no shame!), and sprinkle in some humor to keep it fun. By the end, you’ll be ready to let this Expert Advisor (EA) hunt bearish reversals for you. Let’s roll!

Strategy Blueprint

The 3 Inside Down is a three-candle soap opera signaling a bearish reversal. Here’s the plot:

  1. Candle 1: A bullish candle, strutting its stuff (opens low, closes high). The market’s on a sugar high.

  2. Candle 2: A bearish candle, smaller and sneakier, fitting inside the first candle’s high-low range. It’s like a ninja in disguise.

  3. Candle 3: A big bearish candle that opens below the second’s open and closes below the first’s low, yelling, “Bulls, you’re done!”

Our MQL5 code watches for this drama, spots the pattern, and slaps a red arrow on the chart to say, “Sell now!” It’s like having a market detective on speed dial. See below.

Code Implementation

Time to pop the hood on this MQL5 code and see what makes it tick. We’re not dumping the whole thing at once—oh no, we’re serving it in juicy, meaningful slices with explanations so clear even your grandma could trade (well, maybe). Let’s build this EA like we’re assembling a LEGO masterpiece, one brick at a time.

1. Setting the Stage: Header and Properties

Every EA needs a fancy title card, like a movie poster. This chunk sets up the EA’s identity.

//+------------------------------------------------------------------+
//|                                                  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 says, “Yo, I’m the 3 Inside Down EA, created by Allan in 2025, version 1.00.” The link points to your Telegram channel for more trading goodness. Fun fact: The file name says “3 INSIDE UP,” but we’re coding for “3 Inside Down.” A little typo, but the code’s got the right idea. Think of it as the EA’s quirky personality.

2. Getting Started: Initialization Functions

Next, we need the EA to wake up and shut down properly, like a well-behaved robot.

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

OnInit is the EA’s morning stretch—it runs when you attach it to a chart and says, “I’m good to go!” with INIT_SUCCEEDED. OnDeinit is like the EA’s bedtime routine, but it’s empty here, like forgetting to brush your teeth. These are MQL5’s standard startup and shutdown functions, and we’re keeping it simple.

3. The Heartbeat: OnTick Function

Now we get to the EA’s pulse, which checks for new market action.

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

OnTick runs every time a new price tick hits the chart, like a caffeinated trader checking prices every second. It calls get3insideDOWN(), the real MVP that hunts for our pattern. Think of OnTick as the boss who says, “Go find me a sell signal, now!”

4. The Detective: get3insideDOWN Function (Part 1 - Data Collection)

Here’s where the EA turns into Sherlock Holmes, gathering clues about the last three candles.

int get3insideDOWN(){
   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 open, high, low, and close prices for the last three candles (1 is the latest, 3 is the oldest). _Symbol is your chart’s currency pair (e.g., EURUSD), and PERIOD_CURRENT is the timeframe (e.g., H1). The time variable snags the latest candle’s timestamp for later arrow placement. It’s like the EA’s saying, “Let me take a quick snapshot of the market.”

5. The Detective: get3insideDOWN Function (Part 2 - Pattern Logic)

Now the EA checks if those candles match the 3 Inside Down pattern, like a chef tasting the soup.

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

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

  • Candle 3: Bullish (open3 < close3). The market’s all “Yay, uptrend!”

  • Candle 2: Bearish (open2 > close2) and inside Candle 3’s range (open2 < high3 && close2 > low3). It’s like Candle 2’s playing hide-and-seek.

  • Candle 1: Bearish (open1 > close1), opens below Candle 2’s open (open1 < open2) but above its close (open1 > close2), and closes below Candle 3’s low (close1 < low3). This is the bearish knockout.

If all checks pass, the EA shouts “We found the 3 INSIDE DOWN PATTERN” in the log, calls createARROW to mark the chart, and returns -1 for a sell signal. If not, it returns 0 and chills until the next tick.

6. The Artist: createARROW Function

Finally, the EA gets artsy, painting a red arrow to scream “Sell here!”

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

This function uses ObjectCreate to place a red arrow at the given time and price (above Candle 1’s high). The arrow’s style (OBJPROP_ARROWCODE, 234), color (clrRed), and width (5) make it pop like a neon sign. If the arrow’s already there, it won’t redraw, keeping your chart tidy. For example, you might see.

Putting It All Together

To use this EA:

  1. Open MetaEditor in MetaTrader 5.

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

  3. Compile (F5). If errors pop up, double-check your copy-paste skills.

  4. Drag the EA onto your chart, enable AutoTrading, and watch for red arrows.

  5. Trade smart—don’t bet your rent money on one signal!

Conclusion

The 3 Inside Down EA is like a trusty hound sniffing out bearish reversals. We’ve broken down its MQL5 code into chunks, from setup to sell signals, so you can understand every line. Now you’re ready to automate your trading and let the bears do the heavy lifting. Want to see it in action? Check out our video tutorial on the website!

Disclaimer: Trading’s like juggling flaming torches—exciting but risky. Losses can exceed deposits. Test on a demo account before going live.

Disclaimer: The ideas and strategies presented in this resource are solely those of the author and are intended for informational and educational purposes only. They do not constitute financial advice, and past performance is not indicative of future results. All materials, including but not limited to text, images, files, and any downloadable content, are protected by copyright and intellectual property laws and are the exclusive property of Forex Algo-Trader or its licensors. Reproduction, distribution, modification, or commercial use of these materials without prior written consent from Forex Algo-Trader is strictly prohibited and may result in legal action. Users are advised to exercise extreme caution, perform thorough independent research, and consult with qualified financial professionals before implementing any trading strategies or decisions based on this resource, as trading in financial markets involves significant risk of loss.

Recent Comments

Go to discussion to Comment or View other Comments

No comments yet. Be the first to comment!