Print("0 1 The high of the swing bar "+Swing(5).SwingHighBar(0, 1, 128)+" is " +High[Math.Max(0, Swing(5).SwingHighBar(0, 1, 128))] ); Print("0 2 The high of the swing bar "+Swing(5).SwingHighBar(0, 2, 128)+" is " +High[Math.Max(0, Swing(5).SwingHighBar(0, 2, 128))] ); Print("0 3 The high of the swing bar "+Swing(5).SwingHighBar(0, 3, 128)+" is " +High[Math.Max(0, Swing(5).SwingHighBar(0, 3, 128))] ); Print("0 1 The low of the swing bar "+Swing(5).SwingLowBar(0, 1, 128)+" is " +Low[Math.Min(0, Swing(5).SwingLowBar(0, 1, 128))] ); Print("0 2 The low of the swing bar "+Swing(5).SwingLowBar(0, 2, 128)+" is " +Low[Math.Min(0, Swing(5).SwingLowBar(0, 2, 128))] ); Print("0 3 The low of the swing bar "+Swing(5).SwingLowBar(0, 3, 128)+" is " +Low[Math.Min(0, Swing(5).SwingLowBar(0, 3, 128))] );
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
Swing vs Low[Math.Min] not as expected
Collapse
X
-
Swing vs Low[Math.Min] not as expected
Hi, am trying to get the values for the last 3 x swing highs and swing lows using the swing indicator, and the output for the swing low give the same value for 1,2 and 3 ? is the code below valid ? many thanks for looking
Code:Tags: None
-
Hello 12tkram, thanks for your post.
The code you posted works fine for me. I made a test that draws a dot 3 swing highs. Please see attached. To add it to your system, place the file within Documents\NinjaTrader 8\bin\Custom\Indicators.
Let me know if it is not working after reviewing this, kind regards.Attached FilesChris L.NinjaTrader Customer Service
Comment
-
Hi,
I revised my OnBarUpdate method and this is working for me:
protected override void OnBarUpdate()
{
//Swing(int strength).SwingHighBar(int barsAgo, int instance, int lookBackPeriod)
if(CurrentBar < 128)
return;
Draw.Dot(this, "swing1", false, Swing(5).SwingHighBar(0, 1, 128), High[Swing(5).SwingHighBar(0, 1, 128)], Brushes.Red);
Draw.Dot(this, "swing2", false, Swing(5).SwingHighBar(0, 2, 128), High[Swing(5).SwingHighBar(0, 2, 128)], Brushes.Red);
Draw.Dot(this, "swing3", false, Swing(5).SwingHighBar(0, 3, 128), High[Swing(5).SwingHighBar(0, 3, 128)], Brushes.Red);
Draw.Dot(this, "swingLow1", false, Swing(5).SwingLowBar(0, 1, 128), Low[Swing(5).SwingLowBar(0, 1, 128)], Brushes.Green);
Draw.Dot(this, "swingLow2", false, Swing(5).SwingLowBar(0, 2, 128), Low[Swing(5).SwingLowBar(0, 2, 128)], Brushes.Green);
Draw.Dot(this, "swingLow3", false, Swing(5).SwingLowBar(0, 3, 128), Low[Swing(5).SwingLowBar(0, 3, 128)], Brushes.Green);
}
If you don't get the same thing on your side please let me know.Chris L.NinjaTrader Customer Service
Comment
-
12tkram,
I wanted to add that your swing indicator should be set up at the class level to save resources.
e.g.
Code:public class TestSwing : Indicator { Swing MySwing; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "TestSwing"; Calculate = Calculate.OnBarClose; IsOverlay = true; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; } else if (State == State.Configure) { } else if (State == State.DataLoaded) { MySwing = Swing(5); } } protected override void OnBarUpdate() { //Swing(int strength).SwingHighBar(int barsAgo, int instance, int lookBackPeriod) if(CurrentBar < 128) return; Draw.Dot(this, "swing1", false, MySwing.SwingHighBar(0, 1, 128), High[MySwing.SwingHighBar(0, 1, 128)], Brushes.Red); Draw.Dot(this, "swing2", false, MySwing.SwingHighBar(0, 2, 128), High[MySwing.SwingHighBar(0, 2, 128)], Brushes.Red); Draw.Dot(this, "swing3", false, MySwing.SwingHighBar(0, 3, 128), High[MySwing.SwingHighBar(0, 3, 128)], Brushes.Red); Draw.Dot(this, "swingLow1", false, MySwing.SwingLowBar(0, 1, 128), Low[MySwing.SwingLowBar(0, 1, 128)], Brushes.Green); Draw.Dot(this, "swingLow2", false, MySwing.SwingLowBar(0, 2, 128), Low[MySwing.SwingLowBar(0, 2, 128)], Brushes.Green); Draw.Dot(this, "swingLow3", false, MySwing.SwingLowBar(0, 3, 128), Low[MySwing.SwingLowBar(0, 3, 128)], Brushes.Green); }
Chris L.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by judysamnt7, 03-13-2023, 09:11 AM
|
4 responses
59 views
0 likes
|
Last Post
by DynamicTest
Today, 08:25 PM
|
||
Started by ScottWalsh, Today, 06:52 PM
|
4 responses
36 views
0 likes
|
Last Post
by ScottWalsh
Today, 07:40 PM
|
||
Started by olisav57, Today, 07:39 PM
|
0 responses
7 views
0 likes
|
Last Post
by olisav57
Today, 07:39 PM
|
||
Started by trilliantrader, Today, 03:01 PM
|
2 responses
21 views
0 likes
|
Last Post
by helpwanted
Today, 07:25 PM
|
||
Started by cre8able, Today, 07:24 PM
|
0 responses
10 views
0 likes
|
Last Post
by cre8able
Today, 07:24 PM
|
Comment