Help with script PLEASE! :)

Freddie_CM

New member
VIP
Hello all,

I am asking for anyone's assistance in helping me plot arrows for the following script. I found this script to be extremely useful found at: https://usethinkscript.com/threads/...trategy-for-directional-options.15954/

The script has two volume lines called "SmartVolAvg1" and "SmartVolAvg2." I would like to generate an UpArrow (on the upper chart please) when BOTH lines SIMULTANEOUSLY turn green and a DownArrow when BOTH line SIMULTANEOUSLY turn red. I am no coder but I will forever be grateful for anyones help with this and would love to be able use this to scan as well. Thank you SO much in advance. Script below:

Code:
declare on_volume;
declare real_size;
declare zerobase;

input ShowAvolLabels =  yes;
input ShowAvolLines =  yes;
input ShowAmPmGainLabels =  yes;
input ShowTodayVolume =  yes;
input ShowCurrentBarVolume = yes;
input UnusualVolumePercent = 200;
input ShowCurrentBarBuySellPercent = yes;
input ShowSmartAvgOneBuySellPercent = yes;
input ShowSmartAvgTwoBuySellPercent = yes;
input SmartAverageLineOneLength = 6;
input SmartAverageLineTwoLength = 30;
input ShowRelativeVolumeLines = {default LinePct, LineOnly, None};
input RelativeVolumeThreshold = 2.2;
input RelativeVolumeLength = 90;
input RelativeVolumeLineBuySellPercent = 75;
input RSIOverboughtThreshold = 80;
input RSIOversoldThreshold = 20;
input ShowvolLast30DayAvg = yes;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;

#Buying / Selling Code

def Buying = if H == L then V / 2 else Round (V * (C - L) / (H - L), 0);
def Selling = if H == L then V / 2 else Round (V * (H - C) / (H - L), 0);

#Pre-Mkt Accumulated Volume (AVOL) Comparison Code

def PreMkt = SecondsFromTime(0400) >= 0 and SecondsTillTime(0930) > 0;
def NewPM = PreMkt and !PreMkt[1];
def AVOL = if NewPM then V else if PreMkt then AVOL[1] + V else AVOL[1];

def AVOLB = if NewPM then Buying else if PreMkt then AVOLB[1] + Buying else AVOLB[1];
def AVOLS = if NewPM then Selling else if PreMkt then AVOLS[1] + Selling else AVOLS[1];

def AvolBuyPercent = Round((AVOLB / AVOL) * 100, 0);
def AvolSellPercent = Round((AVOLS / AVOL) * 100, 0);

def Count = Count[1] + if NewPM then 1 else 0;

def AV1;
def AV2;
def AV3;
def AV4;

if (NewPM and Count > 1) {
    AV1 = AVOL[1];
    AV2 = AV1[1];
    AV3 = AV2[1];
    AV4 = AV3[1];
} else {
    AV1 = AV1[1];
    AV2 = AV2[1];
    AV3 = AV3[1];
    AV4 = AV4[1];
}

def NoZeros = if AV1 > 0 and AV2 > 0 and AV3 > 0 and AV4 > 0 then yes else no;
def GoodAgg = if GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN then yes else no;

plot AvolPlot = if ShowAvolLines and GoodAgg and NoZeros and PreMkt
then AVOL else Double.NaN;

def AVOL4 = if Count > 4 then (AV1 + AV2 + AV3 + AV4) / 4 else Double.NaN;

def Avg4 = Round((AVOL - AVOL4) / AVOL4 * 100, 1);
def AvgLG = Avg4 >= -25 and Avg4 <= 25;

plot AvgLn = if ShowAvolLines and GoodAgg and NoZeros and PreMkt and AvgLG
then AVOL4 else Double.NaN;
AvgLn.SetDefaultColor(Color.MAGENTA);

AvolPlot.AssignValueColor(if AvolPlot > AVOL4 then Color.MAGENTA else Color.CYAN);
AvolPlot.SetPaintingStrategy(PaintingStrategy.LINE);

