Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!

Advanced

Fun with ThinkScript

Posted by robert 
Additional Volume on the right side of the chart?
July 13, 2016 11:38PM


Does anybody know how I can add the total volume for the day including pre-market and after hours to this side of the chart that I placed the red box. I'd like the left side to show intraday volume by candle and time frame and the right side to always show total volume regardless of what time frame I am on. I hate having to look at the watch-list to see the total volume. Is there a script for this feature that already exist?



Edited 3 time(s). Last edit at 07/14/2016 01:52PM by Ishyster.
Re: Fun with ThinkScript
July 15, 2016 04:12PM
Given:
haclose = (open + high + low + close) / 4;
haopen = compoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);

Is it possible to find results for haclose = haopen using a Stock Hacker scan?

Thanks in advance...
Re: Fun with ThinkScript
July 16, 2016 09:10AM
Tried this:
def haclose = (open + high + low + close) / 4;
def haopen = compoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
plot hadoji = haclose is equal to haopen;

Passes syntax test, yet "no matching symbols" on various timeframes...

Also tried creating a custom study, HADoji(), using thinkscript above, then entering HADoji() is true in Stock Hacker...

Still "no matching symbols" on various timeframes...

Any thoughts?



Edited 1 time(s). Last edit at 07/16/2016 09:26AM by netarchitech.
Re: Fun with ThinkScript
July 16, 2016 09:46AM
Quote

Passes syntax test, yet "no matching symbols" on various timeframes...

Any thoughts?

That just means that there aren't any HA dojis at this time.

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
July 16, 2016 02:18PM
Quote
Robert
That just means that there aren't any HA dojis at this time.

Thanks for the confirmation. I guess I was thinking, although dojis are not necessarily a frequent occurrence, there would be possibly be at least one returned, given a scan for all stocks on all timeframes...

With that said, would you know a way to scan for HA candles where it is not quite an exact doji? Is there possibly a way to access/reference "body factor" via thinkscript?

Thanks in advance...
Re: Fun with ThinkScript
July 16, 2016 05:47PM
Just set your doji equal to a range, say the close is within 1% of the open.

plot HAdoji = HAclose >= 0.99 * HAopen AND HAclose <= 1.01 * HAopen;

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
July 16, 2016 08:27PM
Quote
Robert
Just set your doji equal to a range, say the close is within 1% of the open.

plot HAdoji = HAclose >= 0.99 * HAopen AND HAclose <= 1.01 * HAopen;

That did it! Thanks a million, Robert. Much appreciated smiling smiley
Re: Fun with ThinkScript
July 17, 2016 02:52AM
would anyone know how to plot a 0% line in a comparison chart?

i have a comparison chart over the last 12 weeks. i'd like to see the zero line but my script is throwing zero down at the bottom of the chart and scrunching up the comparison lines. almost as if 0 exists below the -100% line?

it wouldn't do any good converting it to a fraction and multiplying by 100 to get it in percentage format.... cause 0 is still 0 right? i even tried a cloud but was having similar issue defining 0%.

plot zero = if !comparisonChart then 0 else double.nan;
zero.SetPaintingStrategy(PaintingStrategy.DASHES);
zero.SetStyle(Curve.Medium_DASH);
zero.SetLineWeight(1);
zero.SetDefaultColor(Color.RED);
zero.HideBubble();

#AddCloud(if !comparisonChart then 0 else double.nan, lowestall(low), Color.pink );





Edited 1 time(s). Last edit at 07/17/2016 02:54AM by mntman.
Re: Fun with ThinkScript
July 17, 2016 10:58AM
Quote
mntman
would anyone know how to plot a 0% line in a comparison chart?



Just follow the example to add additional symbols as needed.

# +--------------------------------------------------+
# |        Example: compare multiple symbols         |
# |                   Robert Payne                   |
# |               rrpayne.blogspot.com               |
# +--------------------------------------------------+

declare lower;

