multiple comments from multiple functions or another solution to my problem?

 

Hi - no idea what I am doing(complete novice),  but I have managed to create an EA that uses 'if' and 'else if' logic to display output as a comment.

I have two functions running similar conditions, I am calling both functions in the OnTick function and only the last function display as a comment --> 1st function does run but stops or is cleared by the next function.

Any suggestions or help gratefully appreciated as I want to display both outputs as comments on the chart screen eg 1st function & 2nd function out both displayed at the same time (sort of parallel running I guess??).

my code is constructed as follows below (to keep the post short i have simplified the script content), and compiles without error

//---------------

void OnInit()

{

func_1();

func_2();

}

func_1()

{

double E14_D1 = iMA etc etc ;

double S14_D1 = iMA etc etc ;

double S50_D1 = iMA etc etc ;

double D1_Close=iClose(NULL,PERIOD_D1,1);



int Price_check = (D1_Close>S50_D1);

int MA_Check = (E14_D1>S14_D1);



       if ((Price_Check)&&(MA_Check)) Comment (" Daily Trend in BUY Zone & BUY Signal");

else if ((Price_Check)&&(!MA_Check)) Comment (" Daily Trend in BUY Zone & Reversal Signal")

// readers of this post, please note there are a few more conditions and I've managed to work out syntax for including || OR logic too

}



void func_2()

{

contains similar variables, statments and logic as func_1 (for 4H time period instead of D1) but, Comments are different and I start the comment with a \n, and the comment does display on a line below where the 1st comment would display

eg

       if ((Price_Check_4H)&&(MA_Check_4H)) Comment ("\n, 4H Trend in BUY Zone & BUY Signal");

else if ((Price_Check_4H)&&(!MA_Check_4H)) Comment ("\n 4H Trend in BUY Zone & Reversal Signal")

}


I have tried but failed to include all the logic into one function, hence multiple functions.

Thank you very much in advance :) as ideally, on the chart screen I want to see these comments:

Daily Trend in BUY Zone & BUY Signal"

4H Trend in BUY Zone & Reversal Signal

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
 
fxalert:

Use Alt+S when posting code - It looks like a mess all of it!

attach

 
Kenneth Parling:

Use Alt+S when posting code - It looks like a mess all of it!


Thanks, very constructive advice
 
fxalert:

Any suggestions or help gratefully appreciated as I want to display both outputs as comments on the chart screen eg 1st function & 2nd function out both displayed at the same time (sort of parallel running I guess??).

       if ((Price_Check_4H)&&(MA_Check_4H)) Comment ("\n, 4H Trend in BUY Zone & BUY Signal");
else if ((Price_Check_4H)&&(!MA_Check_4H)) Comment ("\n 4H Trend in BUY Zone & Reversal Signal")

  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Stop trying to use two Comment's. Output two strings in your functions and then combine in the parent function.
    string comment1, comment2;
    ⋮
    func_1(){   comment1=/*Comment(\n, */"4H…";//);
    ⋮
    func_2(){   comment2=/*Comment(\n, */"4H…";//);
    ⋮
    OnInit(){   func_1(); func_2(); Comment(comment1,"\n", comment2);

 
William Roeder:
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Stop trying to use two Comment's. Output two strings in your functions and then combine in the parent function.
Appreciated, thank you. My 1st post so apologies for lack of ethics and ignorance of the rules. I will update/clean it up
 
Maybe the solution in this thread (https://www.mql5.com/en/forum/323918#comment_13490816) helps you with your problem, too.
Display several lines of Comments
Display several lines of Comments
  • 2019.10.08
  • www.mql5.com
Hi there, in have a Comment at the end of each module of the current code I'm working on, and I like to display each one below another...
 
Chris70:
Maybe the solution in this thread (https://www.mql5.com/en/forum/323918#comment_13490816) helps you with your problem, too.

Thank you very much for this link. I'm trying to wrap my head around it (I am a complete novice) but hopefully I can use this and the other suggestions from William Roeder to solve my problem - much appreciated, thank you both :)

Reason: