What is order_id ? - page 2

 
toi10005doi:

@Raptor:

Yes, But i harly undertood because i just star to write EA. Sr for bother you.

 I don't understand why my order close instantly after it star.

If you don't understand my thread you need to read the Book more . . . .  the thread is just about a loop and closing orders and is very simple and clear and you still haven't taken heed of it.


Why do you try to Close your Order 4 times ?  twice at Bid and twice at Ask ?

 
My close condition is a cobine one. But when i wrote it, it 's not work. So i separate that one.
 
toi10005doi:
My close condition is a cobine one. But when i wrote it, it 's not work. So i separate that one.
But you are trying to close the same Order (by ticket number)  four times . .  why ?
 
toi10005doi:

Yeah! i got it.

i fixed my code but my order still close instantly after it star. Please show me what i wrong

In the loop where you close your Order Print these values . . .  DIPlus1  DIMinus1 Main0  Rsi   make sure you use DoubleToStr() to get the correct number of decimal places.
 
Raptor already told you what to do. Add some print statements with the full variable value in your loop and you find out why
 
RaptorUK:
In the loop where you close your Order Print these values . . .  DIPlus1  DIMinus1 Main0  Rsi   make sure you use DoubleToStr() to get the correct number of decimal places.

Do this.  What do you get in the log ?
 
RaptorUK:
Do this.  What do you get in the log ?

Can you show me the code?

 
toi10005doi:

Can you show me the code?

Are you kidding ?  it's just a single line using Print() and DoubleToStr() . . .

Write it yourself,  post it here and I'll give my time for free to review it for you.
 
RaptorUK:
Are you kidding ?  it's just a single line using Print() and DoubleToStr() . . .

Write it yourself,  post it here and I'll give my time for free to review it for you.

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 && DIPlus0 > DIMinus0 && Rsi < x )

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

   if (Main0 > err && Main1 < err && DIPlus0 < DIMinus0  && 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, 4));
         Print("DIMinus1",DoubleToStr(  DIPlus1, 4));
          Print("Main0",DoubleToStr(    DIPlus1, 4));
           Print("Rsi",DoubleToStr(     DIPlus1, 4));  
     {if( DIPlus1 > DIMinus1 || Main0 < err || Rsi < xx)
                   OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);
     } 
   if( OrderMagicNumber() == MagicNumber1      
     && OrderSymbol() == Symbol()          
      &&  OrderType() == OP_BUY          
        || OrderType() == OP_SELL )  
        Print("DIPlus1",DoubleToStr(    DIPlus1, 4));
         Print("DIMinus1",DoubleToStr(  DIPlus1, 4));
          Print("Main0",DoubleToStr(    DIPlus1, 4));
           Print("Rsi",DoubleToStr(     DIPlus1, 4));
    { if( DIPlus1 < DIMinus1 || Main0 < err || Rsi > x  )
                   OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);   
   }
      {  if ( ! OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 3 ) )               
         Print("Order Close failed, order number: ", OrderTicket(), " Error: ", GetLastError() ); 
    }           
    }
 return(0);
 }
   
Do you mean this ? But now it do not close order.
 
toi10005doi:
Do you mean this ? But now it do not close order.
I said add one line . . . that was all that was needed.

Look at your code . . . . follow it line by line,  see what you have added,  see why you have broken it . . . this is how you learn.  Do you understand how an if statement works ?  do you understand the purpose of the braces  {  }  ?
Reason: