#property copyright "user" #property version "1.00" #property strict #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 //--- plot line #property indicator_label1 "line" #property indicator_type1 DRAW_LINE #property indicator_color1 clrBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 2 //--- indicator buffers double line[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping #ifdef __MQL5__ ArraySetAsSeries(line,true); #endif SetIndexBuffer(0,line); //--- 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[]) { //--- #ifdef __MQL5__ ArraySetAsSeries(open,true); #endif int limit = prev_calculated==0 || prev_calculated>rates_total ? rates_total-10 : rates_total-prev_calculated; if(limit==0) limit++; for(int i=0;i<limit;i++) { line[i]=open[i]; if(0<1) { if(line[i]>line[i+10]) { line[i]=open[i]; } else { if(open[i]>open[i+5]) { line[i]=line[i+1]; } } } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { //--- } //+------------------------------------------------------------------+
What is it
if(0<1)
Zero is always less than one. Why is this necessary???
Thank you for the answer!
But the problem is still there, the blue line has many gaps when plotted first. It will only get all the missing values after many ticks. How to get all values plotted at once?
Thank you for the answer!
But the problem is still there, the blue line has many gaps when plotted first. It will only get all the missing values after many ticks. How to get all values plotted at once?
Of course that it has many gaps when you are trying to read future values of open (less problem) and the line buffer (which is casing you the gaps)
Change your code and there will be no gaps
You mean future values of open by
(open[i]>open[i+5])
I though open[i+5] means five candles back from candle "i", shouldn't that be a past value?
You mean future values of open by
I though open[i+5] means five candles back from candle "i", shouldn't that be a past value?
See your loop direction (from future to past)
No gaps code :
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=rates_total-prev_calculated+1; if (limit>=rates_total) limit=rates_total-1; for(int i=limit;i>=0;i--) { line[i]=Open[i]; if (i<rates_total-10) if(line[i]>line[i+10]) line[i]=Open[i]; else if(Open[i]>Open[i+5]) line[i]=line[i+1]; } return(rates_total); }
- Axel D: I though open[i+5] means five candles back from candle "i", shouldn't that be a past value?Think again. There is a difference between the arrays passed to OnCalculate (e.g. low[]) and the MT4 predefined variables (e.g. Low[].) The predefined variables are all ordered AsSeries. The passed arrays have no default direction.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.
Event Handling Functions - Functions - Language Basics - MQL4 Reference -
line[i]=Open[i];
Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. -
Please don't post a link to or attach an image, just insert the image.
Messages Editor
If he carefully looked at my code, he should see
#ifdef __MQL5__ ...; #endifP.S. I honestly. Didn't quite understand he wants to count. It seems simple. Somehow wisely
Logic, let him correct how he wants.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello! I use a for loop on my indicator and I wonder if there is any way to run all the loops at once, instead of having to wait for every tick to update buffer value. As of this moment, the buffer plotted on chart don't fully load at once, only after a few ticks. Is there a way to have it loaded independently from ticks? Thanks in advance!