#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.
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
128 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
74 views
1 like
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
116 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
110 views
1 like
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
88 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment