Use order limit

 

I need an help, i want to use in my EA 3 entry

one at first condition and the other 2 above/belowe depend is long or short with limit order.

For Example i have a buy at 1.4000 i put 2 oder limit at 1.3960 and 1.3930

And when the trailing start to run i want to delete all the order pending that doesn't reached.

But i see that the limir order don't run, why? if i use just order send and OP_buylimit with an ask price, the ea don't put any orderlimit when i made test


ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-Point*StopLoss,Ask+TakeProfit*Point,0,0,Green); // buono dei test //
RefreshRates();
entratalong= OrderOpenPrice( ); 
        
        
ticket=OrderSend(Symbol(),OP_BUYLIMIT,Lots_2ingresso,entratalong-Point*Secentrata,3,Bid-Point*StopLoss+Point*Secentrata,entratalong+TakeProfit*Point,0,0,Magenta); // buono dei test //

ticket=OrderSend(Symbol(),OP_BUYLIMIT,Lots_3ingresso,entratalong-Point*Terzentrata,3,Bid-Point*StopLoss+Point*Terzentrata,entratalong+TakeProfit*Point,0,0,Magenta); // buono dei test //
      



 

Maybe Bid-Point*StopLoss+Point*Secentrata and/or Bid-Point*StopLoss+Point*Terzentrata are not valid SL values. depending on StopLoss.

Another possibility : entratalong gets the wrong price because OrderOpenPrice( ) refers to the order used in the last OrderSelect() function not the last OrderSend() function.

You should have explanation using Print(GetLastError())

 
monpseudo88:

Maybe Bid-Point*StopLoss+Point*Secentrata and/or Bid-Point*StopLoss+Point*Terzentrata are not valid SL values. depending on StopLoss.

Another possibility : entratalong gets the wrong price because OrderOpenPrice( ) refers to the order used in the last OrderSelect() function not the last OrderSend() function.

You should have explanation using Print(GetLastError())

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+Point*StopLoss,Bid-TakeProfit*Point,0,0,Red); // buono senza mony mangemt //
         RefreshRates();
         
         //entratashort= OrderOpenPrice( );
         entratashort= OrderOpenPrice( );
         Print(GetLastError());
         Comment( "entrata short", entratashort, "\n seconda entrata", entratashort + Point*Secentrata,
         "\n stop", entratashort+ Point*StopLoss+2*Point ,
         "\n target " ,entratashort-TakeProfit*Point );
         
         ticket=OrderSend(Symbol(),OP_SELLLIMIT,Lots_2ingresso,entratashort+Point*Secentrata+2*Point,3,entratashort+ Point*StopLoss,entratashort-TakeProfit*Point,0,0,Yellow); // buono dei test //
         ticket=OrderSend(Symbol(),OP_SELLLIMIT,Lots_3ingresso,entratashort+Point*Terzentrata+2*Point,3,entratashort+Point*StopLoss,entratashort-TakeProfit*Point,0,0,Yellow); // buono dei test //
      

Now i try to use comment to see where are stoploss, entry and target

it's seem all ok but in diary i have order send error 3

 

Hi

I posted the same problem 2 days ago. I thought I was doing something wrong but it seems you have the same problem. Come on you experts sort out our simple problem please.

 

Your problem might be in the OrderSend command structure. What I don't understand is why your OP_BUY OrderSend works, but the Limit orders don't. After you specify the stop-loss and take-profit there should be 4 more fields, but you only have 3. Try adding the highlighted text here:

ticket=OrderSend(Symbol(),OP_SELLLIMIT,Lots_2ingresso,entratashort+Point*Secentrata+2*Point,3,entratashort+ Point*StopLoss,entratashort-TakeProfit*Point,NULL,0,0,Yellow);

See if that fixes it. If not, then I don't know.

- Tovan

 
staff - u r very harsh for del my post - give reason!
 
tovan:

Your problem might be in the OrderSend command structure. What I don't understand is why your OP_BUY OrderSend works, but the Limit orders don't. After you specify the stop-loss and take-profit there should be 4 more fields, but you only have 3. Try adding the highlighted text here:

ticket=OrderSend(Symbol(),OP_SELLLIMIT,Lots_2ingresso,entratashort+Point*Secentrata+2*Point,3,entratashort+ Point*StopLoss,entratashort-TakeProfit*Point,NULL,0,0,Yellow);

See if that fixes it. If not, then I don't know.

- Tovan

Mine are like this


ticket=OrderSend(Symbol(),OP_BUYLIMIT,NLots,Ask-Limit*pnt,Slip*pnt,Ask-(Limit+stoploss)*pnt,Ask+(-Limit+takeprofit)*pnt,"R2Buy",MagicN,1800,Cyan);
ticket=OrderSend(Symbol(),OP_SELLLIMIT,NLots,Bid+Limit*pnt,Slip*pnt,Bid+(Limit+stoploss)*pnt,Bid-(Limit+takeprofit)*pnt,"R2Sell",MagicN,1800,Pink);


