What is order_id ? - page 3

 

Why are you printing the value of  DIPlus1    eight times ?

 Use this line . . once.

Print("DIPlus1: ", DoubleToStr(DIPlus1, Digits), " DIMinus1: ", DoubleToStr(DIMinus1, Digits), " Main0: ",DoubleToStr(Main0, Digits), " Rsi: ",DoubleToStr(Rsi, Digits) );
 

You need to make your indenting clearer so that it is easy for you and others to follow . . .

for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)  
   {
   if(  OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue;   
   
   Print("DIPlus1: ", DoubleToStr(DIPlus1, Digits), " DIMinus1: ", DoubleToStr(DIMinus1, Digits), " Main0: ",DoubleToStr(Main0, Digits), " Rsi: ",DoubleToStr(Rsi, Digits) );
   
   if( OrderMagicNumber() == MagicNumber2      
   && OrderSymbol() == Symbol()          
   && OrderType() == OP_BUY         
   || OrderType() == OP_SELL )  
      {
      if( DIPlus1 > DIMinus1 || Main0 < err || Rsi < xx)
         OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);
      } 

   if( OrderMagicNumber() == MagicNumber1      
   && OrderSymbol() == Symbol()          
   &&  OrderType() == OP_BUY          
   || OrderType() == OP_SELL )  
      { 
      if( DIPlus1 < DIMinus1 || Main0 < err || Rsi > x  )
         OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);   
      }

   if ( ! OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 3 ) )                           //  <------  why this extra OrderClose ???
         Print("Order Close failed, order number: ", OrderTicket(), " Error: ", GetLastError() ); 
              
   }
 

Thank Raptor. I hope my EA work.

My new code:

int start()
{
   int i ,times;
   string DIPlus1;
   string DIPlus0;
 
   string DIMinus1;
   string DIMinus0;
   
   string Main1;
   string Main0;
   
   string MACD_main;
   string MACD_signal;
   string Rsi;
   
   string err = 26;
   string x = 70;
   string xx = 30;
   
   double sl = 300;
   double tp = 50;
   
   int MagicNumber1=1234,MagicNumber2=4321;
//----
/*DIPlus1=DoubleToStr(  DIPlus1, 4);
DIPlus0=DoubleToStr(    DIPlus0, 4);
DIMinus1=DoubleToStr(   DIMinus1, 4);
DIMinus0=DoubleToStr(   DIMinus0, 4);
Main1=DoubleToStr(      Main1, 4);
Main0=DoubleToStr(      Main0, 4);
Rsi=DoubleToStr(        Rsi, 4);
//err=DoubleToStr(err,4);
//x=DoubleToStr(x,4);
//xx=DoubleToStr(xx,4);*/

//---
 
DIPlus1=iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,1);
DIPlus0=iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,0);
 
DIMinus1=iADX(NULL,0,14,PRICE_CLOSE,MODE_MINUSDI,1);
DIMinus0=iADX(NULL,0,14,PRICE_CLOSE,MODE_MINUSDI,0);

Main1=iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,1);
Main0=iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,0);

Rsi = iRSI(NULL,0,14,PRICE_CLOSE,0);

times = Minute() % 15 ==0 && Seconds() ==0;

//MACD_main = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); 
//MACD_signal = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
   
//----
if(Minute() % 15 ==0 && Seconds() ==0)
{
  if( Main0 > err && Main1 < err && DIPlus1 > DIMinus1 && Rsi < x )

    
       OrderSend(Symbol(),OP_BUY,0.03,Ask,5,Ask-sl*Point,Ask+tp*Point,"",1234,0,Blue);
          
   

   if (Main0 > err && Main1 < err && DIPlus1 < DIMinus1  && Rsi > xx)
     
       OrderSend(Symbol(),OP_SELL,0.03,Bid,5,Bid+sl*Point ,Bid-tp*Point,"",4321,0,Red);
}
     
  //---
 int PositionIndex;    
 
int TotalNumberOfOrders;  

TotalNumberOfOrders = OrdersTotal();   

