Cleveland Ohio
Posts: 8 since Feb 2017
Thanks Given: 0
Thanks Received: 0
|
Hi
i want to make an indicator that plots the price percentage change of 2 symbols between any timeframe’s current price and that symbol’s prior day’s US market close.
below is what i have so far.
i got the code below for the “price percentage change with histogram” to plot the difference between 2 symbols correctly on a “Daily” timeframe chart only. the code makes the calculation based off the prior “bar’s” close. i want to make it so the calculation of the prior bar is always the prior “day’s” US market close. it plots on lower timeframe charts like a 1-minute chart but it plots the change from the prior bar’s close which is just 1 minute prior and does not calculate it from the prior “Day’s” US market close like i want it to.
any ideas how to proceed from here? any help would be greatly appreciated. Many Thanks.
charts attached for more clarity.
below is the code on TOS for this:
#works on daily chart, need to get it to work on any timeframe like 1 minute
declare lower;
#Symbol Input
input SYMB1 = “PEP”;
input SYMB2 = “KO”;
def Price1 = close(symbol = SYMB1)[1];
def Price2 = close(symbol = SYMB1);
def Price3 = close(symbol = SYMB2)[1];
def Price4 = close(symbol = SYMB2);
plot PercentChg1 = ((Price2 – Price1) / Price1)*100;
plot PercentChg2 = ((Price4 – Price3) / Price3)*100;
plot Hist = (PercentChg1-PercentChg2);
Hist.setPaintingStrategy(paintingStrategy.HISTOGRAM);
Hist.setLineWeight(5);
Hist.assignValueColor(if PercentChg1 >=PercentChg2 then color.green else color.red);
*******************************************************************
******* below is extra code which might help solve issue ********************
********************************************************************
plot DailyClose = close(period=”DAY”)[1];
******************
#HINT: This study plots a chart label for Net Change and Percent Change from prior close (regardless of time period of the chart.
input period_Type = AggregationPeriod.DAY;
def begin = close(period = period_Type)[1];
def end = close(period = period_Type);
def NetChg = end – begin;
def PctChg = (end / begin) – 1;
AddLabel(yes, “Change from Prior close: ” + AsDollars(NetChg) + ” ” + AsPercent(PctChg), if NetChg > 0 then Color.GREEN else if NetChg < 0 then color.RED else color.LIGHT_GRAY);
|