input Symbol01 = "SPY";
input Symbol02 = "AAPL";
input Symbol03 = "NFLX";

def c1 = close(Symbol01);
def c2 = close(Symbol02);
def c3 = close(Symbol03);

def start01 = if BarNumber() == 1 then c1 else start01[1];
def start02 = if BarNumber() == 1 then c2 else start02[1];
def start03 = if BarNumber() == 1 then c3 else start03[1];

plot s1 = Round((c1 / start01 - 1) * 100, 2);
     s1.SetDefaultColor(Color.PINK);
plot s2 = Round((c2 / start02 - 1) * 100, 2);
     s2.SetDefaultColor(Color.YELLOW);
plot s3 = Round((c3 / start03 - 1) * 100, 2);
     s3.SetDefaultColor(Color.LIGHT_GREEN);

plot zero = 0;
     zero.SetDefaultColor(Color.BLACK);

AddLabel(yes, Symbol01 + ": " + s1 + "%", Color.PINK);
AddLabel(yes, Symbol02 + ": " + s2 + "%", Color.YELLOW);
AddLabel(yes, Symbol03 + ": " + s3 + "%", Color.LIGHT_GREEN);

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
July 17, 2016 11:26AM
robert be honest... are you a witch or something? i don't know how you do it... you got to be the smartest man alive hands down! winking smiley

seriously thank you so much! took me days to get mine halfway working when it only takes you seconds. till now I've been using just the limited std TOS comparison study. i figured the % and how to rank them in order last night, but my % script is stuck to just 12 weeks, where yours is flexible and adjusts to the charts time frames like it should be. as always appreciate your help on this website! we'd be in the dark ages without you.





Edited 1 time(s). Last edit at 07/17/2016 11:45AM by mntman.
Re: Fun with ThinkScript
July 22, 2016 06:13PM
I saw the post last year about assigning an angle to the MACD basically to show if it is sloping upward or downward. Would there be any way to incorporate this into a scanner filter with StochRSI and MACD (separately)? For instance, I would want to scan for tickers where the slope of the MACD is positive, or the slope of the StochRSI is positive. Any help on this would be great! I look forward to your response. Thank you!!!



Edited 1 time(s). Last edit at 07/22/2016 07:58PM by trades8281.
Re: Fun with ThinkScript
July 22, 2016 07:00PM
I also could use some help making a custom indicator! I've been trying to make an indicator that looks/moves like an RSI that allows me to input several different indicators/moving averages into it (MACD, SMAs, and StochRSIs). Those studies would all combine together to influence the movement of the RSI line. The goal would be to have an RSI-like indicator that would give me bullish crosses over the 30 and 70 lines. If anyone could help me out with this that would be great, thanks.
Re: Fun with ThinkScript
July 22, 2016 07:36PM
To add on to my original post, i basically want to take this code below and scan for when the angle is positive.

declare lower; 

input fastLength = 12; 
input slowLength = 26; 
input MACDLength = 9; 
input averageType = AverageType.EXPONENTIAL; 

plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength); 
plot Avg = MovingAverage(averageType, Value, MACDLength); 

plot Diff = Value - Avg; 
plot ZeroLine = 0; 

Value.SetDefaultColor(GetColor(1)); 
Avg.SetDefaultColor(GetColor(8)); 
Diff.SetDefaultColor(GetColor(5)); 
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); 
Diff.SetLineWeight(3); 
Diff.DefineColor("Positive and Up", Color.GREEN); 
Diff.DefineColor("Positive and Down", Color.DARK_GREEN); 
Diff.DefineColor("Negative and Down", Color.RED); 
Diff.DefineColor("Negative and Up", Color.DARK_RED); 
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.Color("Positive and Up" ) else Diff.Color("Positive and Down" ) else if Diff < Diff[1] then Diff.Color("Negative and Down" ) else Diff.Color("Negative and Up" )); 
ZeroLine.SetDefaultColor(GetColor(0)); 

