Cumulative Overnight Volume column


Category:
0
0

Hi Pete,

Thanks to your awesome tutorial videos I was able to create a custom column that changes color if the pre market cumulative volume is greater than the 5 day average. My problem is that the watch list color disappears after the premarket is over. Is there a way to keep the watchlist custom color the entire day if the total premarket volume exceeds the 5 day average?  Below I have provided my script. For the sake of space I did not copy the entire TOS Cumulative Overnight Volume script.  Thank you!

<I copied the TOS “Cumulative Overnight Volume Script” and added the code below>

def volumespike = RelativeVolume().”CumulativeOvernightVolume” is greater than RelativeVolume().”AverageOvernightVolume”;
plot scan = volumespike;
assignBackgroundColor(if volumespike then color.white else color.black);

Marked as spam
Posted by (Questions: 19, Answers: 18)
Asked on September 2, 2020 4:58 pm
417 views
0
Private answer

There seems to be an error in your code. You are referencing a study named "RelativeVolume" however no such study exists on Thinkorswim. So it produces an error. Instead you should be using this:

def volumespike = CumulativeOvernightVolume().”CumulativeOvernightVolume” is greater than CumulativeOvernightVolume().”AverageOvernightVolume”;

The reason your watchlist fails to work during regular market hours is that you are referencing a value that is NaN during regular market hours: CumulativeOvernightVolume().”CumulativeOvernightVolume”

You can see this for yourself by adding the ”CumulativeOvernightVolume” study to your chart.

So you need to break that out from your code and create a recursive variable that checks when that value stops plotting and carries it forward into the regular session hours. But it also must check if the original value is available and use that until it becomes unavailable. Confused? Yes, this is folds within folds:

def targetVolume = CumulativeOvernightVolume().”CumulativeOvernightVolume”;
rec trackTargetVolume = if !IsNaN(targetVolume[1]) and IsNaN(targetVolume) then targetVolume[1] else if !IsNaN(targetVolume) then targetVolume else trackTargetVolume[1];
plot volumeSpike = trackTargetVolume > CumulativeOvernightVolume().”AverageOvernightVolume”;
AssignBackgroundColor(if volumeSpike then Color.WHITE else Color.BLACK);

By the way, because I referenced the name of the chart study that code right there is 100% self contained. Works just as it is and no need to add that to the bottom of the original code.

Marked as spam
Posted by (Questions: 37, Answers: 4117)
Answered on September 2, 2020 6:13 pm