How was your first EA developed? - page 2

 
Ryan L Johnson #:

What an accurate statement! 😅😂🤣

Here was me switching from manual trading to algorithmic trading in 2012:


What did you build back then?
 
Wei Xin Sun #:

In the beginning, I was simply stitching pieces of code together without truly understanding position sizing or drawdown control. After only a few days of backtesting, the account was already blown.That experience changed my approach completely.For more than a year afterward, I focused on studying logs, execution flow, and risk management in depth. I stopped chasing maximum profit and started prioritizing risk control above everything else.Today, my EA is much more stable.It uses defined stop-loss rules, with no martingale and no grid systems.In trading, emotions are always the biggest opponent.That is exactly why I continue refining and improving my EA.

What did you tried to build at first?

What was the main concept for you first EA?

 
Osmar Sandoval Espinosa #:
What did you build back then?

There was a web hosted "EA builder." I paid something like 30 USD for a one-year subscription. It was merely a drag-and=drop graphical interface that generated source code from a captive database.

I referred to the EA builder as "garbage" because the generated code was very limited and rather inefficient. I must admit, however, my intense custom code edits to that generated code did inspire me to write completely custom code within that year. The builder was either a waste of 30 USD or the best 30 USD that I ever spent. You be the judge.

 
Ryan L Johnson #:

There was a web hosted "EA builder." I paid something like 30 USD for a one-year subscription. It was merely a drag-and=drop graphical interface that generated source code from a captive database.

I referred to the EA builder as "garbage" because the generated code was very limited and rather inefficient. I must admit, however, my intense custom code edits to that generated code did inspire me to write completely custom code within that year. The builder was either a waste of 30 USD or the best 30 USD that I ever spent. You be the judge.

Lol, then you moved into mql community?

 

Personnaly, I always prefer to start with litterature and research instead of reinventing the wheel.

When I developped my first EA, I do the same and try to copy paste block of code to combine stuff together. The performance was pretty decent but not smart enough to manage Loss...

Now with LLM and AI it is much more easier and we test millions of stuffs without being a coder (Amazing moment of life :))

 
Osmar Sandoval Espinosa #:

Lol, then you moved into mql community?

Yeah. Truth be told, I was still using MT4 at that time─so it was mql4.com.

Metaquotes migrated my mql4.com account over to mql5.com at some point which in turn, led me to migrate myself over to MT5.

 
Emmanuel Christian Aliouat #:

Personnaly, I always prefer to start with litterature and research instead of reinventing the wheel.

When I developped my first EA, I do the same and try to copy paste block of code to combine stuff together. The performance was pretty decent but not smart enough to manage Loss...

Now with LLM and AI it is much more easier and we test millions of stuffs without being a coder (Amazing moment of life :))

I agree, LLM and AI help a lot tbh.
 

This was my very first formal EA (after a some tests)

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2020, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+

#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#include <Trade\Trade.mqh>

