How do I calculate the distance in points/ticks from Close to a Moving Average?  [SOLVED]

Questions about MultiCharts and user contributed studies.
tonyt
Posts: 48
Joined: 21 May 2021
Has thanked: 20 times
Been thanked: 1 time

How do I calculate the distance in points/ticks from Close to a Moving Average?

Postby tonyt » 15 Mar 2022

I am attempting to solve for the distance in points / ticks from the current close or Close[1] to a Simple Moving Average. I have tried

Code: Select all

var: SMA ( 0 ); SMA = AverageFC(Close,10); absvalue(Close - SMA)
and I have tried:

Code: Select all

Value1 = Mod(Close,SMA) * (Num Ticks to BPV, / IE * 4 for e_mini)
Both produce about the same results, which are two digits past the decimal and rounded up, at least this is what the print output displays.

So for the EUROfx for example, it doesn't work, as I need the output to calculate five digits past the decimal.

How can I achieve this? I know I am close and likely missing something obvious. My 'scale' settings for the chart and study are for displaying out to 5 digits, IE .00001. This setting does not seem to have any effect on the output. See screen captures.

Please advise, thank you!

Tony
Attachments
Measure the Distance Btwn Clse and SMA.png
(94.68 KiB) Not downloaded yet
Measure the Distance Btwn Clse and SMA PRINT OUTPUT.png
(28.72 KiB) Not downloaded yet
Euro Chart Scale Settings.png
(187.58 KiB) Not downloaded yet
SMA Scale Settings Euro.png
(188.66 KiB) Not downloaded yet

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: How do I calculate the distance in points/ticks from Close to a Moving Average?

Postby TJ » 15 Mar 2022

go to the wiki

look up the keyword PRINT

study the usage example

pay attention to the explanation of
Expression:C:D

tonyt
Posts: 48
Joined: 21 May 2021
Has thanked: 20 times
Been thanked: 1 time

Re: How do I calculate the distance in points/ticks from Close to a Moving Average?  [SOLVED]

Postby tonyt » 16 Mar 2022

go to the wiki

look up the keyword PRINT

study the usage example

pay attention to the explanation of
Expression:C:D
OK, got it, this will also fix the calculation error in the signal/indicator (not just the print output) and the rounding up of the results too I'm guessing. Thanks!

tonyt
Posts: 48
Joined: 21 May 2021
Has thanked: 20 times
Been thanked: 1 time

Re: How do I calculate the distance in points/ticks from Close to a Moving Average?

Postby tonyt » 16 Mar 2022

go to the wiki

look up the keyword PRINT

study the usage example

pay attention to the explanation of
Expression:C:D
Thanks TJ, this works beautifully in the Print Output...

Now how do I accomplish the same thing in the following calculation?


absvalue(Close - SMA)
absvalue((close:7:5) - (SMA:7:5)); (obviously does not work)

Please point me in the right direction

Thank you I know Im close

T

tonyt
Posts: 48
Joined: 21 May 2021
Has thanked: 20 times
Been thanked: 1 time

Re: How do I calculate the distance in points/ticks from Close to a Moving Average?

Postby tonyt » 16 Mar 2022

Actually TJ I think I understand now. It does provide the correct output. The issue was I was incorrectly optimizing it using whole numbers that did not account for the correct # of digits after the decimal.


Return to “MultiCharts”