Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

can't run this Simple code-2

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

    #16
    Ok Great. Two more questions and I am done.
    1-How can I duplicate the codes of a strategy and save it with a different name? (This comes in handy when a rather long strategy is created.)
    2-How can a strategy be created when conditions are multiple time values (all listed in the condition window) but action is single and is to draw verticle lines at each of those time values? (This is the reverse of the codes I have sent you ).

    Comment


      #17
      1. Bring up the Wizard, change the name on the page, finish up the wizard, you should have a second copy.

      2. Put them into different Sets.
      Josh P.NinjaTrader Customer Service

      Comment


        #18
        There are too many of them to put in ten sets. Any other ideas?

        Comment


          #19
          You will have to go into the Editor than and program it by hand.
          Josh P.NinjaTrader Customer Service

          Comment


            #20
            Any links regarding information on Ninja script language? I know a bit of VBA but Ninja seems different.

            Comment


              #21
              The Help Guide has the most conclusive information on NinjaScript. You can also see the reference samples and tips sections of the forums for some help too.
              Josh P.NinjaTrader Customer Service

              Comment


                #22
                Hi there, I am trying to construct a ray to be drawn from the high of a bar. But the problem is when constructing a ray via the wizard , I don't get an option for style of the line or its' width so I have to unlock the startegy (which make it unaccessable via the wizard next time around) then I save the changes . But when I try to run the startegy many times the startegy doesn't run at all and sometimes when it runs there are no changes to the original ray line.i.e. the style and width of the line has not changed.
                1-Please tell me what is wrong with the code below ?
                2- How can I define the style and width of line via the wizard?
                Thank you.
                // Condition set 1
                if (ToTime(Time[0]) == ToTime(14, 15, 0))
                {
                DrawRay(
                "My ray" + CurrentBar, 1, High[0], 0, High[0], Color.Blue, DashStyle.DashDot, int.MinValue);
                }

                Comment


                  #23
                  That is correct. You cannot make these changes from the Strategy Wizard.

                  The code you are using is improper syntaxing:

                  DrawRay(string tag, bool autoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Color color, DashStyle dashStyle, int width)

                  You are missing the autoScale parameter. You need to set that to either true or false.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #24
                    Anotherwords all I have to do with the code I sent you is to insert True or False where "CurrentBar " is . right? So what happens with CurrentBar? What is meant by auto scale anyways?

                    Comment


                      #25
                      No, you need to reparameterize your code:

                      DrawRay("My ray" + CurrentBar, true, 1, High[0], 0, High[0], Color.Blue, DashStyle.DashDot, int.MinValue);
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #26
                        I edited my code just like you said but there is no change in the drawn line.
                        So I started a new strategy and created the code with the wizard then unlocked it and edited it as you said. Here is the complete code but it doesn't work.Can you please check it on a chart yourself?

                        #region Using declarations
                        using System;
                        using System.ComponentModel;
                        using System.Diagnostics;
                        using System.Drawing;
                        using System.Drawing.Drawing2D;
                        using System.Xml.Serialization;
                        using NinjaTrader.Cbi;
                        using NinjaTrader.Data;
                        using NinjaTrader.Indicator;
                        using NinjaTrader.Gui.Chart;
                        using NinjaTrader.Strategy;
                        #endregion
                        // This namespace holds all strategies and is required. Do not change it.
                        namespace NinjaTrader.Strategy
                        {
                        ///<summary>
                        /// Enter the description of your strategy here
                        ///</summary>
                        [Description("Enter the description of your strategy here")]
                        publicclass ray2 : Strategy
                        {
                        #region Variables
                        // Wizard generated variables
                        // User defined variables (add any user defined variables below)
                        #endregion
                        ///<summary>
                        /// This method is used to configure the strategy and is called once before any strategy method is called.
                        ///</summary>
                        protectedoverridevoid Initialize()
                        {
                        CalculateOnBarClose =
                        true;
                        }
                        ///<summary>
                        /// Called on each bar update event (incoming tick)
                        ///</summary>
                        protectedoverridevoid OnBarUpdate()
                        {
                        // Condition set 1
                        if (ToTime(Time[0]) == ToTime(15, 22, 0))
                        {
                        DrawRay(
                        "My ray" + CurrentBar, true, 1, High[0], 0, High[0], Color.HotPink, DashStyle.DashDotDot, int.MinValue);
                        }
                        }
                        #region Properties
                        #endregion
                        }
                        }

                        Comment


                          #27
                          How are you figuring it doesn't work? You have to run your strategy from a chart not from the strategies tab if you want to see it plot. You also need a bar with the exact timestamp of 3:22 PM.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #28
                            It is 3:51pm right now. So obviously I have a bar stamped 3:22pm on my 1 min chart already. and when I run it it does show up on that bar but it is not a dashed line it is a solid line.
                            Now if you mean I have to right click on a the chart and click on Strategies and then pick the right strategy from the list , I have done that too.I s this what you mean by running it from the chart?
                            Have you run it yourself yet to see what I mean?

                            Comment


                              #29
                              Your problem is this "int.MinValue". Please use a real number like 1 or 2 for the width.
                              Josh P.NinjaTrader Customer Service

                              Comment


                                #30
                                ok thanks. I got it.
                                One more thing . Since I can't arm these lines to place orders when they are hit, I have to do it manually myself but the problem is that I can't run a strategy and the chart trader at the same time. why is that? and what can be done?

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by cmoran13, Yesterday, 01:02 PM
                                0 responses
                                30 views
                                0 likes
                                Last Post cmoran13  
                                Started by PaulMohn, 04-10-2026, 11:11 AM
                                0 responses
                                22 views
                                0 likes
                                Last Post PaulMohn  
                                Started by CarlTrading, 03-31-2026, 09:41 PM
                                1 response
                                160 views
                                1 like
                                Last Post NinjaTrader_ChelseaB  
                                Started by CarlTrading, 04-01-2026, 02:41 AM
                                0 responses
                                95 views
                                1 like
                                Last Post CarlTrading  
                                Started by CaptainJack, 03-31-2026, 11:44 PM
                                0 responses
                                148 views
                                2 likes
                                Last Post CaptainJack  
                                Working...
                                X