Loading ...
Sorry, an error occurred while loading the content.

Re: [TOS_thinkscript] MACD Example Script [2 Attachments]

Expand Messages
  • Scott Levin
    Wow, you re an asset to the group Larry. and Richard and TrendXplorer too ________________________________ From: Larry thompson To: TOS
    Message 1 of 4 , Mar 6, 2013
    • 0 Attachment
      Wow, you're an asset to the group Larry.
      and Richard and TrendXplorer too


      From: Larry thompson <larthomp1@...>
      To: TOS Yahoo Group <TOS_thinkscript@yahoogroups.com>
      Sent: Wed, March 6, 2013 10:17:25 PM
      Subject: [TOS_thinkscript] MACD Example Script [2 Attachments]

       

      A member asked in a private request to have a MACD script with different options to be available that a user can choose to activate.
       
      The script below (also posted in files) has an upper study MACD. It allows for (most on/off selections at input):
       
      - price bar coloring (also option to paint bars when MACD is zero);
      - vertical lines and dots when MACD crosses zero;
      - horizontal lines when MACD crosses zero;
      - vertical line and/or horizontal line when MACD crosses zero on a secondary period;
      - vertical line and/or horizontal line when MACD crosses zero on another secondary period;
      - alert on chart MACD crossover of zero;
       
      Attached is an example of this script with price colors on a 3 minute chart with 5 and 10 minute secondary periods. Vertical lines represent the chart timeframe and the dotted and squared lines represent the higher timeframes.
       
      #Macd_Examples_v3
      declare upper;
      input fastLength        = 12;
      input slowLength        = 26;
      input MACDLength        = 9;
      input AverageType       = {SMA, default EMA};
      input displace          = 0;
      input pricecolorzero    = yes;
      input pricecolortrend   = yes;
      #Thinkorswim MACD definition
      def Diff = MACD(fastLength, slowLength, MACDLength, AverageType).Diff;
      #Option #1 Vertical Lines
      input verticallines = no;
      AddVerticalLine(if verticallines == yes then if Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then 1 else 0 else 0, if  Diff[1] <= 0 and Diff > 0 then "                                                                               Chart Up" else if Diff[1] >= 0 and Diff < 0 then "                                                                                   Chart Down" else "", if Diff[1] <= 0 and Diff > 0 then Color.GREEN else Color.RED, stroke = Curve.LONG_DASH);
      #Option 2 - Dots and Lines connecting Dots
      input showdots=no;
      def count = if Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then 1 else 0;
      plot line = if showdots==yes and count == 1 then close[1] else Double.NaN;
      line.SetPaintingStrategy(PaintingStrategy.LINE);
      line.AssignValueColor(if Diff > 0 then Color.GREEN else Color.RED);
      line.EnableApproximation();
      plot dot = if showdots==yes and count == 1 then close[1] else Double.NaN;
      dot.SetPaintingStrategy(PaintingStrategy.POINTS);
      dot.AssignValueColor(if Diff[1] <= 0 and Diff > 0 then Color.GREEN else Color.RED);
      dot.SetLineWeight(5);
      #Option 3 - Horizontal Lines
      input showhzlinesprimary=no;
      rec count1 = CompoundValue( 1, if IsNaN( Diff ) then count1[1] else if count then close else count1[1], close );
      plot line1 = if showhzlinesprimary then count1[displace] else double.nan;
      line1.SetPaintingStrategy(PaintingStrategy.POINTS);
      line1.assignvalueColor(if Diff > 0 then color.light_green else if Diff==0 then color.yellow else color.light_red);
      line1.setlineweight(1);

      #Option 4 - Colored Price Bars Cross Above / Below Zero (pricecolorzero=yes and pricecolortrend=no)
      #Option 5 - Colored Price Bars Above Below Zero and Trend (pricecolortrend=yes)
      AssignPriceColor(if pricecolorzero == yes and pricecolortrend == no then (if  Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then Color.YELLOW else Color.CURRENT) else if pricecolortrend == yes then if  Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then Color.YELLOW else (if Diff >= 0 then if Diff > Diff[1] then Color.GREEN else Color.light_green else if Diff < Diff[1] then Color.RED else Color.dark_red) else Color.CURRENT);
      #MACD Different Timeframe (#1) Vertical Line and or Horizontal Line
      input period1=aggregationPeriod.Five_MIN;
      def Value1 =  ExpAverage(close(period=period1), fastLength) -  ExpAverage(close(period=period1), slowLength);
      def Avg1   = ExpAverage(ExpAverage(close(period=period1), fastLength) -  ExpAverage(close(period=period1), slowLength), MACDLength);
      def Diff1 = Value1 - Avg1;
      input verticallines1=yes;
      AddVerticalLine(visible = if Verticallines1 == yes then if Diff1[1] <= 0 and Diff1 > 0 or Diff1[1] >= 0 and Diff1 < 0 then 1 else 0 else 0, text = if  Diff1[1] <= 0 and Diff1 > 0 then "                                                             2nd Timeframe UP" else if Diff1[1] >= 0 and Diff1 < 0 then "                                                                        2nd Timeframe DOWN" else "", color = if Diff1[1] <= 0 and Diff1 > 0 then Color.LIGHT_GREEN else Color.LIGHT_RED);
      input showhzlines1=no;
      rec count_1 = if IsNaN( Diff1 ) then count_1[1] else if  Diff1[1] <= 0 and Diff1 > 0 or Diff1[1] >= 0 and Diff1 < 0 then close(period=period1) else count_1[1];
      plot line_1 = if showhzlines1 then count_1[displace] else double.nan;
      line_1.setpaintingStrategy(PaintingStrategy.SQUARES);
      line_1.assignvalueColor(if Diff1 > 0 then color.green else if diff1==0 then color.yellow else color.red);
      line_1.setlineweight(1);
      #MACD Different Timeframe (#2) Vertical Line and or Horizontal Line
      input period2=aggregationPeriod.FiFTEEN_MIN;
      def Value2 =  ExpAverage(close(period=period2), fastLength) -  ExpAverage(close(period=period2), slowLength);
      def Avg2   = ExpAverage(ExpAverage(close(period=period2), fastLength) -  ExpAverage(close(period=period2), slowLength), MACDLength);
      def Diff2 = Value2 - Avg2;
      input verticallines2=yes;
      AddVerticalLine(visible = if Verticallines2 == yes then if Diff2[1] <= 0 and Diff2 > 0 or Diff2[1] >= 0 and Diff2 < 0 then 1 else 0 else 0, text = if  Diff2[1] <= 0 and Diff2 > 0 then "                                                     3rd Timeframe UP" else if Diff2[1] >= 0 and Diff2 < 0 then "                                                              3rd Timeframe DOWN" else "", color = if Diff2[1] <= 0 and Diff2 > 0 then Color.LIGHT_GREEN else Color.LIGHT_RED);
      input showhzlines2=no;
      rec count2 = if IsNaN( Diff2 ) then count2[1] else if  Diff2[1] <= 0 and Diff2 > 0 or Diff2[1] >= 0 and Diff2 < 0 then close(period=period2) else count2[1];
      plot line2 = if showhzlines2 then count2[displace] else double.nan;
      line2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
      line2.assignvalueColor(if Diff2 > 0 then color.dark_green else if Diff2==0 then color.yellow else color.dark_red);
      line2.setlineWeight(3);
      #Alerts
      Alert( if Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then 1 else 0, text = "MACD Cross of Zeroline", "alert type" = Alert.BAR, sound = Sound.Ding);
    • Scott Levin
      I forgot to mention my good buddy JB...Sorry about that ________________________________ From: Scott Levin To:
      Message 2 of 4 , Mar 7, 2013
      • 0 Attachment

        I forgot to mention my good buddy JB...Sorry about that

        From: Scott Levin <esslash@...>
        To: TOS_thinkscript@yahoogroups.com
        Sent: Wed, March 6, 2013 10:31:37 PM
        Subject: Re: [TOS_thinkscript] MACD Example Script

         

        Wow, you're an asset to the group Larry.
        and Richard and TrendXplorer too


        From: Larry thompson <larthomp1@...>
        To: TOS Yahoo Group <TOS_thinkscript@yahoogroups.com>
        Sent: Wed, March 6, 2013 10:17:25 PM
        Subject: [TOS_thinkscript] MACD Example Script [2 Attachments]

         

        A member asked in a private request to have a MACD script with different options to be available that a user can choose to activate.
         
        The script below (also posted in files) has an upper study MACD. It allows for (most on/off selections at input):
         
        - price bar coloring (also option to paint bars when MACD is zero);
        - vertical lines and dots when MACD crosses zero;
        - horizontal lines when MACD crosses zero;
        - vertical line and/or horizontal line when MACD crosses zero on a secondary period;
        - vertical line and/or horizontal line when MACD crosses zero on another secondary period;
        - alert on chart MACD crossover of zero;
         
        Attached is an example of this script with price colors on a 3 minute chart with 5 and 10 minute secondary periods. Vertical lines represent the chart timeframe and the dotted and squared lines represent the higher timeframes.
         
        #Macd_Examples_v3
        declare upper;
        input fastLength        = 12;
        input slowLength        = 26;
        input MACDLength        = 9;
        input AverageType       = {SMA, default EMA};
        input displace          = 0;
        input pricecolorzero    = yes;
        input pricecolortrend   = yes;
        #Thinkorswim MACD definition
        def Diff = MACD(fastLength, slowLength, MACDLength, AverageType).Diff;
        #Option #1 Vertical Lines
        input verticallines = no;
        AddVerticalLine(if verticallines == yes then if Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then 1 else 0 else 0, if  Diff[1] <= 0 and Diff > 0 then "                                                                               Chart Up" else if Diff[1] >= 0 and Diff < 0 then "                                                                                   Chart Down" else "", if Diff[1] <= 0 and Diff > 0 then Color.GREEN else Color.RED, stroke = Curve.LONG_DASH);
        #Option 2 - Dots and Lines connecting Dots
        input showdots=no;
        def count = if Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then 1 else 0;
        plot line = if showdots==yes and count == 1 then close[1] else Double.NaN;
        line.SetPaintingStrategy(PaintingStrategy.LINE);
        line.AssignValueColor(if Diff > 0 then Color.GREEN else Color.RED);
        line.EnableApproximation();
        plot dot = if showdots==yes and count == 1 then close[1] else Double.NaN;
        dot.SetPaintingStrategy(PaintingStrategy.POINTS);
        dot.AssignValueColor(if Diff[1] <= 0 and Diff > 0 then Color.GREEN else Color.RED);
        dot.SetLineWeight(5);
        #Option 3 - Horizontal Lines
        input showhzlinesprimary=no;
        rec count1 = CompoundValue( 1, if IsNaN( Diff ) then count1[1] else if count then close else count1[1], close );
        plot line1 = if showhzlinesprimary then count1[displace] else double.nan;
        line1.SetPaintingStrategy(PaintingStrategy.POINTS);
        line1.assignvalueColor(if Diff > 0 then color.light_green else if Diff==0 then color.yellow else color.light_red);
        line1.setlineweight(1);

        #Option 4 - Colored Price Bars Cross Above / Below Zero (pricecolorzero=yes and pricecolortrend=no)
        #Option 5 - Colored Price Bars Above Below Zero and Trend (pricecolortrend=yes)
        AssignPriceColor(if pricecolorzero == yes and pricecolortrend == no then (if  Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then Color.YELLOW else Color.CURRENT) else if pricecolortrend == yes then if  Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then Color.YELLOW else (if Diff >= 0 then if Diff > Diff[1] then Color.GREEN else Color.light_green else if Diff < Diff[1] then Color.RED else Color.dark_red) else Color.CURRENT);
        #MACD Different Timeframe (#1) Vertical Line and or Horizontal Line
        input period1=aggregationPeriod.Five_MIN;
        def Value1 =  ExpAverage(close(period=period1), fastLength) -  ExpAverage(close(period=period1), slowLength);
        def Avg1   = ExpAverage(ExpAverage(close(period=period1), fastLength) -  ExpAverage(close(period=period1), slowLength), MACDLength);
        def Diff1 = Value1 - Avg1;
        input verticallines1=yes;
        AddVerticalLine(visible = if Verticallines1 == yes then if Diff1[1] <= 0 and Diff1 > 0 or Diff1[1] >= 0 and Diff1 < 0 then 1 else 0 else 0, text = if  Diff1[1] <= 0 and Diff1 > 0 then "                                                             2nd Timeframe UP" else if Diff1[1] >= 0 and Diff1 < 0 then "                                                                        2nd Timeframe DOWN" else "", color = if Diff1[1] <= 0 and Diff1 > 0 then Color.LIGHT_GREEN else Color.LIGHT_RED);
        input showhzlines1=no;
        rec count_1 = if IsNaN( Diff1 ) then count_1[1] else if  Diff1[1] <= 0 and Diff1 > 0 or Diff1[1] >= 0 and Diff1 < 0 then close(period=period1) else count_1[1];
        plot line_1 = if showhzlines1 then count_1[displace] else double.nan;
        line_1.setpaintingStrategy(PaintingStrategy.SQUARES);
        line_1.assignvalueColor(if Diff1 > 0 then color.green else if diff1==0 then color.yellow else color.red);
        line_1.setlineweight(1);
        #MACD Different Timeframe (#2) Vertical Line and or Horizontal Line
        input period2=aggregationPeriod.FiFTEEN_MIN;
        def Value2 =  ExpAverage(close(period=period2), fastLength) -  ExpAverage(close(period=period2), slowLength);
        def Avg2   = ExpAverage(ExpAverage(close(period=period2), fastLength) -  ExpAverage(close(period=period2), slowLength), MACDLength);
        def Diff2 = Value2 - Avg2;
        input verticallines2=yes;
        AddVerticalLine(visible = if Verticallines2 == yes then if Diff2[1] <= 0 and Diff2 > 0 or Diff2[1] >= 0 and Diff2 < 0 then 1 else 0 else 0, text = if  Diff2[1] <= 0 and Diff2 > 0 then "                                                     3rd Timeframe UP" else if Diff2[1] >= 0 and Diff2 < 0 then "                                                              3rd Timeframe DOWN" else "", color = if Diff2[1] <= 0 and Diff2 > 0 then Color.LIGHT_GREEN else Color.LIGHT_RED);
        input showhzlines2=no;
        rec count2 = if IsNaN( Diff2 ) then count2[1] else if  Diff2[1] <= 0 and Diff2 > 0 or Diff2[1] >= 0 and Diff2 < 0 then close(period=period2) else count2[1];
        plot line2 = if showhzlines2 then count2[displace] else double.nan;
        line2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
        line2.assignvalueColor(if Diff2 > 0 then color.dark_green else if Diff2==0 then color.yellow else color.dark_red);
        line2.setlineWeight(3);
        #Alerts
        Alert( if Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then 1 else 0, text = "MACD Cross of Zeroline", "alert type" = Alert.BAR, sound = Sound.Ding);
      • Scott Levin
        Oops...sorry Adam Green...You haven t been around so I almost forgot you...(-: and Fausto Calzone too ________________________________ From: Scott Levin
        Message 3 of 4 , Mar 7, 2013
        • 0 Attachment
          Oops...sorry Adam Green...You haven't been around
          so I almost forgot you...(-: and Fausto Calzone too



          From: Scott Levin <esslash@...>
          To: TOS_thinkscript@yahoogroups.com
          Sent: Thu, March 7, 2013 11:32:56 AM
          Subject: Re: [TOS_thinkscript] MACD Example Script

           


          I forgot to mention my good buddy JB...Sorry about that

          From: Scott Levin <esslash@...>
          To: TOS_thinkscript@yahoogroups.com
          Sent: Wed, March 6, 2013 10:31:37 PM
          Subject: Re: [TOS_thinkscript] MACD Example Script

           

          Wow, you're an asset to the group Larry.
          and Richard and TrendXplorer too


          From: Larry thompson <larthomp1@...>
          To: TOS Yahoo Group <TOS_thinkscript@yahoogroups.com>
          Sent: Wed, March 6, 2013 10:17:25 PM
          Subject: [TOS_thinkscript] MACD Example Script [2 Attachments]

           

          A member asked in a private request to have a MACD script with different options to be available that a user can choose to activate.
           
          The script below (also posted in files) has an upper study MACD. It allows for (most on/off selections at input):
           
          - price bar coloring (also option to paint bars when MACD is zero);
          - vertical lines and dots when MACD crosses zero;
          - horizontal lines when MACD crosses zero;
          - vertical line and/or horizontal line when MACD crosses zero on a secondary period;
          - vertical line and/or horizontal line when MACD crosses zero on another secondary period;
          - alert on chart MACD crossover of zero;
           
          Attached is an example of this script with price colors on a 3 minute chart with 5 and 10 minute secondary periods. Vertical lines represent the chart timeframe and the dotted and squared lines represent the higher timeframes.
           
          #Macd_Examples_v3
          declare upper;
          input fastLength        = 12;
          input slowLength        = 26;
          input MACDLength        = 9;
          input AverageType       = {SMA, default EMA};
          input displace          = 0;
          input pricecolorzero    = yes;
          input pricecolortrend   = yes;
          #Thinkorswim MACD definition
          def Diff = MACD(fastLength, slowLength, MACDLength, AverageType).Diff;
          #Option #1 Vertical Lines
          input verticallines = no;
          AddVerticalLine(if verticallines == yes then if Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then 1 else 0 else 0, if  Diff[1] <= 0 and Diff > 0 then "                                                                               Chart Up" else if Diff[1] >= 0 and Diff < 0 then "                                                                                   Chart Down" else "", if Diff[1] <= 0 and Diff > 0 then Color.GREEN else Color.RED, stroke = Curve.LONG_DASH);
          #Option 2 - Dots and Lines connecting Dots
          input showdots=no;
          def count = if Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then 1 else 0;
          plot line = if showdots==yes and count == 1 then close[1] else Double.NaN;
          line.SetPaintingStrategy(PaintingStrategy.LINE);
          line.AssignValueColor(if Diff > 0 then Color.GREEN else Color.RED);
          line.EnableApproximation();
          plot dot = if showdots==yes and count == 1 then close[1] else Double.NaN;
          dot.SetPaintingStrategy(PaintingStrategy.POINTS);
          dot.AssignValueColor(if Diff[1] <= 0 and Diff > 0 then Color.GREEN else Color.RED);
          dot.SetLineWeight(5);
          #Option 3 - Horizontal Lines
          input showhzlinesprimary=no;
          rec count1 = CompoundValue( 1, if IsNaN( Diff ) then count1[1] else if count then close else count1[1], close );
          plot line1 = if showhzlinesprimary then count1[displace] else double.nan;
          line1.SetPaintingStrategy(PaintingStrategy.POINTS);
          line1.assignvalueColor(if Diff > 0 then color.light_green else if Diff==0 then color.yellow else color.light_red);
          line1.setlineweight(1);

          #Option 4 - Colored Price Bars Cross Above / Below Zero (pricecolorzero=yes and pricecolortrend=no)
          #Option 5 - Colored Price Bars Above Below Zero and Trend (pricecolortrend=yes)
          AssignPriceColor(if pricecolorzero == yes and pricecolortrend == no then (if  Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then Color.YELLOW else Color.CURRENT) else if pricecolortrend == yes then if  Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then Color.YELLOW else (if Diff >= 0 then if Diff > Diff[1] then Color.GREEN else Color.light_green else if Diff < Diff[1] then Color.RED else Color.dark_red) else Color.CURRENT);
          #MACD Different Timeframe (#1) Vertical Line and or Horizontal Line
          input period1=aggregationPeriod.Five_MIN;
          def Value1 =  ExpAverage(close(period=period1), fastLength) -  ExpAverage(close(period=period1), slowLength);
          def Avg1   = ExpAverage(ExpAverage(close(period=period1), fastLength) -  ExpAverage(close(period=period1), slowLength), MACDLength);
          def Diff1 = Value1 - Avg1;
          input verticallines1=yes;
          AddVerticalLine(visible = if Verticallines1 == yes then if Diff1[1] <= 0 and Diff1 > 0 or Diff1[1] >= 0 and Diff1 < 0 then 1 else 0 else 0, text = if  Diff1[1] <= 0 and Diff1 > 0 then "                                                             2nd Timeframe UP" else if Diff1[1] >= 0 and Diff1 < 0 then "                                                                        2nd Timeframe DOWN" else "", color = if Diff1[1] <= 0 and Diff1 > 0 then Color.LIGHT_GREEN else Color.LIGHT_RED);
          input showhzlines1=no;
          rec count_1 = if IsNaN( Diff1 ) then count_1[1] else if  Diff1[1] <= 0 and Diff1 > 0 or Diff1[1] >= 0 and Diff1 < 0 then close(period=period1) else count_1[1];
          plot line_1 = if showhzlines1 then count_1[displace] else double.nan;
          line_1.setpaintingStrategy(PaintingStrategy.SQUARES);
          line_1.assignvalueColor(if Diff1 > 0 then color.green else if diff1==0 then color.yellow else color.red);
          line_1.setlineweight(1);
          #MACD Different Timeframe (#2) Vertical Line and or Horizontal Line
          input period2=aggregationPeriod.FiFTEEN_MIN;
          def Value2 =  ExpAverage(close(period=period2), fastLength) -  ExpAverage(close(period=period2), slowLength);
          def Avg2   = ExpAverage(ExpAverage(close(period=period2), fastLength) -  ExpAverage(close(period=period2), slowLength), MACDLength);
          def Diff2 = Value2 - Avg2;
          input verticallines2=yes;
          AddVerticalLine(visible = if Verticallines2 == yes then if Diff2[1] <= 0 and Diff2 > 0 or Diff2[1] >= 0 and Diff2 < 0 then 1 else 0 else 0, text = if  Diff2[1] <= 0 and Diff2 > 0 then "                                                     3rd Timeframe UP" else if Diff2[1] >= 0 and Diff2 < 0 then "                                                              3rd Timeframe DOWN" else "", color = if Diff2[1] <= 0 and Diff2 > 0 then Color.LIGHT_GREEN else Color.LIGHT_RED);
          input showhzlines2=no;
          rec count2 = if IsNaN( Diff2 ) then count2[1] else if  Diff2[1] <= 0 and Diff2 > 0 or Diff2[1] >= 0 and Diff2 < 0 then close(period=period2) else count2[1];
          plot line2 = if showhzlines2 then count2[displace] else double.nan;
          line2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
          line2.assignvalueColor(if Diff2 > 0 then color.dark_green else if Diff2==0 then color.yellow else color.dark_red);
          line2.setlineWeight(3);
          #Alerts
          Alert( if Diff[1] <= 0 and Diff > 0 or Diff[1] >= 0 and Diff < 0 then 1 else 0, text = "MACD Cross of Zeroline", "alert type" = Alert.BAR, sound = Sound.Ding);
        Your message has been successfully submitted and would be delivered to recipients shortly.