Volume for specific time frame


Category:
0
0

Hi Mr. Hahn,

I would like to know if you have any script that would show volume for a specific time frame such as from from 4am till 929am as a label on the chart. I am trying to learn trading and this would be really helpful in my analysis. Thanks

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on September 1, 2018 9:21 pm
966 views
0

Hey Mr. Hahn. Can you please help me edit this existing code here?
input startTime = 930;
input endTime = 1031;
def startCounter = SecondsFromTime(startTime);
def endCounter = SecondsTillTime(endTime);
plot targetPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
rec volumeTotal = if targetPeriod and !targetPeriod[1] then volume else if targetPeriod then volumeTotal[1] + volume else volumeTotal[1];
AddLabel(yes, Concat(“1stHRvol: “, volumeTotal), Color.LIGHT_GRAY);
 
what I’d like to do is be able to scroll back and get the values (pm high & low, pm volume) for whichever day the chart is currently on.
Also need to edit these 2 codes do do the same thing (1st hour Volume and 2nd hour Volume):
 
input startTime = 930;
input endTime = 1031;
def startCounter = SecondsFromTime(startTime);
def endCounter = SecondsTillTime(endTime);
plot targetPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
rec volumeTotal = if targetPeriod and !targetPeriod[1] then volume else if targetPeriod then volumeTotal[1] + volume else volumeTotal[1];
AddLabel(yes, Concat(“1stHRvol: “, volumeTotal), Color.LIGHT_GRAY);

input startTime = 1031;
input endTime = 1131;
def startCounter = SecondsFromTime(startTime);
def endCounter = SecondsTillTime(endTime);
plot targetPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
rec volumeTotal = if targetPeriod and !targetPeriod[1] then volume else if targetPeriod then volumeTotal[1] + volume else volumeTotal[1];
AddLabel(yes, Concat(“2ndHRvol: “, volumeTotal), Color.LIGHT_GRAY);
 
 
 
 

( at September 21, 2018 9:36 am)
0

If I understand what you are requesting, this is impossible to do on Thinkorswim. So let me explain what I think you are asking and correct me if I’m wrong. You want the chart labels to change the value they display based on the activity of you scrolling through the bars on the chart.

If this is what you are requesting, it is completely impossible. Thinkorswim does not provide anything in their programming language to do this.

( at September 21, 2018 10:22 am)
0
Private answer

In order to handle the start and end times, I’m going to borrow some code we previously published: https://www.hahn-tech.com/thinkorswim-overnight-range-scan-alert/

The code will plot a chart label that contains the total volume for the target period.

input startTime = 400;
input endTime = 929;
def startCounter = SecondsFromTime(startTime);
def endCounter = SecondsTillTime(endTime);
plot targetPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
rec volumeTotal = if targetPeriod and !targetPeriod[1] then volume else if targetPeriod then volumeTotal[1] + volume else volumeTotal[1];
AddLabel(yes, Concat("Target Period Volume: ", volumeTotal), Color.GRAY);

Screenshot below shows how the computations are  accumulated through the target period and held until the next target period begins.

Edit:

After providing the solution shown above, the viewer has requested two additional items to be added to the chart. See the comment section below for details. The second version of the code follows:

input startTime = 400;
input endTime = 929;
def startCounter = SecondsFromTime(startTime);
def endCounter = SecondsTillTime(endTime);
def targetPeriod = startCounter >= 0 and endCounter >= 0;
rec volumeTotal = if targetPeriod and !targetPeriod[1] then volume else if targetPeriod then volumeTotal[1] + volume else volumeTotal[1];
rec targetHighest = if targetPeriod and !targetPeriod[1] then high else if targetPeriod and high > targetHighest[1] then high else targetHighest[1];
rec targetLowest = if targetPeriod and !targetPeriod[1] then low else if targetPeriod and low < targetLowest[1] then low else targetLowest[1];
AddLabel(yes, Concat("Target Period Volume: ", volumeTotal), Color.GRAY);
AddLabel(yes, Concat("Target Period Highest: " , targetHighest), Color.GRAY);
AddLabel(yes, Concat("Target Period Lowest: ", targetLowest), Color.GRAY);

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on September 2, 2018 8:39 am
0

Thank you Mr Hahn! works like a charm. Can it possible to add the high and low for the same time period. Sorry if it is too much to ask for.

( at September 2, 2018 6:52 pm)
0

Always best to include all the details from the start. I have updated my answer to include code that adds these other two values to the chart.

( at September 3, 2018 9:42 am)
0

Thank you Mr Hahn! You sir are awesome!. Thank you for helping a student out!

( at September 3, 2018 3:40 pm)