def APMVL4 = if AvolPlot crosses above AVOL4 then AvolPlot else Double.NaN;

AddVerticalLine (ShowAvolLines and APMVL4, "", Color.MAGENTA, Curve.MEDIUM_DASH);

#AVOL Labels Code

AddLabel(ShowAvolLabels and NoZeros and GoodAgg, if AVOL > AVOL4 then "AVOL " +
(Round((AVOL - AVOL4) / AVOL4 * 100, 0) + "% > 4DA " +
(if AvolBuyPercent > 50 then "Buy " + AvolBuyPercent + "%" else "Sell " + AvolSellPercent + "%"))

else "AVOL " + (Round((AVOL4 - AVOL) / AVOL4 * 100, 0) + "% < 4DA " +
(if AvolBuyPercent > 50 then "Buy " + AvolBuyPercent + "%" else "Sell " + AvolSellPercent + "%"))
, if AVOL > AVOL4 then Color.MAGENTA else Color.CYAN);

AddLabel(ShowAvolLabels and !NoZeros, "AVOL needs 5 days", Color.LIGHT_GRAY);

def Day = GetDay();
def LDay = GetLastDay();
def CTDay = Day == LDay;

def AftMkt = SecondsFromTime(1600) >= 0 and SecondsTillTime(2000) >= 0;

#Continuation Label One:
#####Previous Day Close (PDC) vs After Mkt Close (AMC) Code

def AMClose = if NewPM then C[1] else AMClose[1];

def AMC = AMClose;

#Previous day close code

def PDClose = if !Day then Double.NaN else close (period = "day")[1];

def PDC = PDClose;

def PctChg1 = Round((AMC - PDC) / PDC * 100, 1);

AddLabel(ShowAmPmGainLabels, "AM Gain " + PctChg1 + "%",
if PctChg1 > 0 then Color.GREEN
else if PctChg1 < 0 then Color.RED
else Color.LIGHT_GRAY);

#Continuation Label Two:
#####After Market Close (AMC) vs Pre-Market Price (PMP) Code

#Pre-Market Current Price Code (PMP)

#Current Day Open Code

def CDOpen = if !Day then Double.NaN else open (period = "day");

######

def CurPrice = HighestAll (if IsNaN(C[-1]) and !IsNaN(C) then C else Double.NaN);

def PMP = if CTDay and PreMkt then CurPrice
else if CDOpen then CDOpen
else Double.NaN;

def PctChg2 = Round((PMP - AMC) / AMC * 100, 1);

AddLabel(ShowAmPmGainLabels, "PM Gain " + PctChg2 + "%",
if PctChg2 > 0 then Color.GREEN
else if PctChg2 < 0 then Color.RED
else Color.LIGHT_GRAY);

#Smart Volume Average

def BuyVolAvg1 = Average((Buying), SmartAverageLineOneLength);
def SellVolAvg1 = Average((Selling), SmartAverageLineOneLength);

def BuyVolAvg2 = Average((Buying), SmartAverageLineTwoLength);
def SellVolAvg2 = Average((Selling), SmartAverageLineTwoLength);

def TVolAvg1 = Average((V), SmartAverageLineOneLength);
def TVolAvg2 = Average((V), SmartAverageLineTwoLength);

def CurBuyVolPercent = Round((Buying / V) * 100, 0);
def CurSellVolPercent = Round((Selling / V) * 100, 0);

def SmartVolOneBuyPercent = Round((BuyVolAvg1 / TVolAvg1) * 100, 0);
def SmartVolOneSellPercent = Round((SellVolAvg1 / TVolAvg1) * 100, 0);
def SmartVolTwoBuyPercent = Round((BuyVolAvg2 / TVolAvg2) * 100, 0);
def SmartVolTwoSellPercent = Round((SellVolAvg2 / TVolAvg2) * 100, 0);

#Volume Data

def AggDay = AggregationPeriod.DAY;
def DayVol = volume(period = AggDay);

