Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Wrong execution time stamp
Collapse
X
-
Arnaud, you can't compare the Time prints from the OnBarUpdate() with the ones you get from the OnExecution(), as when you call OnExecution() there's no corresponding bar event aligning - the result you got.
Please compare OnBarUpdate's Time with IExecution's Time property -
-
Thanks for your reply Josh,
but I still do not understand why OnExecution() prints flat 1 bar before being really executed. Only on backtest.
Try on SP500 5 minutes bars, exit on close, OnExecution() prints "flat" at 23h25, instead of 23h30.
Strange isn't it ??
Thanks for your help.
Arnaud
Leave a comment:
-
Printing Time[0] in OnExecution() is not the time of the execution. That is the time of the last processed bar which is historical. Once you finish processing OnBarUpdate() that Time[0] is no longer relevant as it is in the past.
Leave a comment:
-
Here is the complete code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Enter the description of your strategy here
/// </summary>
[Description("Enter the description of your strategy here")]
public class Turtle1_Long_DEBUG : Strategy
{
#region Variables
double NewStop=1;
double FixedStop;
double Risk;
int OneTrade;
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
TraceOrders = true;
EntriesPerDirection=1;
EntryHandling=EntryHandling.UniqueEntries;
ExitOnClose=true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (ToDay(Time[0]) != ToDay(Time[1]))
{
OneTrade = 0;
}
if (Position.MarketPosition==MarketPosition.Flat
&& ToTime(Time[0]) >= 113000
&& OneTrade == 0
)
{
EnterLong(3,"Turtle Long");
NewStop=1;
OneTrade = 1;
}
if (Position.MarketPosition==MarketPosition.Long)
{
Risk=Position.AvgPrice-NewStop;
FixedStop=Position.AvgPrice-30;
if (FixedStop>NewStop)
{NewStop=FixedStop;}
ExitLongLimit(3,Position.AvgPrice+2*Risk,"Exit at X times Risk","");
}
Print("OnBarUpdate");
Print("Date : " +ToDay(Time[0])+" Time : " +ToTime(Time[0]));
Print("Risk= "+Risk);
Print("Situation= "+Position.MarketPosition);
Print ("Position.Quantity :" +Position.Quantity);
Print("");
}
protected override void OnExecution(IExecution execution)
{
Print("OnExecution");
Print("Date : " +ToDay(Time[0])+" Time : " +ToTime(Time[0]));
Print("Risk= "+Risk);
Print("Situation= "+Position.MarketPosition);
Print ("Position.Quantity :" +Position.Quantity);
Print("");
}
#region Properties
#endregion
}
}
Leave a comment:
-
Arnaud, can you please post the full code sample? The copy + paste you provided doesn't take any trades when compiled into a strategy. Thank you.
Leave a comment:
-
Hi Arnaud, ok thanks for clarifying - will attempt to reproduce here.
Leave a comment:
-
Hello Bertrand,
in Executions Tab, I get the correct hour and price level for the trade.
But the problem is still there.
The OnExecution() method returns flat position and quantity=0 at 15h50, ONE bar before trade is closed and even before price has been touched.
The order cannot be executed as the price has not been touched.
I tried this backtest on ES 12-09, yesterday the 11th, with an exit on close.
ES closes at 23h30, everything perfect on graph, trades and Executions tabs.
But print instruction in OnExecution() method returns flat at 23h25.
Just try, you will see !!
Have a nive day
Arnaud
Leave a comment:
-
Arnaud, have you compared this to the Executions tab for this day? What do you get there?
Leave a comment:
-
Wrong execution time stamp
Hello Ninja addicts !!
I get a problem when running a simple backtest.
This stratégie buy after 11h30, and exits after 2 times the initial risk (30 points), on FCE-CAC40 future contract.
With CalculateOnBarClose = true
I need to test when the strategie is flat.
I use Print fonction to get this information, in OnBarUpdate() and in OnExecution() method.
Prints are different, as OnExecution() returns flat information 1 bar before price is reached and trade is closed.
Could anyone explain me this strange action ??
This stratégie has been tested on Ninja 6.5 and Ninja 7, same result.
Here is the graph:
Here is the code:
public class Turtle1_Long_DEBUG : Strategy
{
#region Variables
double NewStop=1;
double FixedStop;
double Risk;
int OneTrade;
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
TraceOrders = true;
EntriesPerDirection=1;
EntryHandling=EntryHandling.UniqueEntries;
ExitOnClose=true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (ToDay(Time[0]) != ToDay(Time[1]))
{
OneTrade = 0;
}
if (Position.MarketPosition==MarketPosition.Flat
&& BarsInProgress==1
&& ToTime(Time[0]) >= 113000
&& OneTrade == 0
)
{
EnterLong(3,"Turtle Long");
NewStop=1;
OneTrade = 1;
}
if (Position.MarketPosition==MarketPosition.Long)
{
Risk=Position.AvgPrice-NewStop;
FixedStop=Position.AvgPrice-30;
if (FixedStop>NewStop)
{NewStop=FixedStop;}
ExitLongLimit(3,Position.AvgPrice+2*Risk,"Exit at X times Risk","");
}
Print("OnBarUpdate");
Print("Date : " +ToDay(Time[0])+" Time : " +ToTime(Time[0]));
Print("Risk= "+Risk);
Print("Situation= "+Position.MarketPosition);
Print ("Position.Quantity :" +Position.Quantity);
Print("");
}
protected override void OnExecution(IExecution execution)
{
Print("OnExecution");
Print("Date : " +ToDay(Time[0])+" Time : " +ToTime(Time[0]));
Print("Risk= "+Risk);
Print("Situation= "+Position.MarketPosition);
Print ("Position.Quantity :" +Position.Quantity);
Print("");
}
#region Properties
#endregion
}
Here is the TraceOrders:
21/01/2009 15:50:00 Entered internal PlaceOrder() method at 21/01/2009 15:50:00: Action=Sell OrderType=Limit Quantity=3 LimitPrice=2935,0 StopPrice=0 SignalName='Exit at X times Risk' FromEntrySignal=''
21/01/2009 15:50:00 Ignore order amendment: Action=Sell OrderType=Limit Quantity=3 LimitPrice=2935,0 StopPrice=0 SignalName=Exit at X times Risk' FromEntrySignal='' Reason='Order already has this stop price/limit price/quantity'
OnBarUpdate
Date : 20090121 Time : 155000
Risk= 30
Situation= Long
Position.Quantity :3
OnExecution
Date : 20090121 Time : 155000
Risk= 30
Situation= Flat
Position.Quantity :0
Thanks a lot, have a nice day.
ArnaudTags: None
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by charlesugo_1, 05-26-2026, 05:03 PM
|
0 responses
70 views
0 likes
|
Last Post
by charlesugo_1
05-26-2026, 05:03 PM
|
||
|
Started by DannyP96, 05-18-2026, 02:38 PM
|
1 response
152 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 05-11-2026, 05:56 AM
|
0 responses
162 views
0 likes
|
Last Post
by CarlTrading
05-11-2026, 05:56 AM
|
||
|
Started by CarlTrading, 05-10-2026, 08:12 PM
|
0 responses
100 views
0 likes
|
Last Post
by CarlTrading
05-10-2026, 08:12 PM
|
||
|
Started by Hwop38, 05-04-2026, 07:02 PM
|
0 responses
288 views
0 likes
|
Last Post
by Hwop38
05-04-2026, 07:02 PM
|

Leave a comment: