I am fairly new to NT and I've been trying to get a simple BackTest to work for several weeks now, unfortunately, without any real success.
I must be missing something!
Intermittently, trades are missed.....Reason='This was an exit order but no position exists to exit'
eg.
OnBarUpdate 707
ShortEntryPrice=36.86 Low[0]=36.96 ConfirmationGap=0.1
The Initial ShortStop value is 37.58 High[0]=37.48
23/10/2012 4:00:00 AM Entered internal PlaceOrder() method at 23/10/2012 4:00:00 AM: BarsInProgress=0 Action=SellShort OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=36.86 SignalName='GoShort' FromEntrySignal=''
23/10/2012 4:00:00 AM Entered internal PlaceOrder() method at 23/10/2012 4:00:00 AM: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=37.58 SignalName='InitialShortStop' FromEntrySignal='GoShort'
23/10/2012 4:00:00 AM Ignored PlaceOrder() method: Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=37.58 SignalName='InitialShortStop' FromEntrySignal='GoShort' Reason='This was an exit order but no position exists to exit'
OnBarUpdate 708....
24/10/2012 High=36.98 Low=36.54 ...should have entered stop at 36.86
I don't understand why this validation occurs as the ExitLongStop(BuyToCover) won't even happen until the some stage on the 24th, if at all. And this problem only happens intermittently, but enough to discount to entire test.
If anyone can spot my problem and let me know, I will be very greatful:-)
Many Thanks,
Joytribe
Overview
End Of Day Bars - Kinetick(Free EOD)
Only Make decisions at the the End of the Day.
Place Long Stop Orders with "If Done" Stops just below.
Place ShortSell Stop Orders with "If Done" Stops just above.
I am trying to mimic manually placing trades/stops after EOD.
My code pretty much looks like this. I have also tried using "SetStopLoss" in place of "ExitLongStop"/"ExitShortStop" but....other errors/problems.
CalculateOnBarClose = true;
TraceOrders = true;
ClearOutputWindow();
protected override void OnBarUpdate()
{
Print("OnBarUpdate " + CurrentBar.ToString() );
// Long
if ( <Long condition met> )
{
if (Position.MarketPosition != MarketPosition.Long)
{
// Setup Long Entry Price
LongEntryPrice = <something>;
// Initial Long Stop Price
LongStop = <something>;
// Place the Long Stop Order
EnterLongStop(0, true, DefaultQuantity, LongEntryPrice, "GoLong");
// Place the Stop for the Long Stop Order (linked to driving order)
ExitLongStop(LongStop, "InitialLongStop", "GoLong");
}
}
// Short
if ( <Short condition met> )
{
if (Position.MarketPosition != MarketPosition.Short)
{
// Setup Short Entry Price
ShortEntryPrice = <something>;
//Initial Long Stop Price
ShortStop = <something>;
// Place the Short Stop Order
EnterShortStop(0, true, DefaultQuantity, ShortEntryPrice, "GoShort");
// Place the Stop for the Short Stop Order (linked to driving order)
ExitShortStop(ShortStop, "InitialShortStop", "GoShort");
}
}
// Manage the Trailing Stops
// Manage No Orders
if (Position.MarketPosition == MarketPosition.Flat)
{
Print("No Orders.....Flat");
}
// Manage Long Trade
if (Position.MarketPosition == MarketPosition.Long)
{
Print("Manage Open Long Orders");
LongStop = <something>;
ExitLongStop(LongStop, "TrailLongStop", "GoLong");
}
// Manage Short Trade
if (Position.MarketPosition == MarketPosition.Short)
{
Print("Manage Open Short Orders");
ShortStop = <something>;
ExitShortStop(ShortStop, "TrailShortStop", "GoShort");
}
}
Comment