ea runs on my broker but not on another

 
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"


//This ea sets the stop loss for a trade, given the lots used in the trade and the risk factor inputed.  

extern double risk_factor = 0.02;
extern double reward_risk_ratio = 2.0;
 
 
 
int auto_stop_loss = 1;
int auto_ticket = 1;
int determine_pip_value = 1;
int symbol_detect = 0;
int ticket = 0;
int set_modify = 1;
 
double stop_loss_points = 0.0; 
double spread = 0.0;
double equity = 0.0;
double a = 0.0;
double b = 0.0;
double lots = 0.0;
double value_per_pip = 10.00;
double pip_value = 0.0;
 
 
int init()
  {
 
   return(0);
  }
 
int deinit()
  {
 
   return(0);
  }
 
int start()
  {
 
 
  if(auto_ticket == 1)
   {
    OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
     {
      ticket = OrderTicket();
      auto_ticket = 0;
     } 
    }
 
  if(OrderSelect(ticket,SELECT_BY_TICKET))
     {
       lots = OrderLots();
      }
     
 
 
  if(auto_stop_loss == 1)
 {
  value_per_pip = MarketInfo(Symbol(),MODE_TICKVALUE);
  equity = AccountEquity(); 
  a = equity * risk_factor;
  b = value_per_pip * lots;
  stop_loss_points =a/b - spread; 
  auto_stop_loss = 0;
 } 
 
 
 symbol_detect = StringFind(Symbol(),"JPY",0);
 
  if(determine_pip_value  == 1)
  {
   if(symbol_detect > 1)
    {
     pip_value = 0.01;
     determine_pip_value = 0;
    }
  else
   {
    pip_value = 0.0001;
    determine_pip_value = 0;
   }
  }
 
  
  
  if(set_modify == 1)
   {
    if(OrderSelect(ticket,SELECT_BY_TICKET))
     {
       OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() + (stop_loss_points * pip_value),OrderOpenPrice() - (stop_loss_points * reward_risk_ratio * pip_value),0,0); 
      set_modify = 0;
     } 
   }
 

 
   return(0);
  }
 
  
 
forestmyopia:

Thank you for sharing that with us :D

I'm guessing that you intended to put a question somewhere?

Maybe EA is written for a 5 digit broker and you are trying it with a 4 digit broker?

One broker may use "EURUSD" whereas another "EURUSDmn"

Without more information, difficult to answer the unasked question.

 

Now that you have supplied some code :)

First of all, this code appears to perform a single modify on a single trade that has to be already opened. Surely it would be more sensible if written as a script?

 

Well, script or not, it doesn't explain why it doesn't work on all brokers, does it? Here is an example of another ea which does work on my broker and the same other broker without any problems. So what is essentially different in this code from the other code? This ea allows you to set a buy stop and calculates the lots for you based on the risk factor and the stoploss that you put in.



//+------------------------------------------------------------------+
//|                                                     buy stop.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"


extern double buy_stop_price = 0.0;   
extern double stop_loss_points = 30.0;
extern double risk_factor = 0.02;
extern double reward_risk_ratio = 2.0;
 
 
 
int auto_lots = 1;
int auto_ticket = 1;
int determine_pip_value = 1;
int symbol_detect = 0;
int ticket = 0;
int enable_trade = 1;
int set_modify = 1;
 
double spread = 0.0;
double equity = 0.0;
double a = 0.0;
double b = 0.0;
double c = 0.0;  
double lots = 0.0;
double value_per_pip = 10.00; 
double pip_value = 0.0;
 
 
int init()
  {
 
   return(0);
  }
 
int deinit()
  {
 
   return(0);
  }
 
int start()
  {
 
 
  if(auto_ticket == 1)
   {
    OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
     {
      ticket = OrderTicket();
      auto_ticket = 0;
     } 
    }
 
  if(auto_lots == 1)
 { 
  value_per_pip = MarketInfo(Symbol(),MODE_TICKVALUE) * 10.0;  
  equity = AccountEquity();
  a = stop_loss_points + spread;
  b = value_per_pip * a;
  c = equity * risk_factor;
  lots = c/b;
  auto_lots = 0;
 } 
 
 
 symbol_detect = StringFind(Symbol(),"JPY",0);
 
  if(determine_pip_value  == 1)
  {
   if(symbol_detect > 1)
    {
     pip_value = 0.01;
     determine_pip_value = 0;
    }
  else
   {
    pip_value = 0.0001;
    determine_pip_value = 0;
   }
  }
 
   if(enable_trade == 1)
   {
    enable_trade = 0;
    ticket = OrderSend(Symbol(),OP_BUYSTOP,lots,buy_stop_price,3,buy_stop_price - stop_loss_points * pip_value,buy_stop_price + reward_risk_ratio * 
      stop_loss_points * pip_value,0,0,0);
    }
   
  if(set_modify == 1)
   {
    if(OrderSelect(ticket,SELECT_BY_TICKET))
     {
       OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() - (stop_loss_points * pip_value),OrderOpenPrice() + (stop_loss_points * 
              reward_risk_ratio * pip_value),0,0); 
      set_modify = 0;
     } 
   }
 

 
   return(0);
  }
 
