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

Is it proper way to have settlement line filter?

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

    Is it proper way to have settlement line filter?


    To use selltlement filter not to trade close to settlement lines Pluse 20 Ticks ,
    Futures Settlement is the closing price of the contract at the end of the Regular Trading Hours (RTH) Session – 3:15 PM Central Time. This indicator will plot the last two settlement prices. Look at the attached chart image to see how price interacts with the lines. This is version 3 of the same indicator […]

    I want to add in my custom strategy.
    in strategy i have

    private settlementLines mySetLines;

    on dataloaded
    mySetLines= settlementLines();

    on bar update
    double dist = Math.abs(settlementLines.Settlement[0] - Close[0])

    Indicator plots these values
    AddPlot(new Stroke(Brushes.Cyan, 2), PlotStyle.Hash, "Settlement");
    AddPlot(new Stroke(Brushes.HotPink, 2), PlotStyle.Hash, "Prior Settlement");


    in Logic for Long
    if (close[0] > open[0]) && (dist >= 20 * TickSize)
    Go Long​

    Is this the right way of doing it? its not working on my end.
    Also are settlement lines backtestable?

    #2
    Hello tkaboris,

    If your dist variable is already an amount of ticks that would be correct, it looks like you are just subtracting two prices though which would just be a price difference. You would need to either convert that value to ticks or change your condition to check a price value instead of ticks. For example how much is 20 ticks in price for the instrument you used? That would be what you replace 20 * TickSize with or that amount of difference in price.

    I wouldn't be able to say if that indicator can be used in a backtest as it was created by a user. You would have to use a Print in your strategy and see what values it produces during a backtest.
    JesseNinjaTrader Customer Service

    Comment


      #3
      HI i am already converting dist to ticks
      if (close[0] > open[0]) && (dist >= 20 * TickSize)

      or it has to be on this level?
      double dist = Math.abs(settlementLines.Settlement[0] - Close[0]) * TickSize? -> would this be right to convert to ticks?

      Comment


        #4
        Hello tkaboris,

        I would suggest using a Print to output the values you are seeing on that instrument to make sure the condition you have makes sense.
        Last edited by NinjaTrader_Jesse; 03-06-2023, 09:50 AM.
        JesseNinjaTrader Customer Service

        Comment


          #5
          ok i am doing something wrong.

          private SettlementLines mySetLines;
          mySetLines = SettlementLines();
          mySetLines.Plots[0].Brush = Brushes.Cyan;

          when i try to print
          Print(mySetLines.Settlement[0]);

          it complains. I dont see that settlement lines have any arguments
          Click image for larger version

Name:	image.png
Views:	82
Size:	109.8 KB
ID:	1238187​​
          Attached Files
          Last edited by tkaboris; 03-06-2023, 10:00 AM.

          Comment


            #6
            Hello Hello tkaboris,

            The error is mentioning that you called the indicator incorrectly, it takes some parameters but you provided 0 parameters.

            The second error mentions that there is no plot named Settlement, you would need to look at the indicators code to see what the actual plots are named and make sure you use the same name when calling the plot.

            You can use the strategy builder to generate the code to use indicators, you would open a new empty strategy builder and make 1 condition using the indicator and plot you wanted. Then click View Code and it will show the syntax to use the indicator.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thank you i fixed that with
              mySetLines = SettlementLines(Close, @"CME US Index Futures RTH");
              Print(mySetLines.SettlementPlotValues[0]);

              I now have this error in output.
              SettlementLines' tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state. Attempted to load MNQ 03-23 Globex: Daily

              Comment


                #8
                Update
                I added daily series and error is gone but also settlement line is gone too
                else if (State == State.Configure)
                {
                AddDataSeries(Data.BarsPeriodType.Tick, 1);
                AddDataSeries(Instrument.FullName, new BarsPeriod { BarsPeriodType = BarsPeriodType.Day, Value = 1 }, "CME US Index Futures RTH", false);
                }​

                Comment


                  #9
                  Hello tkaboris,

                  The error you are seeing about data means the indicator uses a secondary series so the calling strategy needs to add that same series.

                  I wouldn't be able to comment on the line not showing up, that is a user created script so I would have no knowledge of how it works. When you call an indicator from a strategy it won't show up so if you were expecting it to be added to the chart it wont be. You can try using AddChartIndicator to add it visually to see if that helps.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    ok
                    I added indicator
                    I have line
                    AddDataSeries(Instrument.FullName, BarsPeriodType.Day, 1, "CME US Index Futures RTH", false);
                    its complaining on that line.
                    Click image for larger version  Name:	image.png Views:	0 Size:	134.2 KB ID:	1238233​If i keep previous line
                    AddDataSeries(Instrument.FullName, new BarsPeriod { BarsPeriodType = BarsPeriodType.Day, Value = 1 }, "CME US Index Futures RTH", false);
                    i get Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

                    I wish there would be native settlement lines indicator that we could use in our strategies with less issues.
                    Last edited by tkaboris; 03-06-2023, 12:19 PM.

                    Comment


                      #11
                      Hello tkaboris,

                      The code that you are trying to use won't work right, this is mentioned in the AddDataSeries help guide page:

                      Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided.


                      If you want to specify the instrument you need to specify the instrument name as text like "ES 03-23". That or you can use one of the overrides which does not take an instrument meaning it uses the same instrument as the strategy has for the primary.

                      The errors you pictured are because the incorrect arguments are being used with AddDataSeries.

                      To add the series the indicator asked for you can just use the following override:

                      AddDataSeries(BarsPeriodType periodType, int period)
                      which is:

                      Code:
                      AddDataSeries(BarsPeriodType.Day, 1);
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        HI strategy compiles but is not getting enabled.
                        if i remove this then i am able to enable it but its not working.. Could there be any more solution?
                        mySetLines = SettlementLines(Close, @"CME US Index Futures RTH");

                        Comment


                          #13
                          Hello tkaboris,

                          If the strategy does not enable that is likely because its having a runtime error. You can check the log or NinjaScript output window to check if its having an error when you try to enable it.
                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            Yes its showing this error in output
                            SettlementLines' tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state. Attempted to load ES 03-23 Globex: Daily

                            However i have these in my code
                            private SettlementLines mySetLines;

                            else if (State == State.Configure)
                            {
                            AddDataSeries(Data.BarsPeriodType.Tick, 1);

                            AddDataSeries(BarsPeriodType.Day, 1);
                            }
                            else if (State == State.DataLoaded)
                            {
                            {
                            ClearOutputWindow(); //Clears Output window every time strategy is enabled
                            }


                            mySetLines = SettlementLines(Close, @"CME US Index Futures RTH");​
                            AddChartIndicator(mySetLines);

                            Comment


                              #15
                              Hello tkaboris,

                              You would need to look in the code for that indicator and make sure you are using the exact same data that it tried to load inside your strategy. If using AddDataSeries(BarsPeriodType.Day, 1); is not correct you will need to review the indicators code to see what it used.
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Jonafare, 12-06-2012, 03:48 PM
                              5 responses
                              3,984 views
                              0 likes
                              Last Post rene69851  
                              Started by Fitspressorest, Today, 01:38 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post Fitspressorest  
                              Started by Jonker, Today, 01:19 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post Jonker
                              by Jonker
                               
                              Started by futtrader, Today, 01:16 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post futtrader  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              14 responses
                              1,791 views
                              0 likes
                              Last Post aligator  
                              Working...
                              X