Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Basic coding script questions

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

    #16
    Hello,

    NinjaTrader does not provide one however there is some c# Math functionality you can use.

    Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions.


    You can use this math class to use Math.Atan on your points you want to get degree value of and then use one of the following methods to translate that into degrees.

    A tutorial of how to do this can be found here:

    C# angles can be confusing. However knowing the proper way to convert degrees to radians and radians to degrees can make working with Math in your code a lot simpler.


    -Brett
    BrettNinjaTrader Product Management

    Comment


      #17
      Hi Brett,

      I like being able to do some basic coding as it allows me to fully customize my trade set up.

      Here is another specific question where I could do with a little help. I have this in my code:

      Add(new Plot(new Pen(Color.Red, 1), PlotStyle.Line, "MA2"));
      Plots[2].Pen.Width = 2;//HMA7

      That plots a line for an HMA7 with the color being red and a width of "2". Sofar so good. What is the line of code to add if I want to tell it to use DashStyle should be "Dash" rather than "Solid".

      sandman

      Comment


        #18
        Originally posted by sandman View Post
        Hi Brett,

        I like being able to do some basic coding as it allows me to fully customize my trade set up.

        Here is another specific question where I could do with a little help. I have this in my code:

        Add(new Plot(new Pen(Color.Red, 1), PlotStyle.Line, "MA2"));
        Plots[2].Pen.Width = 2;//HMA7

        That plots a line for an HMA7 with the color being red and a width of "2". Sofar so good. What is the line of code to add if I want to tell it to use DashStyle should be "Dash" rather than "Solid".

        sandman
        Try Plots[2].Pen.DashStyle = DashStyle.Dash;

        Comment


          #19
          Radical. Thanks!

          sandman

          Comment


            #20
            Hello Brett,

            I am doing quite ok being able to put together what I want. Here is the next point on which I would appreciate your advice.

            I use a 1/min chart, and I put together an indicator with input from a 5/min and 4/range Data Series.(A set of 2LinRegs in each needs to point in the same direction). I have done it so that it creates a background color in the 1/min chart that moment. I have set this indicator on BarClose false.

            Now, it (the background color) turns on/kicks in quite accurately whenever I need it. But it stays on even though the condition may change two minutes later (meaning one of the LinRegs now no longer points in the same direction). I would like the background color in the 1/min chart to disappear the moment the condition no longer exists. I think it's due to the 5/min input that once it draws it, it remains until that 5/min input has run its course i.e. 5 minutes later.

            Hope I am being clear enough in the description of what I want to achieve.

            Is there some piece of code to use to tell it to kind of cancel drawing the background color the moment the condition no longer exists? If so, what is that piece of code and where do I need to place it?

            sandman

            Comment


              #21
              Hello,

              Not sure exactly how you are coding this but for this to happen you would simply need to set Calculate On Bar Close to False when you apply the indicator. This way the 5 minute indicator can calculate on each new tick instead of once every 5 minutes.

              -Brett
              BrettNinjaTrader Product Management

              Comment


                #22
                Thanks Brett. Got it.

                Comment


                  #23
                  Another coding question:

                  I am using a 3rd party slope indicator which gives me a numerical value in a small box of a Moving Average, the type of which I can select myself, for example: EMA, SMA, HMA. The numerical value for the slope is in the range from around 2 up into the 80's.

                  I would like to use the numerical value which this indicator produces in a strategy. How do I go about accessing this value when I do not have access to the code of this 3rd party indicator? Is there any way to do it?

                  sandman

                  Comment


                    #24
                    sandman,

                    If the 3rd party has exposed these values, you should be able to access them through the code.

                    In the NinjaScript editor, you can type "this." which will load an intellisense box to browse through what methods that are installed that may be available for you to use.

                    For example, this.MyCustomIndicator().ACustomPlot[0];

                    Please see our Help Guide on How to access the Intellisense list box and Understanding Method Description and Signature for more information




                    Ultimately, i'd suggest checking with the 3rd party to see if you can even access their methods through your strategy.
                    MatthewNinjaTrader Product Management

                    Comment


                      #25
                      Thanks Matthew.

                      I tried it through the Intellisense list box but it does not show up in there. I will contact the 3rd party as you suggested.

                      sandman

                      Comment


                        #26
                        I would like some help with changing a line of code.

                        I have used this code to draw an up or down arrow (works nicely):

                        private void Display_Indications()
                        {
                        int Tag_Ct = CurrentBar;
                        string Tag_Strd = "iSignal" + Tag_Ct.ToString();//Print

                        ("Indication: "+bullIndication[0].ToString());

                        if (bullIndication[0] == true) {DrawArrowUp(Tag_Strd, 0, Low[0], Color.Lime); return;}

                        if (bearIndication[0] == true) {DrawArrowDown(Tag_Strd, 0, High[0], Color.Red); return;}

                        BarColor = Color.Empty;
                        return;
                        }

                        --------------

                        I changed it as follows to color the candlestick bar (also works nicely):

                        if (bullIndication[0] == true) {BarColor = upCandle_Color;CandleOutlineColor = upCandle_Color; return;}
                        if (bullIndication[0] == true) {BarColor = downCandle_Color;CandleOutlineColor = downCandle_Color; return;}

                        --------------

                        What do I have to change it to to draw a chart background color. Any help possible?

                        sandman

                        Comment


                          #27
                          Never mind. I worked it out.
                          This works just fine.
                          DrawVerticalLine(CurrentBar.ToString(),0,Color.Pal eGreen,DashStyle.Solid,3);

                          But a different, perhaps more simple, question.

                          I want to create a totally simple indicator/alert when price hits an EMA and have not been able to achieve this. I use the strategy wizard, and I tried under the left side conditions price data (High, Ask, Bid etc.) and on the right hand side EMA20. The middle part asks for cross above, cross below. I tried that. It gives me an alert alright but only when the candlestick bar is completed.

                          Do you have any pointers for me as to what I have to chose to get what I want?

                          Hope the question is clear and that you can assist.

                          sandman

                          Comment


                            #28
                            Hello,

                            You would need to change the center condition from Cross Above or Cross Below to Greater then > or Less Then < to achieve.

                            However be careful as this would trigger the alert everything time the value is higher, you would need to add in some sort of variable you would reset back to 0 when it crosses back below and then only allow the alert to sound if the variable was equal to 0.

                            -Brett
                            BrettNinjaTrader Product Management

                            Comment


                              #29
                              Thanks Brett. I get the overall idea of what you are saying though I will need to sit down and study some things to be able to turn it into practice.

                              Back to my original question. I have not resolved it fully yet. I get the Vertical Line to draw okay - but as a matter of fact a vertical line is not what I am after. I do need the chart background to be colored.

                              DrawVerticalLine(CurrentBar.ToString(),0,Color.Pal eGreen,DashStyle.Solid,3);

                              What do I need to put into this line of code so it gives me a Background color instead of the Vertical Line? I already tried DrawBackgroundColor but that does not seem to work.

                              sandman

                              Comment


                                #30
                                Originally posted by sandman View Post
                                Thanks Brett. I get the overall idea of what you are saying though I will need to sit down and study some things to be able to turn it into practice.

                                Back to my original question. I have not resolved it fully yet. I get the Vertical Line to draw okay - but as a matter of fact a vertical line is not what I am after. I do need the chart background to be colored.

                                DrawVerticalLine(CurrentBar.ToString(),0,Color.Pal eGreen,DashStyle.Solid,3);

                                What do I need to put into this line of code so it gives me a Background color instead of the Vertical Line? I already tried DrawBackgroundColor but that does not seem to work.

                                sandman
                                I doubt that DrawBackgroundColor is even a function in NT.

                                What you are looking for is BackColor. ref: http://www.ninjatrader.com/support/h...?backcolor.htm

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                672 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                379 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                111 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                577 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                582 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X