What do you mean by "passed by reference"?
The value of ask and bid inside the sampleFunction are changing although they are passed by value, from my lessons in c++, the value of inputAsk/inputBid should only be changing if they are passed by reference.
void OnTick() { //--- double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); sampleFunction(Ask,Bid); //--- } void sampleFunction (double inputAsk, double inputBid){ Comment("The value of ask is ", inputAsk, "The value of bid is ", inputBid ); }
The value of ask and bid inside the sampleFunction are changing although they are passed by value, from my lessons in c++, the value of inputAsk/inputBid should only be changing if they are passed by reference.
You have not passed them by reference, you have just passed the values.
If you change the values of the variables in the function when you return to OnTick() the varaiable values will not have changed.
You have not passed them by reference, you have just passed the values.
If you change the values of the variables in the function when you return to OnTick() the varaiable values will not have changed.
Then why does variable inputAsk value changed when variable Ask changes, when you're passing by value, only the initial value gets saved isn't it
Then why does variable inputAsk value changed when variable Ask changes, when you're passing by value, only the initial value gets saved isn't it
Because you are calling the function every tick and passing new values to the function.
The value of ask and bid inside the sampleFunction are changing although they are passed by value, from my lessons in c++, the value of inputAsk/inputBid should only be changing if they are passed by reference.
OnTick is an event-driven function defined by mql4/mql5. it's called when the chart symbol's ask/bid prices change.
OnTick is an event-driven function defined by mql4/mql5. it's called when the chart symbol's ask/bid prices change.
Not relevant to this topic.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use