Expert Advisor Modification for MQL4

MQL4 Indicators Experts

Job finished

Execution time 4 days
Feedback from customer
Everything was all right. I am satisfied.

Specification

I would like you to fix my MQL4 expert advisor source code, which now gives wrong results. It calculates the Andean Oscillator parameters. The PineScript code for the Andean Oscillator can be found in Tradingview, but I have also included in my code in the comments. The Alerts should give the correct Andean Oscillator Bullish Component, Bearish Component and Signal, just as they are shown in Tradingview. Feel free to change any part of the code, if necessary. I have also attached the code as a file.

Here is the code:


//+------------------------------------------------------------------+
//|                                            Andean Oscillator.mq4 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//#property strict   // There is no property strict !!
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
extern datetime BeginCollectTime = D'2023.06.14 15:20:00'; // We begin collecting data for the EMA from this time
extern datetime BeginTradeTime = D'2023.06.14 15:20:00';  // We begin trading from this time; this time must be at least 9 minutes ahead of BeginCollectTime
 
extern double BaseATRMultiplier = 3;
extern double StopATRMultiplier = 1.15;
extern double ProfitATRMultiplier = 2.05;
extern double RiskPercent = 2;
extern double BidAskDistance = 0.00011;

double nz(double v, double r){ if(v == EMPTY_VALUE) v = r; return r; }

