Announcement

Collapse
No announcement yet.

Historical vs Realtime Values

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

  • Historical vs Realtime Values

    The historical OHLC bar doesn't include the tick sequence information that led to the creation of the highs and lows.

    Therefore historical OHLC values may need different efs code handling than their realtime counterparts, especially when developing strategies that need to react to prices before the close of the bar.

    I'm using the following method, any comments appreciated:

    var vRealTime = false;

    function main() {

    var vBarState = getBarState();

    if (vRealTime == false && vBarState == BARSTATE_CURRENTBAR) vRealTime = true;

    if (vRealTime == true) {

    ... code for realtime bars

    }
    else {

    ... code for historical bars

    }

    return;
    }
    Paul Williams
    Strategy & Applications
    www.futurenets.co.uk

  • #2
    Hello Paul,

    Looks like a good method to me. You could also incorporate a check for a bar index of 0.
    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


    • #3
      I am under the impression that if (getCurrentBarIndex() == 0) and if (getBarState() == BARSTATE_CURRENTBAR) will both register as true in the following circumstances:
      • most recent tick of a live data stream
      • most recent tick of a $PLAYBACK.EPF file in tick replay mode
      • current bar in bar replay
      • last bar of historical data when there is no live data stream
      If this is correct then there are two circumstances that will give your code the false sense that you have tick data when you do not.

      I use the following code to distinguish between RT ticks, replay ticks, and historical interval data.
      • bPlayback = getSymbol() == "$PLAYBACK" ? true : false;
      • if (getMostRecentBidSize() > 0 || getMostRecentAskSize() > 0) bLive = true;

      The first statement is placed in the initialization section. The second where it will get executed on every tick. If both are false then I know that I am retrieving interval data with no ticks. Since getMostRecentBidSize() and getMostRecentAskSize() do not work with EPF files I can also code around this issue.

      If there is an easier or more reliable way to accomplish this or any of my assumptions are incorrect, please let me know.


      Thanks.

      Comment


      • #4
        thanks Gavishti but not having any luck at this end with

        bPlayback = getSymbol() == "$PLAYBACK" ? true : false;

        and

        if (getMostRecentBidSize() > 0 || getMostRecentAskSize() > 0) bLive = true;

        could you supply more details?
        Paul Williams
        Strategy & Applications
        www.futurenets.co.uk

        Comment


        • #5
          a simpler option may be to test that the system time is less than the bar close time. if it is then this must be live data.
          Paul Williams
          Strategy & Applications
          www.futurenets.co.uk

          Comment


          • #6
            here's a possible solution, problem being if there is no live feed and the system time is >= current bar start time and < current bar end time.

            if (vRealTimeBars == false) {
            if (getCurrentBarIndex() == 0 && vBarState == BARSTATE_CURRENTBAR) {
            var BarInt = parseInt(getInterval());
            var TodayDate = new Date();
            var BarCloseDate = new Date(getYear(), getMonth()-1, getDay(), getHour(), getMinute());
            var TodayTime = TodayDate.getTime();
            var BarStartTime = BarCloseDate.getTime();
            var BarEndTime = BarStartTime + ((BarInt-1)*60*1000);
            if (TodayTime >= BarStartTime && TodayTime < BarEndTime) vRealTimeBars = true;
            }
            }

            ... comments appreciated
            Paul Williams
            Strategy & Applications
            www.futurenets.co.uk

            Comment


            • #7
              I think you will run into problem using the clock.

              Using the code I supplied in an earlier post. All you have to do to find out if you are real time is the following:

              if (bLive)
              {
              ...your code
              }

              Comment


              • #8
                thanks Gavishti. I liked the idea of using

                if (getMostRecentBidSize() > 0 || getMostRecentAskSize() > 0) bLive = true;

                but I get values > 0 even when the live feed is terminated.

                using the clock work fine but may give problems on the last bar if the live feed is disconnected and the system clock is less than the close time of the last bar.
                Paul Williams
                Strategy & Applications
                www.futurenets.co.uk

                Comment


                • #9
                  Paul, Gavishti
                  FWIW you can check for playback and or replay sessions using isPlayBackMode() and isReplayMode()
                  Hope this helps
                  Alex

                  Comment


                  • #10
                    FWIW, a slight variant. This works for me to see if we are in playback mode:

                    if (isPlayBackMode()==1)


                    The following is an excerpt from Chris's help file


                    isPlayBackMode( $PLAYBACK symbol )


                    Is EFS in Playback mode? Returns true or false.

                    Example:

                    var bInPlayback = isPlayBackMode( $PLAYBACK "ibm" );

                    edit - Alex, you are quick, you answered while I was composing mine

                    Comment


                    • #11
                      The code I supplied was only for distinguishing between RT, playback, and historical intervals. You will have to go a different route, such as checking the clock, to find out if you are no longer receiving data. Beware the differences in granularity between bar time and real time. There is also a slight synchronization lag.

                      Comment


                      • #12
                        I don't use var bInPlayback = isPlayBackMode( $PLAYBACK "ibm" ); because I don't want to supply a symbol (ibm). I just want to know if I am in playback mode. If isPlayBackMode() works without a symbol that would be great. However, the documentation I was able to find does not indicate that to be the case.

                        Comment


                        • #13
                          Gavishti
                          I just ran a quick test and as far as I can see you do not need to provide a symbol.
                          if(isPlayBackMode()==true) will return true if in Tick Replay.
                          Alex

                          Comment


                          • #14
                            Alex/Roger,

                            That is correct, you can check if(isPlayBackMode()) and that should work fine.

                            Regards,

                            Comment


                            • #15
                              thanks everyone, have included in the following (note the use of the exclamation ! for not true) ...

                              if (vRealTimeBars == false) {
                              if (!isPlayBackMode() && !isReplayMode() && getCurrentBarIndex() == 0 && vBarState == BARSTATE_CURRENTBAR) {
                              var BarInt = parseInt(getInterval());
                              var TodayDate = new Date();
                              var BarCloseDate = new Date(getYear(), getMonth()-1, getDay(), getHour(), getMinute());
                              var TodayTime = TodayDate.getTime();
                              var BarStartTime = BarCloseDate.getTime();
                              var BarEndTime = BarStartTime + ((BarInt-1)*60*1000);
                              if (TodayTime >= BarStartTime && TodayTime < BarEndTime) vRealTimeBars = true;
                              }
                              }

                              ... comments appreciated
                              Paul Williams
                              Strategy & Applications
                              www.futurenets.co.uk

                              Comment

                              Working...
                              X