I am using a moving average in a calculation and the code works the way I want it to but I found an exception. Here is the situation:
12 period SMA displayed in the cursor window is 12955. When manually adding the last 12 closes and dividing by 12, the actual 12 period SMA is 12955.916666666.
Here is my code:
var xSMA12 = sma(12);
var nSMA120 = (xSMA12.getValue(0));
n12 = nSMA120.toFixed(4)*1;
The value of nSMA120 is 1.2955916666666 as expected. But the value of n12 is 1.2956. I am attempting to use toFixed(4) to truncate to only 4 decimal positions so the value of n12 matches the average shown in the cursor window (12955).
Why did n12 round up and the cursor window value truncate?
Thanks for the help.
12 period SMA displayed in the cursor window is 12955. When manually adding the last 12 closes and dividing by 12, the actual 12 period SMA is 12955.916666666.
Here is my code:
var xSMA12 = sma(12);
var nSMA120 = (xSMA12.getValue(0));
n12 = nSMA120.toFixed(4)*1;
The value of nSMA120 is 1.2955916666666 as expected. But the value of n12 is 1.2956. I am attempting to use toFixed(4) to truncate to only 4 decimal positions so the value of n12 matches the average shown in the cursor window (12955).
Why did n12 round up and the cursor window value truncate?
Thanks for the help.
Comment