Announcement

Collapse
No announcement yet.

multi-timframe question

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

  • #16
    You might try isInSession()

    "This function compares the current clock time to the start and end times of the eSignal Time Template that you have applied to your chart. It returns true if the current clock time is within the start and end times of your Time Template, otherwise it returns false. If you use a 24-hour Time Template, this function will always return true."

    ...seems far more elegant and flexible a solution.

    Comment


    • #17
      Well, I finally got my test code so it only does processing once when using multiple symbols (or timeframes). It's posted below as it's probably useful to others.

      Instead of processing once, you can change PROCESSING_TYPE at the top of the code to what you want. Valid options are:

      PROCTYPE_ONCE_ONLY
      PROCTYPE_ONCE_PER_REALTIME_NEWBAR
      PROCTYPE_ONCE_PER_REALTIME_TRADE
      PROCTYPE_ALL_BARS

      Note bar states, etc. are printed out on every call to main() for debugging purposes. The multiple symbol prices are only printed according to how PROCESSING_TYPE is set (except once at the beginning when prices values can be null).

      When the multiple symbols are first requested (inside the "if (! bGotAlternateSeries) ..." code block) the prices CAN be null if they haven't been previously requested from your current session. Requesting multiple symbols causes a "pause" after main() returns where all the symbols are requested from the server. Then main() is called with another BARSTATE_ALLBARS. At that point all the multiple symbol prices are valid numbers.

      I'd also like to point out that the following line is only called once per symbol, yet the Series Object returned by close() is automatically updated on all future calls to main(). I believe this is the most efficient way to request and use prices for other symbols/timeframes.

      altSeriesArray[n] = close (sym (symbol + ",D"));

      I requested multiple symbols, but the code could be easily changed to request multiple timeframes as well.

      The utility functions printStates() and barStateAsString() below have made debugging EFS code a lot easier. I don't know how I got along before I wrote them and included printStates() at the top of my scripts. Sample printStates() output:

      getBarState(): BARSTATE_NEWBAR, getCurrentBarIndex() = -8, close: 1.4339, getCurrentBarCount() = 300, getNumBars() = 308

      PHP Code:
      const PROCTYPE_ONCE_ONLY 1;
      const 
      PROCTYPE_ONCE_PER_REALTIME_NEWBAR 2;
      const 
      PROCTYPE_ONCE_PER_REALTIME_TRADE 3;
      const 
      PROCTYPE_ALL_BARS 4;

      // set PROCESSING_TYPE to the PROCTYPE_... you want:
      const PROCESSING_TYPE PROCTYPE_ONCE_ONLY;

      var 
      allBarsInProgress false;

      // Note max # symbols is 7 with eSignal
      const SYM_ARRAY = new Array ("MSFT""INTC""ABT""KO""JPM""RHT""GENZ");
      const 
      TOT_SYMS SYM_ARRAY.length;
      var 
      altSeriesArray = new Array();
      var 
      bGotAlternateSeries false;


      function 
      main() {
          var 
      barState getBarState();
          var 
      currentBarIndex getCurrentBarIndex();

          
      printStates();  // debugging - print state info on every call to m-a-i-n()

          
      if (! bGotAlternateSeries) {
              
      debugPrintln ("...using processing type " processingTypeAsString());

              
      getAlternateSeries();   // Force other symbols to be requested.
                                      // This will cause another BARSTATE_ALLBARS.

              
      debugPrintln ("Prices just requested - may be null (expected behavior)...");
              
      printSymbolPrices();    // Prices are likely "null" at this point, 
                                      // unless symbols were previously requested.

              
      bGotAlternateSeries true;
              return;     
      // since prices likely "null" return
          
      }

          
      // see if start of chart bars display or "refresh"
          
      if (barState == BARSTATE_ALLBARSallBarsInProgress true;

          switch (
      PROCESSING_TYPE) {
              case 
      PROCTYPE_ONCE_ONLY:
                  
      // ignore unless chart is being loaded/reloaded
                  // and latest price bar
                  
      if ((! allBarsInProgress) || (currentBarIndex != 0)) return;
                  break;
              case 
      PROCTYPE_ONCE_PER_REALTIME_NEWBAR :
                  if ((
      barState != BARSTATE_NEWBAR) || (currentBarIndex != 0)) return;
                  break;
              case 
      PROCTYPE_ONCE_PER_REALTIME_TRADE :
                  if (
      currentBarIndex != 0) return;
                  break;
              default :
                  
      // process everything (all bars)...
                  
      break;
          }

          if (
      currentBarIndex == 0allBarsInProgress false;


          
      // process price bar...
          
      printSymbolPrices();

          
      // add real processing here...

      }


      function 
      getAlternateSeries() {
          for (var 
      0TOT_SYMSn++) {
              var 
      symbol SYM_ARRAY[n];
              
      altSeriesArray[n] = close (sym (symbol ",D"));
          }
      }


      function 
      printSymbolPrices() {
          for (var 
      0TOT_SYMSn++) {
              var 
      symbol SYM_ARRAY[n];
              var 
      symClose altSeriesArray[n].getValue (0);
              
      debugPrintln"Symbol: [" symbol "], price: " symClose);
          }
      }


      function 
      printStates() {
          var 
      barState getBarState();
          var 
      numBars getNumBars();
          var 
      currentBarCount getCurrentBarCount();
          var 
      currentBarIndex getCurrentBarIndex();
      //    var newestBarIndex = getNewestBarIndex();
      //    var oldestBarIndex = getOldestBarIndex();

      //    debugPrint (", getNewestBarIndex() = " + newestBarIndex);
      //    debugPrint (", getOldestBarIndex() = " + oldestBarIndex);
          
      debugPrint (", getNumBars() = " numBars);
          
      debugPrint (", getCurrentBarCount() = " currentBarCount);
          
      debugPrint (", close: " close(0));
          
      debugPrint (", getCurrentBarIndex() = " currentBarIndex);
          
      debugPrintln ("getBarState(): " barStateAsString (barState));
      }


      function 
      barStateAsString (barStateNum) {
          if (
      barStateNum == BARSTATE_CURRENTBAR) {
              return 
      "BARSTATE_CURRENTBAR";
          }
          else if (
      barStateNum == BARSTATE_NEWBAR) {
              return 
      "BARSTATE_NEWBAR";
          }
          else if (
      barStateNum == BARSTATE_ALLBARS) {
              return 
      "BARSTATE_ALLBARS";
          }
          else {
              return 
      barStateNum;     // unknown, return number
          
      }
      }


      function 
      processingTypeAsString() {
          if (
      PROCESSING_TYPE == PROCTYPE_ONCE_ONLY) {
              return 
      "PROCTYPE_ONCE_ONLY";
          }
          else if (
      PROCESSING_TYPE == PROCTYPE_ONCE_PER_REALTIME_NEWBAR) {
              return 
      "PROCTYPE_ONCE_PER_REALTIME_NEWBAR";
          }
          else if (
      PROCESSING_TYPE == PROCTYPE_ONCE_PER_REALTIME_TRADE) {
              return 
      "PROCTYPE_ONCE_PER_REALTIME_TRADE";
          }
          else {
              return 
      "PROCTYPE_ALL_BARS";
          }

      Last edited by shortandlong; 12-30-2009, 04:17 PM.

      Comment


      • #18
        Re: multi-timeframe question

        Originally posted by mike_scott

        1. These statements work when the chart is a daily interval.
        aSR[2][3] = sma(50, sym(aSym, "D"),0); //50DMA
        aSR[2][6] = sma(200, sym(aSym, "D"), 0); //200DMA
        But I get 50 and 200-period averages when the chart is in different intervals. Have I written these incorrectly to always give me daily averages independent of chart interval?

        Mike Scott
        Instead of:

        sym(aSym, "D")

        I think you want:

        sym(aSym + ",D")

        So, the lines above would be:

        aSR[2][3] = sma(50, sym(aSym + ",D"),0); //50DMA
        aSR[2][6] = sma(200, sym(aSym + ",D"), 0); //200DMA

        Comment


        • #19
          Re: Re: multi-timeframe question

          shortandlong,
          Thank you for the obvious mistake I made. Of course it works now. Happy New Year!

          Mike Scott
          Tarzana, CA

          Originally posted by shortandlong
          Instead of:

          sym(aSym, "D")

          I think you want:

          sym(aSym + ",D")

          So, the lines above would be:

          aSR[2][3] = sma(50, sym(aSym + ",D"),0); //50DMA
          aSR[2][6] = sma(200, sym(aSym + ",D"), 0); //200DMA
          ....Mike

          Comment

          Working...
          X