#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.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators.AlanIndicators
{
public class PrintChartTraderSelectedAccount : Indicator
{
NinjaTrader.Gui.Tools.AccountSelector xAlselector;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "PrintChartTraderSelectedAccount";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
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;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
}
}
protected override void OnBarUpdate()
{
ChartControl.Dispatcher.InvokeAsync((Action)(() =>
{
//You have to put the stuff below within this ChartControl.Dispatcher.InvokeAsync((Action)(() =>, because you are trying to access something on a different thread.
xAlselector = Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;
Print(xAlselector.SelectedAccount.ToString());
}));
}
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private AlanIndicators.PrintChartTraderSelectedAccount[] cachePrintChartTraderSelectedAccount;
public AlanIndicators.PrintChartTraderSelectedAccount PrintChartTraderSelectedAccount()
{
return PrintChartTraderSelectedAccount(Input);
}
public AlanIndicators.PrintChartTraderSelectedAccount PrintChartTraderSelectedAccount(ISeries<double> input)
{
if (cachePrintChartTraderSelectedAccount != null)
for (int idx = 0; idx < cachePrintChartTraderSelectedAccount.Length; idx++)
if (cachePrintChartTraderSelectedAccount[idx] != null && cachePrintChartTraderSelectedAccount[idx].EqualsInput(input))
return cachePrintChartTraderSelectedAccount[idx];
return CacheIndicator<AlanIndicators.PrintChartTraderSelectedAccount>(new AlanIndicators.PrintChartTraderSelectedAccount(), input, ref cachePrintChartTraderSelectedAccount);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.AlanIndicators.PrintChartTraderSelectedAccount PrintChartTraderSelectedAccount()
{
return indicator.PrintChartTraderSelectedAccount(Input);
}
public Indicators.AlanIndicators.PrintChartTraderSelectedAccount PrintChartTraderSelectedAccount(ISeries<double> input )
{
return indicator.PrintChartTraderSelectedAccount(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.AlanIndicators.PrintChartTraderSelectedAccount PrintChartTraderSelectedAccount()
{
return indicator.PrintChartTraderSelectedAccount(Input);
}
public Indicators.AlanIndicators.PrintChartTraderSelectedAccount PrintChartTraderSelectedAccount(ISeries<double> input )
{
return indicator.PrintChartTraderSelectedAccount(input);
}
}
}
#endregion
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Error Message in OnBarUpdate Event
Collapse
X
-
I don't understand this code. I can understand first part but no others. I want to place orders and handle it in the selected account of ChartTrader. Should I add any code in the StrategyRenderBase Part? How can I integrate my strategy with this code? Please help me in this problem.Code:
-
Hello Rogers101,
If you are having problems understanding code I would suggest to focus efforts on that first before trying to create a custom project.
The code you copied is used to find the account selector in the chart from code. That is all that code does. A strategy cannot make use of that account, the account the strategy will use is the account you select when configuring the strategy.
If you are seeing orders get stuck on the sim account that would be due to logic used. To clear the orders you can right click -> edit the sim account and reset it. To avoid that happening you would need to change your strategies logic so it does not do the conflicting action which leads to the stuck order.
Comment
-
Thanks for your reply. Can you review my code? I am sorry but this is my first NinjaScript so there are a lot of errors.
And I will appreciate if you provide a suggestion how I can convert this strategy to use selected account like Add-On or Indicator.
Thank you in advance.
CustomStrategy.cs
Comment
-
Please help me how can I place and handle orders on the selected account of ChartTrader. I'm not sure if I need to develop an add-on, an indicator or a strategy, what's clear is that I can't do that in the strategy as I select the account when I import the strategy.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
62 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
134 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
75 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
50 views
0 likes
|
Last Post
|

Comment