#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.Indicators; using NinjaTrader.NinjaScript.DrawingTools; #endregion //This namespace holds Strategies in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Strategies { public class test : Strategy { private SMA fast; private SMA slow; private int stopLoss = 30; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"test"; Name = "test"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = false; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 1; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Day; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 20; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; AddDataSeries(Data.BarsPeriodType.Minute, 1); } else if (State == State.Configure) { Description = "An example of a MA crossover strategy."; Name = "MovingAverageCrossover"; fast = SMA(11); slow = SMA(130); } } protected override void OnBarUpdate() { if (CurrentBar < slow.Period) return; // For Long Position if (CrossAbove(fast, slow, 1)) { if (Position.MarketPosition == MarketPosition.Short) ExitShort(stopLoss, "ExitShort", "Short"); EnterLong(stopLoss, "Long"); } // For Short Position if (CrossBelow(fast, slow, 1)) { if (Position.MarketPosition == MarketPosition.Long) ExitLong(stopLoss, "ExitLong", "Long"); EnterShort(stopLoss, "Short"); }//Add your custom strategy logic here. } #region Properties [Range(1, int.MaxValue), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptStrategyParameters", Order = 0)] public int Fast { get; set; } [Range(1, int.MaxValue), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptStrategyParameters", Order = 1)] public int Slow { get; set; } #endregion } }
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strategy not opening in strategy analyzer?
Collapse
X
-
Strategy not opening in strategy analyzer?
Very simple strategy as I'm still learning the coding. However, no matter what I do, I cannot get this strategy to appear in the analyzer. I've tried saving, making a new strat, compiling over and over, and just about everything I can think of. Is there an issue with the code that Ninjascript won't tell me about?
Code:Tags: None
-
Hello RehmaZ,
Thank you for your post.
Do you receive any errors on the Log tab of the Control Center? Are there any errors in the NinjaScript Editor?
Please right-click on your strategy in the Strategies folder from the right-hand side of the NinjaScript Editor - do you have "Exclude From Compilation" checked? If so, please select this option to uncheck it and include the strategy in compilation, and then close and reopen the Strategy Analyzer to test if it is in the list.
I look forward to your reply.Emily C.NinjaTrader Customer Service
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by AaronKoRn, Today, 09:49 PM
|
0 responses
10 views
0 likes
|
Last Post
by AaronKoRn
Today, 09:49 PM
|
||
Started by carnitron, Today, 08:42 PM
|
0 responses
9 views
0 likes
|
Last Post
by carnitron
Today, 08:42 PM
|
||
Started by strategist007, Today, 07:51 PM
|
0 responses
10 views
0 likes
|
Last Post Today, 07:51 PM | ||
Started by StockTrader88, 03-06-2021, 08:58 AM
|
44 responses
3,980 views
3 likes
|
Last Post
by jhudas88
Today, 06:59 PM
|
||
Started by rbeckmann05, Today, 06:48 PM
|
0 responses
9 views
0 likes
|
Last Post
by rbeckmann05
Today, 06:48 PM
|
Comment