Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Pass Value Generated from BarsType to a Strategy
Collapse
X
-
Pass Value Generated from BarsType to a Strategy
Hi, I am trying to do something similar as described in this post, but passing a value generated within a custom BarType, not from an indicator, to a strategy; adopting the same approach as described here does not work. Could you please suggest how to proceed? Thank you, MartinTags: None
-
Hello Martin,Originally posted by martin70 View PostHi, I am trying to do something similar as described in this post, but passing a value generated within a custom BarType, not from an indicator, to a strategy; adopting the same approach as described here does not work. Could you please suggest how to proceed? Thank you, Martin
Thank you for your post.
This thread is in the NinjaTrader 7 portion of the forum. Are you trying to accomplish this in NinjaTrader 8? If so, I would be glad to move your post into its own thread in the appropriate section of the forum and assist you from there. Please clarify your version of NinjaTrader, which may be found at Control Center > Help > About.
I look forward to your reply and assisting you further.
-
Hello martin70,
No worries! Thank you for clarifying; I have moved your post to its own thread in the appropriate topic.
So I may better assist you and understand if what you are describing may be achieved, please provide more details. I understand you want to pass a value generated within a custom BarType to a strategy. What kind of value are you looking to pass over to the strategy? How is this value currently being set in the BarsType script?
I appreciate your patience and look forward to your reply.
Comment
-
Hi Emily, within OnDataPoint a double value is calculated, that represents the high and low where the bar would be closed before creating a new one. I need to pass these values to the startegy in order to place stop and limit orders at those values. I want to avoid streamwriter as working on tick data. Thank you
Comment
-
Hello martin70,
Thank you for your reply.
You should be able to access the desired BarsType value by calling AddDataSeries() in your strategy and adding the custom BarsType. The following tips from the AddDataSeries() page are relevant to using a custom BarsType:2. You can add a custom BarsType which is installed on your system by casting the registered enum value for that BarsPeriodType. For example: AddDataSeries((BarsPeriodType)14, 10);https://ninjatrader.com/support/help...dataseries.htm
3. You can specify optional BarsPeriod values (such as Value2) of a custom BarsType in the BarsPeriod object initializer. For example: AddDataSeries(new BarsPeriod() { BarsPeriodType = (BarsPeriodType)14, Value = 10, Value2 = 20 });
From there, you could access the high and low from the added series using Highs and Lows and reference the proper barsSeriesIndex for the added series:- https://ninjatrader.com/support/help.../nt8/highs.htm
- https://ninjatrader.com/support/helpGuides/nt8/lows.htm
Please let me know if I may be of further assistance.
Comment
-
Hi Emily,
sorry this is not what I need. I have a double value calculated within the BarType code that needs to be passed to the strategy BEFORE highs or lows are formed. This needs probably to be done through a method, but I am not suceeding in making that happen. Thank you, Martin
Comment
-
Hello martin70,
Thank you for your reply.
Is the double being calculated in OnDataPoint() within your BarsType script? OnDataPoint() is solely used to adjust data points for your series. The reason the Update() method would not work to try and get the value is because that forces OnBarUpdate() to be called for indicator values to be updated to the current bar index. For more information regarding Update() and how it works:- https://ninjatrader.com/support/help...nt8/update.htm
- https://ninjatrader.com/support/help...nbarupdate.htm
- See the second bullet point under "Notes" regarding hosted indicators
I appreciate your patience and look forward to your reply.
Comment
-
Hi, I am coming back to an unsolved issue.
Referring to this post
I created a Series<T> within my custom BarType:
....public class MyTestBarType : BarsType
{
Series<double> mySeries;
[...
....]
protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask)
{
MyValue = CalcMyValue(bars, time); //calls method
mySeries = new Series<double>(bars, MaximumBarsLookBack.Infinite);
mySeries[0] = MyValue;
The code compiles correctly.
Where I am asking your support now is: how do I get the mySeries[0] value from outside the custom BarType script, e.g. from a strategy script?
Does this eventually work in backtest as well?
Thank you
Martin
Comment
-
Hello martin70,
You would need to use the code from this post and use the name of the public property that you made instead of the property name used in the sample.
In your code you did not define a public property so you need to fix that:
Series<double> mySeries;
needs to be
public Series<double> mySeries { :get; set; }
As long as you select the bars type in the backtest then yes that would also work there.
- Likes 1
Comment
-
Thank you for your reply.
I am replicating the example of the link you provided to run a test, adding
andpublic double MyTestValue
{
get; set;
}
in the custom BarType (I used UniRenko for the test)protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask)
{
if (high!=null && low !=null)
MyTestValue = (high+low)/2;
Then I did a Test strategy with the following:
It works well on real time, but it does not work in backtest: it is repetedly printing out the first value.protected override void OnBarUpdate()
{
NinjaTrader.NinjaScript.BarsTypes.UniRenkoBarsType testBarType = Bars.BarsType as NinjaTrader.NinjaScript.BarsTypes.UniRenkoBarsType ;
if (testBarType != null)
{
Print(testBarType.MyTestValue);
}
}
Is there a way to get this to work also in backtest?
I attach the scripts of the UniRenkoBarType with the a.m. changes ad of the Test strategy.
Thank you
Martin
Attached Files
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
600 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
347 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
558 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
558 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment