public enum TrendFlags { Up = 0x01, // Bit is set if trend is up, unset if trend is down Momentum = 0x02, // Bit is set if there is momentum Squeeze = 0x04, // Bit is set if there is a squeeze happening Ma = 0x08 // Bit is set if the MA direction is opposite to trend }; /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Check if there is enough bars for the periods of the indicators below if (CurrentBar < 25) return; //******************************** trend[1] = ATR(Close, 21)[0] * atrFactor; //set series trend value //******************************** double newValue = value[1]; // Default to previous value int newTrend = trend[1]; // Default to previous value // Calc some indicators double gap = ATR(Close, 21)[0] * atrFactor; bool momentum = ADX(Close, 14)[0] >= 15.0; KeltnerChannel kc = KeltnerChannel(2, 20); Bollinger bb = Bollinger(2, 24); bool squeeze = bb.Lower[0] > kc.Lower[0] && bb.Upper[0] < kc.Upper[0]; HMA hma = HMA(78); bool ma = false; if (squeeze) newTrend |= (int)TrendFlags.Squeeze; else newTrend &= ~(int)TrendFlags.Squeeze; if (momentum) newTrend |= (int)TrendFlags.Momentum; else newTrend &= ~(int)TrendFlags.Momentum; //************************* // question? what is newTrend value at this point? //************************* if (Close[0] > value[1]) { newTrend |= (int)TrendFlags.Up; // Uptrend ma = (hma[0] < hma[1]); // ma going down in uptrend? else if (Close[0] < Value[1]) { newTrend &= ~(int)TrendFlags.Up; // Its downtrend (Not a uptrend) ma = (hma[0] > hma[1]); // Ma going up in downtrend? .... if (ma) newTrend |= (int)TrendFlags.Ma; else newTrend &= ~(int)TrendFlags.Ma; //************************* // question? what is newTrend value at this point? //************************* } trend[0] = newTrend; value[0] = newValue; }
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
Bitwise operation question
Collapse
X
-
Bitwise operation question
I have no idea how bitwise going to increase or decrease a value, please see questions.
Code:Tags: None
-
Hello nkhoi,
Thank you for the post.
Without running and printing the values at the points you are asking about, I would be unsure what they may be. This would be something you would need to test and also reference a general C# bitwise operation guide online to confirm how each of the operators should work in contrast to the bits being used.
If you will be using bitwise operations this would be a good step for you to take to confirm your logic works as you expect. You can locate a lot of information on this subject at MSDN: https://msdn.microsoft.com/en-us/library/17zwb64t.aspx
or other general tutorial websites: https://www.tutorialspoint.com/cshar..._operators.htm
You can search online for "C# bitwise operation examples" for more similar sites.
I would also suggest that you add Prints into your script so you can see how your logic works as you execute it in the platform, we have a general guide to debugging here: https://ninjatrader.com/support/foru...58&postcount=1
The alternative would be to use a more simple type for the use case such as an enum that has not been assigned bits, which would just be integers. Or a simple int value would generally work best for signals.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by johnnymustard, Today, 09:52 AM
|
0 responses
1 view
0 likes
|
Last Post Today, 09:52 AM | ||
Started by SnailHorn, 03-27-2024, 09:54 AM
|
4 responses
17 views
0 likes
|
Last Post
by SnailHorn
Today, 09:19 AM
|
||
Started by ninza33, Today, 07:16 AM
|
3 responses
18 views
0 likes
|
Last Post
by ninza33
Today, 09:01 AM
|
||
Started by foxtrott21, Today, 08:27 AM
|
0 responses
4 views
0 likes
|
Last Post
by foxtrott21
Today, 08:27 AM
|
||
Started by jaypelle3, Today, 08:26 AM
|
0 responses
3 views
0 likes
|
Last Post
by jaypelle3
Today, 08:26 AM
|
Comment