forestmyopia:

Well, script or not, it doesn't explain why it doesn't work on all brokers, does it? Here is an example of another ea which does work on my broker and the same other broker without any problems. So what is essentially different in this code from the other code? This ea allows you to set a buy stop and calculates the lots for you based on the risk factor and the stoploss that you put in.


Sorry, I had written more but the realised that I had made a mistake, so deleted the rest.

I haven't looked at your 2nd code, but I believe that I see an error in the 1st

There is no need for this code at all, I think

symbol_detect = StringFind(Symbol(),"JPY",0);
 
  if(determine_pip_value  == 1)
  {
   if(symbol_detect > 1)
    {
     pip_value = 0.01;
     determine_pip_value = 0;
    }
  else
   {
    pip_value = 0.0001;
    determine_pip_value = 0;
   }
  }

And change

 OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() + (stop_loss_points * pip_value),OrderOpenPrice()
 - (stop_loss_points * reward_risk_ratio * pip_value),0,0); 
    

to this

OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() + (stop_loss_points * Point),OrderOpenPrice()
 - (stop_loss_points * reward_risk_ratio * Point),0,0); 

Also, you should get into the habit of using and printing GetLastError(). I can guess that you are probably using fairly large lot sizes and the 2 brokers have different StopLevels. You will probably find that GetLastError() returns 130, meaning that the stop is too close to price.

EDIT: I wrote leverage, when I meant StopLevels

 
forestmyopia:

Well, script or not, it doesn't explain why it doesn't work on all brokers, does it? Here is an example of another ea which does work on my broker and the same other broker without any problems. So what is essentially different in this code from the other code? This ea allows you to set a buy stop and calculates the lots for you based on the risk factor and the stoploss that you put in.

Does your OrderModify() fail or isn't it called ? does your OrderSelect() fail ? why aren't you checking these calls ? don't you want to know if they have failed ? and if they do fail don't you want to know why ?


You should read this: What are Function return values ? How do I use them ?

 
No open order, ticket is invalid. Order on another pair, bogus processing.
What are Function return values ? How do I use them ? - MQL4 forum
order accounting - MQL4 forum
  if(auto_ticket == 1)
   {
    OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
     {
      ticket = OrderTicket();
      auto_ticket = 0;
     } 
    }
Assumes 10 digit broker and Ticksize == Point
Why is there NO Complete EA within the Code-Base? - MQL4 forum
  value_per_pip = MarketInfo(Symbol(),MODE_TICKVALUE) * 10.0;
Assumes forex only, no metals, no exotic pairs
Problems with a calculation - MQL4 forum
 symbol_detect = StringFind(Symbol(),"JPY",0);
 
  if(determine_pip_value  == 1)
  {
   if(symbol_detect > 1)
    {
     pip_value = 0.01;
     determine_pip_value = 0;
    }
  else
   {
    pip_value = 0.0001;
    determine_pip_value = 0;
   }
  }
Slippage not adjusted for 4/5 digit brokers
Problems with a calculation - MQL4 forum
What are Function return values ? How do I use them ? - MQL4 forum
ticket = OrderSend(Symbol(),OP_BUYSTOP,lots,buy_stop_price,3,
                      buy_stop_price - stop_loss_points * pip_value,
                      buy_stop_price + reward_risk_ratio * 
                                 stop_loss_points * pip_value,0,0,0);
 
RaptorUK:

Does your OrderModify() fail or isn't it called ? does your OrderSelect() fail ? why aren't you checking these calls ? don't you want to know if they have failed ? and if they do fail don't you want to know why ?


You should read this: What are Function return values ? How do I use them ?

 

Yes, are right. I need to check the calls for error messages. I will work on this.

 
GumRai:


Sorry, I had written more but the realised that I had made a mistake, so deleted the rest.

I haven't looked at your 2nd code, but I believe that I see an error in the 1st

There is no need for this code at all, I think

And change

to this

Also, you should get into the habit of using and printing GetLastError(). I can guess that you are probably using fairly large lot sizes and the 2 brokers have different StopLevels. You will probably find that GetLastError() returns 130, meaning that the stop is too close to price.

EDIT: I wrote leverage, when I meant StopLevels

 

I think I would run into trouble using the Point variable because of the existence of 4 or 5 decimal brokers. Not sure if Point accounts accurately for this.

Reason: