thinkorswim programming

Discussion in 'App Development' started by watchdaride, Feb 15, 2018.

  1. Wow, really? What happened to your firms pledge of securing private conversations? Whenever you dislike something or feel the need to clarify you go out there and put in public domain private conversations with your clients? This is weird on so many levels. Care to clarify? Did this user consent to have his private conversations published to be seen by the rest of the world?

     
    #21     Apr 5, 2019
  2. Hasheesh

    Hasheesh

    I found a sample code that defines the HighestHigh and LowestLow withing a monthly period. It plots vertical lines that cross over these range lines. I need help to code the vertical lines to stay within the high and low lines. Is there a way to truncate these vertical lines to stay with this range?
    Code:
    declare upper;
    
    input numdays    = 21; # added this as a variable rather than hard coded number so you can adjust it
    input numMonths1 = 4;
    input Show1 = yes;
    input lineWeight = 3;
    input extended_days = 21; #should be equal to or less than numdays
    
    input Price = 2.5;
    def barnumber = BarNumber();
    
    def numBars1     = numdays * numMonths1;
    def barNum       = if IsNaN( close ) then Double.NaN else BarNumber();
    def lastBar     = HighestAll( barNum );
    def startBar1    = if lastBar <= numBars1 then 1 else lastBar - numBars1;
    
    def hData1       = If( barNum < startBar1, Double.NaN, high );
    def lData1       = If( barNum < startBar1, Double.NaN, low );
    
    # ===============================================================
    #                Plotting Section
    # ===============================================================
    
    plot HighestHigh1 = If( Show1, HighestAll( hData1 ), Double.NaN );
    plot LowestLow1   = If( Show1, LowestAll( lData1 ),  Double.NaN );
    
    #===================[ Define Plot Appearences ]=====================
    DefineGlobalColor( "H1", Color.VIOLET);
    DefineGlobalColor( "L1", Color.PINK);
    
    HighestHigh1.SetPaintingStrategy( PaintingStrategy.LINE );
    HighestHigh1.SetLineWeight( lineWeight );
    HighestHigh1.AssignValueColor( GlobalColor( "H1" ) );
    HighestHigh1.HideBubble();
    
    LowestLow1.SetPaintingStrategy( PaintingStrategy.LINE );
    LowestLow1.SetLineWeight( lineWeight );
    LowestLow1.AssignValueColor( GlobalColor( "L1" ) );
    LowestLow1.HideBubble();
    
    def months1   = Round( ( lastBar - startBar1 + 1 ) / 21, 0 );
    
    # ===============================================================
    #                Chart Bubbles
    # ===============================================================
    def BeginBarH = if barNum >= startBar1 and HighestAll(HighestHigh1) == high
                    then  BarNumber() else BeginBarH[1];
    def BeginBarL = if barNum >= startBar1 and HighestAll(LowestLow1) == low
                    then  BarNumber() else  BeginBarL[1];
    def BeginBar  = HighestAll(Min(BeginBarH, BeginBarL));
    
    AddChartBubble( Show1 and barNum == BeginBar, HighestHigh1, Concat( "Highest High in ",  Concat( months1, Concat (" Months is ", HighestHigh1)) ), GlobalColor( "H1" ), yes );
    
    AddChartBubble( Show1 and barNum == BeginBar, LowestLow1,   Concat( "Lowest Low in ",   Concat( months1, Concat (" Months is ", LowestLow1)) ), GlobalColor( "L1" ), no  );
    
    # ===============================================================
    #                Extended Dates
    # ===============================================================
    
    def begindate = if BarNumber() == BeginBar then GetYYYYMMDD() else begindate[1];
    def endclose  = if BarNumber() == BeginBar + extended_days then close else endclose[1];
    def enddate   = if BarNumber() == BeginBar + extended_days then GetYYYYMMDD() else enddate[1];
    
    Plot line = if barnumber between BeginBar and BeginBar + extended_days then Price else double.nan;
    line.SetLineWeight(5);
    
    input showverticals = yes;
    AddVerticalLine(showverticals && BarNumber() == BeginBar, "               " + AsPrice(GetYYYYMMDD()) + " " + AsDollars(close), Color.GREEN, Curve.FIRM);
    
    AddVerticalLine(showverticals && BarNumber() == BeginBar + extended_days, "               " + AsPrice(GetYYYYMMDD()) + " " + AsDollars(close), Color.RED, Curve.FIRM);
    
     
    #22     Apr 22, 2019