Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
risingadx with parabolic sar
Collapse
X
-
risingadx with parabolic sar
Hi I am try to setup a strategy that involves a rising ADX. I looked at your sample risingSMA, but am still having trouble creating the strategy. When stocks are moving up from an ADX of 20 I want to enter the stock when it crosses an ADX of 30. But I want my strategy to go long or short only based on whether ParabolicSAR says to go long or go short (Becasue a rising ADX only tells whether the trend is strong not whether one should go short of long). Then I want to exit when ADX stops rising, gets horizontal, or starts decreasing. I would exit when the ParabolicSAR changes from bullish to bearish when the initial exit conditions of the ADX are met. Thanks.Tags: None
-
Hi Wes, I can't code it all out for you, but I can provide an outline:
Code:// check for adx cross 30 line if (CrossAbove(ADX(14), 30, 1) { if (ParabolicSAR says go long) { // go long } else if (parabolicSAR says go short) { // go short } } // other exit conditions - adx first if (ADX(14)[0] < ADX(14)[1]) { if (Position.MarketPosition == MarketPosition.Long) { // exit long } else if (Position.MarketPosition == MarketPosition.Short) { // exit short } } // down here you'd add the parabolicSAR exit conditions tooAustinNinjaTrader Customer Service
-
To minimize error I want it to enter once it crossed 30 only if it started out rising form 20. Would this be appropriate.
And do i need to enter Enterlong() below where it says if(parabolicSAR says go long)// check for adx cross 30 line
if (rising(ADX(14), 20, 30, 1) && (CrossAbove(ADX(14), 30, 1)
{
Also does this (below) only exit if ADX is horizontal. If so, how would I define it greater by adding to exit only if it is horizontal for say three ticks. Also how would I add if if ADX is declining for three days (ticks) exit.
if (Position.MarketPosition == MarketPosition.Long
Comment
-
That first question would not be appropriate. Rising() just checks if the most current data point of the DataSeries is greater than the previous data point. You would need to code your own logic to determine if ADX started rising from 20.
For the second question, yes, you would need to do an EnterLong() after the ParabolicSAR says go long. Keep in mind that "if(parabolicSAR says go long)" would not compile because it is not code. I'm not familiar with ParabolicSAR, so I don't know the specific conditions that would indicate that ParabolicSAR says go long.
Lastly, this code: if (ADX(14)[0] < ADX(14)[1]) means that the current value of a 14 period ADX indicator is less than the previous value of a 14 period ADX indicator. You could create your own definition of "horizontal" because ADX values are rarely (as in .0001% of the time) equal (horizontal), but if you really wanted to check if the previous 3 ADX values were equal you could do this:
If you wanted to check for a decline 3 days in a row:Code:if (ADX(14)[0] == ADX(14)[1] && ADX(14)[1] == ADX(14)[2])
Code:if (ADX(14)[0] < ADX(14)[1] && ADX(14)[1] < ADX(14)[2])
AustinNinjaTrader Customer Service
Comment
-
Well I've tried compiling and keep getting these two errors
NinjaScript File Error Code Line Column Strategy\ADXPAR.cs Operator '<=' cannot be applied to operands of type 'NinjaTrader.Indicator.ADX' and 'int' CS0019 - click for info 51 7 Strategy\ADXPAR.cs The name 'Enterlong' does not exist in the current context CS0103 - click for info 62 10
protected override void OnBarUpdate()
{
//checks to see if ADX value is greater than or equal to 30 if not return. Should I try and use bars in progress?
if(ADX(14)<= 25)
return;
{
//checks to see if slope of adx over the past three bars is greater than or equal to one
if(Slope(ADX(14),3,0) <= 1)
return;
}
{
//if the above conditions are met and the parabolicsar signals long then enter long
if (ParabolicSAR(0.02, 0.2, 0.02)[1] > Close[1]
&& ParabolicSAR(0.02, 0.2, 0.02)[0] < Close[0]
&& Position.MarketPosition == MarketPosition.Flat)
Enterlong("");
}
if ((ADX(14)[0] <= ADX(14)[1]) && (ADX(14)[1] <= ADX(14)[2]));
{
if (ParabolicSAR(0.02, 0.2, 0.02)[1] < Close[1]
&& ParabolicSAR(0.02, 0.2, 0.02)[0] > Close[0]
&& Position.MarketPosition == MarketPosition.Long)
ExitLong("");
}
}
Comment
-
Hi Wes, the first issue deals with how and when to use square brackets [ ]. I recently wrote up an explanation that mentions this located here.
For the second compile error, Enterlong() needs to be EnterLong(). Capitalization is very important in C#.Code:if(ADX(14)<= 25) // that above line needs to be if(ADX(14)[0] <= 25)
AustinNinjaTrader Customer Service
Comment
-
When I did that I just get more errors. This is what I have now.
if (ParabolicSAR(0.02, 0.2, 0.02)[1] > Close[1]
&& ParabolicSAR(0.02, 0.2, 0.02)[0] < Close[0]
&& Position.MarketPosition == MarketPosition.Flat
&& (CrossAbove(ADX(14)[0], 28.5, 1)))
EnterLong("");
Comment
-
Wes, I just copied and pasted that code right into an indicator and it compiled fine... are you sure the error is located within that block of code?
Code:protected override void OnBarUpdate() { if (ParabolicSAR(0.02, 0.2, 0.02)[1] > Close[1] && ParabolicSAR(0.02, 0.2, 0.02)[0] < Close[0] && Position.MarketPosition == MarketPosition.Flat && (CrossAbove(ADX(14)[0], 28.5, 1))) EnterLong(""); }AustinNinjaTrader Customer Service
Comment
-
Yes here are the two new errors that pop up and they both invovle the line CrossAbove part.
The best overloaded method match for 'NinjaTrader.Strategy.StrategyBase.CrossAbove(doub le
Argument '2': cannot convert from 'double' to 'NinjaTrader.Data.IDataSeries'
Comment
-
I see. When I tried compiling it, I just pasted the code into a system indicator and hit compile. It didn't save (because it is a system indicator) so it compiled fine. Sorry about that.
I have no idea if you read the tip I posted earlier or not, but if you did you'd see the correct format for CrossAbove() in the last code section of the tip.
For CrossAbove() and CrossBelow(), the first argument must always be a DataSeries (no square brackets []), and the second argument can either be a double value (a DataSeries with []) or another DataSeries. The third argument must be an integer value.
Try this:
Code:if (ParabolicSAR(0.02, 0.2, 0.02)[1] > Close[1] && ParabolicSAR(0.02, 0.2, 0.02)[0] < Close[0] && Position.MarketPosition == MarketPosition.Flat && (CrossAbove(ADX(14), 28.5, 1))) EnterLong("");AustinNinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
647 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
368 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 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
571 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
573 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment