BIRMINGHAM
Posts: 7 since Oct 2020
Thanks Given: 4
Thanks Received: 2
|
Interesting concept/thought. please see if below code will help you
few notes
- referencing Fin[631] gives you value of it 631 bars before current bar, not the one at 631
- thinkscript expects you to use market time/eastern time , so I changed time to 0930
- the gaps showing are when one of the prices is not present
## this script helps get the open price as defined by openTime and symbol
script openPriceScript {
input openTime = 0930;
input symbol = "META";
def openPrice = if SecondsFromTime(openTime) == 0 and SecondsTillTime(openTime) == 0
then HL2(symbol=symbol) else openPrice[1];
plot op = openPrice ;
}
input AnchorTime = 0930;
input F = "Meta";
input A = "Amzn";
input A2 = "Aapl";
input N = "Nflx";
input G = "Goog";
## get openingPrices at day open
def openPrice_F = openPriceScript(openTime = AnchorTime, symbol = F)."op";
def openPrice_A = openPriceScript(openTime = AnchorTime, symbol = A)."op";
def openPrice_A2 = openPriceScript(openTime = AnchorTime, symbol = A2)."op";
def openPrice_N = openPriceScript(openTime = AnchorTime, symbol = N)."op";
def openPrice_G = openPriceScript(openTime = AnchorTime, symbol = G)."op";
def openPriceSum = openPrice_F + openPrice_A + openPrice_A2 + openPrice_N + openPrice_G;
def currentPrice_F = HL2(symbol=F);
def currentPrice_A = HL2(symbol=A);
def currentPrice_A2 = Hl2(symbol=A2);
def currentPrice_N = HL2(symbol=N);
def currentPrice_G = HL2(symbol=G);
def currentPriceSum = currentPrice_F + currentPrice_A + currentPrice_A2 + currentPrice_N + currentPrice_G;
plot percentChangeForSession = ((currentPriceSum - openPriceSum) / openPriceSum)*100.0;
|