Download MetaTrader 5

New Order at same Price

To add comments, please log in or register
delandee
28
delandee 2016.06.27 03:59 

Hello :)


I need your help for a trick in my EA.

How to place a BUY STOP at price when there is no BUY STOP at this price and while this level stay activ ?

I send buy stop order at level, order was executed and reaches his TP, price fall under the level, how can I  send a new buy stop order with same conditions ?


Here is an exemple :

bool activLevel1 = true;
double level1 = 0.85412;

if (activLevel1 && NO BUY STOP AT THIS LEVEL && Close[0] < level1 - 50 * Point)
{
   OrderSend(...OP_BUYSTOP...);
}


Thanks for your help :)

Aleksei Beliakov
25390
Aleksei Beliakov 2016.06.27 04:44  
delandee:

Hello :)


I need your help for a trick in my EA.

How to place a BUY STOP at price when there is no BUY STOP at this price and while this level stay activ ?

I send buy stop order at level, order was executed and reaches his TP, price fall under the level, how can I  send a new buy stop order with same conditions ?


Here is an exemple :


Thanks for your help :)

Just check all orders and told there is order with same price and same type do or not do ...
delandee
28
delandee 2016.06.27 13:32  
Aleksei Beliakov:
Just check all orders and told there is order with same price and same type do or not do ...

Hi,

I posted in the forum MQL5 but my problem is on mt4, sorry...

I give you the real code to be more precise

double supportLvl[10][2] = {0.0, 0.12345,  1.0, 0.23456,  1.0, 0.34567, ... } //{Activ, Price}

for(int cnt=OrdersTotal()-1; cnt>=0; cnt--)
{
   if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
   {
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderType()==OP_BUYSTOP)
      {
         for(int cnt2 = ArrayRange(supportLvl,0)-1; cnt2=>0; cnt2--)
         {
            if(supportLvl[cnt2][0] == 1.0 && supportLvl[cnt2][1] == OrderOpenPrice())
            {
               //Order is already sent
            }
            else if(supportLvl[cnt2][0] == 0.0)
            {
              //Order does not need to be sent
            }
            else
            {
               //Order not sent at this time but it can be on the next loop...
            }
         }
      }
   }
}


So, how can I be sure that the order was not placed for each level and only at the end of control, place it if necessary ?


Thanks for your help :)




delandee
28
delandee 2016.06.29 20:25  
can someone help me please ?
Maryann Emmanuel
2281
Maryann Emmanuel 2016.06.29 22:38  
you need to place a print message after the final else using the Print()function. Refer to 'MQL4 language for NewbiesDifficult Questions in Simple Phrases' by Antoniuk Oleg. for loop.
Ernst Van Der Merwe
4791
Ernst Van Der Merwe 2016.06.30 09:53  

Maybe like so?

   double supportLvl[10][2]={0.0,0.1234,0.0,0.2345,0.0,0.3456,... } //{Activ, Price}

   for(int cnt2=ArrayRange(supportLvl,0)-1; cnt2=>0; cnt2--)
     {
      for(int cnt=OrdersTotal()-1; cnt>=0; cnt--)
        {
         if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
           {
            if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderType()==OP_BUYSTOP)
              {
               if(supportLvl[cnt2][0]==0.0 && supportLvl[cnt2][1]==NormalizeDouble(OrderOpenPrice(),4))
                 {
                  //Order is already sent
                  supportLvl[cnt2][0]=1.0;
                 }                   
               else if(supportLvl[cnt2][0]==1.0 && supportLvl[cnt2][1]!=NormalizeDouble(OrderOpenPrice(),4))
                 {
                  //Order does not need to be sent
                  supportLvl[cnt2][0]=0.0;
                 }
               else
                 {
                  //Order not sent at this time but it can be on the next loop...
                 }
              }
           }
        }
     }
delandee
28
delandee 2016.07.01 02:14  
pipPod:

Maybe like so?

Thanks but I think my multi dimensional array makes example too complicated.

New (more simple) explanation:

I have supports levels, each time price fall under one of the levels and there is no OP_BUY and no OP_BUYSTOP at this price, place buy stop at this level.

levels are stored in a simple Array => levels[10] = {0.12345, 0.23456, 0.34567, ...}

Price is at 1.0000, goes at 0.9995, no OP_BUY and no OP_BUYSTOP at 1.0000 so sends OP_BUYSTOP at 1.0000, price goes up to 1.0000 and activates BUYSTOP, goes more up to 1.0100 and hits BUY Take profit, goes at 0.9993, no OP_BUY and no OP_BUYSTOP at 1.0000 so sends OP_BUYSTOP at 1.0000 .....


Sorry for my very poor english and thanks for your help.






Ernst Van Der Merwe
4791
Ernst Van Der Merwe 2016.07.01 09:08  
   double supportLvl[10]={ 0.12345,0.23456,0.34567,... } //{Activ, Price}

   for(int lvl=0;lvl<10;lvl++)
     {
      if(Ask+50*_Point<supportLvl[lvl])
        {
         for(int cnt=OrdersTotal()-1; cnt>=0; cnt--)
           {
            if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES) || 
               OrderSymbol()!=Symbol() || 
               OrderMagicNumber()!=MagicNumber || 
               OrderType()!=OP_BUYSTOP)
               continue;
            //---
            if(OrderOpenPrice()!=supportLvl[lvl])
               OrderSend(OP_BUYSTOP...);
           }
        }
     }
delandee
28
delandee 2016.07.01 11:48  
pipPod:
Thanks pipPod, it's almost that, but this code doesn't check if there is already OP_BUY at level.

In addition, the EA places a OP_BUYSTOP at each new tick :/




Ernst Van Der Merwe
4791
Ernst Van Der Merwe 2016.07.01 15:15  

Yeah the code isn't tested and only for suggestion. Maybe if you work with the ticket numbers?

   double supportLvl[10]={ 0.12345,0.23456,0.34567,... } //{Activ, Price}
   int ticket[10]={0,0,0,...}

   for(int lvl=0;lvl<10;lvl++)
     {
      if(!ticket[lvl] && Ask+50*_Point<supportLvl[lvl])
         ticket[lvl]=OrderSend(OP_BUYSTOP...);
     }
   //---
   if(OrderClose(...)
      for(int i=0;i<10;i++)
         if(ticket[i]==OrderTicket() || supportLvl[i]==OrderOpenPrice())
            ticket[i]=0;
delandee
28
delandee 2016.07.01 15:31  
pipPod:

Yeah the code isn't tested and only for suggestion. Maybe if you work with the ticket numbers?

Good idea, but what about orders not closed by OrderClose function but closed by reaching TP ?

I really apreciate your spendt time to help me. Thanks !!

12
To add comments, please log in or register