Announcement

Collapse
No announcement yet.

EFS questions by shaeffer

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

  • #31
    Hello shaeffer,

    Originally posted by shaeffer
    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.
    Your logic seems to be on the right track. See Alex's reply for the coding solution.

    I will move the multiple bar index -10 command outside the loop, as you suggested, thanks.
    You're most welcome as always.


    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?
    When you request .getValue(0) or .getValue(-1), the index value always refers to the bar, not individual ticks. -1 always gives you the previous bar regardless if the formula is processing historical bars or the real time tick data on bar 0. The logic you need to keep track of the previous tick is similar to the color1 and color0 logic Alex pointed you in his reply. Create two global variables (myTick, myTick1). myTick will be immediately assigned with the .getValue(0) method. At the top of main(), or before the .getValue(0) assignment occurs, assign myTick1 with myTick. Now you have two variables that contain the current tick value and the previous tick value that occur on bar 0. Note that this can't be used with setComputeOnClose() as it needs to be evaluated on a tick-by-tick basis.

    PHP Code:
    var myTick null;
    var 
    myTick1 null;
    var 
    myStudy null;
    var 
    bInit false;

    function 
    main() {
        if (
    bInit == false) {
            
    myStudy macdHist(5355);
            
    bInit true;
        }

        
    myTick1 myTick;
        
    myTick myStudy.getValue(0);
        if (
    myTick == null || myTick1 == null) return; // validate vars before use with 
                                                       //conditional statements that follow.



    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?
    Correct.

    -------------------------
    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
    Let me know if my responses above did not answer this question for you. The only difference between local and global variables is the the values assigned to a global variables will remain for the life of the formula. A local variable declared inside main(), or any other user-defined function, will only exist for the single execution of the function. Once the function has executed all of it's contained code, the local variables and the values they were assigned are destroyed, or removed from memory. You won't be able to refer to those values on subsequent calls of main() or other user-defined functions.

    (P.S. are you involved at all in the quote sheet efs formula initiative?)
    No sir, I am not.
    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


    • #32
      Originally posted by JasonK
      ......When you request .getValue(0) or .getValue(-1), the index value always refers to the bar, not individual ticks. -1 always gives you the previous bar regardless if the formula is processing historical bars or the real time tick data on bar 0.
      Hi Jason,
      Just to clarify, .getValue(-1) refers to the previous bar (whether real time or not)... ok. But in real time, if we are currently 5 minutes into a 15 minute bar, then .getValue(0), would refer to the latest (partial) bar, ie .getValue(0) will change tick by tick in real time .. is that correct?
      -----------------------------------
      Unfortunately, I'm out of town for the rest of the month, so I can't tackle your (and Alex's) suggestions (or the new release) for a coupla weeks. Its clearer now to me that to minimize the repainting, I need the tick by previous tick comparison, whereas the 'if conditions' require a current tick (.getValue(0)) by previous bar (.getValue(-1)) comparison.

      I'll look forward to getting back at it.
      Thanks
      shaeffer

      Comment


      • #33
        Hi shaeffer,

        Originally posted by shaeffer
        Hi Jason,
        Just to clarify, .getValue(-1) refers to the previous bar (whether real time or not)... ok. But in real time, if we are currently 5 minutes into a 15 minute bar, then .getValue(0), would refer to the latest (partial) bar, ie .getValue(0) will change tick by tick in real time .. is that correct?
        That is correct.

        Comment


        • #34
          Sad to say, but I've spent since sunrise to 4:00 pm on a holiday Monday trying to get this to work. The wife is very annoyed and I've got no market prep work done.

          I tried (in other versions of this efs not shown) some of the series improvements Jason suggested, but mostly worked on trying to minimize repainting per Alex' suggestion. The setBarBgColor(color0); line near the bottom kept causing invalid parameter errors. Alex' suggestion was originally applied to the setChartBG() command, but should it work for the setBarBgColor() command also?

          Thanks
          shaeffer

          PHP Code:
          var color0 Color.white;
          var 
          color1 Color.cyan;

          function 
          main(){

          color1 color0// = white

          //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) {
                  
          color0 Color.blue;
                  
          setBarFgColor(Color.lime);
                  
               
          // Above 0               
              
          }else if (vHist.getValue(0) >0) {
                  
          color0 Color.green;
                  if (
          vHist.getValue(-1) < vHist.getValue(0)) {
                      
          setBarFgColor(Color.lime);  // rising while above 0
                  
          }else{ 
                      
          setBarFgColor(Color.white);  // falling while above 0
                  
          }
                  
               
          // Crossing DOWN thru 0   
              
          }else if (vHist.getValue(-1) > && vHist.getValue(0) <=0) {
                  
          color0 Color.RGB(180,0,150);  // Pink
                  
          setBarFgColor(Color.RGB(25587192)); // Pink
               
               // Below 0               
              
          }else if (vHist.getValue(0) <=0) {
                  
          color0 Color.maroon;
                  if (
          vHist.getValue(-1) >= vHist.getValue(0)) {         // dropping
                      
          setBarFgColor(Color.RGB(25587192)); // Pink, falling, below 0
                  
          }else{
                      
          setBarFgColor(Color.white);    //rising, below 0
                  
          }
              }
          //------------------------------------  
              
          if (color0 =! color1){
                
          setBarBgColor(color0);
                  for (
          i=0;i<vCntr;i++){
                      
          setBar(Bar.BgColor, -icolor0);
                      
          setBar(Bar.BgColor, -10, (Color.black));
                  }
              }   
          return 
          vHist;

          Comment


          • #35
            Further to Jason's mytick/mytick1 reply, I don't need to directly compare the most recent tick value to the previous tick value to limit repainting, I don't think. Its only if the most recent tick causes an 'if condition' change that I want to see a new barBgColor. Otherwise, the previous barBgColor should repeat. So it seemed like a flag within the condition statements might work. I tried that (per efs below) and it worked well whenever a condition (color) change occurred, but when no condition change occurred, the default barBgcolor appeared (not the previous barBgColor as desired).

            Before I try adding an 'else if' at the end to return the previous barBgColor, is this flag approach worth pursuing or should I focus on Alex's approach in my previous post?

            Thanks
            shaeffer
            PHP Code:
            var ncolor 55;
            var 
            xcolor 66;
            //var vHist = null;
            //var bInit = false;

            function main() {

             
            /*   if (bInit == false) {
                    vHist = macdHist(5, 35, 5);
                    bInit = true;
                }*/

              
            var xcolor ncolor;

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

                var 
            vHist macdHist(5,35,5);
                var 
            vHist1 vHist.getValue(-1);
                
                
            // Crossing UP thru 0 .... BarBg = Blue    
                
            if (vHist1 && vHist >0) {
                    
            setBarFgColor(Color.lime);
                    if(
            xcolor != 1){
                        
            setBarBgColor(Color.blue);
                        for (
            i=0;i<vCntr;i++){
                            
            setBar(Bar.BgColor, -i, (Color.blue));
                        }
                        
            ncolor 1;
                    }
                 
            // Above 0  .... BarBg = Green              
                
            }else if (vHist >0) {
                    if (
            vHist1 vHist) {
                        
            setBarFgColor(Color.lime);  // rising, above 0
                    
            }else{ 
                        
            setBarFgColor(Color.white);  // falling, above 0
                    
            }
                    if(
            xcolor != 2){
                        
            setBarBgColor(Color.green);
                        for (
            i=0;i<vCntr;i++){
                            
            setBar(Bar.BgColor, -i, (Color.green));
                        }
                        
            ncolor 2;
                    }
                 
            // Crossing DOWN thru 0  .... BarBg = Pink   
                
            }else if (vHist1 && vHist <=0) {
                    
            setBarFgColor(Color.RGB(25587192)); // Pink
                    
            if(xcolor != 3){
                        
            setBarBgColor(Color.RGB(180,0,150));  // Pink
                        
            for (i=0;i<vCntr;i++){
                            
            setBar(Bar.BgColor, -i, (Color.RGB(180,0,150))); // Pink
                        
            }
                        
            ncolor 3;
                    }
                 
            // Below 0  .... BarBg = Maroon               
                
            }else if (vHist <=0) {
                    if (
            vHist1 >= vHist) {         // dropping
                        
            setBarFgColor(Color.RGB(25587192)); // Pink, falling, below 0
                    
            }else{
                        
            setBarFgColor(Color.white);    //rising, below 0
                    
            }
                    if(
            xcolor != 4){
                        
            setBarBgColor(Color.maroon);
                        for (
            i=0;i<vCntr;i++){
                            
            setBar(Bar.BgColor, -i, (Color.maroon));
                            
            setBar(Bar.BgColor, -10, (Color.black));
                        }
                        
            ncolor 4;
                    }
                }
                
            setBar(Bar.BgColor, -10, (Color.black));
                
                return 
            vHist

            Comment


            • #36
              shaeffer

              The setBarBgColor(color0); line near the bottom kept causing invalid parameter errors.
              That syntax error is caused by an incorrect operator in line 43 ie.
              if (color0 =! color1){ which should instead be if (color0 != color1){
              Alex

              Comment


              • #37
                Some good progress, I think with both issues:
                1. minimizing repainting, and
                2. optimizing use of the Series.

                Minimizing Repainting
                Thanks for the reply Alex re: the incorrect =!. I'll remember to type it next time as it sounds (not equal).

                Fixing that allowed the efs to load, after which I noticed that a bar with no change in BgColor would appear with the default barBgColor. So I included a setBarBgColor(Color.xxx); line in each condition (and changed the i counter =1 and that appears to work. So the Bg on the very latest bar gets repainted on every tick, but maybe that is unavoidable. But now all ten past bars aren't repainting on every tick. I'll see if that creates a noticeable improvement in program speed (now I can wait 5 or more seconds after double clicking a Last price in a quote list to reset the alert price).

                Would making variables vCntr and i global be an improvement?

                Using a Series
                Jason, I'm not sure if I'm applying the Series in the most optimum way. I created the global variables vHist and vHist1 to compare the latest tick with the close of the previous bar (.getValue(0)). I think my previous mention of tick by tick comparison was confusing, and has been resolved within Alex' repainting solution. So I think vHist and vHist1 acheive the intent of your mytick and mytick1 variables?

                Our previous examples were somewhat different, but I think the carryover lessons are:
                1. By making vHist global, the series is only loaded once at startup and remembered (vs being lost and reloaded on each tick when vHist was local only)?
                2. By making vHist1 global, the (-1) value is remembered during each tick of the (0) bar? And it 'knows' to get a new value when a new (0) bar starts?
                3. Efficiency is improved by having vHist and vHist1 as local variables before the conditions (vs calling up the (-1) and (0) values within each condition.

                Is the above correct? I couldn't get the bInit loop to work, so I'm not sure if I'm missing an optimization. Any other opportunties for improvement?

                Thanks so much for your help
                Regards
                shaeffer

                PHP Code:
                var color0 Color.white;
                var 
                color1 Color.cyan;
                var 
                vHist  null;
                var 
                vHist1 null;
                //var bInit = false;

                function main(){

                color1 color0;
                var 
                vCntr 10;
                var 
                i=1;

                    
                /*if (bInit == false) {
                        vHist = macdHist(5, 35, 5);
                        bInit = true;
                    }*/
                    
                var vHist macdHist(5,35,5);    // value of most recent tick, same as vHist.getValue(0)
                    
                var vHist1 vHist.getValue(-1); // value at close of previous bar
                    
                    // Crossing UP thru 0     
                    
                if (vHist1 && vHist >0) {
                        
                setBarFgColor(Color.lime);
                        
                setBarBgColor(Color.blue);
                        
                color0 Color.blue;
                        
                     
                // Above 0               
                    
                }else if (vHist >0) {
                        
                setBarBgColor(Color.green);
                        
                color0 Color.green;
                        if (
                vHist.getValue(-1) < vHist.getValue(0)) {
                            
                setBarFgColor(Color.lime);  // rising while above 0
                        
                }else{ 
                            
                setBarFgColor(Color.white);  // falling while above 0
                        
                }
                        
                     
                // Crossing DOWN thru 0   
                    
                }else if (vHist1 && vHist <=0) {
                        
                setBarBgColor(Color.RGB(180,0,150));  // Pink
                        
                color0 Color.RGB(180,0,150);  // Pink
                        
                setBarFgColor(Color.RGB(25587192)); // Pink
                     
                     // Below 0               
                    
                }else if (vHist <=0) {
                        
                setBarBgColor(Color.maroon);
                        
                color0 Color.maroon;
                        if (
                vHist.getValue(-1) >= vHist.getValue(0)) {         // dropping
                            
                setBarFgColor(Color.RGB(25587192)); // Pink, falling, below 0
                        
                }else{
                            
                setBarFgColor(Color.white);    //rising, below 0
                        
                }
                    }
                //------------------------------------  
                    
                if (color0 != color1){
                      
                setBarBgColor(color0);
                        for (
                i=1;i<vCntr;i++){
                            
                setBar(Bar.BgColor, -icolor0);
                        }
                    } 
                    
                setBar(Bar.BgColor, -10, (Color.black)); 
                    
                return 
                vHist;

                Comment


                • #38
                  Hello shaeffer,

                  Originally posted by shaeffer
                  Using a Series
                  Jason, I'm not sure if I'm applying the Series in the most optimum way. I created the global variables vHist and vHist1 to compare the latest tick with the close of the previous bar (.getValue(0)). I think my previous mention of tick by tick comparison was confusing, and has been resolved within Alex' repainting solution. So I think vHist and vHist1 achieve the intent of your mytick and mytick1 variables?

                  Our previous examples were somewhat different, but I think the carryover lessons are:
                  1. By making vHist global, the series is only loaded once at startup and remembered (vs being lost and reloaded on each tick when vHist was local only)?
                  2. By making vHist1 global, the (-1) value is remembered during each tick of the (0) bar? And it 'knows' to get a new value when a new (0) bar starts?
                  3. Efficiency is improved by having vHist and vHist1 as local variables before the conditions (vs calling up the (-1) and (0) values within each condition.

                  Is the above correct? I couldn't get the bInit loop to work, so I'm not sure if I'm missing an optimization. Any other opportunties for improvement?

                  Thanks so much for your help
                  Regards
                  shaeffer

                  PHP Code:
                  var color0 Color.white;
                  var 
                  color1 Color.cyan;
                  var 
                  vHist  null;
                  var 
                  vHist1 null;
                  //var bInit = false;

                  function main(){

                  color1 color0;
                  var 
                  vCntr 10;
                  var 
                  i=1;

                      
                  /*if (bInit == false) {
                          vHist = macdHist(5, 35, 5);
                          bInit = true;
                      }*/
                      
                  var vHist macdHist(5,35,5);    // value of most recent tick, same as vHist.getValue(0)
                      
                  var vHist1 vHist.getValue(-1); // value at close of previous bar
                      
                      // Crossing UP thru 0     
                      
                  if (vHist1 && vHist >0) {
                          
                  setBarFgColor(Color.lime);
                          
                  setBarBgColor(Color.blue);
                          
                  color0 Color.blue;
                          
                       
                  // Above 0               
                      
                  }else if (vHist >0) {
                          
                  setBarBgColor(Color.green);
                          
                  color0 Color.green;
                          if (
                  vHist.getValue(-1) < vHist.getValue(0)) {
                              
                  setBarFgColor(Color.lime);  // rising while above 0
                          
                  }else{ 
                              
                  setBarFgColor(Color.white);  // falling while above 0
                          
                  }
                          
                       
                  // Crossing DOWN thru 0   
                      
                  }else if (vHist1 && vHist <=0) {
                          
                  setBarBgColor(Color.RGB(180,0,150));  // Pink
                          
                  color0 Color.RGB(180,0,150);  // Pink
                          
                  setBarFgColor(Color.RGB(25587192)); // Pink
                       
                       // Below 0               
                      
                  }else if (vHist <=0) {
                          
                  setBarBgColor(Color.maroon);
                          
                  color0 Color.maroon;
                          if (
                  vHist.getValue(-1) >= vHist.getValue(0)) {         // dropping
                              
                  setBarFgColor(Color.RGB(25587192)); // Pink, falling, below 0
                          
                  }else{
                              
                  setBarFgColor(Color.white);    //rising, below 0
                          
                  }
                      }
                  //------------------------------------  
                      
                  if (color0 != color1){
                        
                  setBarBgColor(color0);
                          for (
                  i=1;i<vCntr;i++){
                              
                  setBar(Bar.BgColor, -icolor0);
                          }
                      } 
                      
                  setBar(Bar.BgColor, -10, (Color.black)); 
                      
                  return 
                  vHist;

                  1) You're describing the difference between global (outside of main()) and local (inside of main()) variables properly, but your code is not exactly doing what you want. Notice that you have var'd the two variables, vHist and vHist1 both in the global scope and the local scope. You need to choose one or the other, not both. Setting up the Series Object, vHist, globally is the more efficient way to go through either a bInit routine as I showed you in this post or by checking for null as I showed you in this post and those that follow it. Both methods accomplish the same level of efficiency.

                  2) vHist1 does not actually need to be global if you are going to assign the -1 value on every tick. If you don't want to assign the value on each tick, then make it global and only assign the value to it a BARSTATE_NEWBAR. This prevents the assignment from occurring on every tick. The assignment will only occur once per bar when each new bar starts.

                  PHP Code:
                  var vHist1 null;

                  function 
                  main() {
                      ....

                      if (
                  getBarState() == BARSTATE_NEWBAR) {
                          
                  vHist1 vHist.getValue(-1);
                      }

                      ....

                  3) Aside from the issue of having the variables declared both globally and locally, yes, it is more efficient to assign the values of the series to variables that are used within your conditional statements rather than making the .getValue() calls over and over again inside those statements.

                  Your bInit routine did not work because you re-declared vHist after the bInit routine.

                  Part of the problem that is causing some confusion for you is that you are not using any specific naming conventions for your variables. It will help you if you create variables that start with something like "x" to remind you that the variable is storing a Series Object. Use "n" to denote variables that store a single number. Use "s" for strings, "b" for Boolean etc. In your code example you are using vHist to store your macd Series and then using it directly inside your conditional statements. That is fine in this case because you are declaring vHist locally so the EFS2 engine recognizes that your trying to use the Series inside a conditional statement and performs the .getValue(0) call for you. However, this is not the most efficient way to handle this.

                  Create your Series Object variables globally.

                  PHP Code:
                  var xHist null;

                  function 
                  main() {
                      .... 
                  Initialize the Series Object inside main() by checking for null or use the bInit routine.

                  PHP Code:
                  var xHist null;
                  var 
                  bInit false;

                  function 
                  main() {
                      if (
                  bInit == false) {
                          
                  xHist macdHist(5355);
                          
                  bInit true;
                      }
                      .... 
                  Now assign the values of the two numbers you need from the series to their own variables. Make note of the n's and the x in the naming conventions. The n's will be used within your conditional statements.

                  PHP Code:
                  var xHist null;
                  var 
                  bInit false;
                  var 
                  nHist1 null;

                  function 
                  main() {
                      if (
                  bInit == false) {
                          
                  xHist macdHist(5355);
                          
                  bInit true;
                      }

                      var 
                  nHist xHist.getValue(0);  // retrieve the current number from the xHist series.
                      
                  if (getBarState() == BARSTATE_NEWBAR) {
                          
                  nHist1 xHist.getValue(-1); // retrieve the previous bar's closing number from the xHist series.
                      
                  }

                      
                  // validate your variables before processing conditions
                      
                  if (nHist == null || nHist1 == null) 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


                  • #39
                    shaeffer

                    Would making variables vCntr and i global be an improvement?
                    The variable i needs to be local not global. You can even declare it inside the for loop itself ie
                    for(var i=1; i<vCntr; i++){
                    As to vCntr it would make no difference if it is local or global .
                    Alex

                    Comment


                    • #40
                      shaeffer

                      So the Bg on the very latest bar gets repainted on every tick, but maybe that is unavoidable
                      The background on the current bar (or very latest bar to use your definition) does not get repainted on every tick because the setBarBgColor() command is inside the if(color0!=color1){ conditional statement. Hence it gets painted only when that condition is true.
                      Alex

                      Comment


                      • #41
                        Thanks so much for your reply, Jason. You are right, I was confusing my local variables retreived from the series, with the global series variable. Your variable naming convention should help. (My reply here is delayed due to 8.0(?) problems I've addressed in the BETA forum).

                        Summarizing all you've told me about using Series, my 'Rules For Using Series' in non-ComputeOnClose() applications are now:
                        1. Provide the series with a global variable name.
                        2. In main(), use either a bInit true-false loop or null check before defining the series. (I'm not entirely sure why this is necessary, vs simply saying in this case xHist = macdHist(5, 35, 5);)
                        3. Name a local variable to retrieve the current value of the series.
                        4. If the previous bar series value (-1) will be used, give it a global variable name and retreive its value within a if (getBarState() == BARSTATE_NEWBAR) { loop
                        5. Ensure all variables have a null check to validate(?) them (though I'm not sure what validating is... same Q as in 2 above I think).

                        Hopefully the above is correct, and the efs below is now perfect(?).
                        ------------------------------
                        Alex, I included var = i .... in each loop, as you suggested.

                        The unavoidable(?) tick by tick repainting of the current bar I was referring to was in the setBarBgColor(Color.xxxx); command immediately after each if statement. Without that line, consecutive bars meeting the same if condition are painted the default barBg color. Then only after a change in if condition does the if(color0!=color1){ conditional statement give me the BgColor I want.

                        Hey, on a whim I just replaced the setBarBgColor(Color.xxxx); command after each if statement with setDefaultBarBgColor(Color.xxxx);, even though that latter command is intended for use within preMain(). It seemed to work. Will that prevent current barBg repainting, or is it effectively the same thing.

                        Thanks again for all your help
                        Regards
                        shaeffer



                        PHP Code:
                        var color0 Color.white;
                        var 
                        color1 Color.cyan;
                        var 
                        xHist  null;
                        var 
                        bInit false;
                        var 
                        nHist1 null;

                        function 
                        main(){

                        color1 color0;
                        var 
                        vCntr 10;

                            if (
                        bInit == false) {
                                
                        xHist macdHist(5355);
                                
                        bInit true;
                            }
                            
                            var 
                        nHist xHist.getValue(0);  // retrieve the current number from the xHist series.
                            
                        if (getBarState() == BARSTATE_NEWBAR) {
                                
                        nHist1 xHist.getValue(-1); // retrieve the previous bar's closing number from the xHist series.
                            
                        }
                            if (
                        nHist == null || nHist1 == null) return; // validate your variables before processing conditions
                            
                            // Crossing UP thru 0     
                            
                        if (nHist1 && nHist >0) {
                                
                        setBarFgColor(Color.lime);
                                
                        setBarBgColor(Color.blue);
                                
                        color0 Color.blue;
                                
                             
                        // Above 0               
                            
                        }else if (nHist >0) {
                                
                        setBarBgColor(Color.green);
                                
                        color0 Color.green;
                                if (
                        nHist1 nHist) {
                                    
                        setBarFgColor(Color.lime);  // rising while above 0
                                
                        }else{ 
                                    
                        setBarFgColor(Color.white);  // falling while above 0
                                
                        }
                                
                             
                        // Crossing DOWN thru 0   
                            
                        }else if (nHist1 && nHist <=0) {
                                
                        setBarBgColor(Color.RGB(180,0,150));  // Pink
                                
                        color0 Color.RGB(180,0,150);  // Pink
                                
                        setBarFgColor(Color.RGB(25587192)); // Pink
                             
                             // Below 0               
                            
                        }else if (nHist <=0) {
                                
                        setBarBgColor(Color.maroon);
                                
                        color0 Color.maroon;
                                if (
                        nHist1 >= nHist) {         // dropping
                                    
                        setBarFgColor(Color.RGB(25587192)); // Pink, falling, below 0
                                
                        }else{
                                    
                        setBarFgColor(Color.white);    //rising, below 0
                                
                        }
                            }
                        //------------------------------------  
                            
                        if (color0 != color1){
                              
                        setBarBgColor(color0);
                                for (var 
                        i=1;i<vCntr;i++){
                                    
                        setBar(Bar.BgColor, -icolor0);
                                }
                            } 
                            
                        setBar(Bar.BgColor, -10, (Color.black)); 
                           
                        return 
                        nHist;

                        Comment


                        • #42
                          shaeffer

                          Will that prevent current barBg repainting, or is it effectively the same thing.
                          It is the same thing. You need to remove all instances of setBarBgColor() except the one inside the if(color0 != color1) conditional statement which you replace with setDefaultBarBgColor() so that the background painting persists while that condition is not true
                          Alex

                          Comment


                          • #43
                            Hello shaeffer,

                            RE: #2
                            We've covered this in detail earlier in this thread. Please review the following posts, post 1, post 2, and post 3.

                            RE: #5
                            Validation simply means that you are making sure that the variables you will be using in conditional statements or calculations contain valid data. Performing a null check on a variable that your code logic is expecting to contain a number is just good programming practice. Without validating (or performing a null check) a variable, your code will try to evaluate conditions or perform calculations using a piece of 'invalid' data, which will generate invalid results most likely.
                            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


                            • #44
                              Originally posted by JasonK
                              Hello shaeffer,

                              RE: #2
                              We've covered this in detail earlier in this thread. Please review the following posts, post 1, post 2, and post 3.
                              You are right, Jason. Sorry for the repeat question.

                              Below is a stochastic study I've just updated, hopefully now using global and local variables correctly and defining the series correctly. And I've added the setDefaultBarBgColor(color0); in the final if loop per Alex' last comments.

                              In the EFS Developers Reference, two series are defined:
                              1. stochK( 14, 1, 3 ) and
                              2. stochD( 14, 1, 3 )
                              from which the current Fast and Slow line values are then retrieved via .getValue(0).

                              The EFS below seems to work, but is it using 'old' less efficient EFS1 language? If so, I'll update it in which case could I define my vStoch series variable as stoch(5,3,3) or are two series needed per the Developers Ref?

                              Thanks once again
                              shaeffer

                              PHP Code:
                              var color0 Color.white;
                              var 
                              color1 Color.cyan;
                              var 
                              vStoch null;
                              var 
                              stoF1   null;
                              var 
                              stoS1   null;

                              function 
                              main() {
                               
                              color1 color0;
                              var 
                              vCntr 10;

                                  if(
                              vStoch==nullvStoch = new StochStudy(533); // checks for null, and defines the stochastic series
                                  
                                  
                              var stoF vStoch.getValue(StochStudy.FAST); // retreives the current Fast line value from the StochStudy series
                                  
                              var stoS vStoch.getValue(StochStudy.SLOW); // retreives the current Fast line value from the StochStudy series
                                  
                                  
                              if (getBarState() == BARSTATE_NEWBAR) {
                                      
                              stoF1 vStoch.getValue(StochStudy.FAST,-1); // retreives the previous bar Fast line value from the StochStudy series
                                      
                              stoS1 vStoch.getValue(StochStudy.SLOW,-1); // retreives the previous bar Slow line value from the StochStudy series
                                  
                              }
                                  if (
                              stoF  == null || stoS  == null) return;
                                  if (
                              stoF1 == null || stoS1 == null) return; // validates these four variables
                                
                                  
                              addBand80PS_SOLID1Color.lightgrey,2);
                                  
                              addBand20PS_SOLID1Color.lightgrey,3);
                                  
                                   
                                    
                              // Crossing down  F <= S and F1 > S1  
                                  
                              if(stoF <= stoS  && stoF1 stoS1){
                                      
                              color0 Color.RGB(180,0,150);           // Pink)
                                      
                                     // Crossing up   F >= S  and F1 < S1  
                                  
                              }else if(stoF >= stoS  &&  stoF1 stoS1){
                                      
                              color0 Color.blue;                     //  Blue
                                      
                                     // Rising     F >= F1 
                                  
                              }else if(stoF stoF1){
                                      
                              color0 Color.green;                    //  Green 
                                     
                                     // Falling    F <= F1  
                                  
                              }else if(stoF <= stoF1){
                                      
                              color0 Color.maroon;                   //  Maroon
                                  
                                  
                              }else {
                                      
                              setBarBgColorColor.yellow);  // a check, should never happen    //Yellow   
                                  
                              }
                              //------------------------------------  
                                  
                              if (color0 != color1){
                                    
                              setBarBgColor(color0);
                                    
                              setDefaultBarBgColor(color0); 
                                      for (var 
                              i=1;i<vCntr;i++){
                                          
                              setBar(Bar.BgColor, -icolor0);
                                      }
                                  } 
                                  
                              setBar(Bar.BgColor, -10, (Color.black)); 
                                  
                              return new Array(
                              stoFstoS);

                              Comment


                              • #45
                                shaeffer
                                In the for loop you do not need to use setBarBgColor() but only setDefaultBarBgColor()
                                For the efs2 version of the Stochastic study you need to use both the stochK() and the stochD() functions
                                Alex

                                Comment

                                Working...
                                X