Please describe "Arrays cannot be passed to Comment() Function".

To add comments, please log in or register
Agent86
925
Agent86  
Hi all,

The value of my Comment doesn't change once it is initialized.
I"m sure it has something to do with the docs below, but I'm not 100% sure because the Comment does initialize and show the value exactly 1 time then it's static from there on.


From the docs.
Please describe "Arrays cannot be passed to Comment() Function".

https://docs.mql4.com/common/comment


My code sample:
double Momentum(){
   double moment= iMomentum(NULL,0,period,PRICE_CLOSE,0);
   return(moment);
   Comment("Momentum = ",DoubleToStr(Momentum(),3));
   }


I'm sure I've missed something simple on this but it's been a while since I've coded anything.
Please advise.
Thanks

Comment - Common Functions - MQL4 Reference
Comment - Common Functions - MQL4 Reference
  • docs.mql4.com
[in]   Any values, separated by commas. To delimit output information into several lines, a line break symbol "\n" or "\r\n" is used. Number of parameters cannot exceed 64. Total length of the input comment (including invisible symbols) cannot exceed 2045 characters (excess symbols will be cut out during output). Data of double type are output...
Marco vd Heijden
Moderator
12397
Marco vd Heijden  
double Momentum(){
   double moment= iMomentum(NULL,0,period,PRICE_CLOSE,0);
   return(moment);
   }

Comment("Momentum = ",DoubleToStr(Momentum(),3));

You can call a function inside itself.

Put the call outside of the function.

William Roeder
19170
William Roeder  
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. double Momentum(){
       double moment= iMomentum(NULL,0,period,PRICE_CLOSE,0);
       return(moment);
       Comment("Momentum = ",DoubleToStr(Momentum(),3)); < not called.
       }
    
    Your function doesn't call Comment so of course nothing changes.
  3. Your function doesn't have an array, so why is that mentioned?
Agent86
925
Agent86  
Marco vd Heijden:

You can call a function inside itself.

Put the call outside of the function.

Thanks, I did this and error says 'Comment' - declaration without type
Marco vd Heijden
Moderator
12397
Marco vd Heijden  

Yes well you have to call it in Ontick() or Init or timer function obviously.

Maybe you mean like this

double Momentum(){
   double moment= iMomentum(NULL,0,period,PRICE_CLOSE,0);
   Comment("Momentum = ",DoubleToStr(moment,3));
   return(moment);
   }
Agent86
925
Agent86  
William Roeder:
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Your function doesn't call Comment so of course nothing changes.
  3. Your function doesn't have an array, so why is that mentioned?
Thanks for the response.
Sorry, the site is not very intuitive and I used my old bookmarks which use to take me to MT4 forums section directly. However, when I login by default the site brings me to MT5 forums. General section at the top is not clear to suggest "MT5 only" and the long list of questions underneath the MT5 General section also show many similar MT4 questions within.
I was not aware of this and will properly post in the correct section in the future.

I was not aware that the indicators were not an array. I have a lot of catching up to do and forgot a lot of what I once knew about this. I was sort of thinking of the shift option for indicators and assumed this was an index so I concluded an array without knowing anything about it.

I will follow up on how to call Comment to refresh the value of Comment, thanks
Agent86
925
Agent86  
Marco vd Heijden:
Yes well you have to call it in Ontick() or Init or timer function obviously.

Thanks,

To add comments, please log in or register