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

Multitimeframe for backtest not working correctly

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

    Multitimeframe for backtest not working correctly

    Hello,

    I am writing some code to short upon breaking the upper Bollinger band on the 5 minute chart, but want the entry to execute as soon as it happens (rather than waiting for the 5 minute bar to close). I understand to backtest this sort of thing, you need to program a multitimeframe strategy (rather than using CalculateOnBarClose = false).

    The code backtests OK without the multi-frame strategy, although misses a number of entries. But when I add the tick time frame to the strategy to get it to do it on a tick by tick basis, it doesn't even come close to working like it should. It completely misses the breaks of the upper Bollinger band, and ends up entering at a completely unexplained time well within the bands.

    I keep re-examining the code but can't figure out why it's not working. I'm using BarsArray[0] to access the Bollinger band value for the primary 5 min time frame, and checking the close of the current tick against that value.

    Here's the relevant code:


    protected override void Initialize()
    {
    Add(PeriodType.Tick, 1);

    CalculateOnBarClose = true;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;

    }


    protected override void OnBarUpdate()
    {

    if (BarsInProgress == 0)
    {
    return;
    }

    if (BarsInProgress == 1)
    {


    if( Close[0] > Bollinger(BarsArray[0], 4, 20).Upper[0] && Position.MarketPosition == MarketPosition.Flat)
    {
    EnterShortLimit(positionSize, Close[0] - TickSize, "ShortEntry");

    }
    }

    }

    #2
    Hello YngvaiMalmsteve,

    Thanks for your post.

    I've replicated your code and tested on both historical on chart data and the strategy analyzer (using arbitrary profit & stop) and found that your strategy enters as you describe.

    Are you certain that you have tick data for the time period you are analyzing?
    Attached Files
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by truepenny, Today, 03:59 AM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by truepenny, Today, 03:45 AM
    2 responses
    16 views
    0 likes
    Last Post truepenny  
    Started by dcriador, Today, 01:43 AM
    2 responses
    15 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by kujista, Today, 12:39 AM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by tony_28217, Yesterday, 07:04 PM
    1 response
    15 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Working...
    X