CTrade trade;
input int Rango = 14;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   trade.SetExpertMagicNumber(12345);
   ChartSetInteger(0, CHART_COLOR_BACKGROUND, clrBlack);
   ChartSetInteger(0, CHART_COLOR_GRID, clrBlack);
   ChartSetInteger(0, CHART_COLOR_CANDLE_BULL, clrGreen);
   ChartSetInteger(0, CHART_COLOR_CANDLE_BEAR, clrRed);
   ChartSetInteger(0, CHART_COLOR_CHART_UP, clrGreen);
   ChartSetInteger(0, CHART_COLOR_CHART_DOWN, clrRed);
   ChartSetInteger(0, CHART_COLOR_FOREGROUND, clrWhite);
   ChartSetInteger(0, CHART_COLOR_CHART_LINE, clrGray);
   ChartSetInteger(0, CHART_COLOR_BID, clrBisque);
   ChartSetInteger(0, CHART_COLOR_BID, clrBisque);
   ChartSetInteger(0, CHART_COLOR_LAST, clrAquamarine);
   ChartSetInteger(0, CHART_COLOR_STOP_LEVEL, clrLightGray);
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   bool isnewbar = false;

   int CurrBar = iBars(_Symbol, PERIOD_CURRENT);

   static int PrevBar =  CurrBar;

   if(PrevBar == CurrBar)
     {
      isnewbar = false;
     }
   else
     {
      isnewbar = true;
      PrevBar = CurrBar;
     }

   if(isnewbar)
     {
      bool isSwingHigh = true;
      bool isSwingLow = true;
      for(int i=1; i<=Rango; i++)
        {
         if(high(Rango)<high(Rango-i) || high(Rango)<high(Rango+i))
           {
            isSwingHigh = false;
           }
         if(low(Rango)>low(Rango-i) || low(Rango)>low(Rango+i))
           {
            isSwingLow = false;
           }
        }
      static double SwingHigh = 0;

      static double SwingHigh2 = 0;

      static double SwingLow = DBL_MAX;

      static double SwingLow2 = DBL_MAX;

      static datetime HoraSwingHigh1 = time(Rango);

      static datetime HoraSwingLow1 = time(Rango);



      if(close(1) > SwingHigh && SwingHigh2 != SwingHigh)
        {
         datetime LineaA = time(1);

         string textName5 = "MyTextPoint5_" + TimeToString(time(1));
         ObjectCreate(0, textName5, OBJ_TREND, 0, HoraSwingHigh1, SwingHigh, LineaA, SwingHigh);
         ObjectSetInteger(0, textName5, OBJPROP_COLOR, clrWhite);


         SwingHigh2 = SwingHigh;


        }

      if(close(1) < SwingLow && SwingLow2 != SwingLow)
        {
         datetime LineaB = time(1);

         string textName6 = "MyTextPoint5_" + TimeToString(time(1));
         ObjectCreate(0, textName6, OBJ_TREND, 0, HoraSwingLow1, SwingLow, LineaB, SwingLow);
         ObjectSetInteger(0, textName6, OBJPROP_COLOR, clrWhite);

         SwingLow2 = SwingLow;

        }

      if(isSwingHigh && (close(Rango) > SwingHigh || close(Rango+1) > SwingHigh || close(Rango+2) > SwingHigh || close(Rango-1) > SwingHigh || close(Rango-2) > SwingHigh))
        {

         static datetime HoraSwingHigh = time(Rango);
         datetime HoraSwingHigh2 = time(Rango-1);

         string textName = "MyTextPoint1_" + TimeToString(time(Rango));
         ObjectCreate(0, textName, OBJ_ARROW, 0, time(Rango), high(Rango));
         ObjectSetInteger(0, textName, OBJPROP_ARROWCODE, 108);
         ObjectSetInteger(0, textName, OBJPROP_COLOR, clrWhite);
         ObjectSetInteger(0, textName, OBJPROP_WIDTH, 1);
         ObjectSetInteger(0, textName, OBJPROP_ANCHOR, ANCHOR_UPPER);
         if(HoraSwingHigh != HoraSwingHigh2)
           {

            double bajos[];

            CopyLow(_Symbol, PERIOD_CURRENT, HoraSwingHigh, HoraSwingHigh2, bajos);

            datetime tiempo[];

            CopyTime(_Symbol, PERIOD_CURRENT, HoraSwingHigh, HoraSwingHigh2, tiempo);

            int min = ArrayMinimum(bajos);

            SwingLow = bajos[min];

            datetime TiempoBajo = tiempo[min];

            string textName3 = "MyTextPoint2_" + TimeToString(TiempoBajo);
            ObjectCreate(0, textName3, OBJ_ARROW, 0, TiempoBajo, SwingLow);
            ObjectSetInteger(0, textName3, OBJPROP_ARROWCODE, 108);
            ObjectSetInteger(0, textName3, OBJPROP_COLOR, clrWhite);
            ObjectSetInteger(0, textName3, OBJPROP_WIDTH, 1);

            HoraSwingHigh = HoraSwingHigh2;

            HoraSwingLow1 = TiempoBajo;

           }
         SwingHigh = high(Rango);

         HoraSwingHigh1 = time(Rango);
        }
      if(isSwingLow && (close(Rango) < SwingLow || close(Rango+1) < SwingLow || close(Rango+2) < SwingLow || close(Rango-1) < SwingLow || close(Rango-2) < SwingLow))
        {

         static datetime HoraSwingLow = time(Rango);
         datetime HoraSwingLow2 = time(Rango-1);

         string textName2 = "MyTextPoint3_" + TimeToString(time(Rango));
         ObjectCreate(0, textName2, OBJ_ARROW, 0, time(Rango), low(Rango));
         ObjectSetInteger(0, textName2, OBJPROP_ARROWCODE, 108);
         ObjectSetInteger(0, textName2, OBJPROP_COLOR, clrWhite);
         ObjectSetInteger(0, textName2, OBJPROP_WIDTH, 1);
         if(HoraSwingLow != HoraSwingLow2)
           {
            double altos[];

            CopyHigh(_Symbol, PERIOD_CURRENT, HoraSwingLow, HoraSwingLow2, altos);

            datetime tiempo2[];

            CopyTime(_Symbol, PERIOD_CURRENT, HoraSwingLow, HoraSwingLow2, tiempo2);

            int max = ArrayMaximum(altos);

            SwingHigh = altos[max];

            datetime TiempoAlto = tiempo2[max];

            string textName4 = "MyTextPoint4_" + TimeToString(TiempoAlto);
            ObjectCreate(0, textName4, OBJ_ARROW, 0, TiempoAlto, SwingHigh);
            ObjectSetInteger(0, textName4, OBJPROP_ARROWCODE, 108);
            ObjectSetInteger(0, textName4, OBJPROP_COLOR, clrWhite);
            ObjectSetInteger(0, textName4, OBJPROP_WIDTH, 1);
            ObjectSetInteger(0, textName4, OBJPROP_ANCHOR, ANCHOR_UPPER);

            HoraSwingLow = HoraSwingLow2;

            HoraSwingHigh1 = TiempoAlto;
           }
         SwingLow = low(Rango);

         HoraSwingLow1 = time(Rango);
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double high(int index) {return (iHigh(_Symbol,_Period,index));}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double  low(int index) {return (iLow(_Symbol,_Period,index));}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double close(int index) {return (iClose(_Symbol,_Period,index));}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
datetime time(int index) {return (iTime(_Symbol, _Period, index));}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
 
Ryan L Johnson #:

Yeah. Truth be told, I was still using MT4 at that time─so it was mql4.com.

Metaquotes migrated my mql4.com account over to mql5.com at some point which in turn, led me to migrate myself over to MT5.

Is mql4 very different from mql5?
 
Osmar Sandoval Espinosa #:
Is mql4 very different from mql5?

In about 2010 when MQL5 was initially released, MQL4 was like MQL5─for the most part.

At that time, MQL4 remained rather skeletal and didn't support OOP. If I remember correctly, the first deviations from MQL4 in MQL5 were the advents of indicator handles followed by more nuanced order sending code─and MQL5 supported OOP before MQL4 did so. I never used OOP in MQL4 because I switched over to MQL5 to use OOP. As the MQL5 language expands at breakneck speed, MQL4 still remains rather skeletal in comparison to MQL5.

Even though I have a bit of nostalgia for the MQL4 language as an easy start in algo coding, moving forward meant leaving it behind. The faster execution and greater control of MQl5 certainly influenced my thinking as well. IMHO, there is no reason to use antiquated MQL4/MT4 unless of course, you only have access to MT4 in your given region of the world.