I have my EA place a grid on my chart by using this piece of code :
it places the grid perfectly ...but now if the price moves and triggers my pending orders i want to replace them like this... if the price moves up 1 interval (8pips) and hits the 1st pending order then place a new pending order 1 interval above the highest pending buy order and 1 pending sell 1 interval below the lowest buy order (which will be the triggered order)
So I tried to do it like this (with some help from some great guys on this forum)
well this works great for a few intervals but then gaps start to form in the grid and the grid is not evenly spaced by the interval ( a pending order every 8 pips)
Does anyone know how to make it keep the integrity of the grid...in other words it must not create gaps in the grid...
I have attached my EA please run it in visual mode and you will see the gaps form...
This is so important as if this does not work right my whole EA is useless....please help if you know how.
I have attached the EA so you can test it in visual mode
double firstbuystop=9999;
double firstsellstop = 0;
int total=OrdersTotal();
for (int x=total-1;x>=0;x--)
{
OrderSelect(x,SELECT_BY_POS);
if(OrderSymbol()!=Pair) continue;
if(OrderMagicNumber()!=Magic) continue;
if (OrderType()==OP_BUYSTOP || OrderType()==OP_BUY)
{
if (OrderOpenPrice()<firstbuystop)
firstbuystop=OrderOpenPrice();
}
else if (OrderType()==OP_SELLSTOP || OrderType()==OP_SELL)
{
if (OrderOpenPrice()>firstsellstop)
firstsellstop=OrderOpenPrice();
}
}
if (firstbuystop==9999 || firstsellstop==0) return;
int bsdiff= (firstbuystop-firstsellstop)/point();
if (bsdiff >GapPips) //GapPips - define yr gap size in pips that u want to initiate a CloseGrid
CloseGrid(); // a routine to delete all the orders
double firstbuystop=9999;
double firstsellstop = 0;
int total=OrdersTotal();
for (int x=total-1;x>=0;x--)
{
OrderSelect(x,SELECT_BY_POS);
if(OrderSymbol()!=Pair) continue;
if(OrderMagicNumber()!=Magic) continue;
if (OrderType()==OP_BUYSTOP || OrderType()==OP_BUY)
{
if (OrderOpenPrice()<firstbuystop)
firstbuystop=OrderOpenPrice();
}
else if (OrderType()==OP_SELLSTOP || OrderType()==OP_SELL)
{
if (OrderOpenPrice()>firstsellstop)
firstsellstop=OrderOpenPrice();
}
}
if (firstbuystop==9999 || firstsellstop==0) return;
int bsdiff= (firstbuystop-firstsellstop)/point();
if (bsdiff >GapPips) //GapPips - define yr gap size in pips that u want to initiate a CloseGrid
CloseGrid(); // a routine to delete all the orders
ronaldosim,
as usual I really thank you and appreciate your insightful and helpful suggestions, is deleting the entire grid and replacing it the only way to do this?
I was hoping to find a way to simply add the necessary orders to make sure the grid is not full of gaps...I will give this a try though.
thank you!
what worries me about deleting the whole grid and replacing it is that it might set the grid wrong according to the traders already triggered...
if it overlays another grid on top of the already opened trades then the spacing will not be uniform...
I hope I am making myself understood...its a difficult concept to put into words.
ronaldosim, would you mind sending me the way your modifies my EA to get those results please?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have my EA place a grid on my chart by using this piece of code :
it places the grid perfectly ...but now if the price moves and triggers my pending orders i want to replace them like this... if the price moves up 1 interval (8pips) and hits the 1st pending order then place a new pending order 1 interval above the highest pending buy order and 1 pending sell 1 interval below the lowest buy order (which will be the triggered order)
So I tried to do it like this (with some help from some great guys on this forum)
well this works great for a few intervals but then gaps start to form in the grid and the grid is not evenly spaced by the interval ( a pending order every 8 pips)
Does anyone know how to make it keep the integrity of the grid...in other words it must not create gaps in the grid...
I have attached my EA please run it in visual mode and you will see the gaps form...
This is so important as if this does not work right my whole EA is useless....please help if you know how.
I have attached the EA so you can test it in visual mode