def VolLast30DayAvg = (DayVol[1] + DayVol[2] + DayVol[3] + DayVol[4] + DayVol[5] + DayVol[6]
+ DayVol[7] + DayVol[8] + DayVol[9] + DayVol[10] + DayVol[11] + DayVol[12] + DayVol[13]
+ DayVol[14] + DayVol[15] + DayVol[16] + DayVol[17] + DayVol[18] + DayVol[19] + DayVol[20]
+ DayVol[21] + DayVol[22] + DayVol[23] + DayVol[24] + DayVol[25] + DayVol[26] + DayVol[27]
+ DayVol[28] + DayVol[29] + DayVol[30]) / 30;

def PercentOf30Day = Round((DayVol / VolLast30DayAvg) * 100, 0);

def Avg30Bars = (V[1] + V[2] + V[3] + V[4] + V[5] + V[6] + V[7] + V[8] + V[9] + V[10] + V[11]
+ V[12] + V[13] + V[14] + V[15] + V[16] + V[17] + V[18] + V[19] + V[20] + V[21] + V[22] + V[23]
+ V[24] + V[25] + V[26] + V[27] + V[28] + V[29] + V[30]) / 30;

def PercentOf30Bar = Round((V / Avg30Bars) * 100, 0);

#Volume Average Line Code

plot SmartVolAvg1 = Average(V, SmartAverageLineOneLength);
plot SmartVolAvg2 = Average(V, SmartAverageLineTwoLength);

SmartVolAvg1.AssignValueColor
(if BuyVolAvg1 > SellVolAvg1
then Color.GREEN else Color.RED);

SmartVolAvg2.AssignValueColor
(if BuyVolAvg2 > SellVolAvg2
then Color.GREEN else Color.RED);

SmartVolAvg2.SetStyle(Curve.SHORT_DASH);

#Labels

#Todays Volume

AddLabel(ShowTodayVolume, "Today " + DayVol, (if PercentOf30Day >= UnusualVolumePercent
then Color.GREEN else if PercentOf30Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY));

