Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceEntry in multi-bar strategy

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

    BarsSinceEntry in multi-bar strategy

    Hi,

    I am trying to backtest a strategy in which I generate an entry signal on a daily bar series. I want to enter a stock position 1 minute after opening, and exit 1 minute before close. I got it to enter correctly, but I can't seem to nail the exit condition:

    Code:
    			if (BarsInProgress == 0)
    			{
    				if (TestPredictor(BarsArray[0]).Plot[0] > Threshold)
    				{
    					enter = true;
    				}
    			}
    			else if (BarsInProgress == 1)
    			{
    				if (enter == true)
    				{
    					EnterLong(1, DefaultQuantity, "test_entry");
    					enter = false;
    				}
    				if (BarsSinceEntry(1, "test_entry", 0) == 389)
    				{
    					ExitLong(1, DefaultQuantity, "test_exit", "test_entry");
    				}
    			}
    Am I missing something simple here? The I tried debugging in VS and I can't get BarsSinceEntry to return something other than 0. Seems like it has something to do with ExitOnClose, as well as referencing the wrong bar series. As a temporary W/A, I am counting the minute bars and exiting after 389.

    My barsInProgress index is 0 for daily, and 1 for minute based data.

    Thanks
    Last edited by Lavafang; 11-18-2014, 12:20 AM.

    #2
    Lavafang, the issue here would be that the BarsSinceEntry would report back on the primary series for the instrument you're trading and not per the minute series, so for an intraday trade > it would be expected what you see as value through VS.

    I would as alternative run a custom counter on the minute series or go by a timestamp range doing the exit.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    153 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    89 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    133 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    128 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    107 views
    0 likes
    Last Post CarlTrading  
    Working...
    X