Hi pro coders.
Good day,
I've created an EA, but it seems a little missing some positions and I believe I know what the reason is. I don't know how to solve this issue, which is introducing new bar to the EA.
O.k, here I will explain in details. The idea in general is based on previous bars. For example:
I'm not sure what you're intending to do here. You need to allow for the fact that the high, low and close of the current bar will change as the bar is being formed. If you want to make a decision based on previous bars, then something like this may be what you want.
// all days of week except Sunday if (TimeDayOfWeek(TimeCurrent())!=0) if (High[1]<High[2] && Low[1]>Low[2]) { BuyOrdOpen(); SellOrdOpen(); }
Paul
http://paulsfxrandomwalk.blogspot.com/
I'm not sure what you're intending to do here. You need to allow for the fact that the high, low and close of the current bar will change as the bar is being formed. If you want to make a decision based on previous bars, then something like this may be what you want.
Paul
http://paulsfxrandomwalk.blogspot.com/
Hi Paul,
Thanks a lot for your post. I appreciate it.
I used your code and unfortunately didn't work. when I changed the bar numbers from yours to this below, it worked.
if (TimeDayOfWeek(TimeCurrent())!=0) if (High[1]<High[2] && Low[1]>Low[2]) { BuyOrdOpen(); SellOrdOpen(); } //--------------------------------------------------- if (TimeDayOfWeek(TimeCurrent())!=0) if (High[0]<High[1] && Low[0]>Low[1]) { BuyOrdOpen(); SellOrdOpen(); }
Look like the EA can't recognize bar[2] when I say
if (High[1]<High[2] && Low[1]>Low[2])
The idea is simple, I want the EA to compare the high for yesterday and the day before i.e. High[1] and High[2] and the low as well i.e. Low[1] and Low[2]
Then use this condition below to place positions i.e. SellStop and BuyStop on Yesterday's high and low.
If the condition is not met, the EA should return to zero.
if (High[1]<High[2] && Low[1]>Low[2])
I hope this is clear now.
Thanks a lot for your help.
By the way, your website is great.
waiting pro coders reply.
Best wishes,
Hi,
Sample of zero bar monitoring: https://www.mql5.com/en/code/8585
int start () // 01
{ // 02
static int ali.TicksReported.0 ; ali.TicksReported.0 = iVolume ( Symbol () , PERIOD_M1 , 0 ) ; // 03
static int ali.TicksReported.1 ; ali.TicksReported.1 = iVolume ( Symbol () , PERIOD_M1 , 1 ) ; // 04
// 05
static int ali.OpenTime.0 ; ali.OpenTime.0 = iTime ( Symbol () , PERIOD_M1 , 0 ) ; // 06
static int ali.OpenTime.1 ; ali.OpenTime.1 = iTime ( Symbol () , PERIOD_M1 , 1 ) ; // 07
// 08
static int ali.FrameLength ; ali.FrameLength = TimeCurrent () - ali.OpenTime.0 ; // 09
// 10
static int ali.TicksCounted.0 ; // 11
static int ali.TicksCounted.1 ; // 12
// 13
static int ali.LastOpenTime ; // 14
// 15
static int ali.Flag ; if ( ali.Flag != True ) { ali.Flag = True ; // 16
ali.TicksCounted.0 = ali.TicksReported.0 ; // 17
ali.LastOpenTime = ali.OpenTime.0 ; // 18
Alert ( "Start" ) ; return ; } // 19
// 20
if ( ali.LastOpenTime == ali.OpenTime.0 ) // 21
ali.TicksCounted.0 ++ ; // 22
else { ali.TicksCounted.1 = ali.TicksCounted.0 ; // 23
ali.TicksCounted.0 = 1 ; // 24
ali.LastOpenTime = ali.OpenTime.0 ; // 25
Alert ( "Frame 0 " , // 26
"is closed: " , TimeToStr ( ali.OpenTime.0 , TIME_MINUTES | TIME_SECONDS ) , " " , // 27
"Count: " , ali.TicksCounted.1 , " " , // 28
"Report: " , ali.TicksReported.1 ) ; } // 29
// 30
Alert ( Symbol () , " M1: " , "Frame 0: " , // 31
"Open: " , TimeToStr ( ali.OpenTime.0 , TIME_MINUTES | TIME_SECONDS ) , " " , // 32
"Seconds: " , ali.FrameLength , " " , // 33
"Count: " , ali.TicksCounted.0 , " " , // 34
"Report: " , ali.TicksReported.0 , " " , // 35
" // " , "Frame 1: " , // 36
"Open: " , TimeToStr ( ali.OpenTime.1 , TIME_MINUTES | TIME_SECONDS ) , " " , // 37
"Count: " , ali.TicksCounted.1 , " " , // 38
"Report: " , ali.TicksReported.1 ) ; // 39
} // 40
Best regards
Hi Ais,
Thanks for your post.
I have one quick question though, what does this code have to do with my code problem?? Can you explain a little please?
waiting for your reply.
Thanks again.
Best wishes,
This code helps to inspect with every run state of bars 0 and 1:
1. time lenght of zero bar and time lenght of bar number one
2. volume of zero bar and volume of bar number one
Please take look at AIS1 Trading Robot
It seems for me that we are using similar approach for system development
Hi Paul,
Thanks a lot for your post. I appreciate it.
I used your code and unfortunately didn't work. when I changed the bar numbers from yours to this below, it worked.
Look like the EA can't recognize bar[2] when I say
The idea is simple, I want the EA to compare the high for yesterday and the day before i.e. High[1] and High[2] and the low as well i.e. Low[1] and Low[2]
Then use this condition below to place positions i.e. SellStop and BuyStop on Yesterday's high and low.
If the condition is not met, the EA should return to zero.
I hope this is clear now.
Thanks a lot for your help.
By the way, your website is great.
waiting pro coders reply.
Best wishes,
I don't think using [0] shift will give you what you say you want. Suppose you have a rising candle: the High[0] will change with every new high for that candle. The following should work fine, and if it doesn't perhaps it's your order entry code which is not quite right
if (High[1]<High[2] && Low[1]>Low[2])
Paul
http://paulsfxrandomwalk.blogspot.com/
This code helps to inspect with every run state of bars 0 and 1:
1. time lenght of zero bar and time lenght of bar number one
2. volume of zero bar and volume of bar number one
Please take look at AIS1 Trading Robot
It seems for me that we are using similar approach for system development
Hi Ais,
Thanks again for your post.
well, not exactly this is what I'm looking for.
I'm trying to get bar[1] and bar[2] every time they change since my EA can't recognize them. I believe you know that bar[0] is going to be bar[1] if new bar[new] show up, and thus bar[1] is going to be bar[2] and so on.
I want the EA to recognize the bars every new bar change.
Thanks,
I hope some pro coders would show up.
Best wishes,
I don't think using [0] shift will give you what you say you want. Suppose you have a rising candle: the High[0] will change with every new high for that candle. The following should work fine, and if it doesn't perhaps it's your order entry code which is not quite right
Paul
http://paulsfxrandomwalk.blogspot.com/
Hi phampton,
Good day,
Thanks a lot for your post.
well, honestly I'm not sure about that, but here is the code for both buy and sell functions.
void SellOrdOpen()
{
double HigH=iHigh(Symbol(), PERIOD_D1,1);
double LoW=iLow(Symbol(), PERIOD_D1,1);
double SellPrice=LoW;
if (InitialStop) SellStop=HigH+spread;
Profit=0;
ticket = OrderSend(Symbol(),OP_SELLSTOP,Lotsi,NormalizeDouble(SellPrice,digit), Slippage,
NormalizeDouble(SellStop,digit),Profit,"SELL",Magic,0,Red);
OrderOpenDay = DayOfWeek();
SellInTrade=false;
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
void BuyOrdOpen()
{
double LoW=iLow(Symbol(), PERIOD_D1,1);
double HigH=iHigh(Symbol(), PERIOD_D1,1);
double BuyPrice =HigH+spread;
if (InitialStop) BuyStop =LoW;
Profit=0;
ticket = OrderSend(Symbol(),OP_BUYSTOP ,Lotsi,NormalizeDouble(BuyPrice ,digit), Slippage,
NormalizeDouble(BuyStop ,digit),Profit,"BUY",Magic,0,Blue);
OrderOpenDay = DayOfWeek();
BuyInTrade=false;
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
I hope this can help somehow clearing where the problem is.
Best wishes,
Changes are essence of market

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi pro coders.
Good day,
I've created an EA, but it seems a little missing some positions and I believe I know what the reason is. I don't know how to solve this issue, which is introducing new bar to the EA.
O.k, here I will explain in details. The idea in general is based on previous bars. For example:
we know that candle bar value is going to change after every new bar show up. And as we know that for example bar[0] is going to be bar[1] when new candle bar is formed.
The EA performance is as shown on the picture. You can notice that it skipped some bars and didn't place positions.
Now, I don't know how to recalculate bars so the EA recognize new bar every time.
please share your opinions.
Best wishes,