Announcement

Collapse
No announcement yet.

demandindex.efs realtime update

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

  • demandindex.efs realtime update

    Hi,

    Need some help here to try and understand what is happening here.

    While I have had reasonable success fixing realtime update problems with certain efs files, this one is giving me problems. I believe that it is the multiple getBarStates that is causing the problem. Can it be done?

    Here is the code from TS support--

    Thanks,

    Alex

    /************************************************** *****************
    Provided By : TS Support, LLC for eSignal. (c) Copyright 2002
    ************************************************** ******************/

    function preMain()
    {
    setStudyTitle("Demand Index");
    setCursorLabelName("Demand Index", 0);
    setDefaultBarFgColor(Color.blue, 0);
    addBand(0, PS_SOLID, 1, Color.green);
    }

    vAvgTR = new Array();
    var VolAvg_1 = 0;
    var WghtClose_1 = 0;
    var BuyPres_1 = 0;
    var SellPres_1 = 0;
    var WghtClose = 0;
    var VolAvg = 0;
    var BuyPres = 0;
    var SellPres = 0;

    function main(Length)
    {
    if(Length == null)
    Length = 5;
    var i;
    var vSum = 0.0;
    var hh2, ll2;

    var WtCRatio = 1, VolRatio = 1, BuyP = 1, SellP = 1, Sign = 1, Constant = 1, BuyPres = 1, SellPres = 1, TempDI = 1, DMI = 1, WghtClose = 0, AvgTR = high() - low(), VolAvg = volume();
    if(getCurrentBarIndex() - getOldestBarIndex() == 1)
    {
    for(i = -Length + 1; i >= 0; i++)
    vSum += volume(i);
    VolAvg = vSum / Length;

    }

    WghtClose = (high() + low() + 2 * close()) * .25;
    if(high() > high(-1))
    hh2 = high();
    else
    hh2 = high(-1);
    if(low() < low(-1))
    ll2 = low();
    else
    ll2 = low(-1);
    if (getBarState() == BARSTATE_NEWBAR)
    {
    for(i = Length - 2; i >= 0; i--)
    vAvgTR[i + 1] = vAvgTR[i]
    vAvgTR[0] = hh2 - ll2;
    }
    vSum = 0;
    for(i = 0; i < Length; i++)
    vSum += vAvgTR[i]
    AvgTR = vSum / Length;
    VolAvg = ((VolAvg_1 * (Length - 1)) + volume()) / Length;
    if(WghtClose != 0 && WghtClose_1 != 0 && AvgTR != 0 && VolAvg != 0)
    {
    WtCRatio = (WghtClose - WghtClose_1) / Math.min(WghtClose, WghtClose_1) ;
    VolRatio = volume() / VolAvg;
    Constant = ((WghtClose * 3) / AvgTR) * Math.abs(WtCRatio);
    if(Constant > 88)
    Constant = 88;
    Constant = VolRatio / Math.exp(Constant);
    if(WtCRatio > 0)
    {
    BuyP = VolRatio;
    SellP = Constant;
    }
    else
    {
    BuyP = Constant;
    SellP = VolRatio;
    }

    BuyPres = ((BuyPres_1 * (Length - 1)) + BuyP) / Length;
    SellPres = ((SellPres_1 * (Length - 1)) + SellP) / Length;
    TempDI = +1;

    if(SellPres > BuyPres)
    {
    Sign = -1;
    if(SellPres != 0)
    TempDI = BuyPres / SellPres;
    }
    else
    {
    Sign = +1;
    if(BuyPres != 0)
    TempDI = SellPres / BuyPres;
    }

    TempDI = TempDI * Sign;
    if(TempDI < 0)
    DMI = -1 - TempDI;
    else
    DMI = +1 - TempDI;
    }
    if (getBarState() == BARSTATE_NEWBAR)
    {
    WghtClose_1 = WghtClose;
    if(getCurrentBarIndex() - getOldestBarIndex() > 5){
    BuyPres_1 = BuyPres;
    SellPres_1 = SellPres;
    }
    VolAvg_1 = VolAvg;
    }
    return DMI;

    }

  • #2
    Hi,

    If nobody else does it before me, I'll take a look at it later today.

    G
    Garth

    Comment


    • #3
      Thanks very much,

      Cheers,

      Alex

      Comment


      • #4
        Hi Alex:

        A construct near the top of main() does not appear to do anything:

        for (i=-Length+1; i>=0; i++)
        vSum+=volume(i);

        "i" is initially set to a negative number but the for-loop comparison says i>=0, which will never be true.

        I'm not certain about the original algorithm for this indicator but it would seem that this loop should probably be something like:

        for (i=0; i<Length; i++)
        vSum+=volume(-i);

        That being said, even in it's original state if I load it into a 2 minute ES chart, the indicator is updating itself in realtime as each new price comes in. Is it possible you have Compute on Close set in your Formula Engine Settings? Or am I misunderstanding your question.

        Regards,

        Chris

        Comment


        • #5
          Alex:

          Ok, I see now the problem you were referring to... the indicator was indeed updating in realtime but was not tracking correctly... if you refreshed the indicator the display changed.

          Please try the attached version as I think I spotted the problem.

          Chris
          Attached Files

          Comment


          • #6
            Great Chris,

            Thanks for that. By the way, your volume profiles are incredible.

            Have a good weekend,

            Alex

            Comment


            • #7
              Hi Alex:

              I found one more little change that you will need to make.

              About 1/3 of the way down the script, you will see a line that says:

              if (getCurrentBarIndex() - getOldestBarIndex() > 5) {

              you need to change the "5" to frLength or the script won't work with anything other than a length of 5.

              Chris

              Comment


              • #8
                A little plug for Chris, because I had no idea he had this service available until I visited his website today:

                http://www.sr-analyst.com/eSignal.htm

                Very cool!

                Garth
                Garth

                Comment

                Working...
                X