How to Stamp a Custom Value @ MKT Open and Calculate the Difference

westonsloan

New member
Plus
I need help -- I need to stamp a custom value in place that is calculated as soon as market opens at 830AM CST / 930 ET. I intend for this value to remain static so I can calculate the difference. I intend to have further calculations after this value gets stamped in place. This data needs to be stamped within 1 minute of market open. This code is currently ran in a watchlist column on "Daily."

Once the value is stamped -- I need to be able to see the difference between the stamped value and the continuous difference value.

For example -- if @ 830AM market open I need the POWER value (PremarketVolume(period = "Day").Power) to get stamped in place as a static integer of ".0500" within 1 minute of market open -- then that is the new baseline I need it to automatically calculate the difference from the stamped value of "0.500" to whatever it grows to.

Let's say in 15 minutes @ 845AM, it grows from the stamped Power value of "0.0500" (recall this was stamped at market open) to "0.0650" -- then I need the column to show me the resulting difference of "0.0150" in the same watchlist column. I need to be able to sort ascending and descending on the results. I dont need the color conditional formatting.

Definition of done for this question is at least being able to stamp the POWER (PremarketVolume(period = "Day").Power) value in a watchlist column or as a new study or as a label in a new study set on Daily aggregation. The study is ran on "Daily" aggregation in thinkorswim watchlist column.

For the love of God and everything holy and natural -- please somebody assist me with this. Godspeed

Code:
script PremarketVolume {
plot Data = close;#PreMarket Volume
input startTime = 0400;
input endTime = 0929;
def startCounter = SecondsFromTime(startTime);
def endCounter = SecondsTillTime(endTime);
def 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("PreMarket Vol: ", volumeTotal), Color.VIOLET);


#Relative Volume
input ShowPreMarketRV1 = yes;
def volLast50DayAvgRV1 = (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 + volume(period = "DAY")[31] + volume(period = "DAY")[32] + volume(period = "DAY")[33] + volume(period = "DAY")[34] + volume(period = "DAY")[35] + volume(period = "DAY")[36] + volume(period = "DAY")[37] + volume(period = "DAY")[38] + volume(period = "DAY")[39] + volume(period = "DAY")[40] + volume(period = "DAY")[41] + volume(period = "DAY")[42] + volume(period = "DAY")[43] + volume(period = "DAY")[44] + volume(period = "DAY")[45] + volume(period = "DAY")[46] + volume(period = "DAY")[47] + volume(period = "DAY")[48] + volume(period = "DAY")[49] + volume(period = "DAY")[50];
def x = volLast50DayAvgRV1;
def totalvol = volumeTotal;
plot r = Round(volumeTotal/(volume(period = "DAY")[1]),1);
plot b = Round((volume(period = "DAY")/volumeTotal),1);
def PreMarketRv1 = r;
def PMRV1DailyVol = b;
AddLabel(yes, Concat("PreMarket Vol RV1: ", PreMarketRV1), Color.LIGHT_GRAY);
input period = { "1 min", "2 min", "5 min", default "10 min", "15 min", "30 min", "60 min", "4 hours", "Day"};

def xvolume = (volume(period = "DAY")[1]);
def vvol = (volume(period = "DAY"));
plot rvolx = Round((vvol/xvolume),1);
def rvolxapi = rvolx;
def Power = (rvolxapi/PreMarketRV1);
AddLabel(yes, Concat("Power: ", (rvolxapi/PreMarketRV1)), Color.Light_orange);
}
def Power = reference PremarketVolume(period = "Day").Power;
AddLabel(1, Power, if Power < Power[1] then Color.RED else if Power > Power[1] then Color.Light_ORANGE else Color.WHITE);
 
Last edited:

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
220 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