PDA

View Full Version : Using the Swing Indicator



qhtpitiw03
03-11-2016,
Hello

I'm using the standard Ninja Swing indicator and I'd like to add a very simple functionality to it:
Basically, whenever the Swing Line is rather long (let's say, 10+ candles), I want the indicator to draw an arrow next to the Swing Line, in order to highlight its importance (I'm using a Swing Line with a value of 5).

I've played around with the DrawArrowUp/Down function but it only lets me draw an arrow above/below a candle, not next to another element on the chart like the Swing line. How should I go about this?

Thanks in advance for your suggestions.

QUMMelba28
03-12-2016,
Hello laocoon,
A very simple code will be like

Code:
protected override void OnBarUpdate()
{
if (CurrentBar < 10) return;

if (this.Swing(5)[0] == Swing(5)[10])
{
this.DrawArrowUp("swing" + CurrentBar, false, 0, Swing(5)[0], Color.Blue);
}
}
The above code draws an arrow if the current swing value equals the value of the swing 10 bars back.

Rakushak
03-13-2016,
Hello Joydeep

Thanks a lot for your reply and the code snippet.
I'd like to use the code for both the Upper Swing Line and the Lower Swing Line but when I apply the following modification

Old:
this.DrawArrowUp("swing" + CurrentBar, false, 0, Swing(5)[0], Color.Blue);

New:
this.DrawArrowUp("swingUpper" + CurrentBar, false, 0, SwingHigh(5)[0], Color.Blue);
this.DrawArrowDown("swingLower" + CurrentBar, false, 0, SwingLow(5)[0], Color.Blue);

it doesn't work (I get an error message although I'm using SwingHigh & SwingLow in another context and they work perfectly.

Also, I'd like the arrow to appear only ONCE per Swing Line and not on every candle.

Thanks again.

RandallDbo
03-13-2016,
Hello laocoon,
NinjaTrader natively does not comes with any SwingHigh or SwingLow indicator. To access the Swing high value you can use the following code for example
Code:
Swing(5).SwingHigh[0];

Please try this modified code, which will draw only one arrow,

In variable region
Code:
bool onlyOnce = true;
InOnBarUpdate

Code:
if (CurrentBar < 10) return;

if (Swing(5).SwingHigh[0] != Swing(5).SwingHigh[10])
{
onlyOnce = true;
}

if (onlyOnce && this.Swing(5).SwingHigh[0] == Swing(5).SwingHigh[10])
{
this.DrawArrowUp("swing" + CurrentBar, false, 0, Swing(5).SwingHigh[0], Color.Blue);
onlyOnce = false;
}
Joydeep M.

RayfordTume
03-16-2016,
Looks good so far, thanks a lot for helping out Joydeep!