MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
Post Your News in Blogs and Become Famous!

OrderModify error 1

Back to topics list To post a new topic, please log in or register
avatar
108
ckmoied 2008.07.09 16:15
 

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);
}

 
EUR/USD back into the bears den, downside wide open
EUR/USD back into the bears den, downside wide open
kolioo77 | 22 November 2014, 12:24 | Views: 89
As Euro Zone suffered from deflation ,there is no way to rise inflation due to droping energy prices globally due to stronger doller rallies  and high capacity  energy  reservation facailities in europe can rise energy prices for years risk appitte to rise excahge rates.                                              Draghi has indicated that they are prepared to do whatever it takes to lift inflation to their target, almost as a matter of emergency.
avatar
Moderator
1936
BarrowBoy 2008.07.09 18:40 #
 

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-

 
avatar
108
ckmoied 2008.07.09 19:08 #
 

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.

 
avatar
Moderator
1936
BarrowBoy 2008.07.09 19:23 #
 

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-

 
avatar
108
ckmoied 2008.07.09 22:29 #
 
Tried with no luck
avatar
2646
phy 2008.07.10 02:09 #
 

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.

 
avatar
108
ckmoied 2008.07.10 10:54 #
 

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);
    
}
 
avatar
79
riyo 2008.07.10 14:24 #
 

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);
     
}
avatar
Moderator
1936
BarrowBoy 2008.07.10 15:01 #
 

"..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-

 
avatar
108
ckmoied 2008.07.10 15:12 #
 

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

 
Back to topics list  

To add comments, please log in or register