Your code won't work if there are other trades open with a different magic number or symbol because the count will not equal OrdersTotal()
Why not use a bool instead?
bool ShortCheck = true; for (d = OrdersTotal()-1;d>=0;d--) { if (OrderSelect (d, SELECT_BY_POS, MODE_TRADES)){ if ( OrderMagicNumber() == MagicMain ){ if ( OrderSymbol() == Symbol()) { double Shortline = OrderOpenPrice() - GridDistance*Point; double Longline = OrderOpenPrice() + GridDistance*Point; if ( (Shortline > Bid || Longline < Bid)==false ){ ShortCheck=false; break; } } } } } if (ShortCheck){ Check = OrderSend(Symbol(), OP_SELL, MMLots, Bid, Slippage, SellSL, FirstShortTP, "Blok ", MagicMain+i, 0, OrderColor); if (Check<0) Print ("Opening new trade error ", GetLastError()); }
Just a suggestion, not compiled or tested
if (ShortCheck==OrdersTotal()){ if (ShortCheck > 0){
Your code won't work if there are other trades open with a different magic number or symbol because the count will not equal OrdersTotal()
Why not use a bool instead?
Just a suggestion, not compiled or tested
Surprisingly (for me), this seems to be at least opening trades.. Unfortunatelly on in one direction, and that is it it is higher.. Look at the image:
There are missing trades on the way down...
I do not understand this though:
if ( (Shortline > Bid || Longline < Bid)==false ){
Any suggestions?
I am really greatefull for any help, this is quite complex ea...
Thanks a lot!
Surprisingly (for me), this seems to be at least opening trades.. Unfortunatelly on in one direction, and that is it it is higher.. Look at the image:
There are missing trades on the way down...
I do not understand this though:
if ( (Shortline > Bid || Longline < Bid)==false )
Any suggestions?
I am really greatefull for any help, this is quite complex ea...
Thanks a lot!
We have no idea what other criteria you may have coded to open a trade. There is nothing in your posted code to open a Buy trade, so we can't comment on that.
if (Shortline > Bid || Longline < Bid )
This would check if Bid is more than GridDistance away from the open price of any trade
so
if ( (Shortline > Bid || Longline < Bid)==false )
this checks if at least one trade's open price is less than GridDistance away from Bid
- 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 guy,
could anybody help me? I am trying to write a function that checks every trade opened by the EA if the distance from each trade is more than "GridDistance". GridDistance usually about 20 pips.
Right now I am counting if all the trades match the criteria and that I compare it to OrdersTotal(), which obviously is not perfect. I would like it to work its own.
Could anyone help me please?
ShortCheck = 0;
Thanks a lot,
Josif