View Full Version : Swing High
maninjapan
05-12-2008, 01:01 AM
Im trying to enter a position only if the most recent swing high is higher than the swing high before that. I thought this would work, but I must be on the wrong track...
Swing(5).SwingHigh[0]>Swing(5).SwingHigh[1]
If I add this then it wont enter at all.
NinjaTrader_Josh
05-12-2008, 02:37 AM
That line is checking the current bar's swing value with the previous bar's swing value. This is probably not what you want since the current bar's swing high will most likely be the same as the previous bar's unless it just happened to be the place where the swing changed.
Instead you want to use this syntax:
Swing(int strength).SwingHighBar(int barsAgo, int instance, int lookBackPeriod)
An instance of 1 = most recent high. 2 = previous high. Please refer to the Help Guide article on Swing for further examples.
maninjapan
05-12-2008, 03:39 AM
Thanks Josh, the wizard only has Input Series, Strength, Bars Ago and Offset, so I would have to unlock the code to add that then?
NinjaTrader_Dierk
05-12-2008, 03:41 AM
Features beyond the scope of the wizard can be used as you unlock the code.
maninjapan
05-12-2008, 05:20 AM
Ive unlocked it and tried to change the code.
I was able to add the swing high bar
Swing(5).SwingLowbar(0,1,20) > Swing(5).SwingLowbar(0,2,100)
but then got an error saying it isnt defined.
Currently it looks like this.
Add(Swing(5));
Ive tried changing it andwas only able to come up with the following.
Add(Swing(5).SwingHighBar(0,1,100));
This gives me a different error though.
NinjaTrader_Dierk
05-12-2008, 06:11 AM
- not sure what you are trying to achieve by adding Swing: Add(Swing..)).
- it always helps as you post exact and complete error messages on your reports
- note the capitalization of your NS code
Swing(5).SwingLowBar(0,1,20) > Swing(5).SwingLowBar(0,2,100)
- I suggest using the editor intellesense to verify the correct spelling of NS methods
maninjapan
05-12-2008, 06:28 AM
Dierk, Thanks, I went back and checked it. Seems the capitalization was where I had gone wrong.
maninjapan
05-12-2008, 07:06 AM
Ive managed to get the code right (well at least it verifies)
&& Swing(5).SwingLowBar(0,1,20) > Swing(5).SwingLowBar(0,2,100))
The above filter is for a Long entry, the theory behind it a new HL is required before taking a long position.
&& Swing(5).SwingHighBar(0,1,100) < Swing(5).SwingHighBar(0,2,100)
for a short entry
However after applying it, it doesnt seem to be having the desired effect.
(I would post a chart to show what I mean except Im not sure how.)
It still enters short even after a HH has been made and most of the long entries have dissappeared completely.
NinjaTrader_Josh
05-13-2008, 01:36 AM
For your lookback parameter try just using CurrentBar. That way it will just look all the way back to the beginning of the chart.
maninjapan
08-12-2008, 06:11 AM
I would like to enter a position if the close is below the most current Swing Low. Would the following code be correct?
if (Close[0] < Swing(5).SwingLow[0])
{
EnterShort(DefaultQuantity, "");
}
NinjaTrader_Ray
08-12-2008, 08:27 AM
I believe that woudl be correct but to confirm, I suggest print out values to the Output window and correlate to the chart to ensure it is what you expect...
Print(Swing(5).SwingLow[0]);