Enter on CalOnBarClose=True, but Exit Immediately on X Ticks | Traders Hideout


futures.io - futures trading strategies, market news, trading charts and platforms


Traders Hideout


Discuss day trading practices and futures trading strategies on this forum for all markets. This forum is also for discussing and reviews for brokers, data feeds, and commercial or third party add-ons




 

Enter on CalOnBarClose=True, but Exit Immediately on X Ticks

  #7 (permalink)

Crete, IL/USA
 
Trading Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 178 since Aug 2009
Thanks: 103 given, 50 received


ratfink View Post

Hey
so if I understand you correctly you have a strategy and you are in a position and want to exit BEFORE the bar closes.

So is your logic when it goes in your favor by 12 ticks? Are you using either stops or targets or both?
Tell me the logic of your strategy.
If you want to backtest it Historically you need to layer in 1 tick data like this

 
Code
protected override void Initialize()
{
     CalculateOnBarClose = true;
     Add(PeriodType.Tick, 1);  
     // adding 1 tick data to the chart which will make it load slowly so only add no more than 5 days
}
Otherwise you can use OnMarketData which is not historical just real time ticks
You would want to use IOrders

if you are using stops and targets, you can set Target1 to 12 ticks and it will execute intrabar
lots of options depending on your logic.

 
Code
private IOrder entryOrder  = null;
private IOrder target1Order = null;
private IOrder stopOrder = null;

protected override void Initialize()
{
     Add(PeriodType.Tick, 1);  // BarsInProgress == 0 for base chart and 1 for ticks
     Unmanaged = true; // I always use unmanaged strategies because I prefer to cancel my stops and targets myself explicitly
}
protected override void OnBarUpdate()
{
     if (CurrentBars[0] > 3)
    {
        if (BarsInProgress == 0)
        {
            // base chart logic.  So if your using 15 min chart this happens every 15 minutes
        }
        if (BarsInProgress == 1)
       {
           // tick chart logic.  This chart you can't see but is synced with base chart and added in background
           
       }

    }
}
protected override void OnOrderUpdate(IOrder order)
{
    // handle setting stops and targets once the order is "order.Filled"
}


Last edited by spinnybobo; September 13th, 2016 at 08:08 PM.
Follow me on Twitter Visit my Facebook Reply With Quote