Announcement

Collapse
No announcement yet.

Code Help ....Please

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Code Help ....Please

    ISSUE : Two variables that should alter the VIDYA line behaviour, Length and Smooth.

    If you change the smooth number (... and lenght unchanged), the viday line does change its form, HOWEVER when you change the length (...and smooth unchanged ) the vidya line does not change. WHY Not...


    Then length should have an effect...I used 5 min bars to test it...

    Original Code from :http://share.esignal.com/groupconten...ands&groupid=7


    VIDYA Code Standard.....

    function preMain()
    {
    setPriceStudy(true);
    setStudyTitle("VIDYA");
    setCursorLabelName("VIDYA", 0);
    setDefaultBarFgColor(Color.red, 0);

    }
    var AbsCMO = 0.0;
    var CurrentBar = 0;
    var VIDYA = 0.0;
    var VIDYA_1 = 0.0;
    function main(Length, Smooth)
    {
    var BarState = getBarState();
    if (Length == null) Length = 10;
    if (Smooth == null) Smooth = 6;
    var UP = 0.0;
    var DN = 0.0;
    var UpSum = 0.0;
    var DnSum = 0.0;
    var Close = getValue("Close", 0, -(Length + 2));
    var i = 0;
    for (i = 0; i < Length; i++)
    {
    if (Close[0] > Close[1]) UP = Close[0] - Close[1];
    else UP = 0.0;
    if (Close[0] < Close[1]) DN = Math.abs(Close[0] - Close[1]);
    else DN = 0.0;
    UpSum =+ UP;
    DnSum =+ DN;
    }
    if ((UpSum+DnSum) > 0) AbsCMO = Math.abs((UpSum-DnSum)/(UpSum+DnSum));
    var SC= 2/(Smooth+1);
    if (CurrentBar <= Length) VIDYA = Close[0];
    else VIDYA = (SC * AbsCMO * Close[0]) + ((1 - (SC * AbsCMO)) * VIDYA_1);
    if (BarState == BARSTATE_NEWBAR) VIDYA_1 = VIDYA;
    Return VIDYA;
    }

  • #2
    Possible Solution...

    You "For" loop does not do anything...

    PHP Code:
    for (0Lengthi++)
    {
    if (
    Close[0] > Close[1]) UP Close[0] - Close[1];
    else 
    UP 0.0;
    if (
    Close[0] < Close[1]) DN Math.abs(Close[0] - Close[1]);
    else 
    DN 0.0;
    UpSum =+ UP;
    DnSum =+ DN;

    It continually checks the same values (over and over and over and over).

    I would have to GUESS that this could be your problem. The solution is to DEBUG your code and make sure it is doing what it is supposed to.

    Brad
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      The for loop, is suposed to add the changes relative to close over the length, I have no idea how to debug in EFS, please advise on debugging proceedures and or tools,...

      Comment


      • #4
        IS this the fix


        for (i = 0; i < Length; i++)
        {
        if (Close[i] > Close[i-1]) UP = Close[i] - Close[i-1];
        else UP = 0.0;
        if (Close[i] < Close[i-1]) DN = Math.abs(Close[1] - Close[i-1]);
        else DN = 0.0;
        UpSum =+ UP;
        DnSum =+ DN;
        }

        Comment


        • #5
          Here ya go...

          There were a number of small problems in your code...

          1. CurrentBar was never updated or used
          2. Your "for" loop had the initial errors I mentioned, plus the summation functions were incorrect (it should have been "+=" not "=+"). This error was causing the summation routine to be incorrect even if the for loop was correct.
          3. I changed your for loop to use the inherent price functions instead of the "getValue" functions.

          But it should work now.

          Brad
          Brad Matheny
          eSignal Solution Provider since 2000

          Comment


          • #6
            Oops..

            Here is the code.
            Attached Files
            Brad Matheny
            eSignal Solution Provider since 2000

            Comment


            • #7
              Thx works great

              Comment


              • #8
                Didnt work at realtime

                see here


                HAd a drift issue......

                Comment

                Working...
                X