I've always found it a bit tricky when it comes to crafting a strategy from scratch or even tweaking one that's already out there. I've been using ChatGPT Plus, particularly version 4, hoping for the best outcomes. Yet, even with ChatGPT, I've noticed some logical inconsistencies.
Here's something that's been bugging me: I came across a piece of code from this forum, and for some reason, it isn't triggering the ATM strategy I've set up. I'm trying to wrap my head around why certain actions seem to take priority over my commands.
Would any of you mind taking a peek at my code? I'll also share my settings below to give you a clearer picture.
When I am in a trade, I can't even close it manually.
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class Strategy1 : Strategy
{
private LinReg LinReg1;
private VWMA VWMA1;
public class FriendlyAtmConverter : TypeConverter
{
// Set the values to appear in the combo box
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
List<string> values = new List<string>();
string[] files = System.IO.Directory.GetFiles(System.IO.Path.Combine(NinjaTrader.Core.Globals.UserDataDir, "templates", "AtmStrategy"), "*.xml");
foreach(string atm in files)
{
values.Add(System.IO.Path.GetFileNameWithoutExtension(atm));
NinjaTrader.Code.Output.Process(System.IO.Path.GetFileNameWithoutExtension(atm), PrintTo.OutputTab1);
}
return new StandardValuesCollection(values);
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
return value.ToString();
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
return value;
}
// required interface members needed to compile
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{ return true; }
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{ return true; }
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{ return true; }
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{ return true; }}
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "Strategy1";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = true;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.High;
OrderFillResolutionType = BarsPeriodType.Minute;
OrderFillResolutionValue = 2;
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;
LinRegres = 14;
VMARes = 14;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
LinReg1 = LinReg(Close, Convert.ToInt32(LinRegres));
VWMA1 = VWMA(Close, Convert.ToInt32(VMARes));
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if (CrossAbove(LinReg1, VWMA1, 1))
{
EnterLong(Convert.ToInt32(DefaultQuantity), AtmStrategy);
}
// Set 2
if (CrossBelow(LinReg1, VWMA1, 1))
{
EnterShort(Convert.ToInt32(DefaultQuantity), AtmStrategy);
}
}
#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="LinRegres", Order=1, GroupName="Parameters")]
public int LinRegres
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="VMARes", Order=2, GroupName="Parameters")]
public int VMARes
{ get; set; }
[TypeConverter(typeof(FriendlyAtmConverter))] // Converts the found ATM template file names to string values
[PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")] // Create the combo box on the property grid
[Display(Name = "Atm Strategy", Order = 3, GroupName = "AtmStrategy")]
public string AtmStrategy
{ get; set; }
#endregion
}
}

Comment