Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

    NYSE Advancing Issues/Declining Issues Uses historical tick data to calculate the ^ADV index minus the ^DECL index to give a simulation of the ^ADD index. Requires a data feed that supports indexes and provides data for the ^ADV (NYSE Advancing Issues) and ^DECL (NYSE Declining Issues). Update June 16th, 2020 &#8211; Corrected stroke attributes to [&#8230;]




    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 Barry Milan, Today, 10:35 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by WeyldFalcon, 12-10-2020, 06:48 PM
      14 responses
      1,428 views
      0 likes
      Last Post Handclap0241  
      Started by DJ888, Yesterday, 06:09 PM
      2 responses
      9 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      40 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Today, 08:51 AM
      2 responses
      16 views
      0 likes
      Last Post bill2023  
      Working...
      X