Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Time to have order executed
Collapse
X
-
Hi everybody,
made the changes hedgeplay suggested so my entry is
longStopEntry = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "longStopEntry");
nothing happens.
So with my infrastructure 200ms is the best I can achive I suppose, or I can do something else?
-
Originally posted by dieci View PostHi,
thanks for your answer, using your first example I made another script and tested it, the results are the same, about 200ms from entry to execution
Here is my code
What's wrong?
Why live so slowly and so constrained?
Be free!
Run Wild and Naked!
... mod the code to submit without OCO and run the test again.
Leave a comment:
-
Hello dieci,
This would indicate this is how fast your specific computer and CPU is able to process orders.
Leave a comment:
-
Hi,
thanks for your answer, using your first example I made another script and tested it, the reasults are the same, about 200ms from entry to execution
Here is my code
What's wrong?
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
using System.Diagnostics;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class UnmanagedOCOExecutionTime : Strategy
{
private Order longStopEntry, shortStopEntry;
private string ocoString;
Stopwatch st = new Stopwatch();
bool Go = true;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"unmanaged execution time";
Name = "UnmanagedOCOExecutionTime";
Calculate = Calculate.OnPriceChange;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsUnmanaged = true;
}
}
protected override void OnBarUpdate() { }
private void AssignOrderToVariable(ref Order order)
{
if (order.Name == "longStopEntry" && longStopEntry != order)
longStopEntry = order;
if (order.Name == "shortStopEntry" && shortStopEntry != order)
shortStopEntry = order;
}
protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time)
{
st.Stop();
double microseconds = (1000000.0 / Stopwatch.Frequency) * st.ElapsedTicks;
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"test.txt", true))
{
sw.WriteLineAsync(microseconds.ToString());
sw.Close();
}
if (execution.Name == "shortStopEntry")
{
longStopEntry = null;
shortStopEntry = null;
}
Esegui = true;
}
protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
{
if (CurrentBars[0] < 1)
return;
if (Go)
{
if (Close[0] >= High[1])
{
if (longStopEntry == null)
{
st.Reset();
st.Start();
ocoString = string.Format("unmanagedentryoco{0}", DateTime.Now.ToString("hhmmssffff"));
longStopEntry = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, ocoString, "longStopEntry");
Go = false;
}
}
else if (Close[0] <= Low[1])
{
if (longStopEntry != null && shortStopEntry == null)
{
st.Reset();
st.Start();
ocoString = string.Format("unmanagedentryoco{0}", DateTime.Now.ToString("hhmmssffff"));
shortStopEntry = SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.Market, 1, 0, 0, ocoString, "shortStopEntry");
Go = false;
}
}
}
}
protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
{
AssignOrderToVariable(ref order);
}
}
}
Leave a comment:
-
Hi dieci,
Yes it is slow ... by design ... as it executes a long list of 'training wheels" safeguards for you. You are gaining value from that delay.
If instead your priority instead is a "need for speed" it seems like all of these threads end with a recommendation to use "Unmanaged Orders" https://ninjatrader.com/support/help...d_approach.htm
After tiring of NT8's built in by design data lag constantly blowing up strategies and Charttrader ATMs I switched to unmanaged and simulating OCAs on my own machine. Has been a faster and better ride.
Chelsea has posted some great thin starter examples on how use Unmanaged Orders in strategies.
Hedge
Leave a comment:
-
Ok Chelsea
If someone would make a similar test, just to have a comparison...
Leave a comment:
-
Hello dieci,
There would be no predictable or expected amount of time we can provide as the amount of time it would take to process an order depends on each system's performance, and when the order was submitted in relation to data being received on the instrument thread driving the order processing. This would depend on the CPU single threaded performance, internal motherboard speed, and latency time to the data and brokerage servers.
This thread will remain open for any community members that would like to give their opinion.
Leave a comment:
-
Time to have order executed
Hi,
I'm checking how long it takes to an order from the entry to execution in simulation mode
With my Pc Win 10 i5 8gb ram I've have an average time of about 200ms
Is it a good time?
It seems a bit low for me
This is my code
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
using System.Diagnostics;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class TestTempiEsecuzioneordine : Strategy
{
bool Go= true;
Stopwatch st = new Stopwatch();
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"TestExecutionTime";
Name = "Test";
Calculate = Calculate.OnPriceChange;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = false;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.ByStrategyPosition;
BarsRequiredToTrade = 1;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
if (IsFirstTickOfBar)
{
Go= true;
}
if (bEsegui)
{
if (Close[0] >= High[1])
{
if (Position.MarketPosition != MarketPosition.Long)
{
st.Reset();
st.Start();
EnterLong(Convert.ToInt32(DefaultQuantity), @"E");
Go= false;
}
}
else if (Close[0] <= Low[1])
{
if (Position.MarketPosition != MarketPosition.Short)
{
st.Reset();
st.Start();
ExitLong(Convert.ToInt32(DefaultQuantity));
Go= false;
}
}
}
}
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
if (order.OrderState == OrderState.Filled)
{
st.Stop();
double microseconds = (1000000.0 / Stopwatch.Frequency) * st.ElapsedTicks;
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"C:\nj\Test.txt", true))
{
sw.WriteLineAsync(microseconds.ToString());
sw.Close();
}
Go= true;
}
}
}
}
Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Pointtoni, Yesterday, 11:41 PM
|
3 responses
24 views
0 likes
|
Last Post
![]()
by jenacie.com
Today, 12:47 PM
|
||
Started by DayTradingDEMON, Yesterday, 02:10 PM
|
5 responses
29 views
0 likes
|
Last Post
![]() |
||
Started by Nate G, 03-17-2025, 02:53 PM
|
4 responses
60 views
1 like
|
Last Post
![]()
by timko
Today, 11:13 AM
|
||
Started by several, 03-18-2025, 03:53 AM
|
11 responses
175 views
1 like
|
Last Post
![]()
by timko
Today, 10:53 AM
|
||
Started by Amelie4262, Today, 10:45 AM
|
0 responses
10 views
0 likes
|
Last Post
![]()
by Amelie4262
Today, 10:45 AM
|
Leave a comment: