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 rocketman7, Today, 09:41 AM
      2 responses
      5 views
      0 likes
      Last Post rocketman7  
      Started by traderqz, Today, 09:44 AM
      2 responses
      4 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by rocketman7, Today, 02:12 AM
      7 responses
      31 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by guillembm, Yesterday, 11:25 AM
      3 responses
      16 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by junkone, 04-21-2024, 07:17 AM
      10 responses
      150 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X