• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 Tagliareni, Yesterday, 08:10 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by SDaCosta30, Today, 04:19 AM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by memonolog, Today, 02:39 AM
          3 responses
          21 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by memonolog, Today, 07:07 AM
          0 responses
          4 views
          0 likes
          Last Post memonolog  
          Started by juanram, Today, 06:01 AM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Working...
          X