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
help getting this to a second
Collapse
X
-
Hello fgs092790,
Thanks for your post.
I do not see where you are calling AddDataSeries() in the script you shared to add a 1-second data series to the script for calculations.
Something you could consider trying is calling AddDataSeries() in the script to add a 1-second data series. Then, create a condition that checks if BarsInProgress == 1 and assign your calculated values to the plots. By doing so, each time the added 1-second series is processed, the plots would be assigned a value.
Note that it would ultimately be up to your to come up with the specific custom logic in the script to accomplish your overall goal.
See the help guide documentation below for more information.
AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
BarsInProgress: https://ninjatrader.com/support/help...inprogress.htmBrandon H.NinjaTrader Customer Service
-
hi thanks for your quick response this is what I try to do but I don't know what I'm doing wrong.
namespace NinjaTrader.NinjaScript.Indicators
{
public class SampleGetHighLowByTimeRange : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Determines the highest high and lowest low in a specified time range";
Name = "Sample get high low by time range";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
StartHour = 9;
StartMinute = 30;
StartSeconds = 00;
EndHour = 09;
EndMinute = 30;
EndSeconds = 15;
AddPlot(Brushes.Green, "HighestHigh");
AddPlot(Brushes.Red, "LowestLow");
}
else if (State == State.Configure)
{
AddDataSeries(BarsPeriodType.Second, 1); //AddDataSeries(BarsPeriodType.Minute, 1);
}
}
private DateTime startDateTime;
private DateTime endDateTime;
protected override void OnBarUpdate()
{
// Check to make sure the end time is not earlier than the start time
if(BarsInProgress == 1)
{
if (EndHour < StartHour)
return;
// Do not calculate the high or low value when the ending time of the desired range is less than the current time of the bar being processed
if (ToTime(EndHour,EndMinute,0) > ToTime(Time[0]))
return;
// If the stored date time date is not the same date as the bar time date, create a new DateTime object
if (startDateTime.Date != Time[0].Date)
{
startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, StartHour, StartMinute, StartSeconds);
endDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, EndHour, EndMinute, EndSeconds);
}
// Calculate the number of bars ago for the start and end bars of the specified time range
int startBarsAgo = Bars.GetBar(startDateTime);
int endBarsAgo = Bars.GetBar(endDateTime);
/* Now that we have the start and end bars ago values for the specified time range we can calculate the highest high for this range
Note: We add 1 to the period range for MAX and MIN to compensate for the difference between "period" logic and "bars ago" logic.
"Period" logic means exactly how many bars you want to check including the current bar.
"Bars ago" logic means how many bars we are going to go backwards. The current bar is not counted because on that bar we aren't going back any bars so it would be "bars ago = 0" */
double highestHigh = MAX(High, endBarsAgo - startBarsAgo + 1)[CurrentBar - endBarsAgo];
// Now that we have the start and end bars ago values for the specified time range we can calculate the lowest low for this range
double lowestLow = MIN(Low, endBarsAgo - startBarsAgo + 1)[CurrentBar - endBarsAgo];
// Set the plot values
HighestHigh[0] = highestHigh;
LowestLow[0] = lowestLow;
}}
Comment
-
Hello fgs092790,
Thanks for your notes.
What exactly is not working when running the script?
Are you seeing any error messages appear in the Log tab of the Control Center? If so, what exactly does the error message state?
If a script is not behaving as expected then debugging steps should be taken to understand exactly how your logic is behaving. Prints should be added to the script that print out all the values being used for your logic is understand how it is evaluating.
Below is a link to a forum post that demonstrates how to use prints to understand behavior.
https://ninjatrader.com/support/foru...121#post791121
You may also want to review this help guide documentation about working with Multi-timeframe/Multi-Instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.htm
Brandon H.NinjaTrader Customer Service
Comment
-
Hello fgs092790,
Thanks for your notes.
If the plots are not behaving as expected, it is necessary to debug your script by adding prints to the script that print out all the information being used for your logic to see how your custom logic is evaluating and behaving.
In the script add prints that print out all the values being used for your logic so you could understand how it is behaving.
Prints will appear in a New > NinjaScript Output window.
Below is a link to a forum post that demonstrates how to use prints to understand behavior.
https://ninjatrader.com/support/foru...121#post791121
When debugging and testing the script, ensure to keep an eye on the Log tab of the Control Center for any errors that may appear.Brandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Shai Samuel, 07-02-2022, 02:46 PM
|
4 responses
93 views
0 likes
|
Last Post
by Bidder
Today, 12:11 AM
|
||
Started by DJ888, Yesterday, 10:57 PM
|
0 responses
6 views
0 likes
|
Last Post
by DJ888
Yesterday, 10:57 PM
|
||
Started by MacDad, 02-25-2024, 11:48 PM
|
7 responses
158 views
0 likes
|
Last Post Yesterday, 10:23 PM | ||
Started by Belfortbucks, Yesterday, 09:29 PM
|
0 responses
7 views
0 likes
|
Last Post
by Belfortbucks
Yesterday, 09:29 PM
|
||
Started by zstheorist, Yesterday, 07:52 PM
|
0 responses
7 views
0 likes
|
Last Post
by zstheorist
Yesterday, 07:52 PM
|
Comment