How To Assign an MQL Variable Based on Logic


What is the best way to set and update a variable automatically? i.e. If I wanted to change a variable from a default false value to true following some logic evaluation, which function would I use to do this?



This does not require a function, you can simply enter the desired value on the assignment tab of the Variable configuration window.

After you drag, drop and save a variable, the variable is added to the toolbox. From there, multiple copies of the variable can be added to the drawing. Each copy can have its own unique assigned value.


This image shows where the variable “MyTestVar” is saved in the ToolBox:



Multiple copies of MyTestVar can be dragged and dropped onto the drawing pad. In the drawing below, they are attached to the different outputs of a logic element:


Each copy of the variable can assign a unique value. In the drawing above, a value of 10 is assigned to MyTestVar if the logic evaluates to true, otherwise a value of 20 is assigned to MyTestVar.








To get notified about the latest questions and answers, follow us!