you need a time for a pending order but they still don't work.

 
tovan:

Your problem might be in the OrderSend command structure. What I don't understand is why your OP_BUY OrderSend works, but the Limit orders don't. After you specify the stop-loss and take-profit there should be 4 more fields, but you only have 3. Try adding the highlighted text here:

ticket=OrderSend(Symbol(),OP_SELLLIMIT,Lots_2ingresso,entratashort+Point*Secentrata+2*Point,3,entratashort+ Point*StopLoss,entratashort-TakeProfit*Point,NULL,0,0,Yellow);

See if that fixes it. If not, then I don't know.

- Tovan

Now Workk..... Thanks so much

But the orderopenprice evry time give me a different price in backtest, because i want that he give me the price of last opentrade, and about this price depend where i put the limit order!!!

Sometime work correctly and give me the right price of trade, but when it is close, at the next opentrade the funcion give me the last trade closed!!

Esample Entry short 1.40 open tradefunzion give = 1.40, this trade is closed in gain, next trade short at 1.41 the open trade funzion give me 1.40!! e not 1.41


         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+Point*StopLoss,Bid-TakeProfit*Point,0,0,Red); // buono senza mony mangemt //
         RefreshRates();
         
         //entratashort= OrderOpenPrice( );
         
         entratashort= OrderOpenPrice( );
         Print(GetLastError());
         Comment( "entrata short", entratashort, "\n seconda entrata", entratashort + Point*Secentrata,
         "\n stop", entratashort+ Point*StopLoss+2*Point ,
         "\n target " ,entratashort-TakeProfit*Point );
         
         ticket=OrderSend(Symbol(),OP_SELLLIMIT,Lots_2ingresso,entratashort+Point*Secentrata+2*Point,3,entratashort+ Point*StopLoss,entratashort-TakeProfit*Point,NULL,0,0,Yellow); // buono dei test //
         ticket=OrderSend(Symbol(),OP_SELLLIMIT,Lots_3ingresso,entratashort+Point*Terzentrata+2*Point,3,entratashort+Point*StopLoss,entratashort-TakeProfit*Point,NULL,0,0,Yellow); // buono dei test //
      


Here i add on trailing where delete my pending oreder if they are not filled!!!

int TrailStop()
{
   int cnt,result,total=OrdersTotal();

   for(cnt = total-1; cnt >= 0; cnt--)
   {
      RefreshRates();
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if ((OrderSymbol() == Symbol()) && (OrderProfit() > 0.00))
      {
                 
         if (OrderType()==OP_BUY) 
         {
            if(Bid - OrderOpenPrice() > Point * TrailingStop) 
            {
               if(OrderStopLoss() < Bid - Point * TrailingStop) 
               {
                  OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
               
               }
            }
         }
      }
       if (OrderType()==OP_SELL)
      {
         if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) 
         {
            if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) 
            {
               OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
               
            }
         }
      }
      //---- pending orders only are considered
      if( OrderType()!=OP_SELL && OrderType()!=OP_BUY && (OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0) && OrderStopLoss() < Bid - Point * TrailingStop)
         result =OrderDelete(OrderTicket());
   }
   return(0);
}
 
The_Matrix:

Now Workk..... Thanks so much

But the orderopenprice evry time give me a different price in backtest, because i want that he give me the price of last opentrade, and about this price depend where i put the limit order!!!

Sometime work correctly and give me the right price of trade, but when it is close, at the next opentrade the funcion give me the last trade closed!!

Esample Entry short 1.40 open tradefunzion give = 1.40, this trade is closed in gain, next trade short at 1.41 the open trade funzion give me 1.40!! e not 1.41



Here i add on trailing where delete my pending oreder if they are not filled!!!

Now work correctly, and place at right place the pending order, but how i can cancel it give me order this error

ERR_INVALID_TICKET4108Invalid ticket.


// thir version work!!!
OrderSelect
(ticket,SELECT_BY_TICKET,MODE_TRADES);
entratashort= OrderOpenPrice( );
RefreshRates();
ticket=OrderSend(Symbol(),OP_SELLLIMIT,Lots_2ingresso,entratashort+Point*Secentrata+2*Point,3,entratashort+ Point*StopLoss,entratashort-TakeProfit*Point,NULL,0,0,Yellow); // buono dei test //
ticket=OrderSend(Symbol(),OP_SELLLIMIT,Lots_3ingresso,entratashort+Point*Terzentrata+2*Point,3,entratashort+Point*StopLoss,entratashort-TakeProfit*Point,NULL,0,0,Yellow); // buono dei test //
  

  
about trailing

RefreshRates();
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if ((OrderSymbol() == Symbol()) && (OrderProfit() > 0.00))
      {
                
         if (OrderType()==OP_BUY)
         {
            if(Bid - OrderOpenPrice() > Point * TrailingStop)
            {
               if(OrderStopLoss() < Bid - Point * TrailingStop)
               {
                  OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                  result =OrderDelete(OrderTicket());
               }