Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with a strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help with a strategy

    Any ideas why this short strategy is not placing orders? When I put it on a chart it will not initialize. It remains with a (D) in the right top corner.

    #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 Athena : Strategy
    {
    private int ReversalNumber;


    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Buy/Sell at previous bars high. Reversing on loss.";
    Name = "Athena";
    Calculate = Calculate.OnPriceChange;
    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 = true;
    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;
    TP = 12;
    MaxReversals = 4;
    AllowReversals = true;
    StartHour = DateTime.Parse("18:00", System.Globalization.CultureInfo.InvariantCulture) ;
    EndHour = DateTime.Parse("15:45", System.Globalization.CultureInfo.InvariantCulture) ;
    StartingSize = 1;
    ReversalNumber = 0;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    SetProfitTarget(@"Close Order", CalculationMode.Ticks, TP);
    SetStopLoss(@"Stop Loss", CalculationMode.Ticks, (High[1] + (1 * TickSize)) , false);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 2)
    return;

    // Set 1
    if
    // LongEntry
    (High[2] <= High[1])
    {
    EnterShortStopLimit(StartingSize, (Low[1] - (1 * TickSize)), (Low[1] - (1 * TickSize)) , "");
    }

    }

    #region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="TP", Description="Take Profit in Ticks", Order=1, GroupName="Parameters")]
    public int TP
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="MaxReversals", Description="Number of reversal trades allowed", Order=2, GroupName="Parameters")]
    public int MaxReversals
    { get; set; }

    [NinjaScriptProperty]
    [Display(Name="AllowReversals", Description="Allow Reversals?", Order=3, GroupName="Parameters")]
    public bool AllowReversals
    { get; set; }

    [NinjaScriptProperty]
    [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
    [Display(Name="StartHour", Description="When to start Trading", Order=4, GroupName="Parameters")]
    public DateTime StartHour
    { get; set; }

    [NinjaScriptProperty]
    [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
    [Display(Name="EndHour", Description="Stop Trading at this time", Order=5, GroupName="Parameters")]
    public DateTime EndHour
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="StartingSize", Description="Initial Trade Size", Order=6, GroupName="Parameters")]
    public int StartingSize
    { get; set; }
    #endregion

    }
    }

    #2
    Hello Aramunno, thanks for writing in.

    Whenever you get strategy/indicator initialization problems like this, always check the Log tab of the Control Center. There should be no data indexing within the OnStateChanged method. To set your stop loss based on the price, call SetStopLoss right before the entry order in OnBarUpdate.

    (High[2] <= High[1])
    {
    SetStopLoss(@"Stop Loss", CalculationMode.Ticks, (High[1] + (1 * TickSize)) , false);
    EnterShortStopLimit(StartingSize, (Low[1] - (1 * TickSize)), (Low[1] - (1 * TickSize)) , "");
    }

    Please let me know if I can assist any further.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    600 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    347 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    558 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    558 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X