I am creating a strategy with Umanaged orders.
I work fine with:
- Simulated Data Feed;
- Playback max speed;
- Strategy Analyzer.
But, it freezes chart and itself on real-time connection (tested on 3 PCs, 2 connections).
I simplified the strategy, and now I have multiple versions that reproducing the issue.
Let me introduce the simplest version with market entries and market exits:
namespace NinjaTrader.NinjaScript.Strategies.Strat_NTForum
{
public class sTest_07_Market : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "The strategy description";
Calculate = Calculate.OnBarClose;
IsUnmanaged = true;
RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors;
}
else if (State == State.Configure)
{
AddDataSeries( BarsPeriodType.Tick, 1 );
}
}
protected override void OnBarUpdate()
{
if( State != State.Realtime )
{
return;
}
if( BarsInProgress != 1 ) return;
if( CurrentBars[1] < 1 ) return;
if( CurrentBars[1] % 4 == 0 )
{
if( Position.MarketPosition == MarketPosition.Long )
{ SubmitOrderUnmanaged( 0, OrderAction.Sell, OrderType.Market, 1, 0, 0, "", "" ); }
else if( Position.MarketPosition == MarketPosition.Short )
{ SubmitOrderUnmanaged( 0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "" ); }
}
string entry_signal = "";
if( CurrentBars[1] % 2 == 0 )
{
if( Times[1][0].Second % 2 == 0 )
{ entry_signal = "BUY"; }
else
{ entry_signal = "SELL"; }
}
if( entry_signal == "BUY" )
{
double entry_rice = Closes[1][0] +20 * TickSize;
SubmitOrderUnmanaged( 0, OrderAction.Buy, OrderType.Market, 1, 0, entry_rice, "", "" );
}
else if( entry_signal == "SELL" )
{
double entry_rice = Closes[1][0] -20 * TickSize;
SubmitOrderUnmanaged( 0, OrderAction.Sell, OrderType.Market, 1, 0, entry_rice, "", "" );
}
}
}
}
You can see on the video how the strategy freezing and unfreezing chart.
The chart markers off.
No errors in log and trace files.
What can cause this issue in this minimalist strategy?
Thank you.
Comment