Announcement

Collapse
No announcement yet.

Donchian Values

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

  • Donchian Values

    I am running the following code in a 150 tick chart for the Russell 2000. The Donchian values for the individual elements displays correctly in the Formula Output Window, but the array returns [object Series].

    Is there a way to get the array to display it's values correctly?

    Thanks

    function preMain()
    {
    setPriceStudy(true);
    setStudyTitle("Donchiantest");
    setCursorLabelName("D");
    }

    var UpperDonchian = 0;
    var PrevUpperDonchian = 0;
    var MiddleDonchian = 0;
    var PrevMiddleDonchian = 0;
    var LowerDonchian = 0;
    var PrevLowerDonchian = 0;

    var UpperDonchianArray = new Array(3);
    UpperDonchianArray[0] = 0;
    UpperDonchianArray[1] = 0;
    UpperDonchianArray[2] = 0;

    var LowerDonchianArray = new Array(3);
    LowerDonchianArray[0] = 0;
    LowerDonchianArray[1] = 0;
    LowerDonchianArray[2] = 0;

    function main()
    {

    // Get Donchian Values

    if (getBarState() == BARSTATE_NEWBAR)
    {
    PrevUpperDonchian = UpperDonchian;
    }

    UpperDonchian = upperDonchian(14);
    if (UpperDonchian == null) return;

    if (getBarState() == BARSTATE_NEWBAR)
    {
    PrevMiddleDonchian = MiddleDonchian;
    }

    MiddleDonchian = middleDonchian(14);
    if (MiddleDonchian == null) return;

    if (getBarState() == BARSTATE_NEWBAR)
    {
    PrevLowerDonchian = LowerDonchian;
    }

    LowerDonchian = lowerDonchian(14);
    if (LowerDonchian == null) return;

    // Update Donchian Arrays with new values

    if (getBarState() == BARSTATE_NEWBAR)
    {
    LowerDonchianArray[0] = LowerDonchianArray[1];
    LowerDonchianArray[1] = LowerDonchianArray[2];
    LowerDonchianArray[2] = PrevLowerDonchian;
    }

    if (getBarState() == BARSTATE_NEWBAR)
    {
    UpperDonchianArray[0] = UpperDonchianArray[1];
    UpperDonchianArray[1] = UpperDonchianArray[2];
    UpperDonchianArray[2] = PrevUpperDonchian;
    }

    debugClear();
    debugPrintln(" UpperDonchianArray: " + UpperDonchianArray);
    debugPrintln(" UpperDonchianArray[0]: " + UpperDonchianArray[0]);
    debugPrintln(" UpperDonchianArray[1]: " + UpperDonchianArray[1]);
    debugPrintln(" UpperDonchianArray[2]: " + UpperDonchianArray[2]);
    debugPrintln(" ");
    debugPrintln(" LowerDonchianArray: " + LowerDonchianArray);
    debugPrintln(" LowerDonchianArray[0]: " + LowerDonchianArray[0]);
    debugPrintln(" LowerDonchianArray[1]: " + LowerDonchianArray[1]);
    debugPrintln(" LowerDonchianArray[2]: " + LowerDonchianArray[2]);

    }

  • #2
    werosen
    Is there any particular reason why you use an array to store the prior values?
    You can retrieve the prior values of the Donchian using UpperDonchian.getValue(-nn) where -nn is the number of bars back (ie UpperDonchian.getValue(-2) will retrieve the value of 2 bars back)
    Alex

    Comment

    Working...
    X