• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ray line programmer

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

    Ray line programmer

    Hi,

    I'm looking to draw a ray line on the high, between a specific time frame every day. Can anyone please recommend me someone who can create it, since there's big selection on the ninjatrader script consultants. Thanks

    #2
    Thank you for your question Bdg820. The code you are describing is simple enough we can create an educational sample out of two pieces of code in the help guide.

    On the ToTime page we find

    Code:
    
    // http://ninjatrader.com/support/helpGuides/nt8/en-us/totime.htm
    // Only trade between 7:45 AM and 1:45 PM
    if (ToTime(Time[0]) >= 74500 && ToTime(Time[0]) <= 134500)
    {
        // Strategy logic goes here
    }
    In Draw.Ray we find

    Code:
    
    // http://ninjatrader.com/support/helpGuides/nt8/en-us/draw_ray.htm
    // Draws a lime green ray from 10 bars back through the current bar
    Draw.Ray(this, "tag1", 10, 1000, 0, 1001, Brushes.LimeGreen);
    Putting our Draw.Ray code inside our time filter code gives us

    Code:
    
    if (ToTime(Time[0]) >= 74500 && ToTime(Time[0]) <= 134500)
    {
        Draw.Ray(this, "tag1", 10, 1000, 0, 1001, Brushes.LimeGreen);
    }
    Once we have this, the next step will be to set up input times. We can generate time input code with the New -> Strategy Builder, on the Inputs and Variables page, by pressing Add in the Inputs section. I have done so and have received the following example code when I later unlocked my code.


    Code:
            #region Properties
            [NinjaScriptProperty]
            [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
            [Display(ResourceType = typeof(Custom.Resource), Name="StartTime", Order=1, GroupName="NinjaScriptStrategyParameters")]
            public DateTime StartTime
            { get; set; }
    
            [NinjaScriptProperty]
            [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
            [Display(ResourceType = typeof(Custom.Resource), Name="EndTime", Order=2, GroupName="NinjaScriptStrategyParameters")]
            public DateTime EndTime
            { get; set; }
            #endregion

    Finally, we can use these variables in our code sample from earlier :


    Code:
    if (ToTime(Time[0]) >= ToTime(StartTime) && ToTime(Time[0]) <= ToTime(EndTime) && StartTime < EndTime)
    {
        // http://ninjatrader.com/support/helpGuides/nt8/en-us/getbar.htm
    
        // Draw.Ray(NinjaScriptBase owner, string tag, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush)
        Draw.Ray(this, "tag1", StartTime, High[CurrentBar - Bars.GetBar(StartTime)], EndTime, High[CurrentBar - Bars.GetBar(EndTime)], Brushes.LimeGreen);
    }

    Please let us know if there are any questions we can answer, or if any questions come up using this educational sample in your own code.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Hi Jessica,

      Is it possible for you to send me the code as a attachment for the Ray line with time. Thanks

      Comment


        #4
        While the code I gave you previously is more flexible, since you would like a complete code solution, I must provide a context for this code, and so I needed to make the following modifications to, for example, make sure all our indexes were valid in both historical and live processing, and so you'd see results right away if you tried to run this. I recommend using the solution provided in the post rather than that in the provided sample for this reason in your own code. However, this will contain additional information on setting up custom DateTime objects so that the year, month, and day match the currently processed ymd, while still using a user specified hour, minute, and second (hms).

        Code:
        
                protected override void OnBarUpdate()
                {
                    int StartBar = CurrentBar - Bars.GetBar ( new DateTime (
                        Time[0].Year, Time[0].Month, Time[0].Day
                        ,StartTime.Hour, StartTime.Minute, StartTime.Second
                        ));
                    int EndBar   = CurrentBar - Bars.GetBar ( new DateTime (
                        Time[0].Year, Time[0].Month, Time[0].Day
                        ,EndTime.Hour,   EndTime.Minute,   EndTime.Second
                        ));
        
                    if (StartBar < 0)
                    {
                        StartBar = 0;
                    }
                    if (EndBar < 0)
                    {
                        EndBar = 0;
                    }
        
                    // http://ninjatrader.com/support/helpGuides/nt8/en-us/totime.htm
                    if (ToTime(Time[0]) >= ToTime(StartTime) && ToTime(Time[0]) <= ToTime(EndTime) && StartTime < EndTime)
                    {
                        // http://ninjatrader.com/support/helpGuides/nt8/en-us/draw_ray.htm
                        // http://ninjatrader.com/support/helpGuides/nt8/en-us/getbar.htm
                        // Draw.Ray(NinjaScriptBase owner, string tag, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush)
                        Draw.Ray(this, "tag1" + CurrentBar, StartBar, High[StartBar], EndBar, High[EndBar], Brushes.LimeGreen);
                    }
                }
        Code samples we provide are for educational purposes, and are not intended for live trading, and are not guaranteed to accomplish any user goal or to be maintained.
        Attached Files
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Hi Jessica,

          Thanks for the code, but I'm having problems with it, it's plotting a lot of Ray lines, is it possible for it to plot only 1 high horizontal line between TWO timeframes. Thanks

          Comment


            #6
            While this is possible Bdg820, code samples we provide are for educational purposes, and are not intended for live trading, and are not guaranteed to accomplish any user goal or to be maintained. Since the provided samples already demonstrates all the concepts needed to create the indicator you described, and it is easy to modify the code to meet your exact specifications, I will leave this code up so that a member of the community can assist further if they so choose. Please let us know if there are any other ways we can help.
            Jessica P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Atilla, Today, 04:05 PM
            0 responses
            6 views
            0 likes
            Last Post Atilla
            by Atilla
             
            Started by Displacer, Today, 02:57 PM
            2 responses
            13 views
            0 likes
            Last Post Displacer  
            Started by SAILIKITY, 05-22-2019, 05:41 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Started by rmillar, 01-09-2019, 06:02 PM
            6 responses
            71 views
            1 like
            Last Post eDanny
            by eDanny
             
            Started by mlarocco, Today, 11:39 AM
            4 responses
            23 views
            0 likes
            Last Post mlarocco  
            Working...
            X