Problem with OrderSend and OrderClose - page 2

 

Oh yes i realized that the market is closed now...and I found the stupid mistake...

I don't know how, but I changed the open price "bid" and "ask" and that was the reason why it worked with a high slippage...! But I plan to include some parts of Ais' or WHRoaders' code in mine, thank you for that...

Now I tried to improve my ordersending-code with a take profit. So the aim is, that if it reachs the tp, it closes, otherwise, it should close when the ordersend signal in the opposite direction is given...


My code:


extern int Limit=50;
int Position=0, test=0;
int ind, art;
static bool first_order = false;




if(art==-1 && test==1)
     {
      test=-1;
      if (OrderSelect(0,SELECT_BY_POS)==true && Position==1)
            if(OrderType()==OP_BUY)
                  {
                   OrderClose(OrderTicket(),OrderLots(),Bid,3);      
                   OrderSend(Symbol(),OP_SELL,Lot,Bid,3,0,Bid-Limit*Point);
                   Position=-1;
                  }            
      if (OrderSelect(0,SELECT_BY_POS)==false && Position==1)
       {
        OrderSend(Symbol(),OP_SELL,Lot,Bid,3,0,Bid-Limit*Point);
        Position=-1;
       }           
      if ( first_order == false )
      {
       Ticket=OrderSend(Symbol(),OP_SELL,Lot,Bid,3,0,Bid-Limit*Point);
       Position=-1;
       if ( Ticket > 0 )
         first_order = true;     
      }                 
     }                  


I use the contrary code to close a sell-order, if one exists and and to open a buy-order.

I believe I made a logical mistake, because it sometimes closes with the tp, but even if I make the tp as small as possible, it only closes about half of the orders with it, but not in a static sequence. Is there anybody who can see a mistake in there?

Thanks for your help.



Manag


 
My account what problem position