Expert Advisor Modification for MQL4

MQL4 Indicadores Asesores Expertos

Trabajo finalizado

Plazo de ejecución 4 días
Comentario del Cliente
Everything was all right. I am satisfied.

Tarea técnica

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
   
    }   
 
  }


   
 
   
 




Archivos adjuntos:

Han respondido

1
Desarrollador 1
Evaluación
(636)
Proyectos
1008
47%
Arbitraje
33
36% / 36%
Caducado
99
10%
Trabaja
Ha publicado: 6 ejemplos
2
Desarrollador 2
Evaluación
(13)
Proyectos
31
23%
Arbitraje
8
25% / 63%
Caducado
5
16%
Libre
3
Desarrollador 3
Evaluación
(174)
Proyectos
200
12%
Arbitraje
39
38% / 33%
Caducado
5
3%
Libre
Ha publicado: 2 ejemplos
4
Desarrollador 4
Evaluación
(45)
Proyectos
46
24%
Arbitraje
34
9% / 85%
Caducado
10
22%
Libre
5
Desarrollador 5
Evaluación
(61)
Proyectos
83
45%
Arbitraje
27
11% / 70%
Caducado
8
10%
Libre
6
Desarrollador 6
Evaluación
(132)
Proyectos
178
39%
Arbitraje
4
25% / 50%
Caducado
14
8%
Libre
7
Desarrollador 7
Evaluación
(574)
Proyectos
945
47%
Arbitraje
309
58% / 27%
Caducado
125
13%
Libre
Solicitudes similares
Hello I want some that can help with my strategy signal I have the video that you are going to watch if you know you can help me with kindly do well to bid and let discussed it an urgent project and also if you can not work before you get paid please don bid thanks
Existing EA: NEW_CORE_ORB_M5_v021 | MT5 | XAUUSD M5 Early-stage research prototype, not a new EA from scratch. Need an experienced MQL5 developer to audit, complete, repair, improve and test BOTH independent strategies equally: Opening Range Breakout (ORB) and Scalp. Keep code lightweight and preserve an untouched baseline. No unnecessary rewrite or complex filters. 1. ORB Strategy Verify opening-range construction
i need an expert to develop Bot TO trade using MT5 with a profitable strategy ... work daily with good indicators the price will be negotiable will try the bot first after we can decide
The indicator should identify the high and low of two configurable trading sessions, draw their levels on the chart, and generate reliable breakout alerts. 1. Session Settings Symbol: Current chart symbol (EURUSD for testing). Timeframe: M5. Two independent sessions: Session A: 08:00–10:00 Session B: 13:00–15:00 All times use MT5 broker server time. Start and end times must be configurable. The indicator should
Project: Convert TradingView Indicator to MT4 We are looking for an experienced MQL4 developer to convert a high-quality TradingView indicator into a MetaTrader 4 (MT4) indicator. Indicator Details: The TradingView indicator generates buy and sell arrows for trade entries. It is non-repainting, has no lag, and is highly reliable. Arrows appear only after the candle closes and remain visible permanently. Requirements
Hi, I need NinjaTrader 8 Strategy Analyzer backtests on two of my strategies, each over 1 year AND 3 years of data. Please quote the full job. Common settings: NT8 Strategy Analyzer, MCL (Micro WTI Crude Oil) continuous front-month contract (MCL ##-##), 5-minute bars, 1yr + 3yr of the most recent data, $2.50 round-turn commission per contract. Deliverables per run: full Strategy Analyzer summary (net profit, profit
Project Overview: I am looking for an experienced MQL5 developer to convert a suite of 6 custom MT4 indicators into native, fully optimized MQL5 (.mq5) indicators. I will provide the uncompiled .mq4 source files for all seven tools upon hiring. The indicators must compile cleanly in MetaEditor for MT5 without errors or critical warnings, function correctly together on a multi-timeframe chart setup (specifically
Custom MT5 Expert Advisor (EA) Development | MQL5 Automation Turn Your Trading Strategy into a Powerful Automated Trading System! Are you looking for a professional MT5 Expert Advisor developer to automate your trading strategy? I specialize in developing custom MetaTrader 5 (MT5) Expert Advisors and indicators using MQL5 , tailored to your trading rules, risk management preferences, and trading goals. Whether you
I am looking for an experienced MQL5 developer or development team to build a scalable Telegram-to-MT5 copy trading system. The main purpose of the system is to monitor trading signals from my Telegram channel and automatically execute those signals on connected client MT5 accounts. Core Requirements Receive and parse trading signals from Telegram Automatically execute trades on connected MT5 accounts Support more
Thana ram 30 - 200 USD
Hello, I want to develop a custom MT5 Expert Advisor (EA) for XAUUSD Gold. IMPORTANT: I want a proper rule-based automated trading EA, NOT a martingale, grid or guaranteed-profit bot. 1. MARKET & TIMEFRAME - Platform: MT5 - Symbol: XAUUSD only - Main trend timeframe: M15 - Entry timeframe: M5 - Must support broker suffixes such as XAUUSDm, XAUUSD., etc. 2. TREND RULE BUY trend: - M15 price above EMA 50 - EMA 50 above

Información sobre el proyecto

Presupuesto
100 - 110 USD
Plazo límite de ejecución
a 5 día(s)