Announcement

Collapse
No announcement yet.

real-time / reload

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

  • real-time / reload

    In the following simple script, I am finding that I must reload the file for real-time values.

    function preMain() {
    setStudyTitle("Code Test");
    }

    function main(nBars) {
    if(nBars == null)
    nBars = 5;

    var vStudy1 = new MAStudy(nBars, -1, "OHLC/4", MAStudy.SIMPLE);
    var vStudy2 = new MAStudy(nBars, 0, "OHLC/4", MAStudy.SIMPLE);
    var vMALastBar = vStudy1.getValue(MAStudy.MA);
    var vMAThisBar = vStudy2.getValue(MAStudy.MA);

    if(vMALastBar > vMAThisBar) {
    setBarBgColor(Color.lime);
    }
    else if(vMALastBar < vMAThisBar) {
    setBarBgColor(Color.red);
    }
    else if(vMALastBar == vMAThisBar) {
    setBarBgColor(Color.yellow);
    }
    }


    Sure, I could call
    setComputeOnClose();
    But that negates the real-time features that I need.

    Further, each time a new price bar starts, it always the background color is always red. Will fixing the first issue address this as well?

    Thanks in advance,
    Greg

  • #2
    Greg:

    In your script, you are offsetting the first MA back into the past by one bar (e.g., an offset of -1). When run in realtime, there is no value for that.... because it is always one bar back in the past. Load up a standard MA on your chart and set the offset to -1 and you will see what I mean. Technically, it should not be working with historical bars either (but I realize that it does).

    Chris

    Comment


    • #3
      Greg
      Try the enclosed revision
      Alex

      PHP Code:
      var vStudy1=null;

      function 
      preMain() {
          
      setStudyTitle("Code Test");
      }

      function 
      main(nBars) {
          if(
      nBars == null)
              
      nBars 5;

          if(
      vStudy1==nullvStudy1 = new MAStudy(nBars0"OHLC/4"MAStudy.SIMPLE);
          
          var 
      vMALastBar vStudy1.getValue(MAStudy.MA,-1);
          var 
      vMAThisBar vStudy1.getValue(MAStudy.MA);

          if(
      vMALastBar vMAThisBar) {
              
      setBarBgColor(Color.red);
          }
          else if(
      vMALastBar vMAThisBar) {
              
      setBarBgColor(Color.lime);
          }
          else if(
      vMALastBar == vMAThisBar) {
              
      setBarBgColor(Color.yellow);
          }
          
          return;

      Comment


      • #4
        Excellent. In your responses, you have answered a few other issues I was having as well as having it update in real time:

        1. Making sense of BarBgColor logic.
        2. A means to have the vStudy definition called only once.

        And so the code runs more quickly, and with fewer lines. Again, excellent, and thank you!

        What is the purpose of the "return" statement though? In perusing the javascript manual, it mentions using it, but only if returning a value. This code doesn't return a value, so it is just good coding practice? Or does it do something not documented?

        Again, thanks!
        Greg

        Comment


        • #5
          Greg
          It is not required and as far as I know there is no performance advantage either way. I just used it out of habit
          Alex

          Comment


          • #6
            Thanks Alex.

            Next problem with doing real-time/reloading is that I would now like to use T3avg2.efs instead of MAStudy. I can either reference the file, or copy all the code in. How to do the former? Copy it to the Builtin directory & use it? In my attempt to merge the code, I've lost the real-time functionality once again (my first time attaching file - hopefully this will do the PHP window thingie). I would think that merging the code would result in quicker code execution.

            Greg
            Attached Files

            Comment


            • #7
              Greg
              I think the attached does what you were trying to accomplish (I used the original T3avg.efs from TS Support's group in File Sharing)
              Alex
              Attached Files

              Comment


              • #8
                Alex,

                Perfect. Greatly appreciate how expediently you've been responding!

                Is there anything I've been consistently been doing to lose the real-time feature?

                Thanks again,
                Greg

                Comment


                • #9
                  Please correct me if I am wrong, but to answer my own question, you are "loading" the last bar variables as the new one comes in, and I was doing so as the code finished, at the end of main. Would that have been doing it?

                  Comment


                  • #10
                    Greg
                    That is one part of it. I also declared the "current bar" variables as Global ie outside of main() rather than Local.
                    Alex

                    Comment


                    • #11
                      Greg
                      For a brief explanation on the differences between Global and Local variables and their usage see the Guide to Developing EFS Indicators in the EFS Help Center & Library.
                      Alex

                      Comment


                      • #12
                        Alexis,

                        Thanks for your help & suggestions, but I'm still missing something. When I've attempted to combine the 2 efs files into a single indicator (attached), it is now working in real-time, most of the time. Sometimes it is T3 triggering the change alone, sometimes just the stoch, with increasing price value updating almost all the time (vs decreasing price value). Any further suggestions or help you could lend would be greatly appreciated.

                        Thanks,
                        Greg
                        Attached Files

                        Comment


                        • #13
                          Greg
                          Try the attached revsion and see if it now works.
                          Comments are in the efs.
                          Alex
                          Attached Files

                          Comment


                          • #14
                            Greg
                            In line 91 of the revised version I meant to write getValue(sPriceSource); instead of getValue(0,sPriceSource);
                            Alex

                            Comment


                            • #15
                              Alexis,

                              The two global variable declarations have helped, as it is working better, but something's still not correct. At more tricky times, such as with YM U4 in a tight channel since 11:10 to at least 11:35 pacific today on a 1m chart, if the stoch & T3 start to be drawn (say red), then change by the close, this combination EFS that we are working on still draws the bar red.

                              Thanks, & thank you for your expedient responses,
                              Greg

                              Comment

                              Working...
                              X