Plot text where volume forecast is reached


Category:
0
0

Hello Pete, I was working on some code from learning from some of your past posts. However, I am lost when it comes to plotting an arrow when the following condition below in bold is met. Can you use the solution below and show us how to plot an arrow under the candle that triggers this condition.

 

. Best

 

def Pre = if SecondsFromTime(100) > 0 and
SecondsTillTime(0930) >= 0
then 1
else 0;
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def vol = if isRollover and beforeStart then volume else if beforeStart then vol[1] + volume else Double.NaN;
def PreMarketVol = if IsNaN(vol) then PreMarketVol[1] else vol ;
def volumeforecast= (preMarketVol)*10;

#vOLUMEfromopentODAY
def totaldayvolume = volume(period = “DAY”);
plot data = if IsNaN(close[-1]) then totaldayvolume else Double.NaN;

#forecast 50%
def VF50percent = (volumeforecast) /2;
AddLabel(yes, “VF 50%: ” + vf50percent, if totaldayvolume > vf50percent and premarketVol> 500000 then Color.green else Color.white);

#Once VF50% IS GREEN ^^ THEN draw a green big upwards arrow at low of the current candle only in which this event was triggered

Marked as spam
Posted by (Questions: 22, Answers: 63)
Asked on October 19, 2019 6:23 am
384 views
0
Or even better, lets ignore the arrow can we place a text under the candle instead of an arrow that says ”VF50%”
( at October 19, 2019 6:54 am)
0
Yes, but I am going to update the question title to reflect that so the rest of our viewers can search for and find this solution. While doing so, I will also remove non-essential words from the title. Something like: "Plot text where volume forecast is reached"
( at October 19, 2019 8:51 am)
0
Private answer

In the comments section above, the author of the post changed the request to plot text instead of an up arrow. The title of the question has been updated to reflect that change.

The solution to this request is found in this line of code from the chart study provided in the request:

AddLabel(yes, “VF 50%: ” + vf50percent, if totaldayvolume > vf50percent and premarketVol> 500000 then Color.green else Color.white);

From this we just need to grab the if/then/else statement that dynamically sets the color of the label:

if totaldayvolume > vf50percent and premarketVol> 500000

We only need the true/false condition from this snippet (remove the word 'if' from that line). Then we simply assign that to a new variable statement. Which we add at the very bottom of the code you provided:

def signal = totaldayvolume > vf50percent and premarketVol> 500000;

This variable will be true for every bar after the condition is true. If we used just use that signal for our chart bubble it would plot a chart bubble on every candle of the chart after the signal is true. So we just need to capture the very first bar where the condition is true. We do this by forming a statement that checks if the previous bar on the chart is false and the current bar on the chart is true:

!signal[1] and signal

Don't add that to the code. I just wanted to show what that looks like before adding it to the chart bubble statement. As follows:

AddChartBubble(!signal[1] and signal, low, "VF 50%", Color.BLUE, no);

Full details about how to apply the chart bubble here:

https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AddChartBubble.html

Now that I have explained everything step-by-step. Here are the two lines of code you will add to the bottom of the chart study provided in the request above:

def signal = totaldayvolume > vf50percent and premarketVol> 500000;
AddChartBubble(!signal[1] and signal, low, "VF%", Color.BLUE, no);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on October 19, 2019 12:08 pm
0
how can i mod it to display on the price candle... The code logic should not have the bubble trigger premarket so the bubble shouldn't be premarket. 
( at October 19, 2019 3:18 pm)
0
The logic is precisely the same logic used to change the color of your label to green. If you want some other behavior you will have to provide the code to accomplish that. I am only matching your request with the code you provided. If the chart bubble is appearing during premarket hours then your label is also changing during premarket hours. The two are exactly the same.
( at October 19, 2019 5:03 pm)