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

Frustrated!!

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

    Frustrated!!

    Hi, I have spent hours on coding what seems a very simple indicator, and have tried various ways to make it work but have only ended up totally frustrated. So far nothing at all has printed on the chart.
    What I am trying to achieve is a trend indicator that appears in it's own panel under the price panel. It is just a straight line that changes colour as prescribed by the code for 3 different conditions. Being Bull, Bear, or Flat. The line is to be dots, I want it to be straight, not to rise & fall with price. I have used a plot so I can get the dots.
    I have uploaded the file so you can open it and inspect, to be able to advise me accurately.
    You will see some of the other things I tried, commented out. It compiles, but doesn't work.
    The main issue is likely with this line, as I really don't understand it, it's too advanced for me......emaAngle = Math.Atan(emaSlope) * 180 / Math.PI;
    Look fwd to your reply.
    Cheers,
    Ken.
    Attached Files

    #2
    Hello KennyK,

    Thanks for your post.

    When a ninjscript compiles but does not appear on the chart one of the tools you can use is to look at the "log" tab of the control center and I recommend that you always have this open while adding a new indicator to a chart. On my end, the log shows the error, "A hosted indicator tried to load additional data...". In looking at the code you have two lines in State.Configure that should be moved to the OnBarUpdate() as the first line is trying to calculate an EMA slope on data that does not exist yet. The second line calculates based on the first line. These lines can be moved below your CurrentBar check.

    The code does not provide a value for the plot to be plotted at. As you want the plot to be at zero then you will need to add:

    Trend[0] = 0.0; // set the plot for the value of zero.

    As discussed in another thread, you are ending the if(conditions) with a ";" and need to remove the ";" from the end of each if statement in order for the line following the if statement to be actioned when the if statement is true.

    PlotBrushes[0][0] is the correct way to change the individual elements of the plot.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Done but still need help.

      Originally posted by NinjaTrader_Paul View Post
      Hello KennyK,

      Thanks for your post.

      When a ninjscript compiles but does not appear on the chart one of the tools you can use is to look at the "log" tab of the control center and I recommend that you always have this open while adding a new indicator to a chart. On my end, the log shows the error, "A hosted indicator tried to load additional data...". In looking at the code you have two lines in State.Configure that should be moved to the OnBarUpdate() as the first line is trying to calculate an EMA slope on data that does not exist yet. The second line calculates based on the first line. These lines can be moved below your CurrentBar check.
      Moved them which fixed that and thanks for the explanation.

      The code does not provide a value for the plot to be plotted at. As you want the plot to be at zero then you will need to add:

      Trend[0] = 0.0; // set the plot for the value of zero.
      Wasn't sure where this went so tried "onStateConfigure", didn't work,
      so swapped it to "onBarUpdate", seems to be happy there.


      As discussed in another thread, you are ending the if(conditions) with a ";" and need to remove the ";" from the end of each if statement in order for the line following the if statement to be actioned when the if statement is true.
      Yes, I was aware of that, but it was giving errors without the semi colon.
      Due to other code being in the wrong place I guess?


      PlotBrushes[0][0] is the correct way to change the individual elements of the plot.
      Cool.

      I have attached a screen shot of the indicator which is now printing to the screen, it's just not changing color as I expect. I have attached the revised code for you to inspect. I am guessing it is to do with the BullAngle and BearAngle values?
      I was only guessing with them, but in english, BullAngle 30 means the angle is 30 degrees up from 3 o'clock, and BearAngle 60 would be 30 degrees down from 3 o'clock..
      Actually if 12 o'clock is zero BullAngle should be 60 and BearAngle 120. I will give that a go. Tried it, didn't work. Still only seeing all red dots.
      Attached Files
      Last edited by KennyK; 09-12-2017, 01:05 AM. Reason: add something

      Comment


        #4
        Originally posted by KennyK View Post
        Cool.

        I have attached a screen shot of the indicator which is now printing to the screen, it's just not changing color as I expect. I have attached the revised code for you to inspect. I am guessing it is to do with the BullAngle and BearAngle values?
        I was only guessing with them, but in english, BullAngle 30 means the angle is 30 degrees up from 3 o'clock, and BearAngle 60 would be 30 degrees down from 3 o'clock..
        Actually if 12 o'clock is zero BullAngle should be 60 and BearAngle 120. I will give that a go. Tried it, didn't work. Still only seeing all red dots.
        As the slope of a line drawn on variable axes, that are not identically dimensioned, is visually meaningless, you will have to Print() out the values of your triggers to see whether those values are valid for changing your colors.

        Comment


          #5
          Hello KennyK,

          Thanks for your reply.

          Recommend that you divide the slope by the TickSize to obtain a relevant value:

          emaSlope = (Slope(EMA(Period),Lookback,EndBar) / TickSize);

          The "angle" will be 0 for horizontal and upto 90 for up and -90 for down so you may want to adjust your definitions of bear. Note: You may need to adjust the minimum range to allow for a negative angle.

          On Line 82 you have a ";" at the end of the if statement which is causing all of your dots to be red. Remove the ";" for the condition statement to work on the PlotBrush.

          If you want to provide publicly changeable brushes, you will need to serialize them, please see: http://ninjatrader.com/support/forum...ead.php?t=4977

          As member Koganam advises, the angle can be deceiving depending on the view of the chart (IE: expand or contract the horizontal scale and your perception of the angles would change).
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Paul View Post
            Hello KennyK,

            Thanks for your reply.

            Recommend that you divide the slope by the TickSize to obtain a relevant value:

            emaSlope = (Slope(EMA(Period),Lookback,EndBar) / TickSize);
            Ok, done.

            The "angle" will be 0 for horizontal and upto 90 for up and -90 for down so you may want to adjust your definitions of bear. Done.Note: You may need to adjust the minimum range to allow for a negative angle. This I think I understand having got an error, (as attached), without doing it, but don't know how to?
            Can you please explain?


            On Line 82 you have a ";" at the end of the if statement which is causing all of your dots to be red. Remove the ";" for the condition statement to work on the PlotBrush.
            Yep, I keep doing it, don't I, I will keep a good eye on that in the future!
            Done.


            If you want to provide publicly changeable brushes, you will need to serialize them, please see: http://ninjatrader.com/support/forum...ead.php?t=4977
            Will concern myself with that, maybe, once the indicator is working.

            As member Koganam advises, the angle can be deceiving depending on the view of the chart (IE: expand or contract the horizontal scale and your perception of the angles would change).
            Understood, but the angles still stay relevant to price. Meaning adjust either axis and both the angle and the angle of price change by the same amount, unless I am mistaken? So the degree of angle prescribed in my code is not fixed, but will visually change in the same way. This is what I would expect.
            Attached Files
            Last edited by KennyK; 09-12-2017, 04:19 PM. Reason: Forgot attachment

            Comment


              #7
              Got the range sorted

              Hi Paul,
              I worked out how to change the range, it's working now.
              Thanks you, your the man!
              Will reply back if there are any further queries.

              Comment


                #8
                Originally posted by KennyK View Post
                Understood, but the angles still stay relevant to price. Meaning adjust either axis and both the angle and the angle of price change by the same amount, unless I am mistaken? So the degree of angle prescribed in my code is not fixed, but will visually change in the same way. This is what I would expect.
                1. I said that the angle is visually meaningless. The slope value remains the same, sure.
                2. As far as the new error that you have shown, you have these as your properties:
                Code:
                        [NinjaScriptProperty]
                        [COLOR=blue][Range(1, int.MaxValue)][/COLOR]
                        [Display(Name="BullAngle", Description="BullTrendSlope", Order=3, GroupName="Parameters")]
                        public int BullAngle
                        { get; set; }
                
                        [NinjaScriptProperty]
                        [COLOR=blue][Range(1, int.MaxValue)][/COLOR]
                        [Display(Name="BearAngle", Description="BearTrendSlope", Order=4, GroupName="Parameters")]
                        public int BearAngle
                        { get; set; }
                You have specified that the values should never be less than one. Remove the Range restriction.

                Comment


                  #9
                  Thanks koganam, appreciate your help.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Radano, 06-10-2021, 01:40 AM
                  19 responses
                  606 views
                  0 likes
                  Last Post Radano
                  by Radano
                   
                  Started by KenneGaray, Today, 03:48 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post KenneGaray  
                  Started by thanajo, 05-04-2021, 02:11 AM
                  4 responses
                  470 views
                  0 likes
                  Last Post tradingnasdaqprueba  
                  Started by aa731, Today, 02:54 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post aa731
                  by aa731
                   
                  Started by Christopher_R, Today, 12:29 AM
                  0 responses
                  11 views
                  0 likes
                  Last Post Christopher_R  
                  Working...
                  X