https://docs.mql4.com/series/iBars
Number of bars in the current chart.if(i != Bars) i=Bars; |
thanks for the help.. i already try that code but this code continues counting bars, i need " i " to reset to zero in a certain count of bars so that i'm trying to use i++.
if(i<Bars) { //do something i++; }
if you reset i to zero in the loop then the loop will never end
The topic is
need help in counting bars
Bars
is returning Number of bars in the current chart.
So what do you count ??? What is the problem you have ???
if you reset i to zero in the loop then the loop will never end
The topic is
need help in counting bars
is returning Number of bars in the current chart.
So what do you count ??? What is the problem you have ???
thanks for replay.. could you check my code..
int start()
{
valHigh=Low[iHighest(symb,0,MODE_HIGH,NumBars,0)];
if(i<Bars) i++;
if(Close[0]>valLow+(Deviation*Point) && i>=20)
{
valHigh=High[iHighest(symb,0,MODE_HIGH,NumBars,0)];
i=0;
}
the problem is when i use "every tick mode" the i++ is counting faster than bar count.
thanks for replay.. could you check my code..
Could you, please, edit your post and use SRC button when you post code.
int start() { valHigh=Low[iHighest(symb,0,MODE_HIGH,NumBars,0)]; //from bar 0 to bar NumBars you search for the bar with the highest value //and then you want to know the lowest value of that same bar if(i<Bars) i++;//now i get the same value as total of bars you have on CHART_BAR //every new tick i get value +1 until i is equal to the count of //bars of your chart if(Close[0]>valLow+(Deviation*Point) && i>=20) //valLow variable looks not to be defined //normally after 20 ticks i always greater or equal as 20 //Close[0] is same as Bid { valHigh=High[iHighest(symb,0,MODE_HIGH,NumBars,0)]; //now valHigh becomes the highest value of bar 0 till bar number NumBars i=0;// and you reset i to zero when Close[0]>valLow+(Deviation*Point) // but with next tick valHigh will become again // valHigh=Low[iHighest(symb,0,MODE_HIGH,NumBars,0)];So this is not counting bars....
So this is not counting bars....
extern int NumBars =120; extern int Deviation=100; int i; bool buy=false; bool sell=false; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- i=0; //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- string symb = Symbol(); if(Bid<10) int digit=5; else digit=3; //------------------------------------------------- double valHigh, valLow; valHigh=Low[iHighest(symb,0,MODE_HIGH,NumBars,0)]; valLow=High[iLowest(symb,0,MODE_LOW,NumBars,0)]; if(Close[0]>=valHigh) { valLow=valHigh; valHigh=High[iLowest(symb,0,MODE_LOW,NumBars,0)]; if(i<Bars) i++; if(Close[0]>valLow+(Deviation*Point) && i>=20) { valHigh=High[iHighest(symb,0,MODE_HIGH,NumBars,0)]; i=0; buy=true; sell=false; } } if(Close[0]<=valLow) { valHigh=valLow; valLow=Low[iHighest(symb,0,MODE_HIGH,NumBars,0)]; if(i<Bars) i++; if(Close[0]<valHigh-(Deviation*Point) && i>=20) { valLow=Low[iLowest(symb,0,MODE_LOW,NumBars,0)]; i=0; sell=true; buy=false; } } Comment("i : ",i," Bars : ",Bars," valHigh : ",valHigh," valLow : ",valLow); //---- return(0); }
please check again my code.. thanks for your time..
when i use this code " if(i<Bars) i++; " i++ is stuck in one.
if i use this code " if(i!=Bars) i++; " i++ is counting faster than bars count.
When i use "open price mode" i++ is synchronize to bars count, but if "every tick mode" i++ is counting faster than bars count.
will look later to the code
but this
if(Bid<10) int digit=5; else digit=3;
is not a reliable code for having it work as well on all brokers it will fail several Symbols
what timeframe is it you do use this code ??
will look later to the code
but this
is not a reliable code for having it work as well on all brokers it will fail several Symbols
yes i know but this is only for testing ea. i use it on M1 & M5. thank for informing.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
int i;
int int()
i=0;
int start()
if(i<Bars) i++;
problem is when i use "every tick mode" on tester i++ is not synchronize to bar counting, but when i use "open price mode" it is synchronize. can anybody explain to me whats the problem?