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 fx.practic, 10-15-2013, 12:53 AM
|
5 responses
5,406 views
0 likes
|
Last Post
by Bidder
Today, 12:22 AM
|
||
Started by Shai Samuel, 07-02-2022, 02:46 PM
|
4 responses
98 views
0 likes
|
Last Post
by Bidder
Today, 12:11 AM
|
||
Started by DJ888, Yesterday, 10:57 PM
|
0 responses
8 views
0 likes
|
Last Post
by DJ888
Yesterday, 10:57 PM
|
||
Started by MacDad, 02-25-2024, 11:48 PM
|
7 responses
160 views
0 likes
|
Last Post Yesterday, 10:23 PM | ||
Started by Belfortbucks, Yesterday, 09:29 PM
|
0 responses
9 views
0 likes
|
Last Post
by Belfortbucks
Yesterday, 09:29 PM
|
Comment