Whats it going on, chart event? Just add some logic that makes it wait a random amount of time (so each EA doesnt buy at the same time) before it checks to see if it wants to buy. Then obviously have it check OrdersTotal() < 6 {SendOrder};
There is no bar event, you can have a timer set to the bar but no actual bar event to my knowledge.
If you give me a snippet of your code i can show what to change.
Whats it going on, chart event? Just add some logic that makes it wait a random amount of time (so each EA doesnt buy at the same time) before it checks to see if it wants to buy. Then obviously have it check OrdersTotal() < 6 {SendOrder};
Thanks Keelan. I will try that idea. Can you give me an idea of a suitable delay. Secs or milli Secs ? Does OrdersTotal() get updated in between ticks?
Thanks Keelan. I will try that idea. Does OrdersTotal() get updated in between ticks?
You are working on ticks? are you back testing? ticks and bars are different. If you want to work with bars use the onchart event as they they give you all the data for bars. If your working on ticks then your gona have a little bit more of an issue unless you dont mind a slight delay (missing a few ticks). I presume OrderTotal() returns the value for all order not just that EA but ive never tested. Hold on ill tell you.
try. The rand1() is based on old code, i dont know if RAND_MAX is the same as shulgins. It works in my code, it only sleeps from 1-100 milliseconds so you can play with that.
int RAND_MAX = 32767; void OnTick() { //--- MathSrand(GetTickCount()); double newvar = rand1(); int done = 0; newvar*= 100; done = (int)newvar; Sleep(done); if(OrdersTotal() <= 5 ){ //Your code } } double rand1() { return (double)rand() / (double)RAND_MAX ; }
- 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 there,
I have written an EA which I run on several charts simultaneously. In order to keep the margin usage within a reasonable level, I want to prevent having more than 5 orders open at a given time. I use an order counter and compare its result with the value of OrdersTotal() before allowing a new order to open. This works fine when the orders are opened intra-bar. However, when I make the EA to open trades on the appearance of a new bar, several orders open simultaneously in different charts exceeding my max limit.
Can someone guide me to finding a solution to this issue please.
Thanks in advance