Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Indicator to count bars?
Collapse
X
-
Indicator to count bars?
I'm looking for an indicator that keeps a running total of bullish and bearish bars for x period. On a given chart there were 15 bullish candles and 12 bearish candles if that makes sense. Has anyone ever seen an indicator like this before? I looked everywhere but couldn't find anything. Thanks! -
Hello Hando311,
Welcome to our forums.
I'm not familiar with this by name or concept but it should be pretty easy to implement with custom programming.
Here are some questions to consider if you plan to program it:
How are bullish and bearish candles defined?
Are there two lines? (one for counting bullish, the other bearish)
Is this a running total of all bars on the chart or does it reset every session?Ryan M.NinjaTrader Customer Service
-
Hello, im trying to count the last 50 bullish candles and this is what i got so far, but i think there is is something wrong, a little help please?
{
if (Close[0] < Close[50] )
{
if ( Close[0] > Open[0] )
UpCandles = UpCandles +1;
else
UpCandles = UpCandles;
}
else
UpCandles = 0;
}
Comment
-
Ryan; i dont think this is the key (maybe i don't understand it well) but what i need is to know what code should i use to "look-back 50 bars " and start counting from there .
if the bar is bullish then : 1,2,3,4, etc , if its bearish (inside the 50 period bar) then = keep the last count
and start adding again if the next bar is also bullish
Bull - Bull - Bull - Bull - Bull - Bear - Bear - Bear - Bull - Bull
1 2 3 4 5 5 5 5 6 7
etc,
i got the rest done ( i think , he) but how do i tell the script to start the count from the last 50 periods back?
thank you
Comment
-
Countif() has a lookback component and it returns the number of occurrences that the test condition you specify is true within this lookback. The example in the help guide uses a very similar condition to what you're looking for:
if (CountIf(delegate {return Close[0] > Open[0];}, 10) > 8)
EnterLong();Ryan M.NinjaTrader Customer Service
Comment
-
-
Just work with the value returned by the method. Try printing this and checking outputwindow:
if (CurrentBar > 50)
Print(CountIf(delegate {return Close[0] > Open[0];}, 50));
It returns the number of times over the last 50 bars that the close is greater than open.Ryan M.NinjaTrader Customer Service
Comment
-
Countif already does the counting for you. How you use the value returned by it is up to you.
If you have limited time or programming experience but have some ideas for an indicator you would like to see developed, please consider working with one of our 3rd party NinjaScript consultants:
Ryan M.NinjaTrader Customer Service
Comment
-
That's a great attitude, and we're happy to see it and help you along. Try with simple approaches, printing values like shown in the post earlier. See here for additional help using Print() to debug your script:
CountIf is a long expression, so assigning its value to a double variable could make working with it easier.
These introductory tutorials are good for the structure and basics of developing indicators:
Ryan M.NinjaTrader Customer Service
- Likes 1
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by GussJ, 03-04-2020, 03:11 PM
|
11 responses
3,228 views
0 likes
|
Last Post Today, 08:07 PM | ||
Started by andrewtrades, Today, 04:57 PM
|
1 response
13 views
0 likes
|
Last Post Today, 05:02 PM | ||
Started by chbruno, Today, 04:10 PM
|
0 responses
7 views
0 likes
|
Last Post
by chbruno
Today, 04:10 PM
|
||
Started by josh18955, 03-25-2023, 11:16 AM
|
6 responses
440 views
0 likes
|
Last Post
by Delerium
Today, 03:42 PM
|
||
Started by FAQtrader, Today, 03:35 PM
|
0 responses
12 views
0 likes
|
Last Post
by FAQtrader
Today, 03:35 PM
|
Comment