Search code examples
mql4forex

Comment not being used in trade MQL4


Unfortunately I am not able to post the code I am debugging as it is not mine and I am bound not to show it... BUT I will describe it as detailed as possible.

There are 4 strategies base on 4 indicators, custom, and not-custom ones. So basically instead of 4 different EAs running in 4 different charts with the same 4 indicators each... The client asked me to optimise them by putting them all in one to run 4 into 1 EAs in the same chart.

EVERYTHING is the same. They are tested as well that they are the same. They open the same trades, on the same moments. Nothing is changed 100%. The only thing I did (for this part of the debugging, because obviously I had a lot more to do before that) is to copy functions and code. And I seperated all different strategies with an "if" as input

input bool strategy1enabled = true; etc... so he/she can disable/enable individual strategies if wanted.

everything works BUT.... All but 1 strategies, does not show the Comment on the trades.

All 4 use the same Buy/Sell/CloseOrder functions so I just input the values to keep the code shorter.

//---  
bool OrdClose (int ticket_number, double lt, int slp)
  {
      return OrderClose(ticket_number,lt,iClose(NULL,0,0),slp,clrViolet);
  }
//---
int Buy(double lt, int slp, int slss, int tpft, string cmt, int mgc)
  {
      return OrderSend(NULL,OP_BUY,lt,Ask,slp,Ask-slss*Point,Ask+tpft*Point,cmt,mgc,0,clrDarkBlue);
  }
//---
int Sell(double lt, int slp, int slss, int tpft, string cmt, int mgc)
  {
      return OrderSend(NULL,OP_SELL,lt,Bid,slp,Bid+slss*Point,Bid-tpft*Point,cmt,mgc,0,clrDarkRed);
  }

1 strategy just refuses to put comment. Any ideas why? When used seperated WITH THE SAME CODE and the EXACT SAME functions... comment shows...

EDIT:

2021.05.04 18:30:48.670 The_Big_Holla_v1_8_EA CADJPY,H1: open #85710545 buy 0.06 CADJPY at 88.755 sl: 88.655 tp: 88.955 ok 2021.05.04 18:30:48.462 The_Big_Holla_v1_8_EA CADJPY,H1: Holla v4.9 || GreedInjectionMode 2021.05.04 18:30:48.462 The_Big_Holla_v1_8_EA CADJPY,H1: Holla v4.9 || GreedInjectionMode

Comment is passed properly and checked before being passed to function and before OrderSend within function: The function:

int Sell(double lt, int slp, int slss, int tpft, string cmt, int mgc)
  {
      Print(cmt);
      return OrderSend(NULL,OP_SELL,lt,Bid,slp,Bid+slss*Point,Bidtpft*Point,cmt,mgc,0,clrDarkRed);
  }

How the function is called:

Print(EACommentInj);
ticket_val_inj = Buy(lotsizeInj,slippageInj,stoplossInj,takeprofitInj,EACommentInj,MagicInj);

This is how it is initialised and it NEVER changes. It is mentioned only where it is passed. Where I showed you above.

const string EACommentInjGreed = "Holla v4.9 || GreedInjectionMode Greed Mode";

Solution

  • Although this is undocumented, the "string comment=NULL" parameter of the trade function OrderSend() in MQL4 is limited to 31 characters. If this limit is exceeded then the string is rejected as a whole and treated as NULL.

    In your code, just before the OrderSend() function, add the following line:

    cmt=StringSubstr(cmt,0,31);