I do not see anywhere in your code, where is your limit for only a single Order
if (buy==true && OrdersTotal() == XX)// or if (buy==true && delete_pending_sell().....) { ticket= OrderSend(Symbol(),OP_BUYSTOP,lots,Ask+kick,0,(Ask+kick)-straal,0,0,magicb1,0,0); }
if u r using it for a function it's supposed to be
hi qjol,
Thanks for your quick reply. Im not sure if I understand how putting the above code into a function should prevent this ea from producing so many trades at once; I have to call it from somewhere else in the code than. The trigger should be Ask>=certain level which should result in deleting pending orders in the opposite direction and counting open orders. When put in a function like above, this trigger is included in the function it self. Could you please explain a bit more?
thanks!!
I do not see anywhere in your code, where is your limit for only a single Order
In the delete_pending function the number of open trades in the same direction are counted and returned.
if(OrderMagicNumber()==magicb1) { t++; } } return(t);
Only of this function returns 0 (and pending sells where deleted) buy is allowed:
if(delete_pending_sell()==0) { buy =true; }This should prevent the ea from opening multiple trades, right?
If this is not a function & that is written after the start()
Every time he reaches this line (bool buy=false;) it becomes false & After it passes all the lines that follow if (Ask>=boven) & if(delete_pending_sell()==0) It becomes back to True
but if this is a function, the EA does not comes to this line over n over all the time, just if you are calling it
hi qjol,
Thanks for your quick reply. Im not sure if I understand how putting the above code into a function should prevent this ea from producing so many trades at once; I have to call it from somewhere else in the code than. The trigger should be Ask>=certain level which should result in deleting pending orders in the opposite direction and counting open orders. When put in a function like above, this trigger is included in the function it self. Could you please explain a bit more?
thanks!!
If this is not a function & that is written after the start()
Every time The EA reaches this line (bool buy=false;) it becomes false & After it passes all the lines that follow, if (Ask>=boven) & if(delete_pending_sell()==0) It becomes back to True
but if this is a function, the EA does not comes to this line over n over all the time, just if you are calling it
If this is not a function & that is written after the start()
Every time he reaches this line (bool buy=false;) it becomes false & After it passes all the lines that follow if (Ask>=boven) & if(delete_pending_sell()==0) It becomes back to True
but if this is a function, the EA does not comes to this line over n over all the time, just if you are calling it
I see, but the result should be the same; buy can only be set to true of ask<boven and there are 0 open buy trades. In my case there are open buy trades, but still it makes new ones.
I see, but the result should be the same; buy can only be set to true of ask<boven and there are 0 open buy trades. In my case there are open buy trades, but still it makes new ones.
NOP, buy can only be set to true if ask >= boven....
NOP, buy can only be set to true if ask >= boven....
My mistake, i meant ask>=boven.
Sorry, that's the max I see, I tried to help, Unfortunately without success
- 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 all,
Im quite new to programming and I am trying to make an EA that does the following:
When the price gets above a certain level, any pending sell order for the same symbol is deleted and a pending buy is placed at an x number of pips above the current price. The same counts when the price drops below a certain level, only the other way around.
There should be only one pending or market order per symbol. The problem I have is that when I run a backtest, the first few trades are opened an deleted correctly, one at the time.
But after a few trades, it keeps spitting pending buy or sell orders, no matter how many trades are already placed in the relevant symbol. The same happens when I let this ea run on a demo account.
I also have 2 functions that set stop loss at break even and close half of the order as a certain profit level is reached. Maybe they have something to do with the problem.
I cant figure out what's happening. I tried putting Print at some points to see what values are stored, but it hasn't helped me so far.
Could somebody please have a look and tell me what I am missing?
Here's the relevant code: