Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 232

 
Rustam Bikbulatov:
Second. The command to open an order

It doesn't make any sense. What does it have to do with a market order? Maybe it is the indicator call? Then modify the indicator and call it using iCustom instead of iMACD.

Maybe, there is no need to modify anything at all, the kodobase is full of goodies.

 
Vitalie Postolache:

It doesn't make any sense. What does it have to do with a market order? Maybe it is the indicator call? Then modify the indicator and call it using iCustom instead of iMACD.

Maybe I do not need to modify anything, the kodobase is full of goodies.


I tried it via iCustom but it works slowly. I tried it viaiMAOnArray but had a problem with arrays. I had a couple of days trying to bind all the arrays together. It's easier to make iMACD but that's the question

 
Rustam Bikbulatov:

I tried iCustom, but it works slowly. TriediMAOnArray, but there's a problem with arrays. Couldn't bind everything together for a couple of days. It's easier to makeiMACD, but that's the question.


You can't, standard iMACD calculates the signal line using the SMA formula, only custom will help.

 
Vitalie Postolache:

No way, the standard iMACD calculates the signal line using the SMA formula, only custom will help.


Ok, I figured out that it's impossible to do that. thanks a lot for the info

 
Rustam Bikbulatov:

I've realised it's impossible. Thank you very much for the info.


Nothing is impossible, we just need to widen the scope a bit ))))

 
Rustam Bikbulatov:

That's it, I realised it's not possible. thanks a lot for the info

Here is the code of the standard MACD

//+------------------------------------------------------------------+
//|                                                  Custom MACD.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Moving Averages Convergence/Divergence"
#property strict

#include <MovingAverages.mqh>

//--- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property   indicator_color1  Silver
#property   indicator_color2  Red
#property   indicator_width1  2
//--- indicator parameters
input int InpFastEMA=12;   // Fast EMA Period
input int InpSlowEMA=26;   // Slow EMA Period
input int InpSignalSMA=9;  // Signal SMA Period
//--- indicator buffers
double    ExtMacdBuffer[];
double    ExtSignalBuffer[];
//--- right input parameters flag
bool      ExtParameters=false;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   IndicatorDigits(Digits+1);
//--- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexDrawBegin(1,InpSignalSMA);
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtMacdBuffer);
   SetIndexBuffer(1,ExtSignalBuffer);
//--- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD("+IntegerToString(InpFastEMA)+","+IntegerToString(InpSlowEMA)+","+IntegerToString(InpSignalSMA)+")");
   SetIndexLabel(0,"MACD");
   SetIndexLabel(1,"Signal");
//--- check for input parameters
   if(InpFastEMA<=1 || InpSlowEMA<=1 || InpSignalSMA<=1 || InpFastEMA>=InpSlowEMA)
     {
      Print("Wrong input parameters");
      ExtParameters=false;
      return(INIT_FAILED);
     }
   else
      ExtParameters=true;
//--- initialization done
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,
                 const int prev_calculated,
                 const datetime& time[],
                 const double& open[],
                 const double& high[],
                 const double& low[],
                 const double& close[],
                 const long& tick_volume[],
                 const long& volume[],
                 const int& spread[])
  {
   int i,limit;
//---
   if(rates_total<=InpSignalSMA || !ExtParameters)
      return(0);
//--- last counted bar will be recounted
   limit=rates_total-prev_calculated;
   if(prev_calculated>0)
      limit++;
//--- macd counted in the 1-st buffer
   for(i=0; i<limit; i++)
      ExtMacdBuffer[i]=iMA(NULL,0,InpFastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
                    iMA(NULL,0,InpSlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//--- signal line counted in the 2-nd buffer
   SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
   //ExponentialMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
//--- done
   return(rates_total);
  }
//+------------------------------------------------------------------+

The line marked in pink I have added.

If I uncomment the line marked in pink and comment out the line marked in green, the MACD should be calculated using all exponential MACDs.

 
Artyom Trishkin:

Here is the code for the standard MACD

The line marked in pink I added.

If I uncomment the line marked pink and comment out the line marked green, the MACD should be calculated using all exponential MACDs.


The question was how to do it in the EA. The EAautomatically calculatesusing the SMA formula

 
Rustam Bikbulatov:

The question was how to do this in the EA. The EAautomatically calculates theSMA using the formula

I showed you how to make a custom MACD.

That is what you should use in your Expert Advisor through iCustom()

 
Artyom Trishkin:

I showed you how to make a custom MACD.

That is what you should use in your Expert Advisor via iCustom()


I have a lot of data and the bush is slowing down. I've already tried it. It's affecting the results. Thanks anyway.

 
Rustam Bikbulatov:

I have a lot of data and the bush is slowing down. I've already tried it. It's affecting the results. Thanks all the same.

Check your settings, maybe you have too many bars to display, hence the lags.