Any one know how to do this?

 

I have my EA place a grid on my chart by using this piece of code :


 total=OrdersTotal();   
    if(total<1)
      {
       Temp=MarketInfo(Pair, MODE_BID);
       for (int Cnt=1;Cnt<=NormalizeDouble((Range/2),0);Cnt++)
           { 
            OrdSend(Pair, OP_BUYSTOP, Lot, Temp+(Cnt*Interval*point()), 0, Temp+(Cnt*Interval*point())-SL*point() ,0 , CommOrder, Cnt*Magic, 0, Blue);
            OrdSend(Pair, OP_SELLSTOP, Lot, Temp-(Cnt*Interval*point()), 0, Temp-(Cnt*Interval*point())+SL*point() ,0 , CommOrder, (Cnt*Magic)+1, 0, Red);
            Comment(Temp+"Cnt : "+Cnt+" interval: "+Interval);
           } 
      }


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)


void replace_buys()
    {
////////////////////// 
color arrow_color=CLR_NONE   
 if(countbuystop()<6&&countsellstop()>0)
     {
      Temp=MarketInfo(Pair, MODE_BID);
             { 
              OrdSend(Pair, OP_BUYSTOP, Lot, Temp+(6*Interval*point()), 0, Temp+(6*Interval*point())-SL*point() ,0 , CommOrder, Magic, 0, arrow_color);
              OrdSend(Pair, OP_SELLSTOP, Lot, Temp-(1*Interval*point()), 0, Temp-(1*Interval*point())+SL*point() ,0 , CommOrder, Magic+1, 0, arrow_color);
              Comment(" interval: "+Interval);
             } 
        }
/////////////////////
     }  
//+--------------------------

void replace_sells()
   {
/////////////////////
color arrow_color=CLR_NONE
 if(countsellstop()<6&&countbuystop()>0)
        {
         Temp=MarketInfo(Pair, MODE_BID);
             { 
              OrdSend(Pair, OP_BUYSTOP, Lot, Temp+(1*Interval*point()), 0, Temp+(1*Interval*point())-SL*point() ,0 , CommOrder, Magic, 0,arrow_color);
              OrdSend(Pair, OP_SELLSTOP, Lot, Temp-(6*Interval*point()), 0, Temp-(6*Interval*point())+SL*point() ,0 , CommOrder, Magic+1, 0,arrow_color);
              Comment(" interval: "+Interval);
             } 
        }
/////////////////////
   }
//+--------------------------   

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

Files:
mygridea_1.mq4  11 kb
 
23510 wrote >>

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

 
ronaldosim:

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?