Expert Advisor Modification for MQL4

MQL4 Indicateurs Experts

Tâche terminée

Temps d'exécution 4 jours
Commentaires du client
Everything was all right. I am satisfied.

Spécifications

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


   
 
   
 




Dossiers :

Répondu

1
Développeur 1
Évaluation
(636)
Projets
1007
47%
Arbitrage
33
36% / 36%
En retard
99
10%
Travail
Publié : 6 codes
2
Développeur 2
Évaluation
(13)
Projets
31
23%
Arbitrage
8
25% / 63%
En retard
5
16%
Gratuit
3
Développeur 3
Évaluation
(174)
Projets
200
12%
Arbitrage
39
38% / 33%
En retard
5
3%
Gratuit
Publié : 2 codes
4
Développeur 4
Évaluation
(45)
Projets
46
24%
Arbitrage
34
9% / 85%
En retard
10
22%
Gratuit
5
Développeur 5
Évaluation
(61)
Projets
83
45%
Arbitrage
27
11% / 70%
En retard
8
10%
Gratuit
6
Développeur 6
Évaluation
(132)
Projets
178
39%
Arbitrage
4
25% / 50%
En retard
14
8%
Gratuit
7
Développeur 7
Évaluation
(574)
Projets
945
47%
Arbitrage
309
58% / 27%
En retard
125
13%
Gratuit
Commandes similaires
Hi, I want to develop a custom SMC (Smart Money Concepts) EA for MT5. My budget is $100. Here are the strategy requirements: 1. Auto identification of BOS, CHoCH, Order Blocks (OB), and FVG. 2. Auto entry when price returns to OB/FVG. 3. Auto SL above/below OB and TP based on Risk-to-Reward ratio (1:2, 1:3). 4. Risk Management (Risk % per trade or fixed lot size), Trailing Stop, Break-Even, and Max Spread filter. 5
I need an experienced MQL5 developer to build a prototype MT5 Expert Advisor called RiskLock. The software should enforce user-defined trading risk rules before trades are executed. It should support risk percentage or fixed monetary risk, calculate position size using account equity, entry price, stop loss, tick value and contract specifications, block or reduce oversized trades, and include daily loss limits
I need EA Lil-MeProBot for MT5. Phone user, deliver .mq5 + .ex5. Symbols: XAUUSD EURUSD GBPUSD USDJPY BTCUSD, M15, Magic 777001 Strategy 6X Confluence score 4/6: 1. EMA 50/200 trend 2. Break of Structure 3. RSI 14 4. Strong body FVG/Order Block 5. Session 8am-9pm GMT+2 6. ATR filter Money Management LASTING: Lot 0.01 fixed, NO martingale, NO grid, Max 1 per symbol Max 2 total, SL ATR*2 TP ATR*3, Daily loss R40 stop
Project Overview I have an existing MT5 Expert Advisor (EA) written in MQL5. The source code ( .mq5 ) will be provided. The underlying strategy is a trend-following system that performs well during trending market conditions, but requires professional quantitative research to improve its ability to identify and avoid highly sideways/range-bound market conditions. The objective of this project is not to build a new EA
I am looking for an experienced MQL5 Expert Advisor (EA) developer to analyze an existing trading setup and develop a similar automated trading robot. Project Overview I have access to a demo trading account where trades are being executed automatically. The trading results look very promising, but I do not know exactly what strategy, logic, indicators, or trade-management rules are being used. I will provide access
Most of the expert is already coded . Create a panel to show the Ratio for the Range . Trigger is based on ratio . Show Distribution / project starts after we clear Distribution
Modification of existing ea …. Add ema filter, add risk percentage per trade, and modify the pips per day filter. I already have the ea code I just need these things added and modifified
Expert Advisors 300+ USD
double CRiskManager::CalculateLotSize(double slPoints) { double balance = AccountInfoDouble(ACCOUNT_BALANCE); double riskMoney = balance * (m_riskPercent / 100.0); double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE); double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE); double pointValue = tickValue / tickSize; double lot = riskMoney / (slPoints * pointValue);
i share my strategy i need a bot trending bot fo mt5 . i attached the photo with this it help to make bot. it basicly 1 hours time frame base. i try but failed to make it
Title: Simple background trading bot for my Oanda account (v20 REST API) Overview Hi, I need a simple, lightweight event based standalone trading bot that connects directly to my Oanda account using broker’s standard REST API (V20 account) via VPS The bot just needs to look at group of 5 currency pairs (manually selectable and adjustable) in different 4 baskets, do some basic percentage math every period, and place

Informations sur le projet

Budget
100 - 110 USD
Délais
à 5 jour(s)