protected override void Initialize()
{
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (ParabolicSAR(0.02, 0.2, 0.02)[2] > Close[2]
&& ParabolicSAR(0.02, 0.2, 0.02)[1] < Close[1])
{
ExitShort("", "");
EnterLong(Lots, "");
}
// Condition set 2
if (ParabolicSAR(0.02, 0.2, 0.02)[2] < Close[2]
&& ParabolicSAR(0.02, 0.2, 0.02)[1] > Close[1])
{
ExitLong("", "");
EnterShort(Lots, "");
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
PSAR flips not working correctly
Collapse
X
-
PSAR flips not working correctly
Does anyone have any idea why this code makes my trades exit early? I just want it to buy & exit short when PSAR flips down and sell & exit long when psar flips up.
Code:Tags: None
-
Josh,Originally posted by NinjaTrader_Josh View PostLooks correct to me. You are checking 1 bar ago and 2 bars ago for the flip. When the flip is identified it places the trades. The trades execute on the next bar because the signal bar is already closed in backtesting.
But if you look at the screenshot, it shows the trades closing well before a PSAR flip occurs. I don't understand what's wrong with the exits.
Comment
-
Texasnomad, what Josh was saying is that you're checking the PSAR values from one bar back and two bars back, NOT the current bar and one bar back. Changing the values from 2 and 1 to 1 and 0 would fix this.
In addition, the early exits are caused by ExitOnClose being set to true as indicated by "Exit on close" on the chart.
You can try changing these settings and see if the exits/entries are closer to where they should be.AustinNinjaTrader Customer Service
Comment
-
I don't want the strategy to use the current bar. I want to see 2 bars to the left with PSAR above the price, 1 bar to the left with PSAR below the price, then I'll buy at the open of the current bar. This is what this code does, correct?Originally posted by NinjaTrader_Austin View PostTexasnomad, what Josh was saying is that you're checking the PSAR values from one bar back and two bars back, NOT the current bar and one bar back. Changing the values from 2 and 1 to 1 and 0 would fix this.
How do I eliminate ExitOnClose? I don't see any variables or functions of that name in my code.In addition, the early exits are caused by ExitOnClose being set to true as indicated by "Exit on close" on the chart.
Comment
-
Nevermind... I just found exitonclose in the strategy options. I didn't realize it was an external parameter to the code.
Comment
-
Correct. Sorry for not understanding what you wanted to do. Did changing Exit on close resolve the early exit issue?Originally posted by texasnomad View PostI don't want the strategy to use the current bar. I want to see 2 bars to the left with PSAR above the price, 1 bar to the left with PSAR below the price, then I'll buy at the open of the current bar. This is what this code does, correct?AustinNinjaTrader Customer Service
Comment
-
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
558 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
545 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment