Thursday, June 18, 2015

thinkscript included: sdi_afterhours - display pre- and post-market price levels on a daily chart

previously, one needed to switch from a day time-aggregation to an intraday in order to see after-hours pricing. now, with this new chart study, sdi_afterhours, one can see after-hours pricing on a chart with day time-aggregation. here's a picture of this:
spy with after-hours pricing
the blue level shows where after-hours trading has moved price. this includes pre-market pricing. when the pre- or post-market session ends the after-hours price hides.

caveat: the stock must have options trading on it for afterhours to display. 

here's the code:


################################
# sdi_afterhours
input threshold=.10;
#hint: Displays after-hours pricing rev: 1.0.0 from  http://www.smallDogInvestor.com 
def isLastBar= isnan(close) && !isnan(close[1]);
# author: allen everhart
# date: 18june2015
def pc=probabilityOfExpiringCone();
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale or reprinting. 
# Help me get the word out about my blog by keeping notices of origin in place.
#hint threshold: the minimum price change to display. rev: 1.0.0 from http://www.smallDogInvestor.com
def change=pc[1]-close[1];
#from http://www.smallDogInvestor.com
plot ah=if isLastBar && close[1]!=pc[1] && absvalue(change)>threshold then pc[1] else double.NaN;
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale or reprinting. 
# Help me get the word out about my blog by keeping notices of origin in place.
ah.setPaintingStrategy(paintingStrategy.HORIZONTAL);
ah.setdefaultColor(color.BLUE);

addChartBubble(isLastBar && absvalue(change)>threshold,ah,concat(if change>0 then "+" else "",asText(change)), color = ah.takeValueColor(), change>0 );

2 comments:

  1. Allen, I know it's been a long time since you posted this code, but I was wondering if you could write it in a way that is not dependent on options or probabilityOfExpiringCone. Basically, I am trying to create a script that shows me the Gap price on a daily chart, so I can see it visually during pre-market analysis. Thanks, and if you cannot do this, I understand.

    ReplyDelete
  2. Thus far, I've come up with the following, but it only works on certain stocks....

    #Modified from Allen Everhart's sdi_afterhours display code
    def isLastBar = isnan(close) && !isnan(close[1]);
    input threshold =.10;
    def pc = probabilityOfExpiringCone();
    def change = pc[15]-close[1];

    #from http://www.smallDogInvestor.com
    plot ah = if isLastBar && close[1] != pc[1] && absvalue(change) > threshold then pc[1] else double.NaN;
    #plot ah = pc[1];

    # copylefts reserved. This is free software. That means you are free
    # to use or modify it for your own usage but not for resale or reprinting.
    # Help me get the word out about my blog by keeping notices of origin in place.
    ah.setPaintingStrategy(paintingStrategy.HORIZONTAL);
    ah.setdefaultColor(color.ORANGE);

    addChartBubble(isLastBar && absvalue(change) > threshold, ah, concat(if change > 0 then "Current Gap +" else "",asText(change)), color = ah.takeValueColor(), change > 0 );

    ReplyDelete