I have 2 questions about reopening the pending order that being executed and about decimal point when opening order.

 

First I have to tell you the objective of my EA,

I try to create a single side (buy only or sell only) grid ea that opening x pips away from current ask with Buy limit and Buy Stop and take profit at x pips

Ex. 300 pips Grid will be >>> #1 Ask = 0.00300 tp at 0.00600 and #2 BuyStop at 0.00600 tp at 0.00900 and create #3 Buy limit at 0.00000  and take profit at 0.00300 respectively until like 100 orders at the same time

then if #2 Buystop is triggered and graph reach until hit TP point, I need the EA to reopen #2 order that have exactly the same properties with the original #2  

How can I do? Or If you saw my code and figure out something more simple please tell me.


Another question is why I can't use the same logic between BUY_STOP and BUY_LIMIT, If I use the same , it will not open limit order, I have to change tmp3 to AskPrice2 in order to open it. I'm very confused

  

ticket[2]=OrderSend(Symbol(),OP_BUYSTOP,Lot,tmp2,slippage,0,tmp2+0.003,"Buy Stop");

   tmp2=tmp2+0.003; //add 300 pips grid

                              

   ticket[3]=OrderSend(Symbol(),OP_BUYLIMIT,Lot,tmp3,slippage,0,AskPrice2-0.003,"Buy Limit");  

   tmp3=tmp3-0.003; //add 300 pips grid



I'm a novice programmer so the code maybe a bit fuzzy or too straight.


double Lot=0.01;

double GridTakeprofit;

int NumberOfGrid=6;

int i;

int j;

int slippage=3;

double AskPrice1=Ask;

double AskPrice2=Ask;

int ticket[999];

int GridDistance=300;

double tmpGridDistance;

double tmp1;

double tmpPip=0.003;

double tmp2;

double tmp3;

double tmp4;



int start()

{     



            

            

   if(OrdersTotal()==0)

   {

      ticket[1]=OrderSend(Symbol(),OP_BUY,Lot,AskPrice,10,0,AskPrice+GridTakeprofit*0.00001,"My First Order");

   }

   else

    printf("Error");

         

     

         tmp2=AskPrice1+0.003;

         tmp3=AskPrice2-0.003;

   

         

         for(i=0;i<2;i++)

         {

               if(OrdersTotal()<2) // just test for a few order

            {

             

               ticket[2]=OrderSend(Symbol(),OP_BUYSTOP,Lot,tmp2,slippage,0,tmp2+0.003,"Buy Stop");

               tmp2=tmp2+0.003; //add 300 pips grid

                              

               ticket[3]=OrderSend(Symbol(),OP_BUYLIMIT,Lot,tmp3,slippage,0,AskPrice2-0.003,"Buy Limit");  

               tmp3=tmp3-0.003; //add 300 pips grid

               

               //AskPrice2=AskPrice2+tmpGridDistance-0.003;

               

               }

      }

  

  return(0);



Thank you very much 

 
interestgain:

Ex. 300 pips Grid will be >>> #1 Ask = 0.00300 tp at 0.00600

Another question is why I can't use the same logic between BUY_STOP and BUY_LIMIT,

  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. 0.00600-0.00300 is 0.00300 or 30 pips on non-JPY pairs.
               What is a TICK? - MQL4 and MetaTrader 4 - MQL4 programming forum

  3. A buy limit opens at that price or better (better means lower.) You can only create one below the market (Bid) - stoplevel.
    A buy stop, becomres a market order when market reaches it. You can only create one above the market (Ask) + stoplevel.
    You can't move stops (or pending prices) closer to the market than the minimum (MODE_STOPLEVEL * _Point.)
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

 
Kirim
 
whroeder1:
  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. 0.00600-0.00300 is 0.00300 or 30 pips on non-JPY pairs.
               What is a TICK? - MQL4 and MetaTrader 4 - MQL4 programming forum

  3. A buy limit opens at that price or better (better means lower.) You can only create one below the market (Bid) - stoplevel.
    A buy stop, becomres a market order when market reaches it. You can only create one above the market (Ask) + stoplevel.
    You can't move stops (or pending prices) closer to the market than the minimum (MODE_STOPLEVEL * _Point.)
              Requirements and Limitations in Making Trades - Appendixes - MQL4 TutorialTh

I'm so sorry I have already edited it.

and what about re-opening at the same location and the same properties after TP point.

Thank you for the answer

 
interestgain: and what about re-opening at the same location and the same properties after TP point.

You pay the spread each time.

 
whroeder1:

You pay the spread each time.

I Got it Thanks

 

For 2nd Question. How can I fix the pending order that missing when order has closed? I need them to instantly open after TP


This is my code

double Lot=0.01;
double GridTakeprofit;
int NumberOfGrid=6;
int i=0;
int j;
int slippage=3;
double AskPrice1=Ask;
double BidPrice1=Bid;
int ticket[999];
int GridDistance=300;
double tmpGridDistance;
double tmp1;
double tmpPip=0.003;
double tmp2;
double tmp3;
double tmp4;

int start()
{     
    
   if(OrdersTotal()==0)
   {
     
        if(ticket[1]==0)
       {
        // ticket[1]=OrderSend(Symbol(),OP_BUY,Lot,Ask,10,0,Ask+0.003,"My First Order");
       }
   }
   else
    printf("Error");
         
      
         tmp2=AskPrice1+0.003;
         tmp3=BidPrice1-0.003;
   
         
         for(i=0;i<12;i++)
         {
               if(OrdersTotal()<12)
            {

               ticket[2]=OrderSend(Symbol(),OP_BUYSTOP,Lot,tmp2,slippage,0,tmp2+0.003,"Buy Stop");
               tmp2=tmp2+0.003;
           
               ticket[3]=OrderSend(Symbol(),OP_BUYLIMIT,Lot,tmp3,slippage,0,tmp3+0.003,"Buy Limit");  
               tmp3=tmp3-0.003;

    
               }
           }
  
  return(0);
}
 
interestgain: For 2nd Question. How can I fix the pending order that missing when order has closed? I need them to instantly open after TP

You can't. Pending orders will only open when the market reaches their price. And you can't move the pending price to the market per #3.3

When in doubt, think. Delete the pendings and open a new order.

Reason: