Download MetaTrader 5

OrderModify error 1

To add comments, please log in or register
Khurram Moied
337
Khurram Moied  

Whats the workaround??????????????

I am getting "OrderModify error 1" at the execution of the following code in my EA. I simply want the following:

Once the trade is in profit equal to the StopLoss, then stop loss is set to breakeven. AFter that, trailing stop should work in equal steps.

//==================

double TrailingStop=210,StopLoss=100,BuyStop;

bool BE=false;

int k

if(TrailingStop > 0)
{
BuyStop=OrderStopLoss();
if(High[1]-OrderOpenPrice()>0 || OrderStopLoss()==0)
{
if(High[1]-OrderOpenPrice()>=StopLoss*Point && !BE) //First Profit Level equal to intial stop loss is reached.
{
BuyStop=OrderOpenPrice();BE=true;
}
if(OrderStopLoss()==0)//If somehow the orders stop loss was zero
{
BuyStop=OrderOpenPrice()-StopLoss*Point;k=1;BE=false;
}
if(High[1]-OrderOpenPrice()>=k*TrailingStop*Point)//If the current profit is more than trailing stop
{
BuyStop=OrderStopLoss()+k*TrailingStop*Point;k=k+1;
}

OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(BuyStop,digit),OrderTakeProfit(),0,White);
prtAlert("Day Trading: Modifying BUY Order");
}

}

void prtAlert(string str = "") {
Print(Symbol() + " - " + str);
Alert(Symbol() + " - " + str);
}

Brian Dee - Random Trader
1760
Brian Dee - Random Trader  

CK

To use OrderTicket() to supply the ticket number, the order has to be located by an OrderSelect, i.e. looping through the current oprders til you find the one you want to modify.

Alternatives include storing a ticket number (from the original OrderSend) in a static var or array

FWIW

-BB-

Khurram Moied
337
Khurram Moied  

Sorry BB, I posted a part of my EA here, Actually I am already selecting orders and the follwoing coide is already appended on the top of TrailingStop Check.

for(cnt=0; cnt<=totalOrders; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); // the next line will check for ONLY market trades, not entry orders

if(OrderSymbol() == Symbol() && OrderType() == OP_BUY && OrderMagicNumber() == magicEA)
{ // Check for close signal for bought trade
numPos++;
if(isSelling || isClosing)
{
OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Violet); // Close bought trade
//prtAlert("Day Trading: Closing BUY order");
}//if(isSelling || isClosing)

if(TrailingStop > 0)
{
BuyStop=OrderStopLoss();Print("Cond-0 = ",BuyStop);.........................and so on as in my previous post.

Brian Dee - Random Trader
1760
Brian Dee - Random Trader  

in

NormalizeDouble(BuyStop,digit)

use

NormalizeDouble(BuyStop,Digits),

so as to get the right system value for the pair.

If that dont work, write a Print statement for BuyStop - I think its ramping up too far?

-BB-

Khurram Moied
337
Khurram Moied  
Tried with no luck
Ray
2650
Ray  

I am getting "OrderModify error 1"

ERR_NO_RESULT 1 No error returned, but the result is unknown.

...

Insert this line:

.

}

Comment("\n My ticket number is ", OrderTicket(), " and my stop loss setting is ", NormalizeDouble(BuyStop,digit)); // new code

OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(BuyStop,digit),OrderTakeProfit(),0,White);

.

.

One of those values is likely to be erroneous.

Khurram Moied
337
Khurram Moied  

Thanks Gusy..........Somewhere my BuyStop value was messing up.

I am now using the following solution by BorrowBoy in another post. Though I don't know what does "if(OrderStopLoss()<Bid-Point*TrailingStop)" check does on Buy Orders, but its just working for me.

void CheckActiveTradesForStopLoss()
{
int icnt, itotal;
itotal=OrdersTotal();
   for(icnt=0;icnt<itotal;icnt++) 
     {                               // order loop boundary
      OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES);
       // check for opened position, symbol & MagicNumber
      if(OrderType()==OP_SELL && OrderSymbol()==strSymbol  && OrderMagicNumber()==iMagic) 
        {
       
         if (OrderStopLoss()==0)
             {
              OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
             }   
       
         if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
              {
               if(OrderStopLoss()>(Ask+Point*TrailingStop))
                  {
                   OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                  }
              }
        
        }
       
       
       if(OrderType()==OP_BUY && OrderSymbol()==strSymbol  && OrderMagicNumber()==iMagic) 
        {
            if (OrderStopLoss()==0)
             {
              OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
             }
            
             if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                    }
                 }
             
        }
     }  // order loop boundary
return(0);
    
}
Riyo Putra
420
Riyo Putra  

Try this code:


void CheckActiveTradesForStopLoss()
{
int icnt, itotal;
 
itotal=OrdersTotal();
 
   for(icnt=0;icnt<itotal;icnt++) 
     {                               // order loop boundary
      OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES);
       // check for opened position, symbol & MagicNumber
      if(OrderType()==OP_SELL && OrderSymbol()==strSymbol  && OrderMagicNumber()==iMagic)  
        { 
        
         if (OrderStopLoss()==0)
             {
              OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
             }    
        
 
         if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
              {
               if(OrderStopLoss()>(Ask+Point*TrailingStop)+Point)   //////////// MODIFICATION ////////////
                   {
                   OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                  }
              }
         
 
        }
        
        
       if(OrderType()==OP_BUY && OrderSymbol()==strSymbol  && OrderMagicNumber()==iMagic)  
        { 
            if (OrderStopLoss()==0)
             {
              OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
             }
             
             if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop-Point)  ////////// MODIFICATION /////////////
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                    }
                 }
              
        }
 
     }  // order loop boundary
 
return(0);
     
}
Brian Dee - Random Trader
1760
Brian Dee - Random Trader  

"..solution by BorrowBoy..."

Sounds like a really shady character - you do get some very odd folks hanging out on forums! :)

Neat code tho - must have glommed it from someone else ;)

-BB-

Khurram Moied
337
Khurram Moied  

-:)...........I think I misspelled the ID. Its BarrowBoy not BorrowBoy. Hope ther is no shady character up here.

To add comments, please log in or register