G-channel indicator MT5 conversion
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
- www.mql5.com
Converting original mql4 files.
SetIndexBuffer(0,UpperBuffer,INDICATOR_DATA); SetIndexBuffer(1,LowerBuffer,INDICATOR_DATA); SetIndexBuffer(2,MiddleBuffer,INDICATOR_DATA); SetIndexBuffer(3,aBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(4,bBuffer,INDICATOR_CALCULATIONS); ArraySetAsSeries(UpperBuffer, true); ArraySetAsSeries(LowerBuffer, true); ArraySetAsSeries(MiddleBuffer, true); ArraySetAsSeries(aBuffer, true); ArraySetAsSeries(bBuffer, true); for(int i = 0; i <= 5; i++) PlotIndexSetDouble(i,PLOT_EMPTY_VALUE, 0.0); for(int i = 3; i <= 5; i++) PlotIndexSetString(i,PLOT_LABEL, "");
double getPrice(ENUM_APPLIED_PRICE tprice, const double &open[], const double &close[], const double &high[], const double &low[], int i) { ArraySetAsSeries(open, true); ArraySetAsSeries(high, true); ArraySetAsSeries(low, true); ArraySetAsSeries(close, true); if(i >= 0) switch(tprice)
Hi all,
I am a beginner and I'm trying to port in MQL5 an indicator I know in Pinescript and MQL4, the G-Channel made by god coder Alex Grover.
I think I've done all I had to, but the indicators doesn't work as it should...
Here is the code:
Any help or suggestions?
Thanks
Hi
Try this :
#property copyright "5 minute warm up inc." #property version "1.00" #property indicator_chart_window #property indicator_buffers 3 #property indicator_plots 3 //--- plot a #property indicator_label1 "a" #property indicator_type1 DRAW_LINE #property indicator_color1 clrLightCoral #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot b #property indicator_label2 "b" #property indicator_type2 DRAW_LINE #property indicator_color2 clrMediumSeaGreen #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot baseline #property indicator_label3 "baseline" #property indicator_type3 DRAW_LINE #property indicator_color3 clrWhite #property indicator_style3 STYLE_SOLID #property indicator_width3 1 input int Length=100;//length input ENUM_APPLIED_PRICE Price=PRICE_CLOSE;//Price //--- indicator buffers double a[]; double b[]; double baseline[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,a,INDICATOR_DATA); SetIndexBuffer(1,b,INDICATOR_DATA); SetIndexBuffer(2,baseline,INDICATOR_DATA); PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0); ArrayFill(a,0,ArraySize(a),0.0); ArrayFill(b,0,ArraySize(b),0.0); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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[]) { //--- //the open high low close etc are indexed from [0] right most //the index buffers are indexed from [0] left most for(int i=prev_calculated;i<rates_total;i++){ //the previous index in buffers : i-1 int prev_buffer_index=i-1; //is the calculation viable ? if(prev_buffer_index>=0){ double le_price=get_price(Price,open,high,low,close,i); a[i]=MathMax(le_price,a[prev_buffer_index])-((a[prev_buffer_index]-b[prev_buffer_index])/((double)Length)); b[i]=MathMin(le_price,b[prev_buffer_index])+((a[prev_buffer_index]-b[prev_buffer_index])/((double)Length)); baseline[i]=(a[i]+b[i])/((double)2.00); } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ double get_price(ENUM_APPLIED_PRICE price, const double &open[], const double &high[], const double &low[], const double &close[], int i){ if(price==PRICE_CLOSE){ return(close[i]); } else if(price==PRICE_HIGH){ return(high[i]); } else if(price==PRICE_LOW){ return(low[i]); } else if(price==PRICE_OPEN){ return(open[i]); } else if(price==PRICE_MEDIAN){ return((high[i]+low[i])/((double)2.00)); } else if(price==PRICE_TYPICAL){ return((high[i]+low[i]+close[i])/((double)3.00)); } else if(price==PRICE_WEIGHTED){ return((high[i]+low[i]+close[i]+close[i])/((double)4.00)); } return(0.0); }
Thanks @Lorentzos Roussos , it works!
Now I'm gonna study why it works :-D
Awesome , feel free to axe anything here if you need to
Hi all,
I am a beginner and I'm trying to port in MQL5 an indicator I know in Pinescript and MQL4, the G-Channel made by god coder Alex Grover.
I think I've done all I had to, but the indicators doesn't work as it should...
Here is the code:
Any help or suggestions?
Thanks