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!
See more
See less

Partner 728x90

Collapse

swing candle

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    swing candle

    Hey guys I'm trying to identify the last down candle before a swing move up and the last up candle before a swing move down, any suggestions on how to incorporate that into the swing indicator

    #2
    Here are the candles with arrows on the: https://gyazo.com/112adb72eca3b31c4723f68666297b8a

    The indicator shows swings, here is the code:

    / Wizard generated variables
    private int strength = 7; // Default setting for Strength
    private int nbars = 10; // Default setting for Nbars
    // User defined variables (add any user defined variables below)
    private Color color1 = Color.Black;
    private Color color2 = Color.Black;
    private Color color3 = Color.Black;
    private Color color4 = Color.Black;

    private int lastHighBar ()
    {
    return Swing(strength).SwingHighBar(1,1,200);
    }
    private double lastHighBarValue ()
    {
    return Swing(strength).SwingHigh[strength+1];
    }
    private int lastLowBar ()
    {
    return Swing(strength).SwingLowBar(1,1,200);
    }
    private double lastLowBarValue ()
    {
    return Swing(strength).SwingLow[strength+1];
    }
    private double length ()
    {
    return lastHighBarValue() - lastLowBarValue();
    }
    private double curLength()
    {
    return lastHighBarValue() - MIN(Low,nbars)[0];
    }
    private double curLLength ()
    {
    return MAX(High,nbars)[0] - lastLowBarValue();
    }



    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Overlay = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    if (CurrentBar < nbars)
    return;

    if (lastLowBar() > lastHighBar())
    {
    DrawLine("line" + CurrentBar,lastLowBar(),lastLowBarValue(),lastHigh Bar(),lastHighBarValue(),Color1);


    }
    if (lastLowBar() < lastHighBar() && Close[0] < lastHighBarValue())
    {
    DrawLine("line2" + CurrentBar,lastHighBar(),lastHighBarValue(),lastLo wBar(),lastLowBarValue(),Color2);

    }
    if (lastLowBar() > lastHighBar() && GetCurrentAsk() < lastHighBarValue())
    {
    DrawLine("line3", lastHighBar(),lastHighBarValue(),LowestBar(Low,10) ,MIN(Low,10)[0],Color3);

    }
    else if (lastLowBar() <lastHighBar() && GetCurrentAsk() > lastHighBarValue())
    {
    DrawLine("line4", lastLowBar(),lastLowBarValue(),HighestBar(High,10) ,MAX(High,10)[0],Color4);

    }



    }

    #region Properties

    [Description("SwingStrength")]
    [GridCategory("Parameters")]
    public int Strength
    {
    get { return strength; }
    set { strength = Math.Max(1, value); }
    }

    [Description("Number of bars to look back for recent high/low")]
    [GridCategory("Parameters")]
    public int Nbars
    {
    get { return nbars; }
    set { nbars = Math.Max(1, value); }
    }
    #endregion


    #region Color Properties
    // Create our user definable color input
    [XmlIgnore()]
    [Description("Color for painted region")]
    [GridCategory("ColorParameters")]
    [Gui.Design.DisplayName("Up Swing")]
    public Color Color1
    {
    get { return color1; }
    set { color1 = value; }
    }

    // Serialize our Color object
    [Browsable(false)]
    public string Color1Serialize
    {
    get { return NinjaTrader.Gui.Design.SerializableColor.ToString( color1); }
    set { color1 = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
    }

    [XmlIgnore()]
    [Description("Color for painted region")]
    [GridCategory("ColorParameters")]
    [Gui.Design.DisplayName("Down Swing")]
    public Color Color2
    {
    get { return color2; }
    set { color2 = value; }
    }

    // Serialize our Color object
    [Browsable(false)]
    public string Color2Serialize
    {
    get { return NinjaTrader.Gui.Design.SerializableColor.ToString( color2); }
    set { color2 = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
    }
    [XmlIgnore()]
    [Description("Color for painted region")]
    [GridCategory("ColorParameters")]
    [Gui.Design.DisplayName("Current Down")]
    public Color Color3
    {
    get { return color3; }
    set { color3 = value; }
    }

    // Serialize our Color object
    [Browsable(false)]
    public string Color3Serialize
    {
    get { return NinjaTrader.Gui.Design.SerializableColor.ToString( color3); }
    set { color3 = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
    }
    [XmlIgnore()]
    [Description("Color for painted region")]
    [GridCategory("ColorParameters")]
    [Gui.Design.DisplayName("Current Up")]
    public Color Color4
    {
    get { return color4; }
    set { color4 = value; }
    }

    // Serialize our Color object
    [Browsable(false)]
    public string Color4Serialize
    {
    get { return NinjaTrader.Gui.Design.SerializableColor.ToString( color4); }
    set { color4 = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
    }
    #endregion
    }
    }

    Comment


      #3
      Hello brucelevy,

      My suggestion would be to make an array. Each time there is a new swing, record the bar number of the bar that the swing started on to the array. Then you can loop through the array and find all of the bars that a swing began on.

      Just a heads up, the Swing indicator actually goes back in time and sets plots. This means you may need to monitor through the last few bars to detect the swing.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        I'm trying to use something like this to draw a rectangle going forward on all the current and prior swing highs and lows, specifically on the candle before the swing started. For swing lows the rectangle should go from the prior candles high to the open, and for a swing high a rectangle from the prior candles low to open. It looks like the best indicator to modify is the swing indicator but I can't seem to get it right.

        DrawRectangle("tag1", -20,Low[1],0,Open[1], Color.Black);
        Last edited by brucelevy; 09-30-2015, 10:26 PM.

        Comment


          #5
          Hi brucelevy,

          DrawRectangle("tag1", -20,Low[1],0,Open[1], Color.Black);

          There is a negative bars ago index being used here. This would push the rectangle forward into the blank space in front of the chart.

          Are you trying to draw a rectangle from 20 bars ago to the current bar?
          Use a 20 for 20 bars ago.

          If you record the bar numbers of each swing, or just the start of the last swing if you want (or the bar before it if you want), you can use CurrentBar-thatBarsNumber to find how many bars ago this was.

          For example:
          In Initialize():
          private int swingStart = 0;

          In OnBarUpdate():
          if (/* conditions to detect start of swing here */)
          {
          swingStart = CurrentBar;
          }
          if (swingStart > 0)
          {
          int barsAgo = CurrentBar-swingStart;
          DrawRectangle("rectangle", barsAgo, High[barsAgo], 0, Low[barsAgo], Color.Blue);
          }
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by chbruno, Today, 04:10 PM
          0 responses
          3 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          6 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by frslvr, 04-11-2024, 07:26 AM
          9 responses
          127 views
          1 like
          Last Post caryc123  
          Working...
          X