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 benmarkal, Yesterday, 12:52 PM
    3 responses
    23 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by helpwanted, Today, 03:06 AM
    1 response
    19 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    11 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    244 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    388 views
    1 like
    Last Post Gavini
    by Gavini
     
    Working...
    X