# ----- apply linear regression slope to macd line ----- 
def LRlength = 3; 
def angle = ATan(LinearRegressionSlope(Value, LRlength)) * 180 / Double.Pi; 
AddLabel(yes, "macd slope angle: " + round(angle,1), Color.WHITE);
Edit Reply Quote Report



Edited 1 time(s). Last edit at 07/23/2016 09:55AM by trades8281.
Re: Fun with ThinkScript
July 24, 2016 08:35AM
Given the following:



I'm left wondering why "No such function" and why has the compiler flagged only certain instances?

Any thoughts?

Thanks in advance...
Re: Fun with ThinkScript
July 24, 2016 12:11PM
OK...I figured out the error..."noob" that I am, I was confusing a variable with a function...as a result I've gone back and totally rewritten the code to properly address the situation... As a result of the rewrite, I now face another issue, namely brackets cannot be used with a function to reference a prior period...



So while I'm still wondering why the compiler flagged only certain instances of the "no such function" error, now, in addition, I'm hoping there is a way around the invalid statement - prior period brackets issue... Any thoughts?

Thanks in advance...
Re: Fun with ThinkScript
July 24, 2016 01:18PM
For those whom might be interested, here's the solution to the bracket issue:
high(period="day" )[1];  #(array reference after the function)

Thanks to Derek for his assistance...
Re: Fun with ThinkScript
July 24, 2016 09:15PM
I'm not sure if this can be done, and I don't have the knowledge to do it, but here goes nothing....

Sierra Charts has something called a "Flex Renko" bar that has a range that the bar has to reverse in order to create a new bar.
From there, each tick, or 2 ticks, etc, it creates a new bar, until price reverses back on itself again.

It ends up looking like it does below.

I'm wondering if there's any way to simulate this action in TOS.

Re: Fun with ThinkScript
July 26, 2016 06:01PM
hi


assignpricecolor( if  A && B > overbought then Color.red else if  A && B < overSold then Color.green  else Color.yellow);

I want to modify this code to give BUY arrow if [the yellow color came after the green color], and to give SELL arrow if [the yellow color came after the red color] .
Re: Fun with ThinkScript
August 07, 2016 09:57AM
is anyone using roberts put/call ratio labels from page21 of this thread? just like jdbauman posted, i too seem to only get 0 values in the labels after inputting the current dates and i can't understand what I'm doing wrong?

NEED HELP WITH THINKSCRIPT
August 07, 2016 05:15AM
[imgur.com]

Could somebody help me write a code that colors the background of the column to match the color of the current day's candlestick? As you can see the current color of the candlestick on the chart is red, so I would like a code that also changes the background color of the corresponding symbol's column to also be red. I don't need numbers to be on the column. Just a blank column with green or red backgrounds would be perfect. Any help is appreciated!

Also, please show me how to embed images into my forum posts. Thanks.
Re: NEED HELP WITH THINKSCRIPT
August 07, 2016 10:34AM
something like this?

def closelower = close < close[1];
def closehigher = close > close[1];

AddLabel(yes, " ", color.current);
AssignbackgroundColor(if closelower then color.downtick else if closehigher then color.uptick else color.current);

Re: NEED HELP WITH THINKSCRIPT
August 07, 2016 10:36AM
i use imgur BBCode to embed pics...

Re: NEED HELP WITH THINKSCRIPT
August 07, 2016 02:43PM
Thank you so much for your help! I forgot that my chart was actually heiken ashi. Due to the nature of heiken ashi candles, I needed to tweak the code a bit and came up with the code below and it works with flying colors! Thanks again!

def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);

def closelower = haopen > haclose;
def closehigher = haopen < haclose;

AddLabel(yes, " ", color.current);
AssignbackgroundColor(if closelower then color.downtick else if closehigher then color.uptick else color.current);
mgc
Re: Fun with ThinkScript
August 08, 2016 05:22PM
Hi,

