Thats a bug, have the same problem
Do you really expect an answer with the information you've provided? There are no mind readers here and our crystal balls are cracked. We can't
see your broken code.
William Roeder:
Do you really expect an answer with the information you've provided? There are no mind readers here and our crystal balls are cracked. We can't see your broken code.
Do you really expect an answer with the information you've provided? There are no mind readers here and our crystal balls are cracked. We can't see your broken code.
some example:
//+------------------------------------------------------------------+ //| SpreadT.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 3 //--- plot Label1 #property indicator_label1 "Label1" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Label2 #property indicator_label2 "Label2" #property indicator_type2 DRAW_LINE #property indicator_color2 clrRed #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot Label3 #property indicator_label3 "Label3" #property indicator_type3 DRAW_LINE #property indicator_color3 clrRed #property indicator_style3 STYLE_SOLID #property indicator_width3 1 #include <Trade\SymbolInfo.mqh> //--- indicator buffers double Label1Buffer[]; double Label2Buffer[]; double Label3Buffer[]; MqlRates rates1[],rates2[]; int Dstart=0; double ratio=1; input string currency2="GBPUSD"; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA); SetIndexBuffer(1,Label2Buffer,INDICATOR_DATA); SetIndexBuffer(2,Label3Buffer,INDICATOR_DATA); int op=Bars(currency2,Period()); CSymbolInfo m_symbol(); m_symbol.Name(Symbol()); // sets symbol name m_symbol.RefreshRates(); double t1=m_symbol.Bid(); m_symbol.Name(currency2); // sets symbol name m_symbol.RefreshRates(); double t2=m_symbol.Bid(); ratio=t1/t2; Print("Ratio:"+ratio); //--- 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; MqlDateTime str; ResetLastError(); for(int i=limit; i<rates_total && !IsStopped(); i++) { //TimeToStruct(time[limit],str); datetime start=time[i]; datetime end=time[rates_total-1]; int copied2,copied; int op=Bars(currency2,Period(),start,end); copied2=CopyRates(currency2,Period(),start,1,rates2); if(copied2<1 && i>1) { //Print("0 copied"); // Label1Buffer[i]=Label1Buffer[i-1]; // Label2Buffer[i]=Label1Buffer[i]; // Label3Buffer[i]=Label1Buffer[i]; //Print(__FUNCTION__+", Error Code = ",GetLastError()); continue; } else if( ArraySize(rates2)==0) { // Print("0 rates2 size"); continue; } else if(rates2[0].close ==0) { // Print("rates2[0].close==0"); continue; } else { if(prev_calculated==0 && i==limit) { //ArrayFill(Label1Buffer,0,rates_total,close[i]/rates2[0].close); //ArrayFill(Label2Buffer,0,rates_total,close[i]); //ArrayFill(Label3Buffer,0,rates_total,close[i]); } //Print(__FUNCTION__+", Error Code = ",GetLastError()); //Label2Buffer[i]=rates2[0].close; Label1Buffer[i]=close[i]/(ratio*rates2[0].close); Label2Buffer[i]=Label1Buffer[i]; Label3Buffer[i]=Label1Buffer[i]; //if(GetLastError()!=0) // Print(__FUNCTION__+"c:"+i+", Error Code = ",GetLastError()); } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
//+------------------------------------------------------------------+ //| LRCh.mq5 | //| Vladimir M. | //| mikh.vl@gmail.com | //+------------------------------------------------------------------+ #property copyright "Vladimir M." #property link "mikh.vl@gmail.com" #property version "1.00" #property description "Linear Regression Channel" #property indicator_chart_window #property indicator_buffers 5 #property indicator_plots 5 #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_style1 STYLE_SOLID #property indicator_style2 STYLE_DOT #property indicator_style3 STYLE_DOT #property indicator_style4 STYLE_DOT #property indicator_style5 STYLE_DOT #property indicator_color1 Blue #property indicator_color2 Yellow #property indicator_color3 Yellow #property indicator_color4 Red #property indicator_color5 Red #property indicator_applied_price PRICE_CLOSE //--- input params input int InChPeriod = 150; //Channel Period int ExChPeriod,rCount; //---- buffers double rlBuffer[],upBuffer[],downBuffer[],highBuffer[],lowBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- check input variables int BarsTotal; BarsTotal=Bars(_Symbol,PERIOD_CURRENT); if(InChPeriod<2) { ExChPeriod=2; printf("Incorrect input value InChPeriod=%d. Indicator will use InChPeriod=%d.", InChPeriod,ExChPeriod); } else if(InChPeriod>=BarsTotal) { ExChPeriod=BarsTotal-1; printf("Total Bars=%d. Incorrect input value InChPeriod=%d. Indicator will use InChPeriod=%d.", BarsTotal,InChPeriod,ExChPeriod); } else ExChPeriod=InChPeriod; SetIndexBuffer(0,rlBuffer,INDICATOR_DATA); SetIndexBuffer(1,upBuffer,INDICATOR_DATA); SetIndexBuffer(2,downBuffer,INDICATOR_DATA); SetIndexBuffer(3,highBuffer,INDICATOR_DATA); SetIndexBuffer(4,lowBuffer,INDICATOR_DATA); PlotIndexSetString(0,PLOT_LABEL,"Main Line("+string(ExChPeriod)+")"); PlotIndexSetString(1,PLOT_LABEL,"Up Line("+string(ExChPeriod)+")"); PlotIndexSetString(2,PLOT_LABEL,"Down Line("+string(ExChPeriod)+")"); PlotIndexSetString(3,PLOT_LABEL,"High Line("+string(ExChPeriod)+")"); PlotIndexSetString(4,PLOT_LABEL,"Low Line("+string(ExChPeriod)+")"); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { double sumX,sumY,sumXY,sumX2,a,b,F,S; int X; //--- check for bars count if(rates_total<ExChPeriod+1)return(0); //--- if new bar set, calculate if(rCount!=rates_total) { PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,rates_total-ExChPeriod-1); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,rates_total-ExChPeriod-1); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,rates_total-ExChPeriod-1); PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,rates_total-ExChPeriod-1); PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,rates_total-ExChPeriod-1); //--- calculate coefficient a and b of equation linear regression F=0.0; S=0.0; sumX=0.0; sumY=0.0; sumXY=0.0; sumX2=0.0; X=0; for(int i=rates_total-1-ExChPeriod;i<rates_total-1;i++) { sumX+=X; sumY+=price[i]; sumXY+=X*price[i]; sumX2+=MathPow(X,2); X++; } a=(sumX*sumY-ExChPeriod*sumXY)/(MathPow(sumX,2)-ExChPeriod*sumX2); b=(sumY-a*sumX)/ExChPeriod; //--- calculate values of main line and error F X=0; for(int i=rates_total-1-ExChPeriod;i<rates_total;i++) { rlBuffer[i]=b+a*X; F+=MathPow(price[i]-rlBuffer[i],2); X++; } //--- calculate deviation S S=NormalizeDouble(MathSqrt(F/(ExChPeriod+1))/MathCos(MathArctan(a*M_PI/180)*M_PI/180),_Digits); //--- calculate values of last buffers for(int i=rates_total-1-ExChPeriod;i<rates_total;i++) { upBuffer[i]=rlBuffer[i]+S; downBuffer[i]=rlBuffer[i]-S; highBuffer[i]=rlBuffer[i]+2*S; lowBuffer[i]=rlBuffer[i]-2*S; } rCount=rates_total; } return(rates_total); } //+------------------------------------------------------------------+
amando:
Thats a bug, have the same problem
Thats a bug, have the same problem
I dunno, I am still waiting for a tips/clarification.
This problem really bothers me
Marco Montemari: some example:
In both cases you use the passed arrays, and buffers, without setting as-series or not.
To determine the indexing direction of time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[], call
ArrayGetAsSeries(). In order not to depend on default values, you should unconditionally call the ArraySetAsSeries() function for
those arrays, which are expected to work with.
Language Basics / Functions / Event Handling Functions - Reference on algorithmic/automated trading language for MetaTrader 5
Language Basics / Functions / Event Handling Functions - Reference on algorithmic/automated trading language for MetaTrader 5
William Roeder:
In both cases you use the passed arrays, and buffers, without setting as-series or not.
So you mean using ArraySetAsSeries will solve my problem...Ok I will try.
Thanks for your help.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Hi guys,
sometime I need to change TF to show the indicator.
It seems it does not load or laod partially.
Should I preload in On init function or what?
I am struggling with this issue. Any tips?