I have an indicator that doesn't work at the MT5 startup. It doesn't show nothing in the chart.
But, it works perfectly when I just add it to a chart, or when I switch timeframes.
What should be happening?
- Trading Systems Based on Signal Indicators
- Writing EAs for free on interesting strategies
- Update or delete line
The indicator uses the indicator buffers or drawing panel?
Thank you for the answers.
There is no errors in log files.
The indicator uses indcator buffers. Is a simple Pivot Point. If necessary I can share here the source code.
Leandro Tuchtenhagen :
Let's look at the code.
Thank you for the answers.
There is no errors in log files.
The indicator uses indcator buffers. Is a simple Pivot Point. If necessary I can share here the source code.
//+------------------------------------------------------------------+ //| PivotPoint.mq5 | //| Copyright 2015, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 7 #property indicator_plots 7 #property indicator_color1 Red #property indicator_color2 Red #property indicator_color3 Red #property indicator_color4 Orange #property indicator_color5 DodgerBlue #property indicator_color6 DodgerBlue #property indicator_color7 DodgerBlue //--- #property indicator_type1 DRAW_LINE #property indicator_type2 DRAW_LINE #property indicator_type3 DRAW_LINE #property indicator_type4 DRAW_LINE #property indicator_type5 DRAW_LINE #property indicator_type6 DRAW_LINE #property indicator_type7 DRAW_LINE //--- #property indicator_label1 "R3" #property indicator_label2 "R2" #property indicator_label3 "R1" #property indicator_label4 "Pivot Point" #property indicator_label5 "S1" #property indicator_label6 "S2" #property indicator_label7 "S3" enum ENUM_PIVOT_TYPE { CLASSIC3, // Classic Pivot HLC CLASSIC4, // Classic Pivot OHLC FIBONACCI, // Fibonacci Pivot CAMARILLA, // Camarilla Pivot WOODIES // Woodie's Pivot }; //--- external parameters input ENUM_PIVOT_TYPE PivotType = CLASSIC4; // Tipo de Pivot //---- buffers double PPBuffer[]; double S1Buffer[]; double R1Buffer[]; double S2Buffer[]; double R2Buffer[]; double S3Buffer[]; double R3Buffer[]; MqlDateTime dateStr1; MqlDateTime dateStr2; double PP,S1,R1,S2,R2,S3,R3; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping //--- indicator buffers mapping SetIndexBuffer(0,R3Buffer,INDICATOR_DATA); SetIndexBuffer(1,R2Buffer,INDICATOR_DATA); SetIndexBuffer(2,R1Buffer,INDICATOR_DATA); SetIndexBuffer(3,PPBuffer,INDICATOR_DATA); SetIndexBuffer(4,S1Buffer,INDICATOR_DATA); SetIndexBuffer(5,S2Buffer,INDICATOR_DATA); SetIndexBuffer(6,S3Buffer,INDICATOR_DATA); //--- sets first bar from what index will be drawn PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(6,PLOT_EMPTY_VALUE,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[]) { //--- int limit; if(prev_calculated == 0) limit = 0; else limit = prev_calculated - 1; double O, H, L, C, TO; //--- for(int i = limit; i < rates_total-1 && !IsStopped(); i++) { TimeToStruct(time[i],dateStr1); TimeToStruct(time[i+1],dateStr2); if (dateStr1.day != dateStr2.day) { MqlRates r[]; ArraySetAsSeries(r,true); CopyRates(_Symbol, PERIOD_D1, time[i+1], 2, r); O = r[1].open; H = r[1].high; L = r[1].low; C = r[1].close; TO = r[0].open; //Print ("O: ", O, " | H: ", H, " | L: ", L, " | C: ", C); CalculatePivotPoints(O, H, L, C, TO); } PPBuffer[i+1]=PP; S1Buffer[i+1]=S1; R1Buffer[i+1]=R1; S2Buffer[i+1]=S2; R2Buffer[i+1]=R2; S3Buffer[i+1]=S3; R3Buffer[i+1]=R3; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ void CalculatePivotPoints(double O, double H, double L, double C, double TO) { double R = H - L; switch(PivotType) { case CLASSIC3: PP = (C + H + L) / 3; R1 = (2*PP) - L; S1 = (2*PP) - H; R2 = PP + (R1 - S1); R3 = H + (2 * (PP - L)); S2 = PP - (R1 - S1); S3 = L - (2 * (H - PP)); break; case CLASSIC4: PP = (O + C + H + L) / 4; R1 = (2*PP) - L; S1 = (2*PP) - H; R2 = PP + (R1 - S1); R3 = H + (2 * (PP - L)); S2 = PP - (R1 - S1); S3 = L - (2 * (H - PP)); break; case FIBONACCI: PP = (C + H + L) / 3; R1 = PP + (0.382 * (H - L)); R2 = PP + (0.618 * (H - L)); R3 = PP + (1.000 * (H - L)); S1 = PP - (0.382 * (H - L)); S2 = PP - (0.618 * (H - L)); S3 = PP - (1.000 * (H - L)); break; case CAMARILLA: PP = (C + H + L) / 3; R1 = C + R * 1.1/12; R2 = C + R * 1.1/6; R3 = C + R * 1.1/4; S1 = C - R * 1.1/12; S2 = C - R * 1.1/6; S3 = C - R * 1.1/4; break; case WOODIES: PP = (H + L + (2*TO)) / 4; R1 = (2*PP) - L; R2 = PP + R; R3 = H + (2* (PP-L)); S1 = (2*PP) - H; S2 = PP - R; S3 = L - (2* (H-PP)); break; default: break; } }
I made some small changes: the order of Declaration of indicator buffers and output CopyRates:
//+------------------------------------------------------------------+ //| PivotPoint.mq5 | //| Copyright 2015, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 7 #property indicator_plots 7 #property indicator_color1 Red #property indicator_color2 Red #property indicator_color3 Red #property indicator_color4 Orange #property indicator_color5 DodgerBlue #property indicator_color6 DodgerBlue #property indicator_color7 DodgerBlue //--- #property indicator_type1 DRAW_LINE #property indicator_type2 DRAW_LINE #property indicator_type3 DRAW_LINE #property indicator_type4 DRAW_LINE #property indicator_type5 DRAW_LINE #property indicator_type6 DRAW_LINE #property indicator_type7 DRAW_LINE //--- #property indicator_label1 "R3" #property indicator_label2 "R2" #property indicator_label3 "R1" #property indicator_label4 "Pivot Point" #property indicator_label5 "S1" #property indicator_label6 "S2" #property indicator_label7 "S3" //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum ENUM_PIVOT_TYPE { CLASSIC3, // Classic Pivot HLC CLASSIC4, // Classic Pivot OHLC FIBONACCI, // Fibonacci Pivot CAMARILLA, // Camarilla Pivot WOODIES // Woodie's Pivot }; //--- external parameters input ENUM_PIVOT_TYPE PivotType=CLASSIC4; // Tipo de Pivot //---- buffers double R3Buffer[]; double R2Buffer[]; double R1Buffer[]; double PPBuffer[]; double S1Buffer[]; double S2Buffer[]; double S3Buffer[]; MqlDateTime dateStr1; MqlDateTime dateStr2; double PP,S1,R1,S2,R2,S3,R3; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping //--- indicator buffers mapping SetIndexBuffer(0,R3Buffer,INDICATOR_DATA); SetIndexBuffer(1,R2Buffer,INDICATOR_DATA); SetIndexBuffer(2,R1Buffer,INDICATOR_DATA); SetIndexBuffer(3,PPBuffer,INDICATOR_DATA); SetIndexBuffer(4,S1Buffer,INDICATOR_DATA); SetIndexBuffer(5,S2Buffer,INDICATOR_DATA); SetIndexBuffer(6,S3Buffer,INDICATOR_DATA); //--- sets first bar from what index will be drawn PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(6,PLOT_EMPTY_VALUE,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[]) { //--- int limit; if(prev_calculated==0) limit=0; else limit=prev_calculated-1; double O,H,L,C,TO; //--- for(int i=limit; i<rates_total-1 && !IsStopped(); i++) { TimeToStruct(time[i],dateStr1); TimeToStruct(time[i+1],dateStr2); if(dateStr1.day!=dateStr2.day) { MqlRates r[]; ArraySetAsSeries(r,true); int copied=CopyRates(_Symbol,PERIOD_D1,time[i+1],2,r); if(copied>0) { O = r[1].open; H = r[1].high; L = r[1].low; C = r[1].close; TO= r[0].open; //Print ("O: ", O, " | H: ", H, " | L: ", L, " | C: ", C); CalculatePivotPoints(O,H,L,C,TO); } else Print("Failed to get history data for the symbol ",Symbol()); } PPBuffer[i+1]=PP; S1Buffer[i+1]=S1; R1Buffer[i+1]=R1; S2Buffer[i+1]=S2; R2Buffer[i+1]=R2; S3Buffer[i+1]=S3; R3Buffer[i+1]=R3; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CalculatePivotPoints(double O,double H,double L,double C,double TO) { double R=H-L; switch(PivotType) { case CLASSIC3: PP = (C + H + L) / 3; R1 = (2*PP) - L; S1 = (2*PP) - H; R2 = PP + (R1 - S1); R3 = H + (2 * (PP - L)); S2 = PP - (R1 - S1); S3 = L - (2 * (H - PP)); break; case CLASSIC4: PP = (O + C + H + L) / 4; R1 = (2*PP) - L; S1 = (2*PP) - H; R2 = PP + (R1 - S1); R3 = H + (2 * (PP - L)); S2 = PP - (R1 - S1); S3 = L - (2 * (H - PP)); break; case FIBONACCI: PP = (C + H + L) / 3; R1 = PP + (0.382 * (H - L)); R2 = PP + (0.618 * (H - L)); R3 = PP + (1.000 * (H - L)); S1 = PP - (0.382 * (H - L)); S2 = PP - (0.618 * (H - L)); S3 = PP - (1.000 * (H - L)); break; case CAMARILLA: PP = (C + H + L) / 3; R1 = C + R * 1.1/12; R2 = C + R * 1.1/6; R3 = C + R * 1.1/4; S1 = C - R * 1.1/12; S2 = C - R * 1.1/6; S3 = C - R * 1.1/4; break; case WOODIES: PP = (H + L + (2*TO)) / 4; R1 = (2*PP) - L; R2 = PP + R; R3 = H + (2* (PP-L)); S1 = (2*PP) - H; S2 = PP - R; S3 = L - (2* (H-PP)); break; default: break; } } //+------------------------------------------------------------------+
Now you can see where the error occurs.
Thank you for your help.
Still not working, and show no errors.
I'll leave anyway. I had given up, anyway.You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register