When i hit "Immediately Submit" i expect the algo to wait for buy conditons and then execute the code without waiting for the virtual orders to be flat.
But when i turn on the strategy and hit "Immediately submit" the computer says "Order Placed" and places two stop limits, without submitting a working order.
The weirdest part is sometimes it works the way i think it should and sometimes it does this weird thing.
I have tried it on two different computers with the same result. Sometimes it works like i think it should and sometimes it places two limit orders where the stops should be in the strategy.
is there something wrong with my code? I dont think so because it worked earlier this week, but now i'm having problems.
I'm using 8.1.2
I have had the same issue in playback and in a live enviorment, and i have updated NinjaTrader on my other PC with the same results.
Here's a video of whats happening: https://streamable.com/g43by4
And heres the code i'm testing incase i'm missing something.
Thanks!
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;
#endregion
namespace NinjaTrader.NinjaScript.Strategies
{
public class Alex13325 : Strategy
{
private EMA emaFast1;
private EMA emaSlow1;
private EMA emaFast5;
private EMA emaSlow5;
private EMA emaFast15;
private EMA emaSlow15;
private int takeProfitTicks = 400; // Adjust this value for your desired Take Profit in ticks
private int stopLossTicks = 200; // Adjust this value for your desired Stop Loss in ticks
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDes criptionSampleMACrossOver;
Name = "MULTIEMA";
Fast1 = 10;
Slow1 = 50;
Fast5 = 50;
Slow5 = 100;
Fast15 = 100;
Slow15 = 200;
}
else if (State == State.DataLoaded)
{
emaFast1 = EMA(Fast1);
emaSlow1 = EMA(Slow1);
emaFast5 = EMA(Fast5);
emaSlow5 = EMA(Slow5);
emaFast15 = EMA(Fast15);
emaSlow15 = EMA(Slow15);
emaFast1.Plots[0].Brush = Brushes.Goldenrod;
emaFast1.Plots[0].Width = 4;
emaSlow1.Plots[0].Brush = Brushes.Red; // Adjust the color as needed
emaSlow1.Plots[0].Width = 4;
emaFast5.Plots[0].Brush = Brushes.Pink;
emaFast5.Plots[0].Width = 4;
emaSlow5.Plots[0].Brush = Brushes.Red; // Adjust the color as needed
emaSlow5.Plots[0].Width = 4;
emaFast15.Plots[0].Brush = Brushes.SeaGreen;
emaFast15.Plots[0].Width = 4;
emaSlow15.Plots[0].Brush = Brushes.Red; // Adjust the color as needed
emaSlow15.Plots[0].Width = 4;
AddChartIndicator(emaFast1);
AddChartIndicator(emaSlow1);
AddChartIndicator(emaFast5);
AddChartIndicator(emaSlow5);
AddChartIndicator(emaFast15);
AddChartIndicator(emaSlow15);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;
if (emaFast1[0] > emaSlow1[0] && emaFast5[0] > emaSlow5[0] && emaFast15[0] > emaSlow15[0])
{
EnterLong(1);
SetProfitTarget(CalculationMode.Ticks, takeProfitTicks);
SetStopLoss(CalculationMode.Ticks, stopLossTicks);
}
}
region Properties
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(Name = "Fast1", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
public int Fast1 { get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(Name = "Slow1", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
public int Slow1 { get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(Name = "Fast5", GroupName = "NinjaScriptStrategyParameters", Order = 2)]
public int Fast5 { get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(Name = "Slow5", GroupName = "NinjaScriptStrategyParameters", Order = 3)]
public int Slow5 { get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(Name = "Fast15", GroupName = "NinjaScriptStrategyParameters", Order = 4)]
public int Fast15 { get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(Name = "Slow15", GroupName = "NinjaScriptStrategyParameters", Order = 5)]
public int Slow15 { get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(Name = "takeProfitTicks", GroupName = "NinjaScriptStrategyParameters", Order = 6)]
public int TakeProfitTicks
{
get { return takeProfitTicks; }
set { takeProfitTicks = value; }
}
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(Name = "StopLossTicks", GroupName = "NinjaScriptStrategyParameters", Order = 7)]
public int StopLossTicks
{
get { return stopLossTicks; }
set { stopLossTicks = value; }
}
#endregion
}
}

Comment