Which "close" is being used when comparing Stochastic in indicator?

_Merch_Man_

Member
Hey Guys

First post here and I want to say Thank You to all who have contributed to this amazing source of ThinkScript knowledge!

I have written an indicator that draws an arrow and writes to the message center when a slow stochastic is below 20 and a fast stochastic is above 80 (amongst other conditions). I got an odd result today whereby I got the message in the message center but not the arrows. After watching it for a while I realized that the arrow was repainting. I don't understand this as the StochasticSlow is using close as a parameter so how is the condition triggering before the bar has closed? Is there a way (other than multi-timeframe) to have the condition fire only at the close of the bar?

Many thanks!

Matt.


Code:
# Slow Stoch Indicator inspired by BreakpointTrades.com
# Written by Matt Ward
#######################################################
# Version 1.0 3/17/21
# It triggers on two conditions.  The first is when the slow stoch is above "bull upper" (default 80)
# and the fast stock crosses below "bull lower" (default 20).   The second is when the slow stoch is
# below "bear lower" (default 20) and the fast stoch crosses above "bear upper" (default 80). You can
# change the stoch speeds using the inputs "fast stoch" (default 10) and "slow stoch" (default 60). 
#######################################################
# Version 1.1 3/21/21
# Added Alerts.  If the alerts are turned on then and the script triggers then it will write to the
# Message Center and play a sound.   You can chose which sound on the settings screen
# The way I use this is to have a 2x2 chart window open with 5 min charts for the SPY, QQQ, IWM and DIA.
# This way I get a real time alert when the trigger conditions are met.
#######################################################

Input FastStoch = 10;
Input SlowStoch = 60;
Input BullUpper = 80;
Input BullLower = 20;
Input BearUpper = 80;
Input BearLower = 20;
Input AlertsOn = yes;
Input AlertSound = Sound.DING;

def StochSlowSlow = StochasticSlow(80,20,SlowStoch,3,high,low,close,AverageType.SIMPLE).SlowK;
def StochSlowFast = StochasticSlow(80,20,FastStoch,3,high,low,close,AverageType.SIMPLE).SlowK;

def BullCondition = StochSlowSlow >= BullUpper && (StochasticSlow(80,20,FastStoch,3,high,low,close,AverageType.SIMPLE).SlowK) crosses below BullLower;

def BearCondition = StochSlowSlow <= BearLower && (StochasticSlow(80,20,FastStoch,3,high,low,close,AverageType.SIMPLE).SlowK) crosses above BearUpper;

plot Bear = BearCondition;
Bear.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bear.SetDefaultColor(COLOR.RED);
plot Bull = BullCondition;
Bull.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bull.SetDefaultColor(COLOR.GREEN);

Alert( if AlertsOn and BearCondition then yes else no, "MBW BPT Slow stoch Bear Condition", Alert.BAR, AlertSound);
Alert(if AlertsOn and BullCondition then yes else no, "MBW BPT Slow Stoch Bull Condition", Alert.BAR, AlertSound);
 

codydog

Active member
I'm very far from being an expert, but tos labeling 'last price' as close is a bit misleading. tos seems to choose a price out of the avalanche of price data that's available and says, 'here, use this'. Its why different charts, even in tos, show different prices at roughly the same time. tos also limits your ability to pull price at the micro-time level, due to the sheer data tos would have to download to users.

imo, if you need that level of detail for 'last price', tos is the wrong platform for you, probably, any retail platform is the wrong platform
 

Similar threads

Top