Expert Advisor Modification for MQL4

MQL4 Indicadores Experts

Trabalho concluído

Tempo de execução 4 dias
Comentário do cliente
Everything was all right. I am satisfied.

Termos de Referência

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


   
 
   
 




Arquivos anexados:

Respondido

1
Desenvolvedor 1
Classificação
(636)
Projetos
1007
47%
Arbitragem
33
36% / 36%
Expirado
99
10%
Trabalhando
Publicou: 6 códigos
2
Desenvolvedor 2
Classificação
(13)
Projetos
31
23%
Arbitragem
8
25% / 63%
Expirado
5
16%
Livre
3
Desenvolvedor 3
Classificação
(174)
Projetos
200
12%
Arbitragem
39
38% / 33%
Expirado
5
3%
Livre
Publicou: 2 códigos
4
Desenvolvedor 4
Classificação
(45)
Projetos
46
24%
Arbitragem
34
9% / 85%
Expirado
10
22%
Livre
5
Desenvolvedor 5
Classificação
(61)
Projetos
83
45%
Arbitragem
27
11% / 70%
Expirado
8
10%
Livre
6
Desenvolvedor 6
Classificação
(132)
Projetos
178
39%
Arbitragem
4
25% / 50%
Expirado
14
8%
Livre
7
Desenvolvedor 7
Classificação
(574)
Projetos
945
47%
Arbitragem
309
58% / 27%
Expirado
125
13%
Livre
Pedidos semelhantes
I DO NOT need any programming or strategy development. I already have a working NinjaTrader 8 automated strategy based on a 3/5 EMA crossover. I need you to run my existing strategy through NinjaTrader Strategy Analyzer/Optimizer, test the existing adjustable parameters, and find robust settings with the best profit factor and lowest reasonable drawdown. I will provide the existing NinjaScript ZIP. I do not want the
Mr quetta 100+ USD
Yes, that is exactly what I need. The bot should not be restricted to a fixed list of currency pairs. It should technically scan all available Quotex pairs in real time and automatically select the pair where the market conditions are strongest. The bot should analyze each pair using multiple confirmations, such as short-term price momentum, trend direction, market structure, support/resistance, candle formation
Platform: TradingView Programming Language: Pine Script v6 Type: Custom Indicator Project Name: Scalping Reaction Zones + Valid Order Blocks MAIN GOAL I need a custom TradingView indicator for scalping. The indicator must detect: 1. Reaction / Explosion Zones 2. Valid Order Blocks 3. Combined Reaction Zone + Order Block zones The indicator should NOT generate: Buy signals Sell signals TP SL Entry signals Trading
Project Description I am looking for an experienced MQL5/MT5 Expert Advisor developer to develop an automated trading EA for XAUUSD on the M3 timeframe , running on an Exness account . The EA will automate a manual strategy based on SNR/GAP zones , using two setup types: Price Rejection Price Correction The EA should identify valid BUY/SELL setups around predefined SNR/GAP areas, apply configurable RSI, SMA, EMA and
Indicador Maximas e Minimas + Super Trend O Indicador MAX/MIN é um indicador de análise técnica para o MetaTrader 5 , desenvolvido para ajudar você a identificar regiões importantes de preço e possíveis oportunidades de compra e venda. O que ele faz MAX/MIN: identifica máximas e mínimas relevantes do mercado e mostra os preços no gráfico. HH / HL / LH / LL: ajuda a visualizar a estrutura do mercado, mostrando quando
Hello Traders, Have a trading strategy or idea you want to automate? I specialize exclusively in MQL5 development, helping traders turn their concepts into professional trading solutions. Custom Expert Advisors — automate your strategy and reduce manual execution Custom Indicators — transform your market ideas into powerful trading tools Fix & Debug — identify errors and get your existing code working properly
I DO NOT need any programming or strategy development. I already have a working NinjaTrader 8 automated strategy based on a 3/5 EMA crossover. I need you to run my existing strategy through NinjaTrader Strategy Analyzer/Optimizer, test the existing adjustable parameters, and find robust settings with the best profit factor and lowest reasonable drawdown. I will provide the existing NinjaScript ZIP. I do not want the
I'm looking for an experienced developer to create an automated gold trading bot. The bot should be compatible with MetaTrader 4/5 and TradingView. Key Requirements: - Automated trading bot - Compatible with MetaTrader 4/5 and TradingView - Implement scalping and swing trading strategies Ideal Skills and Experience: - Proficiency in trading algorithms - Experience with gold trading - Familiarity with MetaTrader and
I need a robust optimization of my MT5 EA, mainly for XAUUSD (Gold). Please optimize the existing adjustable parameters such as entry/exit settings, SL/TP, trailing/break-even settings, and any other strategy parameters that are appropriate. I want the optimization focused on stable profitability, low/moderate drawdown, and robustness rather than simply the highest possible profit. Please use out-of-sample testing
NinjaTrader 8 / NinjaScript Phase 1 build: convert an existing Auction Market Theory (AMT) strategy into objective, alert-only decision-support logic. Not a bot, no auto-execution — trades stay manual. Covers NQ/MNQ, ES, CL, MGC using 30-min TPO/Volume Profile context with 5-min confirmation: one 5-min close outside VAH/VAL = acceptance, close back inside = rejection. Dashboard shows bias, auction state, location

Informações sobre o projeto

Orçamento
100 - 110 USD
Prazo
para 5 dias