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 NullPointStrategies, Today, 05:17 AM
|
0 responses
27 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
124 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
64 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
41 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment