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
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!
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
NinjaTrader
Ray line programmer
Collapse
X
-
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:[FONT=Courier New] // 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 }[/FONT]
Code:[FONT=Courier New] // 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);[/FONT]
Code:[FONT=Courier New] if (ToTime(Time[0]) >= 74500 && ToTime(Time[0]) <= 134500) { Draw.Ray(this, "tag1", 10, 1000, 0, 1001, Brushes.LimeGreen); }[/FONT]
Code:[FONT=Courier New] #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[/FONT]
Finally, we can use these variables in our code sample from earlier :
Code:[FONT=Courier New]if (ToTime(Time[0]) >= [B]ToTime(StartTime)[/B] && ToTime(Time[0]) <= [B]ToTime(EndTime) && StartTime < EndTime[/B]) {[/FONT] [FONT=Courier New][B] // http://ninjatrader.com/support/helpGuides/nt8/en-us/getbar.htm[/B] [/FONT] [FONT=Courier New][B] // Draw.Ray(NinjaScriptBase owner, string tag, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush)[/B][/FONT] [FONT=Courier New] Draw.Ray(this, "tag1", [B]StartTime[/B], [B]High[CurrentBar - Bars.GetBar(StartTime)][/B], [B]EndTime[/B], [B]High[CurrentBar - Bars.GetBar(EndTime)][/B], Brushes.LimeGreen); }[/FONT]
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
-
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:[FONT=Courier New] protected override void OnBarUpdate() {[B] int StartBar = [/B]CurrentBar - Bars.GetBar ([B] new DateTime ( Time[0].Year, Time[0].Month, Time[0].Day ,StartTime.Hour, StartTime.Minute, StartTime.Second )[/B])[B]; int EndBar = [/B]CurrentBar - Bars.GetBar ([B] new DateTime ( Time[0].Year, Time[0].Month, Time[0].Day ,EndTime.Hour, EndTime.Minute, EndTime.Second )[/B])[B]; if (StartBar < 0) { StartBar = 0; } if (EndBar < 0) { EndBar = 0; }[/B] // 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"[B] + CurrentBar[/B], [B]StartBar[/B], High[[B]StartBar[/B]], [B]EndBar[/B], High[[B]EndBar[/B]], Brushes.LimeGreen); } }[/FONT]
Attached FilesJessica P.NinjaTrader Customer Service
Comment
-
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 andrewtrades, Today, 04:57 PM
|
1 response
5 views
0 likes
|
Last Post Today, 05:02 PM | ||
Started by chbruno, Today, 04:10 PM
|
0 responses
3 views
0 likes
|
Last Post
by chbruno
Today, 04:10 PM
|
||
Started by josh18955, 03-25-2023, 11:16 AM
|
6 responses
436 views
0 likes
|
Last Post
by Delerium
Today, 03:42 PM
|
||
Started by FAQtrader, Today, 03:35 PM
|
0 responses
7 views
0 likes
|
Last Post
by FAQtrader
Today, 03:35 PM
|
||
Started by rocketman7, Today, 09:41 AM
|
5 responses
19 views
0 likes
|
Last Post Today, 03:33 PM |
Comment