Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###########################################################################
- #PriceLevelMarker - Automatically Plot Important Price Levels in ToS
- #Creator: u/--SubZer0--
- #Version: 2.0
- #Last Updated: 12.31.2022
- #############################################################################
- #hint showOnlyLastPeriod: Yes will show plots only for current day. <br />No will show it for all days visible on your chart timeframe
- #hint showPlotLabels: Display labels to clearly identify each plot. The position of these chart labels is controlled by plotLabelOffset
- #hint plotLabelOffset: This value determines where to show the chart label. The default is 5, which means the chart label will be displayed on the far right of the chart at the price axis and the distance between the latest candle and the label will be 5 bars. Note: This number cannot be greater than the <b>Expansion Area</b> defined in "Chart Style -> Settings -> Time Axis -> Expansion Area" otherwise the label will not be displayed.
- #User input
- input showOnlyLastPeriod = yes;
- input showPlotLabels = yes;
- input plotLabelOffset = 0;
- input showOvernightGapRegion = yes;
- input ShowOvernightGapBoundary = no;
- input ShowOvernightGapMean = Yes;
- input showTodayOpen = yes;
- input showTodayHigh = yes;
- input showTodayLow = yes;
- input showYClose = yes;
- input showYHigh = yes;
- input showYLow = yes;
- input showYYHigh = yes;
- input showYYLow = yes;
- input show52WkHigh = yes;
- input show52WkLow = yes;
- input show5YHigh = yes;
- input show5YLow = yes;
- input showDaily50SMA = yes;
- input showDaily100SMA = yes;
- input showDaily200SMA = yes;
- #Default constants
- def paintStrategyLine = PaintingStrategy.LINE;
- def paintStrategyDashes = PaintingStrategy.DASHES;
- def styleSolid = Curve.FIRM;
- def styleShortDash = Curve.SHORT_DASH;
- def styleMediumDash = Curve.MEDIUM_DASH;
- def styleLongDash = Curve.LONG_DASH;
- def stylePoints = Curve.POINTS;
- def lineWeight = 1;
- DefineGlobalColor("OvernightGapRegion", Color.LIGHT_GRAY);
- def aggregationPeriod = AggregationPeriod.DAY;
- def maPriceType = FundamentalType.CLOSE;
- def sma50Length = 50;
- def sma100Length = 100;
- def sma200Length = 200;
- def length = 1;
- def nan = Double.NaN;
- def labelLocBar = !IsNaN(close) and IsNaN(close[-1]);
- def displace0 = 0;
- def displace1 = 1;
- def displace2 = 2;
- ###########################################################################
- ##
- ## Plot Open (Today's Open Price)
- ##
- ###########################################################################
- plot TodayOpen;
- if !showTodayOpen or (showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriod)[-1]))
- {
- TodayOpen = Double.NaN;
- }
- else
- {
- TodayOpen = open(period = aggregationPeriod)[displace0];
- }
- TodayOpen.SetDefaultColor(Color.BLUE);
- TodayOpen.SetPaintingStrategy(paintStrategyDashes);
- TodayOpen.SetLineWeight(lineWeight);
- TodayOpen.HideBubble();
- AddChartBubble(showTodayOpen and showPlotLabels and labelLocBar[plotLabelOffset], TodayOpen[plotLabelOffset], "Op", Color.CYAN);
- ###########################################################################
- ##
- ## Plot High and Low (High and Low of Today)
- ##
- ###########################################################################
- plot High;
- plot Low;
- if !showTodayHigh or (showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]))
- {
- High = nan;
- }
- else
- {
- High = Highest(high(period = aggregationPeriod)[displace0], length);
- }
- if !showTodayLow or (showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]))
- {
- Low = nan;
- }
- else
- {
- Low = Lowest(low(period = aggregationPeriod)[displace0], length);
- }
- High.SetDefaultColor(Color.BLUE);
- High.SetPaintingStrategy(paintStrategyLine);
- High.SetStyle(styleLongDash);
- High.SetLineWeight(lineWeight);
- Low.SetDefaultColor(Color.BLUE);
- Low.SetPaintingStrategy(paintStrategyLine);
- Low.SetStyle(styleShortDash);
- Low.SetLineWeight(lineWeight);
- High.HideBubble();
- Low.HideBubble();
- AddChartBubble(showTodayHigh and showPlotLabels and labelLocBar[plotLabelOffset], High[plotLabelOffset], "Hi", Color.Light_GRAY, 0);
- AddChartBubble(showTodayLow and showPlotLabels and labelLocBar[plotLabelOffset], Low[plotLabelOffset], "Lo", Color.LIGHT_GRAY, 0);
- ###########################################################################
- ##
- ## Plot YClose (Previous day close)
- ##
- ###########################################################################
- plot YClose;
- if !showYClose
- or IsNaN(close(period = aggregationPeriod))
- or (showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]))
- {
- YClose = Double.NaN;
- }
- else
- {
- YClose = close(period = aggregationPeriod)[displace1];
- }
- YClose.SetDefaultColor(Color.ORANGE);
- YClose.SetPaintingStrategy(paintStrategyDashes);
- YClose.SetLineWeight(lineWeight);
- YClose.HideBubble();
- AddChartBubble(showYClose and showPlotLabels and labelLocBar[plotLabelOffset], YClose[plotLabelOffset], "YCl", Color.LIGHT_ORANGE);
- ###########################################################################
- ##
- ## Plot Overnight Gap (Gap between previous day close and today's open)
- ##
- ###########################################################################
- plot UpperGapBoundary = if showOvernightGapBoundary then if YClose > TodayOpen then YClose else TodayOpen else Double.NaN;
- plot LowerGapBoundary = if showOvernightGapBoundary then if YClose > TodayOpen then TodayOpen else YClose else Double.NaN;
- plot GapMean = if showOvernightGapMean then (YClose + TodayOpen) / 2 else Double.NaN;
- AddCloud(if showOvernightGapRegion then YClose else Double.NaN, if showOvernightGapRegion then TodayOpen else Double.NaN, GlobalColor("OvernightGapRegion"), GlobalColor("OvernightGapRegion"));
- UpperGapBoundary.SetStyle(Curve.POINTS);
- UpperGapBoundary.SetDefaultColor(Color.GRAY);
- UpperGapBoundary.SetHiding(!showOvernightGapBoundary);
- UpperGapBoundary.HideBubble();
- LowerGapBoundary.SetStyle(Curve.POINTS);
- LowerGapBoundary.SetDefaultColor(Color.GRAY);
- LowerGapBoundary.SetHiding(!showOvernightGapBoundary);
- LowerGapBoundary.HideBubble();
- GapMean.SetStyle(Curve.POINTS);
- GapMean.SetDefaultColor(Color.GRAY);
- GapMean.SetHiding(!showOvernightGapMean);
- GapMean.HideBubble();
- ###########################################################################
- ##
- ## Plot YHigh and YLow (High and Low of Yesterday)
- ##
- ###########################################################################
- plot YHigh;
- plot YLow;
- if !showYHigh
- or IsNaN(close(period = aggregationPeriod))
- or (showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]))
- {
- YHigh = nan;
- }
- else
- {
- YHigh = high(period = aggregationPeriod)[displace1];
- }
- if !showYLow
- or IsNaN(close(period = aggregationPeriod))
- or (showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]))
- {
- YLow = nan;
- }
- else
- {
- YLow = low(period = aggregationPeriod)[displace1];
- }
- YHigh.SetDefaultColor(Color.ORANGE);
- YHigh.SetPaintingStrategy(paintStrategyLine);
- YHigh.SetStyle(styleLongDash);
- YHigh.SetLineWeight(lineWeight);
- YLow.SetDefaultColor(Color.ORANGE);
- YLow.SetPaintingStrategy(paintStrategyLine);
- YLow.SetStyle(styleShortDash);
- YLow.SetLineWeight(lineWeight);
- YHigh.HideBubble();
- YLow.HideBubble();
- AddChartBubble(showYHigh and showPlotLabels and labelLocBar[plotLabelOffset], YHigh[plotLabelOffset], "YHi", Color.Light_GRAY);
- AddChartBubble(showYLow and showPlotLabels and labelLocBar[plotLabelOffset], YLow[plotLabelOffset], "YLo", Color.LIGHT_GRAY, 0);
- ###########################################################################
- ##
- ## Plot YYHigh and YYLow (High and Low Two days ago)
- ##
- ###########################################################################
- plot YYHigh;
- plot YYLow;
- if !showYYHigh
- or IsNaN(close(period = aggregationPeriod))
- or (showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]))
- {
- YYHigh = nan;
- }
- else
- {
- YYHigh = Highest(high(period = aggregationPeriod)[displace2], length);
- }
- if !showYYLow
- or IsNaN(close(period = aggregationPeriod))
- or (showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]))
- {
- YYLow = nan;
- }
- else
- {
- YYLow = Lowest(low(period = aggregationPeriod)[displace2], length);
- }
- YYHigh.SetDefaultColor(Color.MAGENTA);
- YYHigh.SetPaintingStrategy(paintStrategyLine);
- YYHigh.SetStyle(styleLongDash);
- YYHigh.SetLineWeight(lineWeight);
- YYLow.SetDefaultColor(Color.MAGENTA);
- YYLow.SetPaintingStrategy(paintStrategyLine);
- YYLow.SetStyle(styleShortDash);
- YYLow.SetLineWeight(lineWeight);
- YYHigh.HideBubble();
- YYLow.HideBubble();
- AddChartBubble(showYYHigh and showPlotLabels and labelLocBar[plotLabelOffset], YYHigh[plotLabelOffset], "YYHi", Color.Light_GRAY);
- AddChartBubble(showYYLow and showPlotLabels and labelLocBar[plotLabelOffset], YYLow[plotLabelOffset], "YYLo", Color.LIGHT_GRAY, 0);
- ###########################################################################
- ##
- ## Plot _52WkHigh and _52WkLow - (Highest and lowest during the last 52 weeks)
- ##
- ###########################################################################
- plot _52WkHigh;
- plot _52WkLow;
- if !show52WkHigh
- or IsNaN(close(period = aggregationPeriod))
- or (showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]))
- {
- _52WkHigh = nan;
- }
- else
- {
- _52WkHigh = Highest(high(period = aggregationPeriod)[displace0], 252);
- }
- if !show52WkLow
- or IsNaN(close(period = aggregationPeriod))
- or (showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]))
- {
- _52WkLow = nan;
- }
- else
- {
- _52WkLow = Lowest(low(period = aggregationPeriod)[displace0], 252);
- }
- _52WkHigh.SetDefaultColor(Color.PLUM);
- _52WkHigh.SetPaintingStrategy(paintStrategyLine);
- _52WkHigh.SetStyle(styleLongDash);
- _52WkHigh.SetLineWeight(lineWeight);
- _52WkLow.SetDefaultColor(Color.PLUM);
- _52WkLow.SetPaintingStrategy(paintStrategyLine);
- _52WkLow.SetStyle(styleShortDash);
- _52WkLow.SetLineWeight(lineWeight);
- _52WkHigh.HideBubble();
- _52WkLow.HideBubble();
- AddChartBubble(show52WkHigh and showPlotLabels and labelLocBar[plotLabelOffset], _52WkHigh[plotLabelOffset], "52Hi", Color.Light_RED);
- AddChartBubble(show52WkLow and showPlotLabels and labelLocBar[plotLabelOffset], _52WkLow[plotLabelOffset], "52Lo", Color.LIGHT_GREEN, 0);
- ###########################################################################
- ##
- ## Plot 5YHigh and 5YLow - (Highest and lowest during the last 5 years)
- ## ToS does not support plotting "all time high" or "all time low" because
- ## of data limitations within ToS.
- ##
- ###########################################################################
- plot _5YHigh;
- plot _5YLow;
- def years = 5;
- if !show5YHigh
- or IsNaN(close(period = aggregationPeriod))
- or (showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]))
- {
- _5YHigh = nan;
- }
- else
- {
- _5YHigh = Highest(high(period = aggregationPeriod)[displace1], 252*years);
- }
- if !show5YLow
- or IsNaN(close(period = aggregationPeriod))
- or (showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]))
- {
- _5YLow = nan;
- }
- else
- {
- _5YLow = Lowest(low(period = aggregationPeriod)[displace1], 252*years);
- }
- _5YHigh.SetDefaultColor(Color.GRAY);
- _5YHigh.SetPaintingStrategy(paintStrategyLine);
- _5YHigh.SetStyle(styleLongDash);
- _5YHigh.SetLineWeight(lineWeight);
- _5YLow.SetDefaultColor(Color.GRAY);
- _5YLow.SetPaintingStrategy(paintStrategyLine);
- _5YLow.SetStyle(styleShortDash);
- _5YLow.SetLineWeight(lineWeight);
- _5YHigh.HideBubble();
- _5YLow.HideBubble();
- AddChartBubble(show5YHigh and showPlotLabels and labelLocBar[plotLabelOffset], _5YHigh[plotLabelOffset], "5Hi", Color.Light_RED);
- AddChartBubble(show5YLow and showPlotLabels and labelLocBar[plotLabelOffset], _5YLow[plotLabelOffset], "5Lo", Color.LIGHT_GREEN, 0);
- ###########################################################################
- # Plot Daily 50SMA on Intra-Day Charts
- #
- #############################################################################
- plot Daily50SMA;
- if !showDaily50SMA or (showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]))
- {
- Daily50SMA = Double.NaN;
- }
- else
- {
- Daily50SMA = Average(fundamental(maPriceType, period = aggregationPeriod)[-displace0], sma50Length);
- }
- Daily50SMA.SetDefaultColor(Color.PINK);
- Daily50SMA.SetPaintingStrategy(paintStrategyLine);
- Daily50SMA.SetStyle(styleSolid);
- Daily50SMA.SetLineWeight(lineWeight+1);
- Daily50SMA.HideBubble();
- AddChartBubble(showDaily50SMA and showPlotLabels and labelLocBar[plotLabelOffset], Daily50SMA[plotLabelOffset], sma50Length + "", Color.PINK);
- ###########################################################################
- # Plot Daily 100SMA on Intra-Day Charts
- #
- #############################################################################
- plot Daily100SMA;
- if !showDaily100SMA or (showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]))
- {
- Daily100SMA = Double.NaN;
- }
- else
- {
- Daily100SMA = Average(fundamental(maPriceType, period = aggregationPeriod)[-displace0], sma100Length);
- }
- Daily100SMA.SetDefaultColor(Color.BLACK);
- Daily100SMA.SetPaintingStrategy(paintStrategyLine);
- Daily100SMA.SetStyle(styleSolid);
- Daily100SMA.SetLineWeight(lineWeight+1);
- Daily100SMA.HideBubble();
- AddChartBubble(showDaily100SMA and showPlotLabels and labelLocBar[plotLabelOffset], Daily100SMA[plotLabelOffset], sma100Length + "", Color.CYAN);
- ###########################################################################
- # Plot Daily 200SMA on Intra-Day Charts
- #
- #############################################################################
- plot Daily200SMA;
- if !showDaily200SMA or (showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]))
- {
- Daily200SMA = Double.NaN;
- }
- else
- {
- Daily200SMA = Average(fundamental(maPriceType, period = aggregationPeriod)[-displace0], sma200Length);
- }
- Daily200SMA.SetDefaultColor(Color.MAGENTA);
- Daily200SMA.SetPaintingStrategy(paintStrategyLine);
- Daily200SMA.SetStyle(styleSolid);
- Daily200SMA.SetLineWeight(lineWeight+1);
- Daily200SMA.HideBubble();
- AddChartBubble(showDaily200SMA and showPlotLabels and labelLocBar[plotLabelOffset], Daily200SMA[plotLabelOffset], sma200Length + "", Color.MAGENTA);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement