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
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
-
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.Emily C.NinjaTrader Customer Service
-
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.Emily C.NinjaTrader Customer Service
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.Emily C.NinjaTrader Customer Service
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.Emily C.NinjaTrader Customer Service
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.
JesseNinjaTrader Customer Service
- Likes 1
Comment
-
Thank you for your reply.
I am replicating the example of the link you provided to run a test, adding
public double MyTestValue
{
get; set;
}
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:
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 geddyisodin, Today, 05:20 AM
|
0 responses
3 views
0 likes
|
Last Post
by geddyisodin
Today, 05:20 AM
|
||
Started by JonesJoker, 04-22-2024, 12:23 PM
|
6 responses
32 views
0 likes
|
Last Post
by JonesJoker
Today, 05:14 AM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
12 responses
3,239 views
0 likes
|
Last Post
by Leafcutter
Today, 05:08 AM
|
||
Hi
by AveryFlynn
Started by AveryFlynn, Today, 04:57 AM
|
0 responses
5 views
0 likes
|
Last Post
by AveryFlynn
Today, 04:57 AM
|
||
Started by RubenCazorla, 08-30-2022, 06:36 AM
|
3 responses
79 views
0 likes
|
Last Post
by PaulMohn
Today, 04:44 AM
|
Comment