Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Why? Strategy going back to past days!

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

    Why? Strategy going back to past days!

    I'm trying a simple strategy: Enter long if above stop, Enter short if under stop.
    I can't make it work no matter what, because it uses OLD data in the past without any reason (data that do not even exist.....).
    Simple code here with print to output as debug....

    Code:
            protected override void OnBarUpdate()
            {
                PrintWithTimeStamp("Bar Update: "+ Close[0]+ "; Bar Time " + ToTime(Time[0]));
                if (Position.MarketPosition == MarketPosition.Flat)
                {
                    Print("Flat");                      
                    if (Close[0] >= StopLong)
                    {
                        Print("Enter long");
                    }
                    if (Close[0] <= StopShort)
                    {
                        Print("Enter Short");
                  }}}
    New strategy from strategy panel in control center, 10 seconds data series, required bars 1, calculate on bar close.
    The problem is with Close[0].
    In the output window i should have only the line:
    Code:
    11/04/2008 13.46.40 Bar Update: 1246,25; Bar Time 134640
    Flat
    While instead i have A LOT of previous lines referring to older time and days starting with:

    Code:
    27/03/2008 1.05.10 Bar Update: 1336; Bar Time 10510
    
    Flat
    Enter long
    27/03/2008 1.05.20 Bar Update: 1336,25; Bar Time 10520
    
    Flat
    Enter long
    27/03/2008 1.05.40 Bar Update: 1336; Bar Time 10540
    
    Flat
    Enter long
    27/03/2008 1.05.50 Bar Update: 1336; Bar Time 10550
    
    Flat
    Enter long
    27/03/2008 1.06.00 Bar Update: 1335,75; Bar Time 10600
    
    Flat
    Enter long
    27/03/2008 1.06.20 Bar Update: 1336; Bar Time 10620
    
    Flat
    Enter long
    27/03/2008 1.06.30 Bar Update: 1336; Bar Time 10630
    
    ........
    ........
    What is going on?
    Could it be that it goes back 43200 bars as market analyzer look back period i set? It should NOT be correlated, but i can't explain in any other way....

    help....
    Last edited by skynetman; 04-11-2008, 06:05 AM.

    #2
    >> In the output window i should have only the line
    Incorrect. Real time strategies on the strategies tab are synced be using historical data which if configured by Tools->Options->Data->Lookback period. Only as that historical data is processed they roll to live data.

    Comment


      #3
      So what is the solution to have graph loaded with old data AND strategies working only on new data and not old ones?
      I add to "Initialize" method a variable with strategy launch time and skip in "bar update" old data?

      Comment


        #4
        You could try adding something like
        Code:
        if (Historical)
            return;
        to your OnBarUpdate method. Note: You then no longer can backtest this strategy since it only will work live.

        Comment


          #5
          I thought from the code examples that a return in on bar update stopped completely the strategy.....
          Now i understand that it simply exit the method without a return variable as it should be in standard programming
          Is there a way to stop a strategy completely so that it does not waste any CPU cycle?
          Thx.

          Comment


            #6
            >> Is there a way to stop a strategy completely so that it does not waste any CPU cycle?
            Not that I'm aware of.

            Comment


              #7
              For stopping a strategy please see these reference samples: http://www.ninjatrader-support.com/v...ead.php?t=4804
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Thx Josh i'm already using those examples....
                But the strategy is not completely stopped, it is executed anyway and the return in the first IF inside "on bar update" just allows to skip the rest of the code (less cpu intensive but still useless loop).
                What i meant was a command to really stop a strategy as clicking on stop in strategy tab

                A question: if i set a strategy "on bar close" and as data series i choose "tick", it is less cpu intensive the a false in "on bar close" right? Because it is event driven and not looping as hell, right?

                Thx guys....

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by AaronKoRn, Today, 09:49 PM
                0 responses
                2 views
                0 likes
                Last Post AaronKoRn  
                Started by carnitron, Today, 08:42 PM
                0 responses
                7 views
                0 likes
                Last Post carnitron  
                Started by strategist007, Today, 07:51 PM
                0 responses
                9 views
                0 likes
                Last Post strategist007  
                Started by StockTrader88, 03-06-2021, 08:58 AM
                44 responses
                3,975 views
                3 likes
                Last Post jhudas88  
                Started by rbeckmann05, Today, 06:48 PM
                0 responses
                9 views
                0 likes
                Last Post rbeckmann05  
                Working...
                X