i want to get first green bar after red or vice-versa
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
get Reversal bar
Collapse
X
-
Hello yeshujbp,
Thanks for your post.
i want to get first green bar after red
For example, the following snippet would see if the previous candle was "red":
Code:if(Close[1]<Open[1])
Code:if(Close[0]>Open[0])
Code:if(Close[0]>Open[0] && Close[1]<Open[1])
Josh G.NinjaTrader Customer Service
- Likes 1
-
Thank you reply
That condition is run properly when i use property " Calculate=Calculate.OnBarClose" but I changed property "Calculate=Calculate.OnEachTick" That condition
if(Close[0]>Open[0] && Close[1]<Open[1]) true multi time of each tick
Any option to get signal final result of condition on Each tick.
Comment
-
Hello yeshujbp,
Thanks for your reply.
Correct, that would be the expected behavior when changing to Calculate.OnEachTick (Or Calculate.OnPriceChange). When using Calculate.OnBarClose, the reference to [0] is to the just completed bar which would not change. When using OnEachTick (Or OnPriceChange) the reference to [0] now points to the currently forming bar which is dynamically changing as each execution of your code could determine the conditions differently as the bar itself changes.
You can change the bars ago reference to evaluate just the completed bars: if(Close[1]>Open[1] && Close[2]<Open[2]) and the results would not change.
Paul H.NinjaTrader Customer Service
Comment
-
Hi
Thanks for your reply above, I have applied the logic to find reversal bar which worked, but I am facing issue when I am trying to find retracement after the reversal.
Here retracement is a temporary reversal which is not changing the trend but trade get reversed for few moments.
so we are looking to capture the retracement(Temporary reversal) moments in real time and not after the barclosed.
//this conditions for reversal
if ((Close[0] > Open[0] && Close[1] < Open[1]))
{
//below is the calculation to get 30% retracement which is used in the retracement logic to compare the value after reversal, once the value goes below this 30% retracement we are looking to //draw a DOT.
high = High[1]-Low[1];
flag = true;
per = high * 30 / 100;
comp = High[1] - per;
Draw.Dot(this, "Slave" + comp + "pre=" + per + Close[0], true, 1, Close[0], Brushes.Black);
}
//this conditions for retracement
if(flag)
{
if (Low[0] <= comp)
{
Draw.Dot(this, "S" + CurrentBar, true, 0, High[0], Brushes.Yellow);
flag=false;
}
}
Comment
-
Hello yeshujbp,
Thanks for your reply.
Glad that solution worked for you.
You did not state what you are or are not seeing with your latest post, only what you wish to do and have shown some code.
If your code is not performing as expected, we recommend debugging with print statements to print out the values being used for the conditions that determine when/if to place the dots (if that is your question). Here is a link to our debugging tips: https://ninjatrader.com/support/help...script_cod.htmPaul H.NinjaTrader Customer Service
Comment
-
Hello yeshujbp,
Thanks for your reply.
Did you consider the comments in my earlier post?, "When using OnEachTick (Or OnPriceChange) the reference to [0] now points to the currently forming bar which is dynamically changing as each execution of your code could determine the conditions differently as the bar itself changes. You can change the bars ago reference to evaluate just the completed bars: if(Close[1]>Open[1] && Close[2]<Open[2]) and the results would not change. ".
Paul H.NinjaTrader Customer Service
Comment
-
Hello yeshujbp,
Thanks for your reply.
IsFirstTickOfBar can only be true once per bar. Does your script have additional data series (added by using AdddataSetes())?
Can you post more of your complete code to better understand what you are working with?
Alternatively, if you don't want to post more of your code, you are always welcome to write into PlatformSupport[at]NinjaTrader[dot]com. Please mark the e-mail Atten: Paul and include a link to this thread for reference.
Paul H.NinjaTrader Customer Service
Comment
-
Hi
Thanks for your reply.
I am sending a script of indicator(Alert.cs) check it also send a BarType (chart) which use that indicator.my main problem is that condition true many times.Attached FilesLast edited by NinjaTrader_Jim; 07-05-2019, 06:47 AM.
Comment
-
Hello yeshujbp,
Thanks for your reply.
We removed the bars code to protect the bars source code as it appears the licensing had been bypassed.
The Bars type you are using is set up to "remove last bar" and as such IsFirstTickOfBar is always set true which confirms your observations: Reference: https://ninjatrader.com/support/help...ttickofbar.htm
As you cannot use the system's IsFirstTickOfBar, you will have to create your own logic to detect/determine when you have a new bar if you want to continue working with Calculate.OnEachTick.
As a suggestion, you may want to look at the value of Bars.Count which will usually point to 1 bar ahead so Bars.Count-1 would be the current bar (on live data). When Bars.Count changes, the first time, you could set your own bool to indicate the first tick of a new bar. Again this is something you will have to work out and test/verify. This would not work on historical data but it looks like your code is only intended for live data.
Paul H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by habeebft, Today, 07:27 AM
|
1 response
11 views
0 likes
|
Last Post Today, 08:08 AM | ||
Hi
by AveryFlynn
Started by AveryFlynn, Today, 04:57 AM
|
1 response
12 views
0 likes
|
Last Post Today, 07:57 AM | ||
Started by Max238, Today, 01:28 AM
|
4 responses
37 views
0 likes
|
Last Post
by Max238
Today, 07:49 AM
|
||
Started by r68cervera, Today, 05:29 AM
|
1 response
10 views
0 likes
|
Last Post Today, 07:47 AM | ||
Started by geddyisodin, Today, 05:20 AM
|
1 response
14 views
0 likes
|
Last Post Today, 07:38 AM |
Comment