for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)  
   
   if(  OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue;   
      {
         if( OrderMagicNumber() == MagicNumber2      
           && OrderSymbol() == Symbol()          
            && OrderType() == OP_BUY         
             || OrderType() == OP_SELL )  
             
             Print("DIPlus1: ", DoubleToStr(DIPlus1, Digits), " DIMinus1: ", DoubleToStr(DIMinus1, Digits), " Main0: ",DoubleToStr(Main0, Digits), " Rsi: ",DoubleToStr(Rsi, Digits) );
             
               {if( DIPlus1 > DIMinus1 || Main0 < err || Rsi < xx)
                             OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);
                  else Print("Order Close failed, order number: ", OrderTicket(), " Error: ", GetLastError() ); 
               
               } 
      
      
         
            if( OrderMagicNumber() == MagicNumber1      
              && OrderSymbol() == Symbol()          
               &&  OrderType() == OP_BUY          
                 || OrderType() == OP_SELL ) 
                  
                Print("DIPlus1: ", DoubleToStr(DIPlus1, Digits), " DIMinus1: ", DoubleToStr(DIMinus1, Digits), " Main0: ",DoubleToStr(Main0, Digits), " Rsi: ",DoubleToStr(Rsi, Digits) );
                
                  { if( DIPlus1 < DIMinus1 || Main0 < err || Rsi > x  )
                                 OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); 
                    else Print("Order Close failed, order number: ", OrderTicket(), " Error: ", GetLastError() ); 
                 
                  }
      }
   
    
 return(0);
 }
   

 Close immediately! :(

 
RaptorUK:

//  <------  why this extra OrderClose ???


??  do you have an answer ?
 
RaptorUK:
??  do you have an answer ?

i fixed it !

Please preview my new code. Thank! 

 
toi10005doi:

i fixed it !

Please preview my new code. Thank! 

I gave you the code to use . . . .  all you need to do is copy and paste it.

Your code is still wrong . . .  you need to go back and read the Book  again.

            if( OrderMagicNumber() == MagicNumber1      
              && OrderSymbol() == Symbol()          
               &&  OrderType() == OP_BUY          
                 || OrderType() == OP_SELL )    //  if this is true only the Print is called . . .
                  
                Print("DIPlus1: ", DoubleToStr(DIPlus1, Digits), " DIMinus1: ", DoubleToStr(DIMinus1, Digits), " Main0: ",DoubleToStr(Main0, Digits), " Rsi: ",DoubleToStr(Rsi, Digits) );
                
                  { if( DIPlus1 < DIMinus1 || Main0 < err || Rsi > x  )             //  this happens regardless of the if above . . .
                                 OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); 
                    else Print("Order Close failed, order number: ", OrderTicket(), " Error: ", GetLastError() );   //  this happens if the if above is false . . .  why ??
                 
                  }
 
RaptorUK:
I gave you the code to use . . . .  all you need to do is copy and paste it.

Your code is still wrong . . .  you need to go back and read the Book  again.



Yeah! i will read book more. Can you preview this code for me?

for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)  
   {
   if(  OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue;   
   
               Print("DIPlus1: ", DoubleToStr(DIPlus1, Digits), " DIMinus1: ", DoubleToStr(DIMinus1, Digits), " Main0: ",DoubleToStr(Main0, Digits), " Rsi: ",DoubleToStr(Rsi, Digits) );
   
               if( OrderMagicNumber() == MagicNumber2      
               && OrderSymbol() == Symbol()          
               && OrderType() == OP_BUY         
               || OrderType() == OP_SELL )  
                  {
                  if( DIPlus1 > DIMinus1 || Main0 < err || Rsi < xx)
                     {
                        if(! OrderClose(OrderTicket(),OrderLots(),Bid,3,Green))
                           Print("Order Close failed, order number: ", OrderTicket(), " Error: ", GetLastError() );
                     } 
                  }
               if( OrderMagicNumber() == MagicNumber1      
               && OrderSymbol() == Symbol()          
               &&  OrderType() == OP_BUY          
               || OrderType() == OP_SELL )  
                  { 
                     if( DIPlus1 < DIMinus1 || Main0 < err || Rsi > x  )
                        {
                           if(! OrderClose(OrderTicket(),OrderLots(),Ask,3,Green))  
                              Print("Order Close failed, order number: ", OrderTicket(), " Error: ", GetLastError() );
                        } 
                      
                  }

   
    }
 return(0);
 }
   

why it does not close the order?

 
toi10005doi:

Yeah! i will read book more. Can you preview this code for me?

why it does not close the order?

Can you copy and paste the information printed to the log for the variables in the Print statement.
 
RaptorUK:
Can you copy and pates the information printed to the log for the variables in the Print statement.

I just back test it. But it did not close any order?

 
toi10005doi:

I just back test it. But it did not close any order?

Look in the Journal,  find out what the values Printed are.  Can you copy & paste them here too please . . . .   the whole point of adding the Print statement was for debugging reasons . . .  you need to look at that data and work out what is wrong.
Reason: