Relative Volume Scan first 3 bars


Category:
0
0

I wish to adapt this a relative volume indicator to a scan but am having trouble converting the plot of the indicator into a functional scan line. I wish to have the scan fire whenever volume in any of the first 3 bars is greater than average over the entire period in that specific bar available on 15 min scan which I believe is 20, so avg of that bar over last 19 days. Original indicator plots every bar but I only am interested in the first 3. In the simplest of terms I wish for the scan to fire whenever any of the first three 15 minute bars plot yellow on original indicator.


declare lower;
#declare fullrange;
def na = double.nan;
#input opentime = 0930;
#def AP = getAggregationPeriod();
rec barcounter = if getDay() != getDay()[1] then 1 else barcounter[1] + 1;

rec daycount = if barNumber() == 1 then 0 else if getDay() > getDay()[1] then 1 else 0;

def istoday = if getLastDay() == getDay() then 1 else 0;

def bar1volume = if istoday then 0 else if barcounter == 1 then volume else 0;
def bar2volume = if istoday then 0 else if barcounter == 2 then volume else 0;
def bar3volume = if istoday then 0 else if barcounter == 3 then volume else 0;

def avgbar1 = TotalSum(bar1volume) / TotalSum(daycount);
def avgbar2 = TotalSum(bar2volume) / TotalSum(daycount);
def avgbar3 = TotalSum(bar3volume) / TotalSum(daycount);

def AvgVol = if getDay() != getLastDay() then na
else if barcounter == 1 then avgbar1
else if barcounter == 2 then avgbar2
else if barcounter == 3 then avgbar3

else na;

plot relavgvol=100;
relavgvol.SetDefaultColor(color.dark_gray);
#avgvol.setstyle(curve.points);
relavgvol.SetLineWeight(1);
plot zero = 0;
AddCloud(relavgvol, zero, color.gray);

plot vol = ceil(volume/avgvol*100);
vol.SetLineWeight(3);
vol.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
vol.AssignValueColor(if !istoday then color.cYAN else if vol > relavgvol then color.yellow else color.gray);

zero.hideBubble();
relavgvol.hidebubble();

I shortened the code above in order to fit post limit and for first 3 bars. Original code went up to 81 bars for each section of barxvolume, avgbarx, and barcounter

Thank you very much!

Marked as spam
Posted by (Questions: 6, Answers: 4)
Asked on April 20, 2020 10:51 pm
328 views
0
Edit window was giving me issues but wanted to add that the indicator plots volume in terms of % in whole numbers. If volume is 500k avg and 750k currently plot would show yellow histo at 150
( at April 20, 2020 11:12 pm)
0
Private answer

If I understand how this code works, your volume for bar one is here:

def bar1volume = if istoday then 0 else if barcounter == 1 then volume else 0;

The average of that value for bar one is here:

def avgbar1 = TotalSum(bar1volume) / TotalSum(daycount);

If I am correct then your scan statement would be:

plot scan = bar1volume > avgbar1;

That would be triggered when the volume of bar one is greater than the average for that bar.

If you simply wanted to replicate what the indicator does to color the bar yellow, that logic is found in the following statement of your code:

vol.AssignValueColor(if !istoday then color.cYAN else if vol > relavgvol then color.yellow else color.gray);

Specifically, the portion that sets the candle to yellow is:

if vol > relavgvol then color.yellow

So you can create a scan statement from that by just copying the portion between the if and then:

plot scan = if vol > relavgvol;

 

 

Marked as spam
Posted by (Questions: 37, Answers: 4091)
Answered on April 21, 2020 7:16 am
0
Thank you for the quick response, Pete. I tried the first scan plot but had no luck in returning any results. The second scan plot did return results but isn't picking up many tickers just by glancing at it. For example it did not pick up AMD for having greater than 100% avg volume on the first two 15 minute bars. Would I need to specify agg period in code or is selecting it in the scan sufficient? Thank you
( at April 21, 2020 8:02 am)
0
You cannot specify an aggregation period within the code of any custom scan. Secondary aggregation periods are not supported in scans. The most likely reason your results don't match the charts is because at the 15 min time frame a scan only has 11 days of historical data to look back on: https://tlc.thinkorswim.com/center/howToTos/thinkManual/Scan/Stock-Hacker/studyfilters
( at April 21, 2020 8:23 am)