using System;
using NinjaTrader.Cbi;
using NinjaTrader.NinjaScript.StrategyAnalyzer;
namespace NinjaTrader.NinjaScript.StrategyAnalyzer
{
public class AIBot : StrategyBase // Change inheritance to StrategyBase
{
private int consecutiveBars;
private double lastClose;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "AIBot"; // Renamed the strategy to AIBot
BarsRequiredToTrade = 4;
Calculate = Calculate.OnEachTick;
IsOverlay = false;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true; // Set to true to exit positions at session close
consecutiveBars = 0;
lastClose = 0;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;
if (Close[0] > Open[0] && Close[1] > Open[1] && Close[2] > Open[2]) // Bullish condition
{
consecutiveBars++;
if (consecutiveBars == 3 && Close[3] > lastClose)
{
EnterLong();
}
}
else if (Close[0] < Open[0] && Close[1] < Open[1] && Close[2] < Open[2]) // Bearish condition
{
consecutiveBars++;
if (consecutiveBars == 3 && Close[3] < lastClose)
{
EnterShort();
}
}
else
{
consecutiveBars = 0;
}
lastClose = Close[0];
}
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Custom Strategy not showing on the strategy list.
Collapse
X
-
Custom Strategy not showing on the strategy list.
Trying to figure why the strategy I just did won't show up on the list. It's compiled correctly and no errors in the log.
Code:Tags: None
-
Hello Johndc,
Thanks for your post.
The namespace and class are incorrect for a custom NinjaScript strategy.
The strategy namespace should be changed from namespace.NinjaTrader.NinjaScript.StrategyAnalyzer to the namespace below.
namespace NinjaTrader.NinjaScript.Strategies
The class name should be changed from public class AIBot: StrategyBase to the class below.
public class AIBot : Strategy
See the SampleMACrossover strategy that comes default with NinjaTrader for an example of what the namespace and class of a custom NinjaScript strategy looks like. To view the script, open a New > NinjaScript Editor window, open the Strategies folder, and double-click on the SampleMACrossover file.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CaptainJack, 04-24-2026, 11:07 PM
|
0 responses
34 views
0 likes
|
Last Post
by CaptainJack
04-24-2026, 11:07 PM
|
||
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
130 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|
||
|
Started by M4ndoo, 04-20-2026, 05:21 PM
|
0 responses
183 views
0 likes
|
Last Post
by M4ndoo
04-20-2026, 05:21 PM
|
||
|
Started by M4ndoo, 04-19-2026, 05:54 PM
|
0 responses
94 views
0 likes
|
Last Post
by M4ndoo
04-19-2026, 05:54 PM
|
||
|
Started by cmoran13, 04-16-2026, 01:02 PM
|
0 responses
138 views
0 likes
|
Last Post
by cmoran13
04-16-2026, 01:02 PM
|

Comment