Announcement

Collapse
No announcement yet.

EFS questions by shaeffer

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

  • #16
    Hi Jason,

    Success! I finally understand it. Just to be sure, I ran all four versions of the 10ema efs on a chart today and they did what I expected.

    1. Using return ema10.getValue(0);
    per the efs at the top of your last note, produced the red line, showing todays real time daily ema10 values calculated and plotted based on the close of each 10 minute bar. The prior day, the red line is flat and underneath the cyan line (as only the final close value from the series is used). And as expected, if I changed the symbol or time interval mid-day, the red line became flat until that point, then a curve from then onwards.

    2. Using return getSeries(sma10);
    produced the cyan line, (which is the red line flattened to the last value of the cyan line).

    3. Using return ema10.getValue(-1);
    produced a lime line, not seen because it is underneath the white line. Since it plots the ema based on the close of the previous day, it aligns with cyan line of the previous day.

    4. Using return ema(10, inv("D"), -1);
    with no if statements (the two line PHP in your last note) produced the white line (yesterdays closing ema).
    -----------------------------------------------------------------
    So, now that I know what each option does, I will definitely use 4. above to plot yesterdays daily 50 and 200 MA's in intraday charts, since 4. does least processing, and since these MA's usually change so little in one day. And I'll probably use it for the faster 10 and 20 MA's as well, since the white line (yesterdays closing ema) isn't so much different from the cyan line (the real time daily ema... sma's would change even less). I'll see next week if changing these efs to option 4 makes a noticeable difference in CPU loading, or maybe relative to all my other efs's, alerts and quote lists, it won't make a noticeable difference.

    I beleive we said earlier that options 1 and 2 above look at every tick. I assume I could use setComputeOnClose in 1. or 2. which should greatly reduce their CPU requirements?

    In retrospect, I was thinking the If statement was loading a cast-in-stone series, and I wasn't understanding that the return statement was updating the latest value in that series. So thanks for all your help in breaking my mental block.

    Regards
    shaeffer
    Attached Files

    Comment


    • #17
      Originally posted by shaeffer
      Strange, on my trading computer, the Paste command will not appear when I right-click in a forum note. I am typing this on my older computer, where the Paste command does appear. Maybe an internet explorer setting difference?
      Originally posted by JasonK
      Sounds like there was nothing copied to your clip board. To paste, you can also use Ctrl-V on the keyboard. If there was anything in your clip board it will get pasted to the form.
      Hi Jason,
      Further to the above, I discovered that the Paste command works fine in my trading computer if I open the Forums via Internet Explorer. It is when I open the Forums via the Customer Support >> eSignal Forums link in the eSignal program that Paste will not work.

      In eSignal, Paste works fine when modifying efs's, so I know something is in the clipboard. Cntl V made no difference. When I right click within a forum note opened via I.E. I see Undo, Cut, Copy, Paste, Delete, and Select All. A right click in a forum note opened via the eSignal app shows Back, Forward, Print, Refresh. So for some reason, different commands are available depending on how the Forums were opened (at least in my case).

      Interesting. I have small "d" as a charting hot key, which results in my not being able to use a small "d" in a forum note, to change a chart symbol, or in a Header in a quote list (though cap 'D' works). But small "d" works fine in an I.E.>>Forums note. The same thing occurs with other single-letter-hotkeys I use.

      I don't know if these minor Paste and single-letter-hotkey glitches are related, but from now on I'll know to open Forums via I.E. .... so no worries.

      Regards
      shaeffer

      Comment


      • #18
        Hello shaeffer,

        It's good to hear about your progress. Regarding setComputeOnClose(), yes, it would reduce processing requirements as it prevents the formula from executing on every tick. It will only be executed once per bar during real time processing.
        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


        • #19
          Hello Jason,
          Some further clarifications... Before, you said:
          However, if you do not need to plot the current day's ema value of the series you can simply retrieve the previous day's ema value directly and plot it. There is no need for a series object in that case, which is more efficient. Try the following
          PHP Code:
          function main() {
              return 
          ema(10inv("D"), -1);

          So, primarily because there is NO series involved in the above, it is the least processor intensive of the four options mentioned before. And including setComputeOnClose in preMain would make it even less processor intensive.

          I'm wondering if that return statement still includes some unneccessary work? When you said "...you can simply retrieve the previous day's ema value directly and plot it", where is it retreived from? Is there an eSignal math module within the program (on my computer) that knows what an ema is, and so can calculate it based on the parameters provided? If so, in the format above, would it retrieve (calculate) that ema on every tick (or else on every new bar start if setComputeOnClose was used)? If so, the same value would be calculated over and over again. If instead the following was done:
          PHP Code:
          var null;
          function 
          main() {
             if(
          == null){
                  
          =  ema(10inv("D"),-1);
              }
          return 
          x;

          would the calculation only occur (be retreived) once, and therefore be even less processor intensive?
          -----------------------------------------------------------
          I'm curious what setComputeOnClose actually does. Somehow, does main() see that command in preMain, and also 'see' when a new bar starts, and so just halts its execution until a new bar starts?

          Regards
          shaeffer

          Comment


          • #20
            Hello shaeffer,

            Originally posted by shaeffer
            Hello Jason,
            Some further clarifications... Before, you said:

            PHP Code:
            function main() {
                return 
            ema(10inv("D"), -1);

            So, primarily because there is NO series involved in the above, it is the least processor intensive of the four options mentioned before. And including setComputeOnClose in preMain would make it even less processor intensive.

            I'm wondering if that return statement still includes some unneccessary work? When you said "...you can simply retrieve the previous day's ema value directly and plot it", where is it retreived from?
            It's retrieving the value from the EFS2 engine, which is maintaining the series. The EFS code in this case is not storing the series object in a local or global variable.

            Is there an eSignal math module within the program (on my computer) that knows what an ema is, and so can calculate it based on the parameters provided?
            It's all handled by the EFS2 engine.

            If so, in the format above, would it retrieve (calculate) that ema on every tick (or else on every new bar start if setComputeOnClose was used)?
            The value is only being calculated once by the EFS2 engine. The EFS code just retrieves it on every tick in the code example above. Make note that retrieving the value and calculating the value are not the same thing. Just because a value is retrieved like in the code examples we are discussing does not mean that the value is being recalculated at the same time.

            If so, the same value would be calculated over and over again. If instead the following was done:
            PHP Code:
            var null;
            function 
            main() {
               if(
            == null){
                    
            =  ema(10inv("D"),-1);
                }
            return 
            x;

            would the calculation only occur (be retreived) once, and therefore be even less processor intensive?
            No, the value is not be recaclulated over and over, just retreived. In the code example above, the value would only be retrieved as long as x is null. The first time x is assigned a value the ema value will never be retrieved again because the if() statement will never be true again. The result will be a flat line on the chart of that one value, which is not what you want. Try running it on a chart to see for yourself.

            What you could add to the code that will make it even more efficient is to only retrieve the value on the first bar of each new day. Add a condition that detects the first bar of each new day to the if() statement and try it out.

            PHP Code:
            var null;

            function 
            main() {
                if(
            == null || day(-1) != day(0)){
                    
            =  ema(10inv("D"),-1);
                }
                return 
            x;

            -----------------------------------------------------------
            I'm curious what setComputeOnClose actually does. Somehow, does main() see that command in preMain, and also 'see' when a new bar starts, and so just halts its execution until a new bar starts?

            Regards
            shaeffer
            The behavior is controlled by the EFS/EFS2 engine. The setComputeOnClose() function is a formula setting that tells the engine how the formula is to be executed. When a formula is first applied to a chart preMain() runs once and sets up all the formula settings and formatting that are in preMain(). After that, preMain() doesn't get called again, only main(). If setComputeOnClose() is present in preMain(), main() only gets called once per bar in real time when each bar closes. The instance this occurs is on the first tick of a new bar. At that moment, just before the new bar is inserted to the chart, main() is called by the engine and processes the bar that has just closed and plots it return statement values if any are used.
            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


            • #21
              Minimum EFS OVerhead?

              Hi Jason,

              I've now changed all my daily ema's and sma's viewed in 15 minute charts to the efs format you last provided (where the day is checked in the if statement), and with setComputeOnClose, thanks.

              Specifically I view daily 10ema, 20ema, 50ema, 50sma and 200sma plots in 27, 15 minute charts. Is their any efficiency improvement to combine these five MA efs's into one, so that only 27 efs's are running vs 135? Either way, the visible end product would be the same, but is there some 'minimum resource overhead' required by any efs that could be eliminated by combining efs's?

              Thanks
              shaeffer

              Comment


              • #22
                Hello shaeffer,

                Yes, absolutely. Most of the efficiency gained would be during the initialization at start up. Once that has completed and your formulas are processing real time you probably wouldn't notice much of a gain but there would still be some amount.
                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


                • #23
                  Originally posted by JasonK
                  What you could add to the code that will make it even more efficient is to only retrieve the value on the first bar of each new day. Add a condition that detects the first bar of each new day to the if() statement and try it out.

                  PHP Code:
                  var null;

                  function 
                  main() {
                      if(
                  == null || day(-1) != day(0)){
                          
                  =  ema(10inv("D"),-1);
                      }
                      return 
                  x;

                  Hi Jason,

                  Is x=null in the if statement required just to get the first bar loaded? ....because without it, with no previous bar then day(-1) would have no meaning? In other words, we couldn't remove the global variable and just use " if(day(-1) != day(0)){" instead?

                  I think we said that the series, ema(10,inv("D")) , gets calculated and the values stored by the EFS engine while creating the very first bar of the chart. So the efficiency of including "|| day(-1) != day(0)" in the if statement is that:
                  1) the successive "-1" values of the series would need to be retreived far fewer times during the initial loading of the chart/efs, hence faster loading, and,
                  2) the "-1" value of the series would only need to be retreived once from the EFS engine, at the first tick of the current trading day? So then evaluating the "|| day(-1) != day(0)" condition each time must be less processor intensive that retrieving the "-1" value?

                  Regards
                  shaeffer

                  Comment


                  • #24
                    Hello shaeffer,

                    Originally posted by shaeffer
                    Hi Jason,

                    Is x=null in the if statement required just to get the first bar loaded? ....because without it, with no previous bar then day(-1) would have no meaning? In other words, we couldn't remove the global variable and just use " if(day(-1) != day(0)){" instead?
                    You could just check for the new day. However, if you want a value to be plotted for the oldest day in the chart you will still need the global variable. Did you try it?

                    I think we said that the series, ema(10,inv("D")) , gets calculated and the values stored by the EFS engine while creating the very first bar of the chart. So the efficiency of including "|| day(-1) != day(0)" in the if statement is that:
                    1) the successive "-1" values of the series would need to be retrieved far fewer times during the initial loading of the chart/efs, hence faster loading,
                    Correct.


                    and,

                    2) the "-1" value of the series would only need to be retrieved once from the EFS engine, at the first tick of the current trading day? So then evaluating the "|| day(-1) != day(0)" condition each time must be less processor intensive that retrieving the "-1" value?

                    Regards
                    shaeffer
                    The check for the new day is evaluated on every bar, which prevents the retrieval of the "-1" value on every bar. Is this more efficient? Yes, however, the difference is nominal.
                    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


                    • #25
                      Originally posted by JasonK
                      You could just check for the new day. However, if you want a value to be plotted for the oldest day in the chart you will still need the global variable. Did you try it?
                      Hi Jason,

                      Well, I think I've learned about all the basics I can from that single ema efs ... thanks for your patience..

                      I don't need the value plotted for the oldest day of the chart. And I think removing a variable (particularly a global variable) improves efficiency, so I removed the x = null statement in my attempt below to combine my MA efs's (per our notes of 4/26).

                      PHP Code:
                          setComputeOnClose;
                      }
                      var 
                      myArray null;

                      function 
                      main() {

                          if(
                      day(-1) != day(0)){
                             
                      =  sma(200inv("D"),-1);
                             
                      =  sma50inv("D"),-1);
                             
                      =  ema50inv("D"),-1);
                             
                      =  ema20inv("D"),-1);
                             
                      =  ema10inv("D"),-1); 
                           
                      myArray = new Array(a,b,c,d,e);
                          }
                      return 
                      myArray;
                      //return new Array(a,b,c,d,e);

                      After over an hour of trying different things, I was able to get it to work. Can the efficiency of this be improved?

                      Do you know of a good link that describes how to use arrays? For example, do I have to define a variable myArray? Must it be a global variable? Why wouldn't return new Array(a,b,c,d,e); with no "myArray" statements work?

                      Thanks again
                      shaeffer

                      Comment


                      • #26
                        Hello shaeffer,

                        Originally posted by shaeffer
                        Hi Jason,

                        Well, I think I've learned about all the basics I can from that single ema efs ... thanks for your patience..

                        I don't need the value plotted for the oldest day of the chart. And I think removing a variable (particularly a global variable) improves efficiency, so I removed the x = null statement in my attempt below to combine my MA efs's (per our notes of 4/26).

                        PHP Code:
                            setComputeOnClose;
                        }
                        var 
                        myArray null;

                        function 
                        main() {

                            if(
                        day(-1) != day(0)){
                               
                        =  sma(200inv("D"),-1);
                               
                        =  sma50inv("D"),-1);
                               
                        =  ema50inv("D"),-1);
                               
                        =  ema20inv("D"),-1);
                               
                        =  ema10inv("D"),-1); 
                             
                        myArray = new Array(a,b,c,d,e);
                            }
                        return 
                        myArray;
                        //return new Array(a,b,c,d,e);

                        After over an hour of trying different things, I was able to get it to work. Can the efficiency of this be improved?
                        If you're using setComputeOnClose() you'll need to add the call operators (i.e. () )to the end of the function. It will not take affect otherwise. Also you should var the local variables, a, b, c and d. Other than than, I can't think of any thing else you could do here to improve efficiency.

                        Do you know of a good link that describes how to use arrays?
                        Here's a link to our Core JavaScript 1.5 Guide on the Array Object. This resource is pretty inclusive, but you can find many more resources by searching the internet. The Array Object is not an EFS specific extension.

                        For example, do I have to define a variable myArray? Must it be a global variable? Why wouldn't return new Array(a,b,c,d,e); with no "myArray" statements work?

                        Thanks again
                        shaeffer
                        Because you are only retrieving the values once on the first bar of each day, then yes your myArray variable needs to be declared globally. The global array retains its values in between executions of main(), or between bars. If it was not global, then your formula would produce a run-time error. On any bar that is not the first bar of the day, a, b, c and d have not been initialized. The return statement can't return variables that are undefined. In order to remove the global array variable and just use return new Array(a, b, c, d); you would have to remove the conditional statement that checks for the new day and assign the values to a, b, c and d on every execution of main(). This would have to be done because local variables (declared inside main()) do not store their values in between executions of main(). They have to be reinitialized on each execution.
                        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


                        • #27
                          Thanks for the reply Jason. and for catching the ()'s I missed in setComputeOnClose(). I gotta do some more reading/thinking about arrays.

                          Meanwhile, below is an efs I use in many charts. You can see where I changed , var vCntr from equalling getNumBars() to = 10. This was because I could see the program bogging down while trying to execute setBarBgColor(...) for all bars, whereas it seemed to be able to handle repainting just the last 10.

                          Right now, the barFg and Bg colors get painted (either repainted the same color or changed) on every tick. I am debating whether to include an additional if statement prior to the color commands in each of the four major if/else if conditions, to prevent the repainting while the same condition is occurring sequentially (i.e. so the Fg and Bg color changes would only be made when a new condition occurs). Do you think that would improve the efficiency of this efs? Otherwise, does anything look terribly wrong (inefficient)?

                          Regards
                          shaeffer

                          PHP Code:
                          function main(){

                          //var vCntr = getNumBars();  // Jan 20-06
                          var vCntr 10// Jan 20-06
                          var i=0;

                              var 
                          vHist macdHist(5,35,5);
                              
                              
                          // Crossing UP thru 0     
                              
                          if (vHist.getValue(-1) < && vHist.getValue(0) >0) {
                                  
                          setBarFgColor(Color.lime);
                                  
                          setBarBgColor(Color.blue);
                                  for (
                          i=0;i<vCntr;i++){
                                      
                          setBar(Bar.BgColor, -i, (Color.blue));
                                      
                          setBar(Bar.BgColor, -10, (Color.black));// Jan 20-06
                                  
                          }
                               
                          // Above 0               
                              
                          }else if (vHist.getValue(0) >0) {
                                  if (
                          vHist.getValue(-1) < vHist.getValue(0)) {
                                      
                          setBarFgColor(Color.lime);  // rising, above 0
                                  
                          }else{ 
                                      
                          setBarFgColor(Color.grey);  // falling, above 0
                                  
                          }
                                  
                          setBarBgColor(Color.green);
                                  for (
                          i=0;i<vCntr;i++){
                                      
                          setBar(Bar.BgColor, -i, (Color.green));
                                      
                          setBar(Bar.BgColor, -10, (Color.black));// Jan 20-06
                                  
                          }       
                               
                          // Crossing DOWN thru 0   
                              
                          }else if (vHist.getValue(-1) > && vHist.getValue(0) <=0) {
                                  
                          setBarFgColor(Color.RGB(25587192)); // Pink
                                  
                          setBarBgColor(Color.red);
                                  for (
                          i=0;i<vCntr;i++){
                                      
                          setBar(Bar.BgColor, -i, (Color.red));
                                      
                          setBar(Bar.BgColor, -10, (Color.black));  // Jan 20-06
                                  
                          }
                               
                          // Below 0               
                              
                          }else if (vHist.getValue(0) <=0) {
                                  if (
                          vHist.getValue(-1) >= vHist.getValue(0)) {         // dropping
                                      
                          setBarFgColor(Color.RGB(25587192)); // Pink, falling, below 0
                                  
                          }else{
                                      
                          setBarFgColor(Color.grey);    //rising, below 0
                                  
                          }
                                  
                          setBarBgColor(Color.maroon);
                                  for (
                          i=0;i<vCntr;i++){
                                      
                          setBar(Bar.BgColor, -i, (Color.maroon));
                                      
                          setBar(Bar.BgColor, -10, (Color.black));// Jan 20-06
                                  
                          }  
                              }
                              return 
                          vHist;

                          Comment


                          • #28
                            Hello shaeffer,

                            Originally posted by shaeffer
                            Thanks for the reply Jason. and for catching the ()'s I missed in setComputeOnClose(). I gotta do some more reading/thinking about arrays.

                            Meanwhile, below is an efs I use in many charts. You can see where I changed , var vCntr from equalling getNumBars() to = 10. This was because I could see the program bogging down while trying to execute setBarBgColor(...) for all bars, whereas it seemed to be able to handle repainting just the last 10.
                            Right, a loop that iterates only 10 times is processed much faster than a loop that goes all the way back to the oldest bar in the chart on every tick. Depending on your time template settings getNumBars() could be a fairly large number resulting in a very process intensive loop.

                            Right now, the barFg and Bg colors get painted (either repainted the same color or changed) on every tick. I am debating whether to include an additional if statement prior to the color commands in each of the four major if/else if conditions, to prevent the repainting while the same condition is occurring sequentially (i.e. so the Fg and Bg color changes would only be made when a new condition occurs). Do you think that would improve the efficiency of this efs?
                            The portion of your logic that loops back and repaints historical bars does not need to be performed on every tick. I would look for BARSTATE_NEWBAR using getBarState(), evaluate the conditions on the bar that just completed (bar -1) and then execute the loop starting at bar -1. This will prevent the loop from occurring on every tick and only do the loop once per bar. Also, in your loop you have a setBar() call that is using a fixed index of -10. There is no need to make this call 10 times. Move it outside of the loop.



                            Otherwise, does anything look terribly wrong (inefficient)?

                            Regards
                            shaeffer

                            PHP Code:
                            function main(){

                            //var vCntr = getNumBars();  // Jan 20-06
                            var vCntr 10// Jan 20-06
                            var i=0;

                                var 
                            vHist macdHist(5,35,5);
                                
                                
                            // Crossing UP thru 0     
                                
                            if (vHist.getValue(-1) < && vHist.getValue(0) >0) {
                                    
                            setBarFgColor(Color.lime);
                                    
                            setBarBgColor(Color.blue);
                                    for (
                            i=0;i<vCntr;i++){
                                        
                            setBar(Bar.BgColor, -i, (Color.blue));
                                        
                            setBar(Bar.BgColor, -10, (Color.black));// Jan 20-06
                                    
                            }
                                 
                            // Above 0               
                                
                            }else if (vHist.getValue(0) >0) {
                                    if (
                            vHist.getValue(-1) < vHist.getValue(0)) {
                                        
                            setBarFgColor(Color.lime);  // rising, above 0
                                    
                            }else{ 
                                        
                            setBarFgColor(Color.grey);  // falling, above 0
                                    
                            }
                                    
                            setBarBgColor(Color.green);
                                    for (
                            i=0;i<vCntr;i++){
                                        
                            setBar(Bar.BgColor, -i, (Color.green));
                                        
                            setBar(Bar.BgColor, -10, (Color.black));// Jan 20-06
                                    
                            }       
                                 
                            // Crossing DOWN thru 0   
                                
                            }else if (vHist.getValue(-1) > && vHist.getValue(0) <=0) {
                                    
                            setBarFgColor(Color.RGB(25587192)); // Pink
                                    
                            setBarBgColor(Color.red);
                                    for (
                            i=0;i<vCntr;i++){
                                        
                            setBar(Bar.BgColor, -i, (Color.red));
                                        
                            setBar(Bar.BgColor, -10, (Color.black));  // Jan 20-06
                                    
                            }
                                 
                            // Below 0               
                                
                            }else if (vHist.getValue(0) <=0) {
                                    if (
                            vHist.getValue(-1) >= vHist.getValue(0)) {         // dropping
                                        
                            setBarFgColor(Color.RGB(25587192)); // Pink, falling, below 0
                                    
                            }else{
                                        
                            setBarFgColor(Color.grey);    //rising, below 0
                                    
                            }
                                    
                            setBarBgColor(Color.maroon);
                                    for (
                            i=0;i<vCntr;i++){
                                        
                            setBar(Bar.BgColor, -i, (Color.maroon));
                                        
                            setBar(Bar.BgColor, -10, (Color.black));// Jan 20-06
                                    
                            }  
                                }
                                return 
                            vHist;

                            Regarding this line of code inside main():
                            PHP Code:
                            var vHist macdHist(5,35,5); 
                            Earlier in this thread we discussed in detail the issue of initializing built-in Series Objects inside main() and how to improve this. I suggest you go back through this thread and apply some of the suggestions we've already covered to your vHist Series Object.

                            One other thing I see where you can improve this code is to reduce the number of .getValue() calls you are making. You are making the same call multiple times throughout main(). If you make the call once at the top of main() and assign the result to a local variable, you can then use that variable throughout main() in your conditional statements. This would be more efficient.

                            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


                            • #29
                              Originally posted by JasonK
                              The portion of your logic that loops back and repaints historical bars does not need to be performed on every tick. I would look for BARSTATE_NEWBAR using getBarState(), evaluate the conditions on the bar that just completed (bar -1) and then execute the loop starting at bar -1. This will prevent the loop from occurring on every tick and only do the loop once per bar. Also, in your loop you have a setBar() call that is using a fixed index of -10. There is no need to make this call 10 times. Move it outside of the loop.
                              Hi Jason,

                              My reason for painting the historic bars is so I can readily see the 'if condition' associated with the most recent bar, in multiple tiny charts. If I paint the Bg of just the most current bar, it will be too narrow to notice, hence I also repaint the previous 9 bars with the same color as the most recent bar. So I need to check (on every tick) if the most recent tick changes the 'if' condition, in which case all previous 9 bar Bg colors need to change. So I think your BAR_STATE suggestion doesn't apply in this application? (I had asked / hoped for a new setStudyBgColor command (similar to setChartBgColor) that might more efficiently do this, but looks like no luck in the near future).

                              I'm still thinking that a new if statement within each condition that checks if the current condition is the same as the last tick, and if so then does not repaint the previous bars with the same color they already are, might improve efficiency. But if the current tick did result in a new if condition, then repainting a different color would occur.

                              I will move the multiple bar index -10 command outside the loop, as you suggested, thanks.

                              Earlier in this thread we discussed in detail the issue of initializing built-in Series Objects inside main() and how to improve this. I suggest you go back through this thread and apply some of the suggestions we've already covered to your vHist Series Object.
                              Our previous discussions re built in series objects in main() were for one value being retreived from the series. This time we've got two, the (-1) and the (0) values, so I need to think about how to do this. Since the (0) value in the current tick evaluation becomes the (-1) value in the next tick evaluation, should I create a global variable for the (-1) value and as the last line in main(), make the (0) value = the (-1) value. Then the (-1) value would be known already as the next tick evaluation starts? Is that the idea?

                              From our previous discussions, I know the entire series is born in the efs engine when the earliest bar is created. And at that time, I beleive all bar index values (associated with the chart interval) are defined within the series. But then in real time, each bar gets 'built', tick by tick. I'm fumbling here..... I see the need for a global variable for the (-1) value. Is there also a need for a global variable for the real time (0) value, or should that only be a local variable?

                              One other thing I see where you can improve this code is to reduce the number of .getValue() calls you are making. You are making the same call multiple times throughout main(). If you make the call once at the top of main() and assign the result to a local variable, you can then use that variable throughout main() in your conditional statements. This would be more efficient.
                              I will define two local variables so there is only one each .getValue() call. Is it correct though that since I have a string of if/else if statements, they would only be called once for each tick?
                              -------------------------
                              I'm still a little confused re: historical bars series (interval) values vs real time (0) and (-1) tick values, relative to use of global vs local variables, but hopefully answers to the above will clarify this for me.

                              Regards
                              shaeffer

                              (P.S. are you involved at all in the quote sheet efs formula initiative?)

                              Comment


                              • #30
                                shaeffer

                                I'm still thinking that a new if statement within each condition that checks if the current condition is the same as the last tick, and if so then does not repaint the previous bars with the same color they already are, might improve efficiency. But if the current tick did result in a new if condition, then repainting a different color would occur.
                                To do that you can use the example I provided to you in this thread. The logic required is the same
                                Alex

                                Comment

                                Working...
                                X