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
Simple Pivot Strategy Not Capturing All Trades
Collapse
X
-
Simple Pivot Strategy Not Capturing All Trades
I'm new to testing strategies on NT8. I tried to run a simple strategy where I sell one contract of NQ futures whenever the bar hits R1 using Ninjatrader's standard Pivots calculation. Stop loss and target profits where both set at $200. The backtest showed 5 total trades and although the target and stop loss worked on each I noticed that there were several times when trades should have been activated but weren't. I have attached a picture where a trade should have been executed but was not. Any help would be greatly appreciated - thanks!1 PhotoTags: None
-
Sure thing - strategy should be attached. Let me know if it doesn't come through.Attached Files
Comment
-
Got it. Thanks!
Your OnBarUpdate is this,
Code:protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; // Set 1 if (Close[0] == Pivots1.R1[0]) { EnterShort(1, ""); }
You're entering a short a position only if the Close of the most recent bar falls exactly on R1.
Here is where you gotta ask yourself, how often does that happen? Because if you look back
at your first post, you can see how the bar does not close exactly at R1, but a little above it.
Well, the way the logic is coded, that's why it missed the trade -- the code is wanting a very
precise and exact kind of occurrence to happen, but that kind of exactness (Close just happens
to be exactly at R1) is rare.
What you need to think about is the act of "crossing" the R1 price level. That is, if the previous
bar's close is below R1, and the current bar's close is above R1, well that below/above pairing
of the 2 most recent bars is called "CrossAbove" -- as in, Close has "crossed above" price at R1.
Check out these web pages,
Each method has 2 signatures shown in the syntax section. You'd want to use the
signature where you pass in the R1 price level, something like this,
Code:if (CrossAbove(Close, Pivots1.R1[0], 1)) Print("Close of bar crossed above R1");
Make sense?
- Likes 1
Comment
-
Ah ha - makes perfect sense! The one last question I have is if this can be fixed through the standard 'strategy builder' inputs or if I have to code this in by myself. Apologize for the rookie questions - I'll catch up quickly after I get through this first test.
Comment
-
I think so, but, uh, sorry, you're on your own with that (I don't know 'Strategy Builder' that well, because I don't use it).
CrossAbove and CrossBelow are standard in NinjaTrader, so just look for way to select from a list of standard available methods, and you should see them both there.Last edited by bltdavid; 03-24-2019, 12:34 PM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Brevo, Today, 01:45 AM
|
0 responses
6 views
0 likes
|
Last Post
by Brevo
Today, 01:45 AM
|
||
Started by aussugardefender, Today, 01:07 AM
|
0 responses
3 views
0 likes
|
Last Post Today, 01:07 AM | ||
Started by pvincent, 06-23-2022, 12:53 PM
|
14 responses
242 views
0 likes
|
Last Post
by Nyman
Today, 12:47 AM
|
||
Started by TraderG23, 12-08-2023, 07:56 AM
|
9 responses
384 views
1 like
|
Last Post
by Gavini
Today, 12:29 AM
|
||
Started by oviejo, Today, 12:28 AM
|
0 responses
6 views
0 likes
|
Last Post
by oviejo
Today, 12:28 AM
|
Comment