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 sjsj2732, Yesterday, 04:31 AM
    0 responses
    30 views
    0 likes
    Last Post sjsj2732  
    Started by NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    286 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    282 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    132 views
    1 like
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    90 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Working...
    X