Is it possible to append the pair symbol in trade comments for ease or sorting by pair later?

 

Hello,

I am a "newbie" to programming and am enjoying learning, even though it is MT4 stuff.


I have made an EA to work off my indicator and trade plan and would like to get the trade comment to include the pair so I can sort easily and see which pairs work well and those that don't.

This is the line of code where the trade comment is:


ticket = OrderSend(Symbol(), OP_SELL, SellLots, Bid, Slippage, 0, 0, "MyEA_v6_rev_1_Short", SellOrderId, 0, Red);


Presently I can tell it is generated by my EA version 6, Revision 1 and that it was a Short trade. I am wondering if I can modify this line so the symbol (say) EURUSD can also be included so the trade comment would be something like "MyEA_v6_rev_1_EURUSD Short" instead of just "MyEA_v6_rev_1_Short"

I have been trying to figure this out without success and it occurred to me one kind MQL savvy programmer may be able to point me in the right direction.

All help gratefully appreciated and TIA

Newton51

 
You can only set the comment when u send the trade using OrderSend(). No way to change it afterwards.
 
gordon:
You can only set the comment when u send the trade using OrderSend(). No way to change it afterwards.


Many thanks for prompt reply.

If it is possible to append the symbol it is quite okay to be recorded with order at time of order creation

Does this clarify? My apologies for not being specific enough right off

 
I don't understand your question but you can put whatever u want in the comment. Note that some servers overwrite the last characters of an order's comment in certain situations.
 
gordon:
I don't understand your question but you can put whatever u want in the comment. Note that some servers overwrite the last characters of an order's comment in certain situations.
I was hoping the answer would be something like...


ticket = OrderSend(Symbol(), OP_SELL, SellLots, Bid, Slippage, 0, 0, "MyEA_v6_rev_1_Short"[++Symbol()], SellOrderId, 0, Red); <- inserting the code required [..thus....] to append the Symbol in the text string.


So when the trade is initiated the comment is "MyEA_v6_rev_1_Short EURUSD" or even better would be "EURUSD MyEA_v6_rev_1_Short" 1


I am learning by knowing what I want to do then going looking for a resource where I can "fiddle" around until I get what I need. I have managed to put together my EA opening and intuitively closing if the trend reverses so I am losing far less than manual trading. I am pasting the trade data into an Excel spreadsheet and want to filter / sort by variaous attributes. If I could include the pair in the trade comment it would be great.

 
NewtonLeo:

ticket = OrderSend(Symbol(), OP_SELL, SellLots, Bid, Slippage, 0, 0, "MyEA_v6_rev_1_Short"[++Symbol()], SellOrderId, 0, Red); <- inserting the code required [..thus....] to append the Symbol in the text string.

ticket = OrderSend(Symbol(), OP_SELL, SellLots, Bid, Slippage, 0, 0, Symbol() + " MyEA_v6_rev_1_Short", SellOrderId, 0, Red);
 
gordon:
ticket = OrderSend(Symbol(), OP_SELL, SellLots, Bid, Slippage, 0, 0, Symbol() + " MyEA_v6_rev_1_Short", SellOrderId, 0, Red);


Many thanks, I was kind of right but didnt do that. I am very appreciative of you help, time and patience.
 
gordon:
ticket = OrderSend(Symbol(), OP_SELL, SellLots, Bid, Slippage, 0, 0, Symbol() + " MyEA_v6_rev_1_Short", SellOrderId, 0, Red);


It worked brilliantly. I am so thankful to your suggestion. This has led me to wonder if I can also append my "key" variable settings too ... may I ask another question?

I have four global variables defined in "extern int" They are SettingA_Long, SettingB_Long, SettingA_Short and SettingB_Short. The values of the two "Longs" are +ve (say 25 and 3 respectively) and the two "Shorts" are -ve values (say -25 and -3 respectively). My question now is can I append the variable values so my trade comment would then be (say) EURUSD 25 3 MyEA_v6_rev_1_Long and (say) EURUSD -25 -3 MyEA_v6_rev_6_Short ?? Is this do-able?? It would be handy as the settings are different for different pairs and I will then readily see what the setting were retrospectively.


Newton

 

The symbol name is already part of the order (as well as the information "short" or "long"). I don't see why there would be any valid reason to waste valuable room in the comment field to redundantly include this information a second time!?

 
NewtonLeo:
[...] This has led me to wonder if I can also append my "key" variable settings too [...]

You can append whatever u want. If you append non-string types then they will be type-casted into string (see here -> https://docs.mql4.com/basis/types/casting). You can use the addition operations (+) to concatenate strings or alternatively use StringConcatenate(). You should be aware that comment length is "31 characters + zero terminator. Server can rewrite 6 last characters. ie safety length is 25" (https://www.mql5.com/en/forum/101419), but I have seen cases where more than 6 characters are overwritten...

Note 7bit's comment... What is the point of adding all this info in the order's comment?

 

You can but be aware the comment field is rather limited in the total number of characters it can accomodate. You get 31 characters, including spaces.

Reason: