I have hard time to figure out where and which condition I need to put to prevent the script from throwing an error if the ATM strategy on the chart trader is none or custom
Basically look into the forum to compile a script that will run a sell limit order taking the information of the account , the quantity and the atm strategy name on click ( Code will be below for reference)
Now the problem is that I am unsure what is the if else condition i need to do to prevent the script from running or even running the script but without ATM if it's null
I attempt this condition which is basically checking if not null and length of the string is greater than 0 than i can use the atm strategy if not i use a normal order without atm
But then it throws an error when i do a sell limit with the ATM none or custom
"Error on triggering custom event for NinjaScript 'ClickLimitOrderIndicatorExpanded' on bar 508: Could not find file 'myfolder\NinjaTrader 8\templates\AtmStrategy\.xml'."
if ( (ChartControl.OwnerChart.ChartTrader.AtmStrategy.Template) != null || (ChartControl.OwnerChart.ChartTrader.AtmStrategy.Template.ToString().Length) > 0 ) {
entryOrder = myAccount.CreateOrder(Instrument, OrderAction.Sell, OrderType.Limit,
TimeInForce.Day, quantitySelector.Value, priceClicked, 0, string.Empty, "Entry", null);
// Submits our entry order with the ATM strategy named "myAtmStrategyName"
NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(ChartControl.OwnerChart.ChartTrader.AtmStrategy .Template.ToString(), entryOrder);
}else {
limitOrder = myAccount.CreateOrder(Instrument, OrderAction.Sell, OrderType.Limit, OrderEntry.Manual, TimeInForce.Day, quantitySelector.Value, priceClicked, 0, "", "limitOrder"+DateTime.Now.ToString(), DateTime.MaxValue, null);
}
Thanks in advance
Code that do an entry on ctrl + Click in case
private Account myAccount;
private ChartScale MyChartScale;
private Order entryOrder;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "ClickLimitOrderIndicatorExpanded";
Calculate = Calculate.OnPriceChange;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
AccountName = "Sim101";
}
else if (State == State.DataLoaded)
{
if (ChartControl != null)
ChartControl.MouseLeftButtonDown += LeftMouseDown;
if (ChartControl != null)
ChartPanel.MouseMove += ChartControl_MouseMove;
// Find our account
lock (Account.All)
myAccount = Account.All.FirstOrDefault(a => a.Name == AccountName);
}
else if (State == State.Terminated)
{
if (ChartControl != null)
ChartControl.MouseLeftButtonDown -= LeftMouseDown;
if (ChartControl != null)
ChartPanel.MouseMove -= ChartControl_MouseMove;
}
}
protected override void OnBarUpdate()
{
}
protected void LeftMouseDown(object sender, MouseButtonEventArgs e)
{
NinjaTrader.Gui.Tools.QuantityUpDown quantitySelector = (Window.GetWindow(ChartControl.Parent).FindFirst(" ChartTraderControlQuantitySelector") as NinjaTrader.Gui.Tools.QuantityUpDown);
Print("Quantity: "+quantitySelector.Value);
NinjaTrader.Gui.Tools.AccountSelector xAlselector = Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;
Print("Which Account Name"+ xAlselector.SelectedAccount.ToString());
lock (Account.All)
myAccount = Account.All.FirstOrDefault(a => a.Name == xAlselector.SelectedAccount.ToString());
if ( (ChartControl.OwnerChart.ChartTrader.AtmStrategy.T emplate) != null) {
Print("ATMStrategyName is : "+ ChartControl.OwnerChart.ChartTrader.AtmStrategy.Te mplate);
}
Print(ChartControl.OwnerChart.ChartTrader.AtmStrat egy.Template.ToString().Length);
TriggerCustomEvent(o =>
{
int Y = ChartingExtensions.ConvertToVerticalPixels(e.GetPo sition(ChartControl as IInputElement).Y, ChartControl.PresentationSource);
double priceClicked = MyChartScale.GetValueByY(Y);
Order limitOrder = null;
Order stopOrder = null;
if (priceClicked > Close[0] && Keyboard.IsKeyDown(Key.LeftCtrl))
{
// stopOrder = myAccount.CreateOrder(Instrument, OrderAction.Buy, OrderType.StopMarket, OrderEntry.Manual, TimeInForce.Day, 1, 0, priceClicked, "", "stopOrder"+DateTime.Now.ToString(), DateTime.MaxValue, null);
if ( (ChartControl.OwnerChart.ChartTrader.AtmStrategy.T emplate) != null || (ChartControl.OwnerChart.ChartTrader.AtmStrategy.T emplate.ToString().Length) > 0 ) {
entryOrder = myAccount.CreateOrder(Instrument, OrderAction.Sell, OrderType.Limit,
TimeInForce.Day, quantitySelector.Value, priceClicked, 0, string.Empty, "Entry", null);
// Submits our entry order with the ATM strategy named "myAtmStrategyName"
NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(ChartControl.OwnerChart.ChartTrader.AtmStrategy .Template.ToString(), entryOrder);
}else {
limitOrder = myAccount.CreateOrder(Instrument, OrderAction.Sell, OrderType.Limit, OrderEntry.Manual, TimeInForce.Day, quantitySelector.Value, priceClicked, 0, "", "limitOrder"+DateTime.Now.ToString(), DateTime.MaxValue, null);
}
}
else if (priceClicked < Close[0] && Keyboard.IsKeyDown(Key.LeftCtrl))
{
limitOrder = myAccount.CreateOrder(Instrument, OrderAction.Buy, OrderType.Limit, OrderEntry.Manual, TimeInForce.Day, quantitySelector.Value , priceClicked, 0, "", "limitOrder"+DateTime.Now.ToString(), DateTime.MaxValue, null);
// stopOrder = myAccount.CreateOrder(Instrument, OrderAction.Sell, OrderType.StopMarket, OrderEntry.Manual, TimeInForce.Day, 1, 0, priceClicked, "", "stopOrder"+DateTime.Now.ToString(), DateTime.MaxValue, null);
}
myAccount.Submit(new[] { limitOrder, stopOrder });
}, null);
e.Handled = true;
}
void ChartControl_MouseMove (object sender, System.Windows.Input.MouseEventArgs e)
{
}
protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
base.OnRender(chartControl, chartScale);
MyChartScale = chartScale;
}
[TypeConverter(typeof(NinjaTrader.NinjaScript.Accou ntNameConverter))]
public string AccountName { get; set; }
}
}

. That is exactly the answer I needed to unblock me
Comment