int OnInit()
  {
   
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
   {
   
   datetime CurrentTime = TimeCurrent();
   
   static int MinutesCounter = 1;
   static bool SignalForBuy = false; // We only want to buy one open trade, we use this flag for this purpose.
   static bool SignalForSell = false; // We only want to buy one sell trade, we use this flag for this purpose.
 
   static double BearishComponent[200];
   static double BullishComponent[200];
   static double Signal[200];
   static double MaxBullBear[200];
   
   double Length = 50;
   double SignalLength = 9;  
   int SignalLengthInt = 9;
   
   double Alpha = 2/(Length+1);
   double AlphaS = 2/(SignalLength+1);
   
   double SignalNominator;  // For the EMA calculation
   double SignalDenominator; // For the EMA calculation
   
   static double up1[200]; // Arrays for the Andean Oscillator calculator
   static double up2[200];
   static double dn1[200];
   static double dn2[200];
      
   double BarOpen;
   double BarClose;
   
   double ATR;
   double Balance;
   double LotSize;
   double StopLoss;
   double TakeProfit;
   double ClosePrice;
   
   static int Ticket1 = 0;
   static int Ticket2 = 0;
   
   int i;
       
   up1[0] = 0;
   up2[0] = 0;
   dn1[0] = 0;
   dn2[0] = 0;
   BearishComponent[0] = 0;
   BullishComponent[0] = 0;
   Signal[0] = 0;
   
           
   if (CurrentTime > BeginCollectTime + (MinutesCounter*60))    // We do the following operations once per 1 minute, after a candle closes
   
       {
         
         Alert("One minute has passed.");
                 
         Balance = AccountBalance();      // We calculate lot size, stoploss and take profit here.
         ATR = iATR(0,0,14,1);
         ClosePrice = iClose(NULL,0,1);
         StopLoss = BaseATRMultiplier*StopATRMultiplier*ATR;
         TakeProfit = BaseATRMultiplier*ProfitATRMultiplier*ATR;
             
         LotSize = NormalizeDouble(((Balance*(RiskPercent/100))/(BaseATRMultiplier*StopATRMultiplier*ATR))*0.00001,2);
         
         
    //=========================== We calculate the Andean Oscillator parameters here ==========================================================================================================================        
         
         BarOpen = iOpen(NULL,0,1);
         BarClose = iClose(NULL,0,1);
         
       
         // This is the Andean Oscillator indicator from Tradingview:
       
         /*
            up1 := nz(math.max(C, O, up1[1] - (up1[1] - C) * alpha), C)
            up2 := nz(math.max(C * C, O * O, up2[1] - (up2[1] - C * C) * alpha), C * C)

            dn1 := nz(math.min(C, O, dn1[1] + (C - dn1[1]) * alpha), C)
            dn2 := nz(math.min(C * C, O * O, dn2[1] + (C * C - dn2[1]) * alpha), C * C)

         //Components
         
            bull = math.sqrt(dn2 - dn1 * dn1)
            bear = math.sqrt(up2 - up1 * up1)

            signal = ta.ema(math.max(bull, bear), sig_length)
         
          */  
         
          // Here we calculate the Andean Oscillator in MQL4 (calculation of Components):
          
          up1[MinutesCounter+1] = nz(MathMax(BarClose, MathMax(BarOpen, up1[MinutesCounter] - ((up1[MinutesCounter] - BarClose)*Alpha))),BarClose);
          up2[MinutesCounter+1] = nz(MathMax(BarClose*BarClose, MathMax(BarOpen*BarOpen, up2[MinutesCounter] - (up2[MinutesCounter] - (BarClose*BarClose)*Alpha))),BarClose*BarClose);
          
          
         
        
                                
          dn1[MinutesCounter+1] = nz(MathMin(BarClose, MathMin(BarOpen, dn1[MinutesCounter] + ((BarClose-dn1[MinutesCounter])*Alpha))),BarClose);
          dn2[MinutesCounter+1] = nz(MathMin(BarClose*BarClose, MathMin(BarOpen*BarOpen, dn2[MinutesCounter] + (((BarClose*BarClose)-dn2[MinutesCounter])*Alpha))),BarClose*BarClose);
          
          
          
          BullishComponent[MinutesCounter] = MathSqrt(dn2[MinutesCounter] - (dn1[MinutesCounter] * dn1[MinutesCounter]));
          
          BearishComponent[MinutesCounter] = MathSqrt(up2[MinutesCounter] - (up1[MinutesCounter] * up1[MinutesCounter]));
          
          MaxBullBear[MinutesCounter] = MathMax(BullishComponent[MinutesCounter],BearishComponent[MinutesCounter]);
          
           
          // Here we calculate the Andean Oscillator in MQL4 (calculation of Signal):
       
          
          
          SignalNominator = 0;
          SignalDenominator = 0;
          
          
          for (i=1; i<=SignalLengthInt; i++)
                           
                                 
                                      {
                                 
                                          SignalNominator = SignalNominator + (MaxBullBear[MinutesCounter - (SignalLengthInt-i)] * MathPow(1-AlphaS,i-1) );  // Formula for calculation of exponential moving averages
                                    
                                          SignalDenominator = SignalDenominator + MathPow(1-AlphaS,i-1);                                                     // this formula is from here: https://www.alpharithms.com/moving-averages-083315/
                                    
                                      }
                           
                   
          Signal[MinutesCounter] = NormalizeDouble(SignalNominator / SignalDenominator,3);
                                 
          
   //=========================== End of calculating the Andean Oscillator parameters here ==========================================================================================================================   
   
   
                                                                          
   
          if (CurrentTime > BeginTradeTime )  // At this time, 9 candles have already passed with data collection, so we can begin trading with the right 9-period EMA
 
                {
           
                    Alert("BearishComponent = ", BearishComponent[MinutesCounter]);  // We check here, if the components are calculated correctly
                    Alert("BullishComponent = ", BullishComponent[MinutesCounter]);                      
                    Alert("Signal = ", Signal[MinutesCounter]);
 
 
    
          
                    if (SignalForBuy == false) // Send BUY order only once.
         
                          {

                                if ( BullishComponent[MinutesCounter] - Signal[MinutesCounter] >= 3 )  // If the Bullish Component of Andean is larger than the Signal Component of Andean by 3, then we buy.
                  
                                      {
              
                                          SignalForBuy = true;  // This flag makes sure, that we send BUY order only once
                       
                                          Alert("Vétel: ", LotSize);
                                          Ticket1 = OrderSend(Symbol(), OP_BUY, LotSize, Ask, 12, ClosePrice - StopLoss - BidAskDistance, ClosePrice + TakeProfit - BidAskDistance, "Buy Order");
                                          Alert("Ticket number: ", Ticket1);
                      
                                      }
                  
                          }  
          
 
 
 
                    if (SignalForSell == false) // Send SELL order only once.
         
                          {
                         
                                if ( BearishComponent[MinutesCounter] - Signal[MinutesCounter] >= 3 )  // If the Bearish Component of Andean is larger than the Signal Component of Andean by 3, then we sell.
                  
                                     {
              
                                          SignalForSell = true;  // This flag makes sure, that we send BUY order only once
                        
                                          Alert("Eladás: ", LotSize);
                                          Ticket2 = OrderSend(Symbol(), OP_SELL, LotSize, Bid, 12, ClosePrice + StopLoss + BidAskDistance, ClosePrice - TakeProfit + BidAskDistance, "Buy Order");
                                          Alert("Ticket number: ", Ticket2);
                       
                                     }
                  
             }  
    

 
 
       }
      
         MinutesCounter = MinutesCounter + 1;  // We step one minute further, this ensures, that the above block is only executed once per minute
   
    }   
 
  }


   
 
   
 




Files:

Responded

1
Developer 1
Rating
(636)
Projects
1008
47%
Arbitration
33
36% / 36%
Overdue
99
10%
Working
Published: 6 codes
2
Developer 2
Rating
(13)
Projects
31
23%
Arbitration
8
25% / 63%
Overdue
5
16%
Free
3
Developer 3
Rating
(174)
Projects
200
12%
Arbitration
39
38% / 33%
Overdue
5
3%
Free
Published: 2 codes
4
Developer 4
Rating
(45)
Projects
46
24%
Arbitration
34
9% / 85%
Overdue
10
22%
Free
5
Developer 5
Rating
(61)
Projects
83
45%
Arbitration
27
11% / 70%
Overdue
8
10%
Free
6
Developer 6
Rating
(132)
Projects
178
39%
Arbitration
4
25% / 50%
Overdue
14
8%
Free
7
Developer 7
Rating
(574)
Projects
945
47%
Arbitration
309
58% / 27%
Overdue
125
13%
Free
Similar orders
I am commissioning the development and reverse-engineering of a commercial-grade, multi-strategy quantitative trading portfolio modeled on proven institutional frameworks (Reference methodology: https://whop.com/the-agent-algo/products/ ). The goal is to develop a standalone, fully owned commercial trading system covering Nasdaq (NQ) and Gold (XAUUSD) with an integrated licensing engine ready for commercial
Hello, I already have an MT5 Expert Advisor for XAUUSD based on Fibonacci, market structure, BOS/CHoCH and swing trading. I need an experienced MQL5 developer to modify my existing EA, not develop a completely new one. Required modifications: Partial take-profit system with multiple TP levels. Keep profit targets conservative, using Fibonacci extension levels. Stop-loss placement beyond liquidity areas, not exactly
Exir AI 30 - 200 USD
I need an experienced MQL5 developer to build a custom AI-assisted Expert Advisor (EA) for MetaTrader 5. The EA will run on a live MT5 account with Tickmill and must support Forex and Crypto CFDs. Required instruments: - EURUSD - GBPUSD - USDJPY - XAUUSD - BTCUSD - ETHUSD Required timeframes: - M5, M15, and M30 Trading logic: - M30 determines the overall trend. - M15 identifies entry zones, support/resistance, and
Hello, I am an independent developer selling an Expert Advisor (EA) on the MQL5 Market. I am looking for an experienced Forex affiliate marketing company or professional marketer to promote my existing MT5 trading robot to customers worldwide. My proposed partnership offers a 35% commission per verified sale, with the possibility of a long-term collaboration. I would like to know: Do you promote third-party MT5
I am a serious buyer looking to acquire an existing, stable, and consistently profitable Expert Advisor (EA) specifically designed primarily for Gold (XAUUSD). This is an outright purchase. I am not interested in developing a new EA from scratch. I am only interested in ready-to-use systems with a genuine, verifiable track record of performance. ✅ EA Requirements Mandatory Demo Testing on DuraMarket Testing on a
USD54 Applications The bot should open trades when the price breaks out of the band by a specified percentage, for example, 0.10%. If the price breaks above the band, the bot should open a long position. If the price breaks below the band, it should open a short position. The bot should also open trades when the price touches a band: Bullish band cross: When a bullish cross occurs between the bands, the bot should
#property strict #property version "1.00" #property description "EMA Trend + Pullback + Engulfing EA" // Include the standard MT5 trade library. #include <Trade/Trade.mqh> CTrade trade; //============================================================== // INPUT SETTINGS //============================================================== // Trend indicators input int FastEMA = 20; input int SlowEMA = 50; // Pullback
Title: Build a Semi-Automated MT5 Execution Assistant (MQL5) with Custom Panel Description: I am looking for an experienced MQL5 developer to build a semi-automated execution assistant for MetaTrader 5. I know this is a standard semi-automated panel with trade management. I am looking for a developer who has an existing GUI/panel library and standard trade management modules that can be adapted quickly. If you are
Trade copier EA 40+ USD
Develop a low-latency trade copier EA supporting MT4 and MT5 in all directions, across different brokers, with one master account copying to multiple follower accounts. Automatically adapt symbol names, price digits, contract sizes, and lot-size limits, with manual symbol mapping available. Support fixed lots, lot multipliers, and equity-proportional sizing. Synchronize market and pending orders, modifications
Hello, I’m looking for an experienced MQL5 developer to build a genuine ultra-fast HFT robot for MetaTrader 5, not a conventional scalping EA. The main instruments are EURUSD, BTCUSD, and XAUUSD. Requirements include fast execution, independent strategies, strict risk management, spread/slippage protection, separate optimization for each instrument, full MQ5 source code without a mandatory license lock, and detailed

Project information

Budget
100 - 110 USD
Deadline
to 5 day(s)