I can't figure out from your code what you are trying to do but in 2 places you do not give variable i a value. You need to address this.
int start() // Special function start() { if (Crosses()) count++; int i, n, // Bar index Counted_bars; Buf_1[i]= count; // Number of counted bars double Sum_H; //-------------------------------------------------------------------- Counted_bars=IndicatorCounted(); // Number of counted bars i=Bars-Counted_bars-1; // Index of the first uncounted while(i>=0) // Loop for uncounted bars { Sum_H=0; // Nulling at loop beginning for(n=i;n<=i+Aver_Bars-1;n++) // Loop of summing values { Buf_0[i]=Buf_1[n]; // Value of 0 buffer on i bar i--; // Calculating index of the next bar } } //-------------------------------------------------------------------- return(0); // Exit the special funct. start() } //-------------------------------------------------------------------- bool Crosses() { int i; double H=iHigh(NULL,PERIOD_M1,i); double L=iLow(NULL,PERIOD_M1,i); double O=iOpen(NULL,PERIOD_D1,i); if (O > L && O < H) return(true); else return(EMPTY_VALUE); }
Sorry to be blunt, but your code shows that you are trying to achieve something far beyond your capability
Example
bool Crosses() { int i; double H=iHigh(NULL,PERIOD_M1,i); double L=iLow(NULL,PERIOD_M1,i); double O=iOpen(NULL,PERIOD_D1,i); if (O > L && O < H) return(true); else return(EMPTY_VALUE);
Let's say that i = 1 for example
double O=iOpen(NULL,PERIOD_D1,1);
This will return yesterday's open price
double H=iHigh(NULL,PERIOD_M1,1); double L=iLow(NULL,PERIOD_M1,1);
These 2 will return values for the last closed 1 minute bar.
So you are comparing the values from 1 minute ago to yesterday's open.
If i = 2, you will be comparing values from 2 minutes ago to the open 2 days ago
You must see that this cannot be what you want.
Sorry to be blunt, but your code shows that you are trying to achieve something far beyond your capability
Example
Let's say that i = 1 for example
This will return yesterday's open price
These 2 will return values for the last closed 1 minute bar.
So you are comparing the values from 1 minute ago to yesterday's open.
If i = 2, you will be comparing values from 2 minutes ago to the open 2 days ago
You must see that this cannot be what you want.
Hi GumRai,
Thanks for taking time helping me. You are right, I am just a beginner and eagerly trying hard to learn coding EA. Here is what I am trying to do:
1. Compare PERIOD_D1 Open to every minute PERIOD_M1 bar on it's own D1 bar, so there are 1440 M1 bars to compare with the D1 bar. Then count the M1 bars that satisfy the condition if (O > L && O < H).
2. Store the counted bars in an array then proceed again to the next D1 bar and repeat the cycle again.
3. Counted bars will be plotted by the indicator on a daily chart. So if say the M1 bars that satisfy the statements is 5 this 5 will be plotted as the value of the daily Bar1. Then say for the next daily bar the M1 bar counted is 10 then it will be plotted again on Bar1 as the previous bar moved to Bar2.
Kindly show me how best to code this seemed simple statement that i struggle with. Let me know is you need further explanation. and big thanks.
Hi GumRai,
Thanks for taking time helping me. You are right, I am just a beginner and eagerly trying hard to learn coding EA. Here is what I am trying to do:
1. Compare PERIOD_D1 Open to every minute PERIOD_M1 bar on it's own D1 bar, so there are 1440 M1 bars to compare with the D1 bar. Then count the M1 bars that satisfy the condition if (O > L && O < H).
2. Store the counted bars in an array then proceed again to the next D1 bar and repeat the cycle again.
3. Counted bars will be plotted by the indicator on a daily chart. So if say the M1 bars that satisfy the statements is 5 this 5 will be plotted as the value of the daily Bar1. Then say for the next daily bar the M1 bar counted is 10 then it will be plotted again on Bar1 as the previous bar moved to Bar2.
Kindly show me how best to code this seemed simple statement that i struggle with. Let me know is you need further explanation. and big thanks.
I will be happy to help you, but I will not write the code as this would not help you to learm.
First, you have to realise that 1440 M1 bars will not always correspond to a 1 day period. If there are no ticks during a bar, that bar will be missing from history and there may be less than you expect.
So you need the datetime value for the open of the D1 candle. Can you do this? Try it and post your code
not so fast
i do know what u r trying to do & ur code (if (O > L && O < H)) doesn't gonna get u what u want
look @ the chart attached

the arrow facing up is the todays opening
& the arrow facing right is the first bar matching to your code (if (O > L && O < H)) so count = 1
but if you pay attention the bar closed above the today opening so, actually count supposed to be = 2 (at least (might be a few more crosses that you can't c only in tick chart))
but in ur code count = only 1
not so fast
i do know what u r trying to do & ur code (if (O > L && O < H)) doesn't gonna get u what u want
look @ the chart attached
the arrow facing up is the todays opening
& the arrow facing right is the first bar matching to your code (if (O > L && O < H)) so count = 1
but if you pay attention the bar closed above the today opening so, actually count supposed to be = 2 (at least (might be a few more crosses that you can't c only in tick chart))
but in ur code count = only 1
From how I understand it, he wants to count the bars that straddle the opening price - I may be wrong though :)
- Zaldy: PLEASE HELP ANYONE! IS THIS POSSIBLE AT ALL?Don't SHOUT at us. Off course it's possible.
- Integers and booleans are convertible. False == 0, true = non-zero.
return(true); else return(EMPTY_VALUE); return(true); else return(2147483647); return(true); else return(true);
- You are also dealing with three timeframes, D1, chart, M1. You must convert.Not compiled or tested.
Counted_bars=IndicatorCounted(); // Number of counted bars for(iCht = Bars - 1 - Counted_bars; iCht >= 0; iCht--){ // Chart bars int iD1 = iBarShift(NULL, PERIOD_D1, Time[iCht]; double openD1 = iOpen(NULL, PERIOD_D1, iD1); int iM1Beg = iBarShift(NULL, PERIOD_M1, Time[iCht], iM1End = -1; if(iCht > 0) iM1End = iBarShift(NULL, PERIOD_M1, Time[iCht-1]; for(Buf_0[i] = 0; iM1Beg > iM1End; iM1Beg--){ double hM1 = iHigh(NULL, PERIOD_M1, iM1Beg), lM1 = iLow(NULL, PERIOD_M1, iM1Beg); // count Bars of M1 Period that crisscross Open price of D1 Period if( hM1 >= openD1 && openD1 >= lM1) Buf_0[iCht]++; } }
Not compiled or tested.
not so fast
i do know what u r trying to do & ur code (if (O > L && O < H)) doesn't gonna get u what u want
look @ the chart attached
the arrow facing up is the todays opening
& the arrow facing right is the first bar matching to your code (if (O > L && O < H)) so count = 1
but if you pay attention the bar closed above the today opening so, actually count supposed to be = 2 (at least (might be a few more crosses that you can't c only in tick chart))
but in ur code count = only 1
Hi Qjol, Yes the arrow facing right is the first count that I want. Those that criss-cross the D1 Open only is counted. Thanks again for your efforts.
- Zaldy: PLEASE HELP ANYONE! IS THIS POSSIBLE AT ALL?Don't SHOUT at us. Off course it's possible.
- Integers and booleans are convertible. False == 0, true = non-zero.
- You are also dealing with three timeframes, D1, chart, M1. You must convert.Not compiled or tested.
Not compiled or tested.
Thanks WHRoeder and sorry for using caps here! I will try your suggestions and come back here for the result.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Greetings! I need help on this indicator. Been trying different method to count number of Bars in M1 Period that came across the level of Open price in the D1 Period. I attached my attempt to code it but unable to run it successfully. Been trying hard on this but I hit the wall so now I ask the help of kind gentlemen here for help!
Here's what I need for this indicator:
1. When ever a Bar in M1 Period price came across the price of Open in D1 Period it will be counted. There are 1440 bars in M1 Period for each D1 Period so every 1440 bars will be tested.
2. For each D1 Bar the total count/D1 Bar will be summed up and averaged by a certain value. Say the average is 30, this 30 is the number of D1 bars.
3. Then the average value will be plotted as the indicator.