Q:
I want to use the range from a channel with 15 bars and a channel with 8 bars. I have set variables to get the highest and lowest from the long channel and the same for the shorter channel (in the OpenBuy trade). Now I want to calculate the range of both channels and check if the short channel range is less than 0.75 of the long channel range.
If this is correct, then I want to open a trade.
Is this possible? How can I calculate the range of the channels so I can use this in the isOpenBuyTrue logic element?
A.
Yes, it’s possible, and you are almost there.
Let’s assume you named the functions like this:
highFromLong
lowFromLong
highFromShort
lowFromShort
Now, in VTS, when you create a function that returns a value, VTS automatically creates a variable to store that value in a variable with same name as the function, but with a preceding underscore _
Like this:
_highFromLong
_lowFromLong
_highFromShort
_lowFromShort
These variables are holding the data returned from the respective functions. In this case, they are price values, like 1.2345.
To get the range for each channel, we need to subtract the high from the low. We can do this in the assignment tab of a variable.
A good name for this variable would be rangeLong
_highFromLong – _lowFromLong
And we can do the same for the short channel (and name the variable rangeShort)
_highFromShort – _lowFromShort
OK here comes the fun math:
if the short channel range is less than 0.75 of the long channel range
This can be written as:
IF rangeShort < 0.75*rangeLong
Note, that in MQL, the asterisk (*) is used to multiple.
This expression can be entered into a logic element like this:
The drawing would look something like this, except right before the End Element coming from the True output of the logic element, you would probably put your trade action (open, close, modify).
Oh I see you did mention isOpenBuyTrue, so you would likely add the elments to that drawing.
To get notified about the latest questions and answers, follow us!
Follow @iExpertAdvisor