Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Fill Order on Secondary Timeframe- Backtest

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

    Fill Order on Secondary Timeframe- Backtest

    I would like to calculate and submit a limit order based on a 5 minute timeframe but have the fill occur based on a more granular 1 minute time frame for backtesting.

    protected override void Initialize()

    Add(PeriodType.Minute, 1); //5min timeframe chosen for chart, adding secondary timeframe

    protected override void OnBarUpdate()

    if (BarsInProgress==0)

    EnterLongLimit(0 or 1?,false,contracts,buy,"buy");

    if (BarsInProgress==1)

    //(this is the part i need help with, how to fill on 1 minute OHLCV not 5min OHLCV timeframe

    #2
    Hello Megbers,
    To do this, specify the int barsInProgressIndex parameter for you EnterLongLimit method.
    Here is the BarsInProgress and EnterLongLimit()Help Guide to assist you further.
    Here is an example of this.
    Code:
    protected override void Initialize()
    {
    Add(PeriodType.Minute, 1);}
    
    
    protected override void OnBarUpdate()
    if (BarsInProgress == 1)
        {
    [LEFT][FONT=Courier New][SIZE=2]EnterLongLimit([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], Close[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]3[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]"myOrder1"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT][/LEFT]
        }

    Comment


      #3
      Thank you for your response, so if I understand correctly that will enter an order every 1 min at the price specified by the 5min chart is that correct?

      Comment


        #4
        Hello Megbers,


        "so if I understand correctly that will enter an order every 1 min at the price specified by the 5min chart is that correct?"


        Yes this is correct. This will enter an order every 1 min at the price specified by the 5min chart. However, the number of entries that can be submitted is limited by Entry Handling.


        The EntriesPerDirection and EntryHandling are there to help you control how many trades you are entering at a time. EntriesPerDirection Indicates the maximum number of entries allowed per direction while a position is active based on the EntryHandling property.


        EntryHandling sets the manner in how entry orders are handled. If set to "EntryHandling.AllEntries", NinjaScript will process all order entry methods until the maximum allowable entries set by the EntriesPerDirection property has been reached while in an open position.


        If set to "EntryHandling.UniqueEntries", NinjaScript will process order entry methods until the maximum allowable entries set by the EntriesPerDirection property per each uniquely named entry.


        Here is the EntryHandling and EntriesPerDirection Help Guides to assist you further.

        Comment


          #5
          This does not work, in the backtest the profit targets are taken after the 5min bar close regardless of order entry time and the orders are not executed in order (not at all realistic). I think I will need to use a 1min chart as the base and add a 5min period type to create the buy/sell signals.

          I have attached an image to show the problem, I created a 1 second period to illustrate.
          Attached Files

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          102 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          144 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          71 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          125 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          79 views
          0 likes
          Last Post PaulMohn  
          Working...
          X