I am brand new to ninja trader. I am coming from thinkorswim thinkscript and have self taught myself to code in their script format. I have just begun the learning process of the NinjaScript and getting used to it but not fast enough. I am hoping with your help I can speed up the process which in turn will allow me to view a fully functional script with my logic to study and base coding off of.
I think my logic is simple but I am running into issues when it comes to apply multi charts (multiple time frame analysis)
I currently have a script developed for the primary chart (which will always be the 5-minute chart)
What I need is to include in my logic the 15-minute current low price and 15-minute 5-simple period moving average.
I need the logic to play out that the 15-minute low price >= to the 15-minute sma.
I already have the 5-minute logic complete and have begun to or attempt to develop the 15minute multichart but have become stuck.
Can someone please help me code this process to save some time.
The end result should be that my current strategy and entry price confirmation will also include that the condition of the 15-minute low is >= to the 15minute 5sma in order to enter long.
Thanks in advance!
My current code below:
namespace NinjaTrader.NinjaScript.Strategies
{
public class SMAtrendUnlocked : Strategy
{
private SMA SMA1;
private SMA SMA2;
private DM DM1;
private ATR ATR1;
private SMA SMA3;
private SMA SMA4;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "SMAtrendUnlocked";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
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;
FiveSMA2 = 5;
FivaSMA1 = 5;
Sharesize = 1000;
FiveSMA0 = 5;
DMIplusconfirm = 30;
}
else if (State == State.Configure)
{
SetProfitTarget(CalculationMode.Currency, 150);
SetStopLoss(CalculationMode.Currency, 100);
// Add a 15 minute Bars object to the strategy
AddDataSeries(Data.BarsPeriodType.Minute, 15);
}
else if (State == State.DataLoaded)
{
SMA1 = SMA(Close, Convert.ToInt32(FivaSMA1));
SMA1.Plots[0].Brush = Brushes.Goldenrod;
AddChartIndicator(SMA1);
SMA2 = SMA(Close, Convert.ToInt32(FiveSMA2));
DM1 = DM(Close, 14);
DM1.Plots[0].Brush = Brushes.DarkSeaGreen;
DM1.Plots[1].Brush = Brushes.DodgerBlue;
DM1.Plots[2].Brush = Brushes.Crimson;
AddChartIndicator(DM1);
ATR1 = ATR(Close, 14);
SMA3 = SMA(Close, Convert.ToInt32(FiveSMA0));
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;
if (SMA4 == null)
{
// Note: Bars are added to the BarsArray and can be accessed via an index value
// E.G. BarsArray[1] ---> Accesses the 5 minute Bars object added above
SMA4 = SMA(BarsArray[1], 5);
}
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 2)
return;
// Set 1
if ((Low[1] >= SMA1[1])
&& (Low[2] >= SMA2[2])
&& (High[0] > High[1])
&& (DM1.DiPlus[0] >= DMIplusconfirm)
&& (ATR1[0] >= 0.05))
{
EnterLong(Convert.ToInt32(Sharesize), "");
}
// Set 2
if (GetCurrentBid(0) < SMA3[0])
{
ExitLong(Convert.ToInt32(Sharesize), @"5mastop", @"");
}
}
Comment