Announcement

Collapse
No announcement yet.

What exactly does BARSTATE_NEWBAR mean?

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

  • What exactly does BARSTATE_NEWBAR mean?

    What exactly does BARSTATE_NEWBAR mean?

    I am having a little trouble understand eSignal EFS code.

    I coded the TRO_AROON for a friend and noticed the TREND was incorrect.

    So I tried a few things and this:

    PHP Code:
    if( getBarState() == BARSTATE_NEWBAR ) {
    if( 
    tR1C1 == tR1C11  ) { xR1C1Count xR1C1Count ; }
      else { 
    xR1C1Count ; }
    tR1C11 tR1C1 ;

    seems to work right.

    I checked it on a few charts and the count was correct.

    But something just doesn't seem right to me!

    If the BarState is a NEW BAR then is the code processing the last tick data of the previous bar or the first tick data of the new bar?

    Yes, I looked in the Knowledgebase and found:

    if (nState == BARSTATE_NEWBAR) {

    //this flag is set when a new bar is coming in

    debugPrint("The first tick of a new bar has arrived\n");
    But that doesn't really answer my question. Anyone who has coded in RPGII would understand why I ask.

    Is there a chart somewhere that shows the EFS processing cycle?

    Before I go back and change all the code I have written, I need to understand this!

    Thanking You In Advance.
    Last edited by buzzhorton; 08-06-2006, 09:43 AM.

  • #2
    I am trying to figure this out and am only getting more confused...LOL!

    Here's part of the code:

    PHP Code:

    // PROCESS ROW 1 COLUMN 1  


    if(zArnUp zArnUp1) {
               
    xFGColor Color.black
               
    xBGColor Color.lime
               
    tR1C1    "+" ;
    } else if(
    zArnUp <zArnUp1) {
               
    xFGColor Color.black
           
    xBGColor Color.red
               
    tR1C1    "-" ;   
    } else {   
    xFGColor Color.black
           
    xBGColor Color.yellow
               
    tR1C1    "=" ;  
    }
     
    if( 
    getBarState() == BARSTATE_NEWBAR ) {
    if( 
    tR1C1 == tR1C11  ) { xR1C1Count xR1C1Count ; }
      else { 
    xR1C1Count ; }
    tR1C11 tR1C1 ;
    }

    tCurrentR1C1 tR1C1 ;

    if( 
    getBarState() == BARSTATE_CURRENTBAR ) {
    if( 
    tCurrentR1C1 == tCurrentR1C11  ) { xCurrentR1C1Count xCurrentR1C1Count ; }
      else { 
    xCurrentR1C1Count ; }
    tCurrentR1C11 tCurrentR1C1 ;

    I dump the variables with debug:

    PHP Code:


    if( iDebug == true ){

      
    debugPrint"  "  "\n" );
      
    debugPrint"tCurrentR1C21: " +tCurrentR1C21   "\n" ); 
      
    debugPrint"tCurrentR1C2 : " tCurrentR1C2  "\n" );
      
    debugPrint"  "  "\n" );
      
    debugPrint"tR1C21: " +tR1C21   "\n" ); 
      
    debugPrint"tR1C2 : " tR1C2  "\n" );
      
    debugPrint"  "  "\n" );
      
    debugPrint"tCurrentR1C11: " +tCurrentR1C11   "\n" ); 
      
    debugPrint"tCurrentR1C1 : " tCurrentR1C1  "\n" );
      
    debugPrint"  "  "\n" );
      
    debugPrint"tR1C11: " +tR1C11   "\n" ); 
      
    debugPrint"tR1C1 : " tR1C1  "\n" );
      
    debugPrint"  "  "\n" );
      
    debugPrint"zArnDn1      : " +zArnDn1   "\n" ); 
      
    debugPrint"zArnUp1      : " +zArnUp1   "\n" );
      
    debugPrint"  "  "\n" );
      
    debugPrint"zArnDn       : " +zArnDn   "\n" );  
      
    debugPrint"zArnUp       : " +zArnUp   "\n" ); 

      
    debugPrint"getCurrentBarCount() : " getCurrentBarCount() +  "\n" );  
      
    debugPrint"----------------: "  "\n" );

    My question is what's the reason the Current values are NULL until what looks like the second tick of the last bar on the chart which is bar 275?
    Attached Files

    Comment


    • #3
      What eSignal developers decided to do was to give a way for EFS script developers to poll for 3 events that they felt were most important during the lifetime of a chart:

      1. When historical data is filling up your chart (BARSTATE_ALLBARS).

      2. When is the very start of the next price bar on the chart (BARSTATE_NEWBAR).

      3. When is the chart receiving the next "chunk" of data to update the current price bar (BARSTATE_CURRENTBAR).

      Number 3, of course, can be very CPU intensive depending upon what you're trying to do (e.g., regression analysis calculations for every new piece of data coming into your script instead of using #2 where a new calculation is done only once per new price bar).


      To give you a clear example of what is going on with #2, let me just iterate over several different timeframes in detail:

      1. If you have a 133T chart (133 transactions per price bar) then getBarState() will be BARSTATE_NEWBAR on the 1st tick of each 133 ticks that make up a bar.

      2. Let's say you're trading the ER2 futures contract and you're using a volume chart of 250V (250 contracts in each price bar), then the state of getBarState() will be BARSTATE_NEWBAR on the very first group of contracts that create the next price bar in your chart. Note: in the 1st case, 1 transaction (aka, a tick) could contain 50 contracts traded whereas the "V chart" is counting the contracts to ensure that each price bar is exactly the number specified (i.e. 250 in this example) regardless of how many individual transactions were required to generate that specific volume size.

      3. The more common case (to those who trade stocks) is something like a 5 minute chart where getBarState() will change to BARSTATE_NEWBAR at precisely the beginning of a new 5 min interval

      Needless to say, this isn't "event-driven programming" where one would normally register a function to be executed automatically upon some message received from the controlling program (in this case, the eSignal charting program). This is called "polling" where you're constantly checking upon every execution of your script to see if the system is letting you know that a "bar state" has changed.

      You're right Avery. There are no "bar state" events that tell you that you have recieved the last piece data for a price bar and then the next data coming in is the start of the new bar. If you wanted to do something like that in real-time then you would need to create your own way of counting either the minutes (min charts), seconds (S charts), volume (V charts) or ticks (T charts) in order to know when that event is occurring. And this can turn out to be CPU intensive in some cases. The EFS profiler is a great way to tell what scripts are bogging down your system.

      I hope this is the detail you're looking for. I have never programmed in a report generation language like RPG.

      Comment


      • #4
        Avery,

        If you run this on the weekend when the markets are closed, you'll only get 1 BARSTATE_ALLBARS event and then a BARSTATE_NEWBAR event for every bar of the historical data. You won't get any BARSTATE_CURRENTBAR events unless the symbol you're using is currently trading (i.e., market is open):

        PHP Code:
        function main() {
        var 
        nState;
           
        nState getBarState();
           if (
        nState == BARSTATE_ALLBARS) {
              
        //the bars are being loaded by the script. This happens when a script is first loaded
              
        debugPrint("Script is loading\n");
           }
           else if (
        nState == BARSTATE_NEWBAR) {
              
        //this flag is set when a new bar is coming in
              
        debugPrint("The first tick of a new bar has arrived\n");
           }
           else if (
        nState == BARSTATE_CURRENTBAR) {
              
        //this flag is set as each new tick comes in
              
        debugPrint("A new tick has arrived\n");
           }

        Does that help?

        Comment

        Working...
        X