Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Finding Swings with Swing method - CalculateOnBarClose = false

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

    Finding Swings with Swing method - CalculateOnBarClose = false

    Hi,

    The attached code works very well for finding double tops (DT) with a swing strength of 1. http://screencast.com/t/DHec5Q27

    The problem I have with the indicator though, is, it works perfect to show DTs on past data but does not work proper with "CalculateOnBarClose = false;" Somehow Swing method returns a "number of bars ago" count of 1 bar smaller.

    Is there another workaround except to check for historical and have a second condition, which would blow up source code a lot?

    Maybe it would it be possible to change Swing method accordingly to solve this.

    Thanks

    Thomas


    Code:
                double DT_Tolerance        = Math.Max(ATR(20)[0]/4, 1.1*TickSize);
                int LB_S = 10; //Lookback
            
    //DT
                if (High[1]<=High[0] && Low[1]<=Low[0] && DrawObjects["DT"+(CurrentBar-1)] != null) {RemoveDrawObject("DT"+(CurrentBar-1));} //CandleOutlineColorSeries[1] = Color.Empty;}
                
            //one swing back
                if (((Open[0]>Close[0] && Math.Abs(High[Swing(1).SwingHighBar(1,1,LB_S)]-High[0])<=DT_Tolerance && High[Swing(1).SwingHighBar(1,1,LB_S)]>High[1] && High[1]<High[0]) ||
                     (Open[0]>Close[0] && BarBull()[1]==1 && Math.Abs(High[Swing(1).SwingHighBar(1,1,LB_S)]-MAX(High,2)[0])<=DT_Tolerance && High[Swing(1).SwingHighBar(1,1,LB_S)]>High[2] && High[2]<MAX(High,2)[0]))
                      && Swing(1).SwingHighBar(1,1,LB_S)>1 && Swing(1).SwingHighBar(1,1,LB_S)<Bars.BarsSinceSession)
                {
                    DrawText("DT"+CurrentBar, true, "DT"+Swing(1).SwingHighBar(1,1,LB_S), 0, MAX(High,2)[0]+4*TickSize, 0, Color.Red, new Font ("Arial",FontSize), StringAlignment.Center, Color.Empty, Color.Empty, 0);
                }
                else if (DrawObjects["DT"+(CurrentBar)] != null) {RemoveDrawObject("DT"+(CurrentBar));}
    Last edited by td_910; 12-20-2012, 05:58 PM.

    #2
    Thomas, running with the Swing indicator on CalculateOnBarClose = false you would unfortunately see this limitation - this is on our list to look into for our next major platform update.

    In the meantime, I would suggest to look into splitting up real-time and historical calculations needed for your study.

    Comment


      #3
      could use

      MAX(High, 2)[Swing(1).SwingHighBar(1,1,LB_S)]

      to have a proper price

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      569 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      548 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X