And here are the screenshots concerning the problems, as you can see, the buy order is triggered by the Di- line crossing Di+ line from below, which should not happen! I hope I was clear with my problem, Im really counting on some tips, as I spent the whole day trying to figure out what is the problem with that!
- tomekbuka:
Does the digit in the last place (in this case 1) mean, that the point that will be used comes from the one bar before the last one? Do I interpret that correctly?Yes, however on the first tick the b4+ and now+ will be very close. As the new bar forms you may get many small crosses.
instead look at the last two complete bars b4p... = IADX(.... 2); nowp... = IADX(... 1);
if(ticket > 0) { if((b4plusdi>b4minusdi) && (nowplusdi<nowminusdi)) OrderClose(ticket,LotSize,OpenPrice,2) ;}
This wont work. The first comparison will always be false or you wouldn't have opened. The next tick comes in and you will open another order. Instead wait for a new bar, then check for close.
int start(){ static datetime Time0; if (Time0 == Time[0]) return(0); Time0 = Time[0]; ... // Check for close if((b4plusdi>b4minusdi) && (nowplusdi<nowminusdi)){ for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() ){ // and my pair. if (!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),2)) Alert("OrderClose failed: ", GetLastError()); } // Check for open.
Also always check return codes (orderSend)
Thanks a lot!
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
Does the digit in the last place (in this case 1) mean, that the point that will be used comes from the one bar before the last one? Do I interpret that correctly?
Here is the code to the whole EA, and some screenshots showing the problem.