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

TrendLine indicator

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

    TrendLine indicator

    Hi I have a few questions regarding creating a new indicator. I want to create some sort of automating trend channel indicator.

    - Firstly, I was wondering what would be the best approach, and would it be possible to import ML.NET for machine learning into the indicator itself.
    - Secondly, I was wondering would there be a possible way to capture the market's volatility, such as being able to check how much point is the market up by since the yesterday market, I understand that I can access the previous bars with Close[n] and Open[n] but is there anyway that I can access the bar that's from yesterday's market close since the "n" is always changing I'm not sure how to keep it constant
    - How to check how volatile it was for the previous bar.
    - I know there is a method "CrossAbove()" that check does an indicator cross above another, I was wondering would there be any other method that can check does a High of a bar cross above a trendline object or a trend channel object?
    - If I have a trend line object, would there be any possible way to assess the trendline object's height at the current bar? such as checking does the current bar high cross above the trendline object.
    - Lastly, currently, I don't have access to my desktop(windows) and I'm using my laptop(MAC OS) to program, would it be possible if you can attach the "TrendLine Indicator" source code(indicator that is included within ninjatrader) below for me since currently, I don't have access to it. Thanks

    #2
    Hello horace chow,

    Machine Learning would be very exciting but would be far outside of what is supported by NinjaTrader.
    But I highly encourage you to explore and report back what you find.

    Tensorflow is python based and would take an extra layer to interface with c#.

    Below is a link to an educational project I found through a google search.
    .NET Standard bindings for Google's TensorFlow for developing, training and deploying Machine Learning models in C# and F#. - SciSharp/TensorFlow.NET



    The Net change display indicator included with NinjaTrader can show you how to detect the amount of change from the previous open.
    New > NinjaScript Editor > Indicators > NetChangeDisplay

    You can also write custom logic to decide what is "volatile" to you.
    The PriorDayOHLC indicator shows how to get the open, high, low, and close from the previous day.

    Crossing a drawing object requires math and checking the slope between points. Check out the alert for manually draw lines logic for NT7 to get some ideas.
    Updated 9-28-11: Used a simpler approach for horizontal lines and improved "no alert" message handling so that these messages should always be correctly removed. ========= This indicator will alert when the most recent bar crosses manually drawn lines. Works on lines, rays, horizontal lines, and extended lines. Apply the indicator to a chart and manually […]


    Once you have this down you can find intersections on any bar.

    Attached is the @TrendLines.cs file.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Would it be possible that you may attach the NetChangeDisplay indicator source code?

      Other than that, I was wondering what method does EMA use for storing the EMA data for each individual bar(EMA[1]) such as a list or linked list?

      Comment


        #4
        Hello horace chow,

        I highly recommend that you install NinjaTrader within Windows if you are going to be working with it. This way you can test scripts and you see the code of all open source indicators included with NinjaTrader.

        The EMA values are stored in a plot series. The EMA would be called as a method, and the plot will be series returned.
        https://ninjatrader.com/support/help.../nt8/value.htm
        https://ninjatrader.com/support/help...t8/seriest.htm
        https://ninjatrader.com/support/help...t8/addplot.htm
        Last edited by NinjaTrader_ChelseaB; 01-16-2023, 10:38 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi thanks for all the replies, I'm trying to create an indicator that automates the current trend line. I was wondering what would be the best strength setting for the swing if my strategies is scalping?

          Comment


            #6
            Hello horace chow,

            Our platform support team is not able to provide trading advice.

            This thread will remain open for any community members that would like to give their thoughts.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi,
              - I have noticed that on the TrendLine indicator, there is AddPlot() and Values[0][0] methods. I was wondering are these two methods available on strategies? If so, how does Values[0][0] work if I'm trying to draw a ray on the chart?
              - I was wondering does OnCalculateMinMax() run's whenever the chart sizing has been changed? would it be possible to use it on strategies?
              - Lastly, I have taken these out from the TrendLine Indicator, does any of these are not compatible with strategies?

              "
              IsOverlay = true;
              DisplayInDataBox = false;
              DrawOnPricePanel = false;
              PaintPriceMarkers = false;
              Strength = 5;
              NumberOfTrendLines = 1;
              OldTrendsOpacity = 25;
              AlertOnBreak = false;
              AlertOnBreakSound = System.IO.Path.Combine(NinjaTrader.Core.Globals.In stallDir, "sounds", "Alert2.wav");
              TrendLineHighStroke = new Stroke(Brushes.DarkCyan, 1f);
              TrendLineLowStroke = new Stroke(Brushes.Goldenrod, 1f);
              "

              Comment


                #8
                Hello horace chow,

                While it is possible to plot from a strategy, it is recommended that you plot from an indicator, which can be added to the chart with AddChartIndicator().
                https://ninjatrader.com/support/help...tegy_plots.htm
                https://ninjatrader.com/support/help..._a_ninjasc.htm

                OnCalculateMinMax() does run when the chart is resized (or scrolled). However, this is something that would be specific to indicators which can do custom rendering.
                https://ninjatrader.com/support/help...lateminmax.htm

                IsOverlay, DrawOnPricePanel are NinjaScript properties than can be used in strategies. DisplayinDataBox and PaintPriceMarkers are for indicators.
                The others are custom for that script. You can add custom variables to strategies.
                Last edited by NinjaTrader_ChelseaB; 06-28-2020, 06:10 PM.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi,

                  I've been trying to include my strategy into my chart, however it give me this error in the NinjaScript Output.

                  "Strategy 'AutoTrendChannel': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object."

                  I was wondering how can i fix it?

                  thanks,
                  horace

                  Comment


                    #10
                    Hello horace_chow,

                    You can add prints to your script to see which line of code is throwing the error. Once the line of code is identified, you can use prints to check if any objects on that line are null.
                    You can then add a check if that object is not null before calling the line of code that makes the null reference.

                    Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

                    Checking for null references - https://ninjatrader.com/support/help...references.htm

                    We look forward to assisting.
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      protected override void OnBarUpdate(){
                      Print(BarsInProgress)
                      if (BarsInProgress == 0){ //2000 Ticks Bar
                      Print("Testing 1 worked")
                      if (CurrentBar < 0){return;}
                      int swingHighBar = swing.SwingHighBar(0, 1, Strength + 1);
                      if (swingHighBar != -1){
                      double swingHighPrice = High[swingHighBar];


                      This is my code, I have tested with the print statement and the output is

                      "
                      0
                      Strategy 'AutoTrendChannel': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object.
                      "

                      I assume that the error is within the if statement checking does BarsInProgress==0, since Print("Testing 1 worked") was never displayed. I have tried multiple ways of debugging such as changing the line "if (CurrentBar < 6){return;}", but it still doesn't work.

                      I was hoping you would have more of an idea of what does this error message mean.

                      Thanks
                      Last edited by horace chow; 06-26-2020, 10:23 PM.

                      Comment


                        #12
                        I have found the error, for some reason sometimes CurrentBar == null. I was wondering in what type of condition would CurrentBar ever equal to null?

                        Comment


                          #13
                          Hello horace chow,

                          Is the State property past State.DataLoaded?

                          Are there multiple series in this script?

                          Are you certain that CurrentBar is null and not -1?

                          If you add:

                          if (CurrentBar == null)
                          {
                          Print("CurrentBar is null");
                          }

                          Do you see this print appear in the output window?

                          Can you provide a script that removes all code except for this print so that I may test and confirm this on my end?

                          To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
                          1. Click Tools -> Export -> NinjaScript...
                          2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
                          3. Click the 'Export' button
                          4. Enter a unique name for the file in the value for 'File name:'
                          5. Choose a save location -> click Save
                          6. Click OK to clear the export location message
                          By default your exported file will be in the following location:
                          • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
                          Below is a link to the help guide on Exporting NinjaScripts.
                          Chelsea B.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by PhillT, 04-19-2024, 02:16 PM
                          4 responses
                          30 views
                          0 likes
                          Last Post PhillT
                          by PhillT
                           
                          Started by ageeholdings, 05-01-2024, 05:22 AM
                          5 responses
                          36 views
                          0 likes
                          Last Post ageeholdings  
                          Started by reynoldsn, Today, 02:34 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post reynoldsn  
                          Started by nightstalker, Today, 02:05 PM
                          0 responses
                          14 views
                          0 likes
                          Last Post nightstalker  
                          Started by llanqui, Yesterday, 09:59 AM
                          8 responses
                          30 views
                          0 likes
                          Last Post llanqui
                          by llanqui
                           
                          Working...
                          X