Hi can anyone help me with translate a code from MT4 to PRT? It’s an Moving average histogram.
Best Regards Mikael
Here is the code:
#property strict
#include <MovingAverages.mqh>
//— indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 clrDodgerBlue
#property indicator_color2 clrHotPink
#property indicator_width1 4
#property indicator_width2 4
#property indicator_minimum -0.05
#property indicator_maximum 1.05
//— indicator parameters
extern int PMA = 100; // Period Moving Average
extern ENUM_MA_METHOD MMM = MODE_SMA; // Method Moving Average
extern ENUM_APPLIED_PRICE MAP = PRICE_CLOSE; // Price for Moving Average
extern int PSMA = 5; // Period Signal Moving Average
//— indicator buffers
double MA1[];
double MA2[];
double UP[];
double DN[];
//— right input parameters flag
bool ExtParameters=false;
//+——————————————————————+
//+——————————————————————+
//+——————————————————————+
int OnInit(void)
{
//— 2 additional buffers are used for counting.
IndicatorBuffers(4);
//— drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexDrawBegin( 0, PMA + PSMA);
SetIndexDrawBegin( 1, PMA + PSMA);
IndicatorDigits(Digits+2);
//— 4 indicator buffers mapping
SetIndexBuffer( 0, UP);
SetIndexBuffer( 1, DN);
SetIndexBuffer( 2, MA1);
SetIndexBuffer( 3, MA2);
//— name for DataWindow and indicator subwindow label
IndicatorShortName(“MAOMAH(“+IntegerToString(PMA)+”,”+IntegerToString(PSMA)+”)”);
//— check for input parameters
if(PMA<=1 || PSMA<=1)
{
Print(“Wrong input parameters”);
ExtParameters=false;
return(INIT_FAILED);
}
else
ExtParameters=true;
//— initialization done
return(INIT_SUCCEEDED);
}
//+——————————————————————+
//+——————————————————————+
//+——————————————————————+
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<=PMA + PSMA || !ExtParameters)
return(0);
//— last counted bar will be recounted
limit=rates_total-prev_calculated-1;
if(prev_calculated>0)
limit++;
for( i = limit; i >= 0; i–)
MA1[i] = iMA( NULL, 0, PMA, 0, MMM, MAP, i );
SimpleMAOnBuffer(rates_total,prev_calculated,0,PSMA,MA1,MA2);
for( i = limit-1; i >= 0; i–)
{
UP[i]=0.0;
DN[i]=0.0;
if( MA1[i] > MA2[i])
UP[i]=1.0;
else
if( MA1[i] < MA2[i])
DN[i]=1.0;
else
{
UP[i]=UP[i+1];
DN[i]=DN[i+1];
}
}
return rates_total;
}
//+——————————————————————+