Couldn't modify the order due to 0 no error

 
Hi, I seem to have this problem across all my EA's it doesn't effect the performance but it is annouying me. "Couldn't modify the order due to 0 no error". I can't see why it is even running this line of code as it does modify the order. I have put it in a simple buying script so you can see my issue with everything commented. Thanks in advance 
//+------------------------------------------------------------------+
//|                                                 BuyingScript.mq4 |
//|                                   BOAFX Trading Signal Solutions |
//|                                            https://www.boafx.com |
//+------------------------------------------------------------------+
#property copyright "BOAFX Trading Signal Solutions"
#property link      "https://www.boafx.com"
#property version   "1.00"
#property strict
#include <stdlib.mqh>
#property show_inputs
extern int StopLoss=20;
extern int TakeProfit=50;
extern double RiskPercent=2;

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   double pips=Point;//0.0001 0.001
   if(Digits==3 || Digits ==5)pips *=10;
   
   double Lotsize = NormalizeDouble(AccountEquity()*((RiskPercent/100)/StopLoss)/10,2);//lotsize calculation based on user percent input
  
   Comment("Your lotsize is ", Lotsize);
   
   int err = 0;
   int  TicketNumber= OrderSend(Symbol(),OP_BUY,Lotsize,Ask,30,0,0,"BuyingScript",1234,0,clrGreen);//send order 
   if (TicketNumber == -1)//if a ticket numebr isnt returned run error message
   {
      err=GetLastError();
      Print("Could not place the order due to  ", err,"  ",ErrorDescription(err));
   }
   else// if we have a good ticket number 
   {
     if (!OrderSelect(TicketNumber,SELECT_BY_TICKET))//if order isnt selected run error message
     {
     err=GetLastError();
      Print("Could not select the order due to  ", err,"  ",ErrorDescription(err));
      if(err==ERR_TRADE_NOT_ALLOWED)Alert("YOU NEED TO ENABLE YOUR AUTOTRADING BUTTON!");
     }
     else//if we able to select an order
     {
      double price = OrderOpenPrice();
      if (!OrderModify(TicketNumber,price,price-(StopLoss*pips),price+(TakeProfit*pips),0,clrGreen))//if order isnt modify run error message
      err=GetLastError();
      Print("Could not modify the order due to  ", err,"  ",ErrorDescription(err));
   
     }
   }
   
 
  }
//+------------------------------------------------------------------+
 

Hi and good morning,

the line with the print statement will be executed every time, because it depends not on the result of the if statement. You should
modify it like this:

      double price = OrderOpenPrice();
      if (!OrderModify(TicketNumber,price,price-(StopLoss*pips),price+(TakeProfit*pips),0,clrGreen))//if order isnt modify run error message
      {
          err=GetLastError();
          Print("Could not modify the order due to  ", err,"  ",ErrorDescription(err));
      }
   


I hope, this helps you.

Best regards

 
Werner Klehr #:

Hi and good morning,

the line with the print statement will be executed every time, because it depends not on the result of the if statement. You should
modify it like this:


I hope, this helps you.

Best regards

IT'S always something simple.. thanks 

 
Werner Klehr #: You should modify it like this:
      double price = OrderOpenPrice();

You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

  3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
    Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).