Thank you for all the help.

Was wondering if anyone could help me with creating an alert in TOS/ThinkScript for the following. I have a renko chart with a MovAvgExponential(CLOSE, 13, 0), and would like to be alerted whenever the renko bricks cross the MovAvg and have a price movement of two bricks. As an example, it would be all the yellow arrows on the chart below.

So far, I have come up with the following but I'm not sure if this is quite correct:

MovAvgExponential("length" = 13) crosses close within 2 bars


Renko Chart with EMA

Thank you!
mgc



Edited 4 time(s). Last edit at 08/08/2016 05:27PM by mgc.
Re: Fun with ThinkScript
August 09, 2016 02:06AM
Hi,

I am new to thinkscript. can you please let me know how to get current time?

Thanks
Re: Fun with ThinkScript
August 09, 2016 07:36AM
Look up in the upper left corner of your screen. It's beside you account # info.
Re: NEED HELP WITH THINKSCRIPT
August 10, 2016 08:13AM
mntman Wrote:
-------------------------------------------------------
> i use imgur BBCode to embed pics...
>
> [i.imgur.com]


Any answer to this? I'm having the same issue.

Thanks!
Re: Fun with ThinkScript
August 10, 2016 03:49PM
how to get the price of the stock and store it as a constant value in a variable? Suppose I use below
def price123 = close;

price123 will keep on changing based on close price. I want the value of variable price123 fixed with with price of the stock at particular time.

how can I do this?
confused smiley Scalper Value Chart ! confused smiley Trend Analyzer confused smiley
August 11, 2016 02:50AM
I was searching and found these blogs :


[scalperindicators.blogspot.com]


[scalperindicators.blogspot.com]





It looks like an awesome oscillator to me , I think, it is a combination between "Value Chart Indicator" with " Bollinger Bands".
I tried to find the script for these indicators to ask experts to try to create this indicator if got the idea behind it. I got only " Value Chart" Indicator
I think the idea is changing the histogram with a line and when this line crosses up the upper band then go down and crosses below the upper band it will give red arrow, and the vice versa with the lower band.

I'm not expert in coding, so if any one who can do this idea I'll be really appreciate.

++++++++++

declare lower;

input length = 5;
input capSpikesAt = 10;

def VarP = Round(length / 5);
def VarA = Highest(high, VarP) - Lowest(low, VarP);
def VarR1 = if VarA == 0 and VarP == 1 then AbsValue(close - close[VarP]) else VarA;
def VarB = Highest(high, VarP)[VarP + 1] - Lowest(low, VarP)[VarP];
def VarR2 = if VarB == 0 and VarP == 1 then AbsValue(close[VarP] - close[VarP * 2]) else VarB;
def VarC = Highest(high, VarP)[VarP * 2] - Lowest(low, VarP)[VarP * 2];
def VarR3 = if VarC == 0 and VarP == 1 then AbsValue(close[VarP * 2] - close[VarP * 3]) else VarC;
def VarD = Highest(high, VarP)[VarP * 3] - Lowest(low, VarP)[VarP * 3];
def VarR4 = if VarD == 0 and VarP == 1 then AbsValue(close[VarP * 3] - close[VarP * 4]) else VarD;

def VarE = Highest(high, VarP)[VarP * 4] - Lowest(low, VarP)[VarP * 4];
def VarR5 = if VarE == 0 and VarP == 1 then AbsValue(close[VarP * 4] - close[VarP * 5]) else VarE;
def LRange = ((VarR1 + VarR2 + VarR3 + VarR4 + VarR5) / 5) * 0.2;
def Var0 = if AbsValue(close - close[1]) > (high - low) then AbsValue(close - close[1]) else (high - low);
def LRange2 = if high == low then Average(AbsValue(close - close[1]), 5) * 0.2 else Average(Var0, 5) * 0.2;