def volLast30Day = (volume(period = "DAY")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;


AddLabel(VolLast30Day, "30D Avg: " + Round(volLast30DayAvg, 0), Color.PLUM);
AddLabel(volLast30day, percentOf30Day + "%", (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.orange else Color.DARK_red) );
#AddLabel(Show30BarAvg, "30 Bar: " + Round(avg30Bars, 0), Color.GRAY);

#Current Bar Volume

AddLabel(ShowCurrentBarVolume, "CurBar " + V, (if PercentOf30Bar >= UnusualVolumePercent
then Color.GREEN else if PercentOf30Bar >= 100 then Color.ORANGE else Color.LIGHT_GRAY));

#Current Bar Buy/Sell Percent

AddLabel(ShowCurrentBarBuySellPercent,
if CurBuyVolPercent >= 50 then "CurBarBuy " + CurBuyVolPercent + "%"
else if CurSellVolPercent >= 50 then "CurBarSell " + CurSellVolPercent + "%"
else "",
(if CurSellVolPercent > 55 then Color.RED else if CurSellVolPercent < 45
then Color.GREEN else Color.LIGHT_GRAY));

#Smart Average One Buy/Sell Percent

AddLabel(ShowSmartAvgOneBuySellPercent,
if SmartVolOneBuyPercent >= 50 then SmartAverageLineOneLength + "BarAvgBuy " + SmartVolOneBuyPercent + "%"
else if SmartVolOneSellPercent >= 50 then SmartAverageLineOneLength + "BarAvgSell " + SmartVolOneSellPercent + "%"
else "",
(if SmartVolOneSellPercent > 55 then Color.RED else if SmartVolOneSellPercent < 45
then Color.GREEN else Color.LIGHT_GRAY));

#Smart Average Two Buy/Sell Percent

AddLabel(ShowSmartAvgTwoBuySellPercent,
if SmartVolTwoBuyPercent >= 50 then SmartAverageLineTwoLength + "BarAvgBuy " + SmartVolTwoBuyPercent + "%"
else if SmartVolTwoSellPercent >= 50 then SmartAverageLineTwoLength + "BarAvgSell " + SmartVolTwoSellPercent + "%"
else "",
(if SmartVolTwoSellPercent > 55 then Color.RED else if SmartVolTwoSellPercent < 45
then Color.GREEN else Color.LIGHT_GRAY));

#Volume Plots

plot SellVol = Selling;
;
plot BuyVol = V;

#Volume Histogram

BuyVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BuyVol.SetLineWeight(1);
BuyVol.SetDefaultColor(Color.GREEN);

SellVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SellVol.SetLineWeight(1);
SellVol.SetDefaultColor(Color.RED);

#Relative Volume Code

def RawRVOL = (V - Average(V, RelativeVolumeLength)) / StDev(V, RelativeVolumeLength);
def RVOL = Max(0, RawRVOL);

#Relative Volume Line Mode Switch

def RvolLineUp1;
def RvolLineDn1;
def RvolLineUp2;
def RvolLineDn2;

switch (ShowRelativeVolumeLines)

{
case LinePct:
    RvolLineUp1 = if RVOL > RelativeVolumeThreshold
  and CurSellVolPercent <= 100 - RelativeVolumeLineBuySellPercent then yes else no;
    RvolLineDn1 = if RVOL > RelativeVolumeThreshold
  and CurSellVolPercent >= RelativeVolumeLineBuySellPercent then yes else no;
    RvolLineUp2 = no;
    RvolLineDn2 = no;
case LineOnly:
    RvolLineUp1 = no;
    RvolLineDn1 = no;
    RvolLineUp2 = if RVOL > RelativeVolumeThreshold
  and CurSellVolPercent <= 100 - RelativeVolumeLineBuySellPercent then yes else no;
    RvolLineDn2 = if RVOL > RelativeVolumeThreshold
  and CurSellVolPercent >= RelativeVolumeLineBuySellPercent then yes else no;
case None:
    RvolLineUp1 = no;
    RvolLineDn1 = no;
    RvolLineUp2 = no;
    RvolLineDn2 = no;
}

#Chart RSI

def NetChgAvg1 = MovingAverage(AverageType.WILDERS, close - close[1], 14);
def TotChgAvg1 = MovingAverage(AverageType.WILDERS, AbsValue(close - close[1]), 14);
def ChgRatio1 = if TotChgAvg1 != 0 then NetChgAvg1 / TotChgAvg1 else 0;
def ChartRSI = 50 * (ChgRatio1 + 1);
def RsiOverBought = ChartRSI >= RSIOverboughtThreshold;
def RsiOverSold = ChartRSI <= RSIOversoldThreshold;

#Relative Volume Vertical Line Code

#Line and Percent

AddVerticalLine (RvolLineUp1 and !RsiOverBought, "                      RV "
+ CurBuyVolPercent + "%", Color.GREEN, Curve.SHORT_DASH);

AddVerticalLine (RvolLineDn1 and !RsiOverSold, "                      RV "
+ CurSellVolPercent + "%", Color.RED, Curve.SHORT_DASH);

AddVerticalLine (RvolLineUp1 and RsiOverBought, "                      RV "
+ CurBuyVolPercent + "% OB", Color.LIME, Curve.SHORT_DASH);

AddVerticalLine (RvolLineDn1 and RsiOverSold, "                      RV "
+ CurSellVolPercent + "% OS", Color.PINK, Curve.SHORT_DASH);

#Line Only

AddVerticalLine (RvolLineUp2 and !RsiOverBought, "",
Color.GREEN, Curve.SHORT_DASH);

AddVerticalLine (RvolLineDn2 and !RsiOverSold, "",
Color.RED, Curve.SHORT_DASH);

AddVerticalLine (RvolLineUp2 and RsiOverBought, "                      OB",
Color.LIME, Curve.SHORT_DASH);

AddVerticalLine (RvolLineDn2 and RsiOverSold, "                      OS",
Color.PINK, Curve.SHORT_DASH);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
358 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top