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
setting a crossover within n bars form another condition
Collapse
X
-
Hello guidoisot,
Thanks for your reply.
I have attached an example of a strategy builder script that will count bars after an event. As you know math in the strategy builder is done by using "Offset". In the strategy builder offset cannot be used on user defined variables and on certain other variables such as current bar. What can be done is to create custom series which will allow you to perform math operations.
BarCounterBuilderExample_NT8.zip
in the attached example there are two custom int series, one to hold the bar number where the event occurs and the other is to hold the current bar number.
Sets 1 & 2 must be in the order provided.
Set1 initializes the custom series.
Set 2 updates the custom series, the counter gets updated with the previous bar value, the current bar series gets updated with the current bar.
There are no conditions in Set2, there is only 1 condition in set 1.
Set 3 demonstrates a crossover condition of two moving averages (and adds them to a chart), saves the current bar number into the bar counter (myCounter) and draws a color on the pane;l to indicate the bar that the cross is determined.
Set 4 Demonstrates the bar counting, the condition checks to see if the current bar counter (CBcounter) minus the event counter (myCounter) is equal 10 10 meaning 10 bars have passed, this is proven on the chart by drawing a dot 10 bars after the cross.
Here is what you would expect to see on a 1 minute chart of ES 12-19 when the strategy is applied.Last edited by NinjaTrader_ChelseaB; 10-14-2022, 01:00 PM.
- Likes 1
Leave a comment:
-
Hello Paul,
thank you for your reply.
since lineA is an indicator I will try to apply a proximity filter by replacing:
"== MAX (lineB, period m)[0])"
__with___
" >=0.99* MAX (lineB, period m)[0])"
because I would not know how to make such filter by using the price tick value of the underlying instrument.
Regarding how to store the bar number at the crossover, in order to then compare it with the current bar, do you know whether there is an example of this on another post here of the forum, maybe a similar type of question has already been asked here by someone else, or whether a similar example is considered by the ninjascript help documentation ?
One last question, do you think this storing and comparing bar numbers, would be a possible and worthwhile new feature to add to the Strategy Builder?
If it is could I ask to submit this new feature request?
Thank you,
gt
Leave a comment:
-
Hello guidoisot,
Thanks for your post.
We can certainly leave this open for any community members who may want to assist with your strategy. An alternative would be to use a 3rd party programmer and if this is of interest we can provide a link to such.
I would suggest that lineB[1] == MAX (lineB, period m)[0]) would be problematic because you are dealing with double values that rarely line up exactly. You may want to print these values out to see if that is or is not the case. If they do not line up then you may want to consider using a filter of 1 tick to see if they are aligned within 1 tick (or some other close approximation that is appropriate for the values you are working with).
When you have a cross condition, you can save the current bar number (of when the cross occurs) into an int variable and then compare the int variable to CurrentBar to see how many bars have occurred since the cross event. This would be very difficult and may not be possible in the strategy builder but can be easily done in Ninjascript.
- Likes 1
Leave a comment:
-
setting a crossover within n bars form another condition
with regard to the attached image:
Line A is an indicator
Line B is the m period MAX of line A
Line C is an average of this indicator A
Line D is another average of this indicator A
is it possible, possibly using the strategy builder, but without adding a temporary variable, to set on the condition:
line C crosses below line D within a variable n number of bars since when line B has been detaching from line A (ie: its last highest value)
I understand this last part would be a condition like:
if ((LineB[1] > LineB[0]) AND lineB[1] == MAX (lineB, period m)[0]),
but I do not see how to combine this “if” with the first part of the condition.
Any suggestion on how to get this? with or without the strategy builder?
Thanks.
Last edited by guidoisot; 11-21-2019, 05:49 AM.Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Net Change
by Segwin
Started by Segwin, 05-07-2018, 02:15 PM
|
10 responses
1,768 views
0 likes
|
Last Post
by Leafcutter
Today, 03:01 AM
|
||
Change colour of Stop market and limit orders to red and green via indicator script
by Rapine Heihei
Started by Rapine Heihei, 04-23-2024, 07:51 PM
|
2 responses
30 views
0 likes
|
Last Post
by Max238
Today, 02:25 AM
|
||
Started by Shansen, 08-30-2019, 10:18 PM
|
24 responses
943 views
0 likes
|
Last Post
by spwizard
Today, 01:29 AM
|
||
Started by Max238, Today, 01:28 AM
|
0 responses
10 views
0 likes
|
Last Post
by Max238
Today, 01:28 AM
|
||
Started by rocketman7, Today, 01:00 AM
|
0 responses
7 views
0 likes
|
Last Post
by rocketman7
Today, 01:00 AM
|
Leave a comment: