Help with indicator programing from MT4 – Moving average histogram
Forums › ProRealTime English forum › ProBuilder support › Help with indicator programing from MT4 – Moving average histogram
- This topic has 4 replies, 2 voices, and was last updated 7 years ago by
mikael.
-
-
09/04/2017 at 4:37 PM #45398
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;
}
//+——————————————————————+09/04/2017 at 4:56 PM #4540209/05/2017 at 10:26 AM #4546109/08/2017 at 8:11 AM #45775Fine, here is the code of this indicator converted to probuilder:
12345678910111213141516171819// https://www.prorealcode.com/topic/help-with-indicator-programing-from-mt4/PMA = 100 // Period Moving AverageMMM = 0 // Method Moving AverageMAP = customclose // Price for Moving AveragePSMA = 5 // Period Signal Moving AverageMA1 = average[PMA,MMM](MAP)MA2 = average[PSMA](MA1)if MA1>MA2 thenup = 1dn = 0elsif MA1<MA2 thendn = 1up = 0endifRETURN up coloured(65,105,225) style(histogram) as "up", dn coloured(255,0,255) style(histogram) as "dn"Tell us if it is similar to the original one!
09/11/2017 at 7:09 AM #45913 -
AuthorPosts
Find exclusive trading pro-tools on