Announcement

Collapse
No announcement yet.

Is this BUG in tick playback?

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

  • Is this BUG in tick playback?

    Greetings! A weird issue I've run into. I was playing back my strategy to see where its going a foul. Anyway when I use tick replay $PLAYBACK and watch it in real time there are 'black' spots in the chart where the red/green bar background didnt print. But as soon as I hit pause and replay, or hit jump 10minutes they all fill in. Here is a screen capture of what I mean. Nothing has been change in the code between the two captures. All I did was stop and restart the tick play (without reloading the file). When its playing real time I can very quickly see red or blue starting to fill the black back ground in then when the chart shifts left it disappears.



    Here is the part of the code that calls the red/blue background bar print.

    PHP Code:
        //{{STRATEGY CODE -------REPLACE THIS WITH SOMETHING GOOD
             
    if (
                
    vEMA8.getValue(MAStudy.MA) < vEMA21.getValue(MAStudy.MA) &&
                
    getBarState()== BARSTATE_NEWBAR &&  
                
    AllowTrading == true 
            
    onAction4()
        
    //}}
        
        //{{
             
    else if (
                
    vEMA8.getValue(MAStudy.MA) > vEMA21.getValue(MAStudy.MA) &&
                
    getBarState()== BARSTATE_NEWBAR && // LESSON FALSE SIGNALS ON TICK REPLY
                
    AllowTrading == true 
            
    onAction5() 
    Here is the code for action4 and action5:
    PHP Code:
        //{{Action_4
        
    function onAction4() {
            
    setBarBgColor(Color.red);
            
    //       if (Strategy.isShort() == false)   
           
    if (vLastAlert != )   
           {
           
    Strategy.doShort("Short Entry"Strategy.CLOSEStrategy.THISBARStrategy.DEFAULT, 0); 
           
    EntryPrice close(0);
           }
           
    vLastAlert 4;    
        }
        
    //}}Action 4 over and out
        
        //{{Action_5
        
    function onAction5() {
            
    setBarBgColor(Color.blue);
            
    //       if (Strategy.isLong() == false)  
             
    if (vLastAlert != 
            { 
            
    Strategy.doLong("Long Entry"Strategy.CLOSEStrategy.THISBARStrategy.DEFAULT, 0);
            
    EntryPrice close(0); 
            
    vLastAlert 5; }
       }
        
    //}}The end of action 5 
    Is this a bug or am I somehow incompitent in many ways

    P.S. No im not editing the code in the wizard but thats how it started out

  • #2
    Geoff
    It is not a bug but the result of the logic used in your code.
    Both your conditional statements include the following condition getBarState()== BARSTATE_NEWBAR which means that in real time the background of the bar will be painted only on the first tick of a new bar (assuming the other conditions evaluate to true). Once other ticks occurr on that same bar it will no longer be painted.
    In fact if you look at the top chart of your image you will see that the bars that have the colored background appear to be all made of a single tick which is why the color persisted when the code was run in real time.
    When you then jumped forward in tick replay the efs reloaded executing once only on all historical bars hence it painted all the bar backgrounds appropriately.
    If you remove the getBarState()== BARSTATE_NEWBAR from your conditional statements you should see the bar backgrounds paint correctly even in real time.
    Alex

    Comment

    Working...
    X