Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy with custom indicator

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

    Strategy with custom indicator

    Hi

    I'm trying to make a strategy based on a custom indicator. But I get an error when I run the strategy analyzer.

    "Indicator "CustomIndicator": Error on calling 'OnStateChange' method: Object reference not set to an instance of an object."

    The strategy analyzer gets to the piece of code I have highlighted in bold.

    I have a piece of my code and hope that someone can help me.

    #region Variables
    private int upSize = 7;
    private UpStyle upType = UpStyle.Standard;
    private int dtbStrength = 15;
    private Series<double> upTrend;
    private CustomIndicator cusInd;
    #endregion


    protected override void OnStateChange()
    {

    if (State == State.SetDefaults)
    {
    Description = @"High volume with hammer in downwaves or shooting star in upwaves.";
    Name = "ReversalVolumeCandle";
    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 = 0;
    IsInstantiatedOnEachOptimizationIteration = true;

    }
    else if (State == State.Configure)
    {

    cusInd = CustomIndicator(UpStyle.Standard, 7, 15, false, true, true);

    AddChartIndicator(cusInd);
    }
    }

    #2
    Hello The_Wiz,

    Thank you for writing in.

    Without the code I’m unable to test on my end. Would you upload a copy of CustomIndicator so I can look into what the issue may be?

    To export a NinjaScript from NinjaTrader 8 do the following:

    From the Control Center window select Tools -> Export -> NinjaScript...
    Click Add>Select the indicator>OK>Export.
    Then from the forum locate that file you saved, usually under My Docs>NT8>Bin>Custom>Select the downloaded .zip file.

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      I've got it working now. Thanks

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      69 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      42 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      24 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      27 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      54 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X