Announcement

Collapse
No announcement yet.

Syncing indicator from higher time frame?

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

  • Syncing indicator from higher time frame?

    Hi all,
    I have been wracking my brain for about half a day on this. I've written some code to put a colored line in an indicator window to represent the higher time frame trend. Because I am comparing the higher time frame series to historical values I am using the getValue function instead of getSeries, which cause the problem that my indicator gets out of phase with the higher time frame. I have tried running reloadefs() at the start of every new bar, but it hangs the computer. So all day long I manually reload the indicator to make sure it is synced up.

    Is there an easiers way?

    Thanks,

    Jonathan
    Attached Files

  • #2
    wrong efs

    Here is the correct efs....
    Attached Files

    Comment


    • #3
      Jonathan
      The first thing I would suggest is that you read this post as it provides a detailed explanation of what happens when using the getValue() method on studies that are based on external intervals.
      To answer your question there is a way to accomplish what you are trying to do without the need of manually reloading the efs or using reloadEFS() (which is in itself a dangerous command).
      For a practical example of the code that is required see the efs attached to this post.
      Alex

      Comment


      • #4
        What a relief....

        Alex, THanks for the repsonse. The second link looks like it will perfectly do what I need! What a relief to know there is an easier way.
        Thanks for all your tireless effort.
        Jonathan

        Comment


        • #5
          Jonathan
          My pleasure
          Alex

          Comment


          • #6
            having redraw issue

            Hi Alex,
            I implemented the recursive For loop to redraw the indicator based on the HTF interval. but I am running into a problem. Sometimes, it will not redraw for the entire interval. Unfortunately it doesn;t seem consisten so I haven't been able to discerne a pattern. I've attached the code and will attach a screen shot too.
            Thanks,
            Jonathan

            PS The long trend code was updated while the short was not.
            Attached Files

            Comment


            • #7
              screenshot of problem

              The original indicator is shown below the updated one. I circled the areas where the problem is happening.
              Thanks for your help,
              Jonathan
              Attached Files

              Comment


              • #8
                Jonathan
                The first thing I would suggest is to assign a unique name to the graphic object ie change ImageCntr+i to for example "image1"+ImageCntr+i
                Also if I understood your logic correctly the conditional statement
                if (Trigger == "Up-Strong" || Trigger == "Up-Weak" )
                should actually be
                if (Trigger != "Up-Strong" && Trigger != "Up-Weak" )
                Regardless it appears to be redundant in the overall logic so you may want to remove it unless you have a specific reason for including it.
                Another thing you may want to consider is to make the code slightly more efficient by retrieving the values of the studies only once on every iteration of the efs rather than multiple times within the conditions. For example you could write it along the lines of the following schematic

                PHP Code:
                var CCI1_0 xCCI1.getValue(0);//retrieve the value and assign it to a variable;
                var CCI1_1 xCCI1.getValue(-1);//as above
                var TCCI1_0 xTCCI1.getValue(0);//as above
                var TCCI1_1 xTCCI1.getValue(-1);//as above
                    
                if(CCI1_1==null || TCCI1_1==null) return;//null check on oldest value used
                    
                var BothUp TCCI1_0 TCCI1_1 && CCI1_0 CCI1_1;//assign condition to variable
                var TurboLeadingUp TCCI1_0 CCI1_0;//as above

                if(BothUp){
                    if(
                TurboLeadingUp){
                        for (...){
                            
                drawTextRelative(...);
                        }
                    } else {
                        for (...){
                            
                drawTextRelative(...);
                        }
                    }
                } else {
                    for (...){
                        
                removeText(...);
                    }

                Lastly I would suggest that in reviewing your code you work on one condition and corresponding action at a time and not add other conditions/actions until you are satisfied that the graphical objects for that condition are working properly
                Hope this helps
                Alex

                Comment


                • #9
                  It works!

                  Alex, thanks again. I made the changes you suggested and it works great. ALso is faster. The efficiency tips are much appreciated!
                  till next time,
                  Jonathan

                  Comment


                  • #10
                    Jonathan
                    You are most welcome
                    Another thing you may want to consider to further improve the efficiency of the script is to limit the amount of graphic objects that are drawn as these can be resource intensive.
                    To do that you would simply need to modify the ImageCntr as shown in the following example

                    PHP Code:
                    if(getBarStateInterval(FirstInterval+"")==BARSTATE_NEWBAR){//at every new higher interval bar
                            
                    newBarMarker getCurrentBarCount();//assign a value to the marker
                            
                    if(ImageCntr==50){//if the counter is equal to 50
                                
                    ImageCntr 0;//reset to 0
                            
                    }else{
                                
                    ImageCntr++;//increment the counter by 1
                            
                    }

                    Once the ImageCntr reaches 50 (or whatever number you will set it to) it resets to 0 and starts counting again. In this way there will be no more than 50 (groups) of each drawn object on the chart.
                    Alex

                    Comment


                    • #11
                      Alex, Thanks for another helpful tip. As a non-programmer (I just dabble) I haven't learned these techniques and nuances yet. I use counters in a lot of functions so I will add this to those as well.

                      till next time,

                      Jonathan

                      Comment

                      Working...
                      X