Download MetaTrader 5

False in Passing Parameter Document?

To add comments, please log in or register
MichaelSoros
26
MichaelSoros  

https://docs.mql4.com/basis/function/parameterpass

Heres the code above, 1st Method

#property strict //I added this one, not sure its gonna mean something for thise sort of code but Im stil a beginner n wanted to add it in.

//+------------------------------------------------------------------+
//| Passing parameters by value                                      |
//+------------------------------------------------------------------+
double FirstMethod(int i,int j)
  {
   double res;
//---
   i*=2;
   j/=2;
   res=i+j;
//---
   return(res);
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   int a=14,b=8;
   Print("a and b before call:",a," ",b);
   double d=FirstMethod(a,b);
   Print("a and b after call:",a," ",b);
  }
//--- Result of script execution
//  a and b before call: 14 8
//  a and b after call: 14 8

I am still new at programming so correct me if Im wrong. When I use the code above to get to know better of how it works, It doesnt show(Print) on the Journal Log.


I guess this doesnt show up in the log because its a script program? So i used this one.

#property strict

//Passing Parameter by Value
double FirsthMethod(int &i,int &j)
   {
      double res;
      
      i*=2;
      j/=2;
      res=i*j;
      Print("RES==",res);
      return(res);
    }
    
//Script Program start function
void OnTick()
   {
      int a=14, b=8;
      Print("a and b before call==",a," and ",b);
      double d=FirsthMethod(a,b);
      Print("a and b after after call==",a," and ",b);
      return;
      }
//Result of script execution
//a and b before call: 14 8
//a and b after call 14 8

      


It just shows up and it works fine. I added & in the function(int &i, int &j) and void OnTick()

 Isnt the intention of the Document suppsoe to show the leaners how it works? (in log, cuz they used print)      OR is my understanding wrong  with thje code described in the document(since its not printing out in my log)

Im using Alpari, if that helps.  

Passing Parameters - Functions - Language Basics - MQL4 Reference
Passing Parameters - Functions - Language Basics - MQL4 Reference
  • docs.mql4.com
Passing Parameters - Functions - Language Basics - MQL4 Reference
whroeder1
16102
whroeder1  

Perhaps you should read the manual again. Event Handling Functions - Functions - Language Basics - MQL4 Reference

The OnStart() function is the Start event handler, which is automatically generated only for running scripts.

Your second code is in OnTick and your image shows that is is working.

Your first code is in OnStart but your image shows "Expert A7." If it is an expert, why would you think OnStart would be called?

MichaelSoros
26
MichaelSoros  
whroeder1:

Perhaps you should read the manual again. Event Handling Functions - Functions - Language Basics - MQL4 Reference

Your second code is in OnTick and your image shows that is is working.

Your first code is in OnStart but your image shows "Expert A7." If it is an expert, why would you think OnStart would be called?

Thank you whoreder1. Yes I definitely agree that Im not paying enough attention to what the manual said. Appreciate
To add comments, please log in or register