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.Brandon H.NinjaTrader Customer Service
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by fx.practic, 10-15-2013, 12:53 AM
|
5 responses
5,404 views
0 likes
|
Last Post
by Bidder
Today, 12:22 AM
|
||
Started by Shai Samuel, 07-02-2022, 02:46 PM
|
4 responses
95 views
0 likes
|
Last Post
by Bidder
Today, 12:11 AM
|
||
Started by DJ888, Yesterday, 10:57 PM
|
0 responses
8 views
0 likes
|
Last Post
by DJ888
Yesterday, 10:57 PM
|
||
Started by MacDad, 02-25-2024, 11:48 PM
|
7 responses
159 views
0 likes
|
Last Post Yesterday, 10:23 PM | ||
Started by Belfortbucks, Yesterday, 09:29 PM
|
0 responses
8 views
0 likes
|
Last Post
by Belfortbucks
Yesterday, 09:29 PM
|
Comment