Announcement

Collapse
No announcement yet.

daily high

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

  • daily high

    Hi all,

    I wrote a script that uses the last 20 days DAILY highs & lows on an intraday chart. I retrieve them as
    (for i=0 to 19 loop) DH[i]=high(-i,getSymbol()+",D");

    However when the new day begins I have to update the DH array so I run the same function at the first tick of the new day i.e.

    if (TimeofDay>1030) then....(for i=0 to 19 loop)... DH[i]=high(-i,getSymbol()+",D");

    But I can not retrieve the new days high & low if I don't reload the script manually. Although the new days high & low is registered I keep getting yesterday's high and low in DH[0] and DL[0].


    Can anyone tell what must I do?

    thank you

  • #2
    Hello izakD,

    Make sure you don't have the setComputeOnClose(true) function in preMain() or the EFS Performance option checked for "Make all formulas compute on close" under Tools-->EFS-->Settings. Then try the following method. This code waits until the formula has processed all bars on the initial load then fills in the aDH array for the previous 20 daily bars. You'll see in the formula output window the value for aDH[0], or today's high. Hope this helps.

    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("test");
        
    setShowCursorLabel(false);
    }

    var 
    bChartLoaded false;
    var 
    aDH = new Array();

    function 
    main() {
        if (
    getCurrentBarIndex() == && bChartLoaded == false) {
            for (var 
    020; ++i) {
                
    aDH[i] = high(-igetSymbol() + ",D");
            }
            
    debugPrintln("Today's High: " aDH[0]);
            
    bChartLoaded true;
        }
        
        return;

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Jason,

      Thank you for your reply, but my code is just similar to the one you sent. Except that I have another check where I assign bChartLoaded to true if the time>1030. That is where my problem starts. The loop is repeated to get the new session's high but I still have the same old array. Only after a manual reload I can get the true array with it.

      Do you have any suggestions?

      thanks again

      Izak

      Comment


      • #4
        I meant I assign bChartLoaded to false at the first tick after 1030.

        Sorry

        Comment


        • #5
          Hello Izak,

          What symbol, interval and time template are you using? Also, can you attach your formula so I can test it directly?
          Jason K.
          Project Manager
          eSignal - an Interactive Data company

          EFS KnowledgeBase
          JavaScript for EFS Video Series
          EFS Beginner Tutorial Series
          EFS Glossary
          Custom EFS Development Policy

          New User Orientation

          Comment


          • #6
            Hi Jason,

            My code is something like below. and I am running this on ES M4=2.

            thanks

            Izak



            flg=Text.ONTOP| Text.BOLD| Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM|Text.FRAME;
            t1=false;t2=false;

            function preMain(){
            setPriceStudy(true);
            setShowCursorLabel(false);
            setShowTitleParameters(false);
            tckrD=getSymbol()+",D";
            }



            function get1(){
            DR=new Array();DH=new Array();DL=new Array();CL=new Array();TAR=new Array();
            for (i=0;i<20;i++) {DH[i]=high(-i,tckrD);DL[i]=low(-i,tckrD);CL[i]=close(-i,tckrD);DR[i]=DH[i]-DL[i]}
            for (i=0;i<20;i++) drawTextPixel(250,(20*i)+15,i+" "+DH[i].toFixed(2)+" "+DL[i].toFixed(2)+" "+CL[i].toFixed(2)+" "+DR[i].toFixed(2),null,null,flg,null,12,"T1"+i,300);
            }

            function get2(){
            DR=new Array();DH=new Array();DL=new Array();CL=new Array();TAR=new Array();AvgDR=0;kbar=0; mxR=-1e10;mnR=1e10;
            for (i=0;i<20;i++) {DH[i]=high(-i,tckrD);DL[i]=low(-i,tckrD);CL[i]=close(-i,tckrD);DR[i]=DH[i]-DL[i]}
            for (i=0;i<20;i++) drawTextPixel(555,(20*i)+15,i+" "+DH[i].toFixed(2)+" "+DL[i].toFixed(2)+" "+CL[i].toFixed(2)+" "+DR[i].toFixed(2),null,null,flg,null,12,"T2"+i,300);

            }


            function main(){
            if (getBarState()== BARSTATE_ALLBARS) {t1=false;t2=false;return;}
            if (getCurrentBarIndex()==0){
            if(!t1) {get1(); t1=true;}
            t=new Date();
            if (t.getHours()*100+t.getMinutes()>=1030 && !t2) {get2();t2=true;}
            }}

            Comment


            • #7
              Hello Izak,

              After testing your code today on 1-minute interval, It seems to me that your code should be working as expected. I did make some minor changes, but shouldn't have affected the outcome of the results. I've attached it for your reference anyway. Test it and see if you're still seeing the same problem.

              I think what we might be dealing with here is a logical problem, not a code problem. Let's say that you first run the formula at 930 and the high was 1130.00. At 1030 DH[0] will be set to 1130.00 in get2() as long as a new high for the day wasn't reached between 930 and 1030. I'm not seeing DH[0] being set to yesterday's high as you stated when get2() gets called. Have I misunderstood the problem you're seeing?

              Time for get2() was set to 1246 for the test seen below.
              Attached Files
              Jason K.
              Project Manager
              eSignal - an Interactive Data company

              EFS KnowledgeBase
              JavaScript for EFS Video Series
              EFS Beginner Tutorial Series
              EFS Glossary
              Custom EFS Development Policy

              New User Orientation

              Comment


              • #8
                Thank you for your help Jason,

                But the problem still remains. What I want and expect the code to do is say at 1031, the left colum should stay the same whereas the right column should be shifted by one row since a new session begun and a new daily high is registered, whatever it is. (also a new daily range and low and etc. )

                Those new values should be retrieved by get2().

                But it does not until you reload it. Could I explain the problem?

                thanks again,

                Comment


                • #9
                  Hello Izak,

                  Are you running this formula on a daily interval?
                  Jason K.
                  Project Manager
                  eSignal - an Interactive Data company

                  EFS KnowledgeBase
                  JavaScript for EFS Video Series
                  EFS Beginner Tutorial Series
                  EFS Glossary
                  Custom EFS Development Policy

                  New User Orientation

                  Comment


                  • #10
                    I should also tell you that 1030 is the session start time. So you load it before the new session and get DH[0] as yesterday's high. But when the new session starts at 1030 DH[0] should be that new session's high logically. But you keep getting yesterday's high.

                    Maybe this explains the problem better.

                    all the best,

                    Izak

                    Comment


                    • #11
                      no, I want to use it on a 5-min chart and retrieve the Daily values thru the script.

                      Comment


                      • #12
                        Hello Izak,

                        Thanks for the details. Let me test this at tomorrow's open. I think I know what's happening. Have a good evening.
                        Jason K.
                        Project Manager
                        eSignal - an Interactive Data company

                        EFS KnowledgeBase
                        JavaScript for EFS Video Series
                        EFS Beginner Tutorial Series
                        EFS Glossary
                        Custom EFS Development Policy

                        New User Orientation

                        Comment


                        • #13
                          I believe...

                          Jason is correct...

                          Your code was never designed to handle the new days.. Once the t1 and t2 variables were set to "true" - there was never an instance where you recalced the values.

                          In this code, I have added a simple routine that checks for a NEW DAY, then resets your logical variables to "recalc". Of course, I did not test this (as no new days now), but it should work.

                          B
                          Attached Files
                          Brad Matheny
                          eSignal Solution Provider since 2000

                          Comment


                          • #14
                            ok, thank you Jason,

                            I am impatient to learn what is happening

                            Izak

                            Comment


                            • #15
                              thank you Doji3333,

                              I tested something similar to your code also. But I could not succeed. I managed to retrieve the true values at the first new bar after the session open but not at the first bar of the session.
                              Actually it has to update at the first tick after 10:30.

                              Izak

                              Comment

                              Working...
                              X