int NumBullishCandle = CountIf(delegate {return Close[0] > Open[0];}, 50);
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Indicator to count bars?
Collapse
X
-
Originally posted by kabott View Post
Code:
-
Thank you very much Koganam!!
i had this working but couldn't compare both values
DrawTextFixed("Up",CountIf(delegate {return Close[0] >Open[0];}, periods).ToString("N0"), TextPosition.TopRight ,Color.White,new Font ("Arial", 20), Color.Black, Color.Green, 10);
DrawTextFixed("Dn",CountIf(delegate {return Close[0] < Open[0];}, periods).ToString("N0"), TextPosition.BottomRight ,Color.White,new Font ("Arial", 20), Color.Black, Color.Red, 10);
now i am, thank you man!!
Comment
-
Originally posted by NinjaTrader_RyanM1 View PostYou could custom code a counter, but using built-in method CountIf() should work well for this:
http://www.ninjatrader.com/support/h...t7/countif.htm
For example I have this code
PHP Code:if (CountIf(() => High[0] - Low[0] >= 25*TickSize, 5) > 0)
{
Print("# of Bar Ranges >= 25 Ticks : " + ?);
}
What do i substitute the"?'" with?
It's supposed to means, if over the previous 5 Bars there is any (>0) bar whose range is greater or equal 25 ticks, then print the number of bars that meet that condition.
For illustration example, the Countif() would return 2 (for Bar[2] and Bar[3] below)
High[0] - Low[0] (Bar[0]) = 7 ticks
High[0] - Low[0] (Bar[1]) = 12 Ticks
High[0] - Low[0] (Bar[2) = 31 ticks
High[0] - Low[0] (Bar[3]) = 29 Ticks
High[0] - Low[0] (Bar[4]) = 21 Ticks
Thanks!
I've found a way with the Draw.FixedText method to draw it on the chart without variable declaration
PHP Code:protected override void OnBarUpdate()
{
if(CurrentBar < 5)
{
return;
}
if (CountIf(() => High[0] - Low[0] >= 25*TickSize, 5) > 0)
{
Draw.TextFixed(this, "myTextFixed", CountIf(() => High[0] - Open[0] >= 25*TickSize, 5).ToString(), TextPosition.BottomRight, ChartControl.Properties.ChartText, ChartControl.Properties.LabelFont, Brushes.Blue, Brushes.Transparent, 0);
}
}
but for the print it needs variable declaration
PHP Code:namespace NinjaTrader.NinjaScript.Indicators
{
public class up25 : Indicator
{
private string up25;
...
PHP Code:if (CountIf(() => High[0] - Low[0] >= 25*TickSize, 5) > 0)
{
up25 = CountIf(() => High[0] - Open[0] >= 25*TickSize, 5).ToString();
Print("up25 : " + up25);
}
With output
PHP Code:up25 : 2
up25 : 3
up25 : 3
up25 : 4
up25 : 4
Last edited by PaulMohn; 02-22-2022, 12:44 PM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by algospoke, 04-17-2024, 06:40 PM
|
6 responses
48 views
0 likes
|
Last Post
by algospoke
Today, 06:18 PM
|
||
Started by arvidvanstaey, Today, 02:19 PM
|
4 responses
11 views
0 likes
|
Last Post Today, 04:08 PM | ||
Started by samish18, 04-17-2024, 08:57 AM
|
16 responses
61 views
0 likes
|
Last Post
by samish18
Today, 03:30 PM
|
||
Started by jordanq2, Today, 03:10 PM
|
2 responses
9 views
0 likes
|
Last Post
by jordanq2
Today, 03:23 PM
|
||
Started by traderqz, Today, 12:06 AM
|
10 responses
19 views
0 likes
|
Last Post
by traderqz
Today, 02:49 PM
|
Comment