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 selu72, Today, 02:01 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Zachary  
      Started by WHICKED, Today, 02:02 PM
      2 responses
      12 views
      0 likes
      Last Post WHICKED
      by WHICKED
       
      Started by f.saeidi, Today, 12:14 PM
      8 responses
      21 views
      0 likes
      Last Post f.saeidi  
      Started by Mikey_, 03-23-2024, 05:59 PM
      3 responses
      51 views
      0 likes
      Last Post Sam2515
      by Sam2515
       
      Started by Russ Moreland, Today, 12:54 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Erick  
      Working...
      X