Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Synthetic Instrument Indicator completely freezes Ninjatrader 8

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

    Synthetic Instrument Indicator completely freezes Ninjatrader 8

    Hi,

    I coded an indicator for a Synthetic instrument. After a while it simply freezes the chart window and after that, the main Ninjatrader windows freezes up too.
    I can only kill the whole process with Task Manager forcefully.

    I was wondering if you could point out my error somewhere in the code.
    It feels like a deadlock is happening somewhere. I tried to force it onto a single thread using an object, but that didn't work.
    Code:
    lock (lockObj) {
      // main code here
    }
    I tried to change the (BarsInProgress == 0), that wasn't helpful either.

    So if you could help, that would be great. Thanks in advance.

    Code:
    protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"SyntheticInstrument4";
                    Name                                        = "SyntheticInstrument4";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = false;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = false;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                    //
                    CalculateCurrentDayOnly                        = true;
                    SelectedBarsPeriodType                        = BarsPeriodType.Minute;
                    SelectedBarsPeriodValue                        = 1;
                    ESMultiplier                                = 1;
                    NQMultiplier                                = 1;
                    YMMultiplier                                = 1;
                    FDAXMultiplier                                = 1;
                    AddPlot(new Stroke(Brushes.Green, DashStyleHelper.Solid, 1), PlotStyle.Square, "SyntheticHigh");
                    AddPlot(new Stroke(Brushes.Red, DashStyleHelper.Solid, 1), PlotStyle.Square, "SyntheticLow");
                    AddPlot(new Stroke(Brushes.Yellow, DashStyleHelper.Solid, 1), PlotStyle.Hash, "SyntheticClose");
                }
                else if (State == State.Configure)
                {
                    AddDataSeries("ES 09-20", SelectedBarsPeriodType, SelectedBarsPeriodValue);
                    AddDataSeries("NQ 09-20", SelectedBarsPeriodType, SelectedBarsPeriodValue);
                    AddDataSeries("YM 09-20", SelectedBarsPeriodType, SelectedBarsPeriodValue);
                    AddDataSeries("FDAX 09-20", SelectedBarsPeriodType, SelectedBarsPeriodValue);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (CalculateCurrentDayOnly && Time[0].Date != DateTime.Now.Date) {
                    return;
                }
                if (CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1 || CurrentBars[3] < 1 || CurrentBars[4] < 1) {
                    return;
                }
                if (BarsInProgress == 0) {
                    //XOpen[0] = ((Opens[1][0] * ESMultiplier) + (Opens[2][0] * NQMultiplier) + (Opens[3][0] * YMMultiplier) + (Opens[4][0] * FDAXMultiplier)) / 4;
                    Values[0][0] = ((Highs[1][0] * ESMultiplier) + (Highs[2][0] * NQMultiplier) + (Highs[3][0] * YMMultiplier) + (Highs[4][0] * FDAXMultiplier)) / 4;
                    Values[1][0] = ((Lows[1][0] * ESMultiplier) + (Lows[2][0] * NQMultiplier) + (Lows[3][0] * YMMultiplier) + (Lows[4][0] * FDAXMultiplier)) / 4;
                    Values[2][0] = ((Closes[1][0] * ESMultiplier) + (Closes[2][0] * NQMultiplier) + (Closes[3][0] * YMMultiplier) + (Closes[4][0] * FDAXMultiplier)) / 4;
                }
            }
    
            #region Properties
            [NinjaScriptProperty]
            [Display(Name="CalculateCurrentDayOnly", Order=5, GroupName="Properties")]
            public bool CalculateCurrentDayOnly
            { get; set; }
    
            [NinjaScriptProperty]
            [Display(Name="SelectedBarsPeriodType", Order=10, GroupName="Properties")]
            public BarsPeriodType SelectedBarsPeriodType
            { get; set; }
    
            [NinjaScriptProperty]
            [Range(1, int.MaxValue)]
            [Display(Name="SelectedBarsPeriodValue", Order=12, GroupName="Properties")]
            public int SelectedBarsPeriodValue
            { get; set; }
    
            [NinjaScriptProperty]
            [Range(1, double.MaxValue)]
            [Display(Name="ES Multiplier", Order=20, GroupName="Properties")]
            public double ESMultiplier
            { get; set; }
    
            [NinjaScriptProperty]
            [Range(1, double.MaxValue)]
            [Display(Name="NQ Multiplier", Order=21, GroupName="Properties")]
            public double NQMultiplier
            { get; set; }
    
            [NinjaScriptProperty]
            [Range(1, double.MaxValue)]
            [Display(Name="YM Multiplier", Order=22, GroupName="Properties")]
            public double YMMultiplier
            { get; set; }
    
            [NinjaScriptProperty]
            [Range(1, double.MaxValue)]
            [Display(Name="FDAX Multiplier", Order=23, GroupName="Properties")]
            public double FDAXMultiplier
            { get; set; }
            #endregion
        }

    #2
    Hello Gorkhaan,

    Looking at the given syntax I don't see what may be causing the issue. I could suggest to make sure you don't have anything else running while testing this to make sure it is your item and not a combination of items.

    There is another script which does essentially the same process for the ^ADV and ^DECL instruments, that is on the app share as advance decline. You could try this indicator to see if you get a similar result and if not it could be used to compare and contrast.

    The only other observation I would have here is to avoid using user inputs for the AddDataSeries, that is not expected to work in all areas of the platform. I am not certain that is related but is something you can test.

    https://ninjatraderecosystem.com/use...vance-decline/



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse for the tips. I see what I can do.

      Have a great day!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Hyper, Today, 09:56 AM
      0 responses
      2 views
      0 likes
      Last Post Hyper
      by Hyper
       
      Started by Kediil, Today, 09:26 AM
      0 responses
      3 views
      0 likes
      Last Post Kediil
      by Kediil
       
      Started by bootize, Today, 08:37 AM
      0 responses
      6 views
      0 likes
      Last Post bootize
      by bootize
       
      Started by _Zero_, 01-06-2020, 01:16 PM
      4 responses
      138 views
      2 likes
      Last Post globaljobber  
      Started by sukhob, Yesterday, 04:27 PM
      2 responses
      22 views
      0 likes
      Last Post sukhob
      by sukhob
       
      Working...
      X