def range = high + low;
def delta = high - low;
def median = range / 2;
def floatingAxis = Average(median, length);
def dynamicVolatilityUnit = if length <= 7 then LRange2 else LRange;
def relativeHigh = (high - floatingAxis) / dynamicVolatilityUnit;
def relativeLow = (low - floatingAxis) / dynamicVolatilityUnit;
def relativeOpen = (open - floatingAxis) / dynamicVolatilityUnit;
def relativeClose = (close - floatingAxis) / dynamicVolatilityUnit;

plot "High" = Min(relativeHigh, capSpikesAt);
"High".SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
"High".AssignValueColor(if "High" >= 8 then Color.RED else Color.BLACK);
"High".SetLineWeight(4);

plot "Low" = Max(relativeLow, -capSpikesAt);
"Low".SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
"Low".AssignValueColor(if "Low" <= -8 then Color.GREEN else Color.BLACK);
"Low".SetLineWeight(4);

plot backgroundColor = if "Low" > 0 then "Low" else if "High" < 0 then "High" else Double.NaN;
backgroundColor.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
backgroundColor.SetDefaultColor(Color.BLACK);
backgroundColor.SetLineWeight(4);

#plot "Open" = Min(AbsValue(relativeOpen), capSpikesAt) * relativeOpen / AbsValue(relativeOpen);
#"Open".SetStyle(Curve.POINTS);
#"Open".SetLineWeight(1);
#"Open".SetDefaultColor(Color.WHITE);
#"Open".Hide();

#plot "Close" = Min(AbsValue(relativeClose), capSpikesAt) * relativeClose / AbsValue(relativeClose);
#"Close".SetStyle(Curve.POINTS);
#"Close".SetLineWeight(1);
#"Close".AssignValueColor(if "Close" < "Open" then GetColor(5) else GetColor(6));
#"Close".Hide();

plot zero = 0;
zero.SetDefaultColor(Color.WHITE);

plot "Moderately O/B" = 4;
plot "Moderately O/S" = -4;
"Moderately O/B".SetDefaultColor(Color.YELLOW);
"Moderately O/S".SetDefaultColor(Color.YELLOW);

plot "Edge O/B" = 12;
plot "Edge O/S" = -12;
"Edge O/B".SetDefaultColor(Color.RED);
"Edge O/S".SetDefaultColor(Color.RED);

plot "Significantly O/B" = 8;
plot "Significantly O/S" = -8;
"Significantly O/B".SetDefaultColor(Color.RED);
"Significantly O/S".SetDefaultColor(Color.RED);

AddCloud("Moderately O/B","Moderately O/S", Color.Green, Color.Green);
AddCloud("Moderately O/B","Significantly O/B", Color.Yellow, Color.Yellow);
AddCloud("Moderately O/S","Significantly O/S", Color.Yellow, Color.Yellow);
AddCloud("Edge O/B","Significantly O/B", Color.RED, Color.RED);
AddCloud("Edge O/S","Significantly O/S", Color.RED, Color.RED);

Plot highline = if "High" > 0 then "High" else 0;
highline.assignValueColor(if "High" > "High"[1] then color.GREEN
else if "High" < "High"[1] then Color.RED
else Color.YELLOW);
highline.setLineWeight(1);
Plot lowline = if "low" < 0 then "low" else 0;
lowline.assignValueColor(if "low" > "low"[1] then color.GREEN
else if "low" < "low"[1] then Color.RED
else Color.YELLOW);
lowline.setLineWeight(1);

++++++++++++++++++++++++++

these Charts are awesome :



Mechanical MACD Divergence
August 14, 2016 07:39AM
Mechanical MACD Divergence Indicator

This indicator is one that I have wanted to create since I very first began learning ThinkScript. Different divergence indicators do exist, but NONE of them have lines drawn on them in the manner that is always shown in technical analysis books. This one does just that.



- robert


Professional ThinkorSwim indicators for the average Joe
Sorry, only registered users may post in this forum.

Click here to login