declare lower; def O = open; def H = high; def C = close; def L = low; def V = volume; def Buying = V*(C-L)/(H-L); def Selling = V*(H-C)/(H-L); # Selling Volume Plot SV = selling; SV.setPaintingStrategy(PaintingStrategy.Histogram); SV.SetDefaultColor(createColor(144,144,144)); SV.HideTitle(); SV.HideBubble(); SV.SetLineWeight(5); # Buying Volume # Plot BV = Buying; # Note that Selling + Buying Volume = Volume. Plot BV = volume; BV.setPaintingStrategy(PaintingStrategy.Histogram); BV.SetDefaultColor(createColor(10,93,128)); BV.HideTitle(); BV.HideBubble(); BV.SetLineWeight(5); # Show total volume in gray. Buying volume in green. Sell Volume in red. # Volume average is gray line. # Specified percent over average volume is cyan triangles. # Horserider 12/30/2019 derived from some already existing studies. #Inputs input Show5DayAvg = yes; input ShowTodayVolume = yes; input ShowPercentOf5DayAvg = yes; input UnusualVolumePercent = 180; input Show5BarAvg = yes; input ShowCurrentBar = yes; input ShowPercentOf5BarAvg = yes; input ShowSellVolumePercent = yes; input ShowBuyVolumePercent = yes; # Selling Volume Plot SellVol = selling; SellVol.setPaintingStrategy(PaintingStrategy.Histogram); SellVol.SetDefaultColor(Color.Red); SellVol.HideTitle(); SellVol.HideBubble(); SellVol.SetLineWeight(1); #Volume Data def volLast5weekAvg = (volume(period = "WEEK")[1] + volume(period = "WEEK")[2] + volume(period = "WEEK")[3] + volume(period = "WEEK")[4] + volume(period = "WEEK")[5] + volume(period = "WEEK")[5]) / 5; def today = volume(period = "WEEK"); def percentOf5Day = Round((today / volLast5weekAvg) * 100, 0); def avg5Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5]) / 5; def curVolume = volume; def percentOf5Bar = Round((curVolume / avg5Bars) * 100, 0); def SellVolPercent = Round((Selling / Volume) * 100, 0); def BuyVolPercent = Round((Buying / Volume) * 100, 0); # Labels AddLabel(Show5DayAvg, "5 Day Avg Vol: " + Round(volLast5weekAvg, 0), CreateColor(144,144,144)); AddLabel(ShowTodayVolume, "Today: " + today, (CreateColor(144,144,144))); AddLabel(ShowPercentOf5DayAvg, percentOf5Day + "%", (if percentOf5Day >= UnusualVolumePercent then CreateColor(10,127,72) else if percentOf5Day >= 100 then CreateColor(10,93,128) else CreateColor(144,144,144))); #AddLabel(Show5BarAvg, "Avg 5 Bars: " + Round(avg5Bars, 0), CreateColor(144,144,144)); #AddLabel(ShowCurrentBar, "Current Bar: " + curVolume, (CreateColor(144,144,144))); #AddLabel(ShowPercentOf5BarAvg, PercentOf5Bar + "%", (if PercentOf5Bar >= UnusualVolumePercent #then CreateColor(10,127,72) else if PercentOf5Bar >= 100 then CreateColor(10,93,128) else #CreateColor(144,144,144))); AddLabel(ShowBuyVolumePercent, "Current Buy %: " + BuyVolPercent, (if BuyVolPercent > 75 then CreateColor(10,127,72) #(if BuyVolPercent > 50 then CreateColor(255,255,0) else if BuyVolPercent < 50 then CreateColor(185,40,40) #else if BuyVolPercent > 74 then CreateColor(255,255,0) else CreateColor(144,144,144))); AddLabel(yes, Concat("RSI: ", RSI()."RSI"), if RSI()."RSI" is greater than 69 then createColor(10,127,72) else createColor(144,144,144)); AddLabel(yes, Concat("MACD: ", MACD()."DIFF"), if MACD()."Diff" is greater than 0 then createColor(10,127,72) else createColor(144,144,144)); input length = 5; plot VolAvg = Average(volume, length); VolAvg.SetDefaultColor(CreateColor(10,127,72)); VolAvg.HideTitle(); VolAvg.HideBubble(); VolAvg.SetLineWeight(2); #---------- RSI Inputs input rsiLength = 14; input rsiPrice = close; input rsiAverageType = AverageType.simple; #---------- RSI def netChgAvg = MovingAverage(rsiAverageType, rsiPrice - rsiPrice[1], rsiLength); def totChgAvg = MovingAverage(rsiAverageType, AbsValue(rsiPrice - rsiPrice[1]), rsiLength); def chgRatio = if totChgAvg != 0 then netChgAvg / totChgAvg else 0; def rsi = 50 * (chgRatio + 1); #---------- Condition def paintBar = buyVolPercent between 81 and 100; def paintBar1 = buyVolPercent between 51 and 80; def paintBar2 = buyVolPercent between 0 and 50; #---------- Paint Candles AssignPriceColor(if paintBar then CreateColor(10,127,72) else Color.Current); AssignPriceColor(if paintBar1 then CreateColor(175,175,0) else Color.Current); AssignPriceColor(if paintBar2 then CreateColor(185,40,40) else Color.Current);