NexusFi: Find Your Edge


Home Menu

 





Price Percentage Change indicator for TOS


Discussion in ThinkOrSwim

Updated
    1. trending_up 4,951 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 0 posts
    2. attach_file 2 attachments




 
Search this Thread

Price Percentage Change indicator for TOS

  #1 (permalink)
Hawkeye1
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);

Attached Thumbnails
Click image for larger version

Name:	PEP Daily price perc change.png
Views:	543
Size:	113.4 KB
ID:	259292   Click image for larger version

Name:	PEP 1-minute price perc change.png
Views:	408
Size:	104.2 KB
ID:	259293  
Reply With Quote




Last Updated on November 23, 2018


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts