USER INPUT: N VARIABLES: HighOfCrossOver if PRICE crosses above KAMA { HighOfCrossOver = high } if within N bars { if price closes below { set HighOfCrossOver = 0 cancel all calculations } else if price closes above or equal to HighOfCrossOver { print a dot/cross at the closing price that NT DataBox can read. } }
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
Doing a calculation within N bars where N is an user
Collapse
X
-
Doing a calculation within N bars where N is an user
Hi, I saw a video where they said, you can create an strategy using strategy builder and then copy the conditions from there and put it inside of an indicator. I wanted to do that, but I got stuck at "Within N bars" I can't seem to do that using the NT strategy builder.
Code:Tags: None
-
Hello fawzanalim,
Thanks for your post.
Yes, this is a limit in the strategy builder to use a bar counter. This can be done but requires a custom series and some extra effort in the strategy builder that would not be needed in a Ninjascript.
What you would do in Ninjascript is to create an int type variable that you would save the value of CurrentBar (this is the system bar counter) when you do HighOfCrossOver = high. Then to find out within N bars you would subtract CurrentBar minus the variable to determine the number of bars.
Paul H.NinjaTrader Customer Service
-
Correct me if I'm wrong.
Code:for (i = 0; i < N, i++) { if (close of current bar > high of (currentBar - i)) print a dot at the closing price of the current bar. }
Last edited by fawzanalim; 12-03-2020, 09:07 AM.
Comment
-
The code and screenshot is here. As I'm new in this sector, I'm having so much trouble. My only hope is the NT Forum. I will be glad if you let me know where the problem is in my code.
Comment
-
Hello fawzanalim,
Thanks for your reply.
The draw code will draw one and only one dot because the tag name is the same on every dot. Each draw object must use unique tag names, if they use the same tag name then as one is drawn the previous one is removed.
The draw code will draw the dot at the value of "Entryoffset" which is set to 5, which means the one dot you could see would be drawn at a price level of 5.
I would suggest something like: Draw.Dot(this, @"KAMA3rdSetup Dot_1"+CurrentBar, false, 0, Close[0], Brushes.CornflowerBlue); // print a dot on the close of every bar that meets the conditions.
If you want to offset the dot from the bar then you could use something like: Draw.Dot(this, @"KAMA3rdSetup Dot_1"+CurrentBar, false, 0, High[0] + EntryOffset * TickSize, Brushes.CornflowerBlue); // draw the dot at Entryoffset ticks above the high of the bar
Note that I added +CurrentBar to the tag name. This creates a unique tag name and it means that all of the drawn dots will now show on the chart. CurrentBar is the systems bar counter so its number will be different for every bar.Paul H.NinjaTrader Customer Service
Comment
-
Hello fawzanalim,
In addition to the above, you also need to add the following to properly initialize the KAMA indicator in your code
else if (State == State.DataLoaded)
{
KAMA1 = KAMA(2, 10, 30); // you can apply any settings that you need for the KAMA
}
NOTE: Current your code shows:
else if (State == Sttae.Configure)
{
}
which is not used, so you can change .Configure to .DataLoaded then put the KAMA1 line between the { }
Paul H.NinjaTrader Customer Service
Comment
-
Sir, I added an custom series instead of drawing dots. But why is it not showing up in the Data Box? Can you also please include the link to NT Help Guide where I can learn in details how to add a custom series that appears in the Data Box and also how to customize the design of it. Thank you.
Comment
-
-
I tried to use amaSuperTrendU11 from Lizard Indicator. I have a folder named LizardIndicators in my Indicators list. Inside of that, I have amaSuperTrendU11. I tried to use that in my indicator, but I am having this error. Line 48 and 95 is generated using Ninja Trader Strategy Builder.
Comment
-
I did, I did that. i created the a complete logic using strategy builder. when i got error, i erased everything and kept only 2 lines. but it still giving me the error. the error log is in the drive link. i am adding it here as well.
NinjaScript File: KAMA3rdSetupInd.cs
Error: The type or namespace name 'LizardIndicators' could not be found (are you missing a using directive or an assembly reference?)
Code: CS0246
Line: 48
Column: 11
Comment
-
Hello fawzanalim,
Thanks for your reply.
Please make sure you are using the latest version of NinjaTrader 8.0.23.2. (Check under help about).
If not please update to the latest version and create a new strategy from the strategy builder accessing the same indicator.
If that does not work, or you are on the latest version, I would suggest contacting the 3rd party vendor to let them know the indicator is not working in the Strategy Builder.
Paul H.NinjaTrader Customer Service
Comment
-
How to check if today's Sunday? I actually need to know how do I get the today's day, at the moment, at my time zone. Thank you.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by andrewtrades, Today, 04:57 PM
|
1 response
5 views
0 likes
|
Last Post Today, 05:02 PM | ||
Started by chbruno, Today, 04:10 PM
|
0 responses
3 views
0 likes
|
Last Post
by chbruno
Today, 04:10 PM
|
||
Started by josh18955, 03-25-2023, 11:16 AM
|
6 responses
436 views
0 likes
|
Last Post
by Delerium
Today, 03:42 PM
|
||
Started by FAQtrader, Today, 03:35 PM
|
0 responses
7 views
0 likes
|
Last Post
by FAQtrader
Today, 03:35 PM
|
||
Started by rocketman7, Today, 09:41 AM
|
5 responses
19 views
0 likes
|
Last Post Today, 03:33 PM |
Comment