Hi I´m new to the stuff - page 2

 
Rosh:
You need to use loop , for example

int i,y;
 
 
int start()
 
{
 
 
Print(OrdersTotal());
if (OrdersTotal()== 0)
 {
 OrderSend (Symbol(),OP_BUY,1,Ask,NULL,NULL,NULL,NULL,0,0,Green);
 }
else
 {
 for (i=OrdersTotal();i>=0;i--)
 if (OrderSelect(i,SELECT_BY_POS))
 if (OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
 }
 
}

It is more safely code.


for (i=OrdersTotal();i>0;i--)
 {
      Print("Position ist offen!!");
      if( D>=0 && D1<0)
         {
               Print("Ausstiegsignal gefunden!!! -> versuche zu verkaufen!!!");
               y++;
               if (OrderSelect(y,SELECT_BY_TICKET))
                     {
                        Print("Order ist gewählt");
                        if (OrderType()==OP_BUY)
                              {
                                 Print("Order ist Buy und wird geschlossen!!");
                               
                                 OrderClose(y,OrderLots(),Bid,NULL,Red);
                              }
                     }
               else 
                  Print("Order konnte nicht gewählt werden");
         }
 }
the code above isn´t working... the one below is - wheres the difference?
How can I increase the Moddeling quality of the EA?
 
Of cource, because Long should be closed on Bid price.

int i,y;
 
 
int start()
 
{
 
Print(OrdersTotal());
if (OrdersTotal()== 0)
 {
 OrderSend (Symbol(),OP_BUY,1,Ask,NULL,NULL,NULL,NULL,0,0,Green);
 }
else
 {
 for (i=OrdersTotal();i>=0;i--)
 if (OrderSelect(i,SELECT_BY_POS))
 if (OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
 }
 
}
This EA can open Buy but not to close.
Reason: