i write this code but some of values are not correct , and the condition dosent work well ,
for example after runing this code and and es take prev day low and i still see long positon , i want enter when in curr time nq take low and es dont take is prev low
this is the code:
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 NQTEST : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "NQTEST";
Calculate = Calculate.OnBarClose;
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;
}
else if (State == State.Configure)
{
AddDataSeries("MNQ DEC24", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);// 1
AddDataSeries("MES DEC24", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);// 2
AddDataSeries(Data.BarsPeriodType.Minute, 1); //3
AddDataSeries("MES DEC24", Data.BarsPeriodType.Minute, 1); //4
}
}
private double nqLow = 0;
private double esLow = 0;
private double currNQLow = 0;
private double currESLow = 0;
protected override void OnBarUpdate()
{
if (CurrentBars[1] < 1 || CurrentBars[2] < 1 || CurrentBars[0] < 1)
return;
nqLow = Lows[1][0];
esLow = Lows[2][0]
currNQLow = Lows[3][0];
currESLow = Lows[4][0];
bool nqTakeLow = currNQLow < nqLow;
bool esTakeLow = currESLow >= esLow;
if(nqTakeLow && !esTakeLow)
{
EnterLong();
}
}
}
}

Comment