Announcement

Collapse
No announcement yet.

Cursor Window Value vs. Actual Value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cursor Window Value vs. Actual Value

    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.

  • #2
    Cursor Window Value vs. Actual Value - Part II

    I appreciate all the views on my prior question but since I haven't received an answer, let me try to explain my issue differently.

    9840 - value of the 8 SMA shown in the cursor window.

    .984075 - manually calculated average using last 8 closes.

    .984074999999998 - value of sma(8) for current bar within the EFS.

    I then use toFixed(4)*1 on the value of sma(8) and receive a value of .9841 This is different than the cursor window value.

    How is the average in the cursor window calculated? What can I do in the EFS to get the same value of .9840? Why does toFixed round before it truncates?

    Additional info:
    If the value of sma(8) is .98404166666666 and I use the toFixed(4)*1, the returning value is .9840. This rounds DOWN and then truncates.

    My objective is to get the same value as displayed in the cursor window. Thanks for the help.

    Comment


    • #3
      I'm no expert but you can find the actual calculation for a simple moving average at:
      ...\eSignal\Formulas\Library\ma.efs

      It plots exactly the same as the "moving average" study accessed via:
      right click on chart, select "Basic Studies" then "Moving Average"
      and "Formulas" then "EFS2 Custom" then "customMA.efs"

      Wayne

      Comment


      • #4
        Wayne - thanks for the info.

        After reviewing ma.efs, there's no indication of why it truncates. The actual value is .984075 (without the floating point) and the quote window shows 9840. But within my efs, I use the toFixed(4) on sma(8) and receive a value of .9841. I'm trying to get my value in my efs to equal the quote window value.

        Still trying to figure this out . . .

        Comment

        Working...
        X