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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X