Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!

Advanced

Fun with ThinkScript

Posted by robert 
Re: Mechanical MACD Divergence
August 14, 2016 09:21AM
Quote
robert
This indicator is one that I have wanted to create since I very first began learning ThinkScript.

you did it! thats awesome... i can't wait to throw out my reg macd and swap it with yours now. it's going to look good next to your adv market forecast. congrats on completing your long time goal!
Re: Fun with ThinkScript
August 22, 2016 09:48AM
First time poster.

I am trying to do a simple script that changes the background color of the upper panel when the 8ema crosses above or below the 20ema.

The following code does not work, any thoughts? Thanks!

==============

declare upper;

plot avg = ExpAverage(close, 8);
plot avg = ExpAverage(close, 20);

ExpAverage8.hide();
ExpAverage20.hide();

plot isAbove = Average(close, 8) crosses above Average (close, 20);
plot isBelow = Average(close, 8) crosses below Average (close, 20);

AssignBackgroundColor(if close, 8) > (close, 20) then CreateColor(153, 255, 153) else if (close, 8) < (close, 20) then CreateColor(255, 102, 255) else (color.current);
Re: Fun with ThinkScript
August 22, 2016 10:21AM
How 'bout this:

declare upper;

def isAbove = ExpAverage(close, 8) crosses above ExpAverage(close, 20);
def isBelow = ExpAverage(close, 8) crosses below ExpAverage(close, 20);

AssignBackgroundColor(if isAbove then CreateColor(153, 255, 153) else if isBelow then CreateColor(255, 102, 255) else (color.current));

Also, unless you want to draw on a chart, use def instead of plot, which will negate the need for hide().

Hope this helps...



Edited 1 time(s). Last edit at 08/22/2016 10:25AM by netarchitech.
Re: Fun with ThinkScript
August 22, 2016 10:40AM
Thanks!

The code was accepted by TOS, but it does not change the background color on the crossovers.

Any other thoughts???
Re: Fun with ThinkScript
August 22, 2016 11:05AM
You are certainly welcome smiling smiley

Is there a particular ticker you're working with? It should work, but this wouldn't be the first time TOS threw a curveball...
Re: Fun with ThinkScript
August 22, 2016 11:24AM
/TF, /NQ & /ES

However, after you mentioned it, I tried some other equities (like AAPL), but still no luck. ???

I also tried to change the code for the color from: CreateColor(153, 255, 153) to Color.LIGHT_GREEN ...
but it still would not work. ???

Maybe it's my computer? [MacBook Pro]

Thanks anyway!
Re: Fun with ThinkScript
August 22, 2016 11:51AM
Quote
Erica, Netarchitech
I am trying to do a simple script that changes the background color of the upper panel when the 8ema crosses above or below the 20ema.

Maybe it's my computer? (MacBook Pro)

i use a mac too and i havent had any issues with scripts so i dont think it would be that.

i might be wrong but i believe "crosses over" command only works on the candle that satisfies the conditions. in this case the very next candle (after the cross) the moving averages would no longer be crossing (they would be crossed already) and thus the condition would no longer be valid. is this possibly why the background is not showing green? if so, then you may try playing with this condition... as long as 8 is greater than 20 the screen will stay green:

declare upper;

def isAbove = ExpAverage(close, 8) > ExpAverage(close, 20);
def isBelow = ExpAverage(close, 8) < ExpAverage(close, 20);

AssignBackgroundColor(if isAbove then CreateColor(153, 255, 153) else if isBelow then CreateColor(255, 102, 255) else (color.current));



Edited 1 time(s). Last edit at 08/22/2016 11:58AM by mntman.
Re: Fun with ThinkScript
August 22, 2016 12:04PM
The following code works, now I need to tweak the colors! smileys with beer drinking smiley

========

declare upper;

def avg8 = ExpAverage(close, 8);
def avg20 = ExpAverage(close, 20);

def isAbove = Average(close, 8) crosses above Average (close, 20);
def isBelow = Average(close, 8) crosses below Average (close, 20);

AssignBackgroundColor(if ExpAverage(close, 8)>=ExpAverage(close, 20) then color.LIGHT_GREEN else color.pink);
Same concepts as Erica's. Colorize background
August 24, 2016 06:46PM
Hi Guys, I'm trying to color the background as well but when price crosses the 20 period hull moving average. green up red down. I'am using the original tos code. I tried multiple ways to assign background color but to no avail. didn't know one line of code would be that tough. any help would be greatly appreciated. Here is the code.




#
# TD Ameritrade IP Company, Inc. (c) 2008-2016
#

input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up"winking smiley else HMA.color("Down"winking smiley);



Edited 1 time(s). Last edit at 08/24/2016 06:49PM by Trader.
Re: Same concepts as Erica's. Colorize background
August 24, 2016 09:38PM
Hi Trader,

Actually, I believe that code should colorize the moving average itself, not the chart background. Try something like this...

input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

AssignBackgroundColor(if price > HMA then Color.GREEN else Color.RED);

Hope this helps...

One more thing...you might want to substitute LIGHT_GREEN and PINK for GREEN and RED as the primary colors might be a little too "vibrant" for chart reading smiling smiley
Re: Fun with ThinkScript
August 25, 2016 07:09AM
Admins, could you please take care of this twerp?? Pretty please, with sugar on top. smiling smiley
Re: Fun with ThinkScript
August 25, 2016 01:19PM
RichieRick Wrote:
-------------------------------------------------------
> Admins, could you please take care of this twerp??
> Pretty please, with sugar on top. smiling smiley


Done!
Re: Fun with ThinkScript
August 25, 2016 03:24PM
You guys are AWESOME!!!!!
Re: Fun with ThinkScript
August 25, 2016 03:56PM
Hi netarchitech,

Your right the above code does color the HULL ma when price is above or below it. what i should have stated was i wanted to colorize my charts with clouds when that criteria was met. that is when price crosses the HULL ma there should be a green cloud as long as price is above the hull. when price crosses below the hull i should get a red cloud. kinda like Roberts code listed below, but this one is based on different criteria but it does come close!



def RSI = reference RSI(length = 13).RSI;
def highestRSI = Highest(RSI, 21);
def lowestRSI = Lowest(RSI, 21);
def RSIS = 100 * (RSI - lowestRSI) / (highestRSI - lowestRSI);
def "%K" = Average(RSIS, 3);
def "%D" = Average("%K", 5);

def value1 = highestall(high);
def value2 = lowestall(low);
def neg = if "%D" < "%D"[1] then lowestall(low) else Double.NaN;

AddCloud(value1, value2, Color.GREEN);
AddCloud(value1, neg, Color.RED);



Edited 1 time(s). Last edit at 08/25/2016 03:59PM by Trader.
Re: Fun with ThinkScript
August 25, 2016 06:26PM
Hello, I've been trying to setup the ThinkorSwim scanner so as to scan for a condition with the TTM Squeeze indicator. Its designed by John Carter but included in the TOS indicators. On his site he pasted some code for conditions that almost work but not quite work for my purposes..

Can you give coding and setup advice for using the TOS scanner?

I'd like to find stocks/ETFs on Weekly charts, with close above 52sma, with higher cap and volume, and for this Squeeze condition;

'The first weekly bar after the squeeze begins, ie. the first red dot. This is when the BBands have moved inside the Keltner channels.and sideways consolidation begins.(not when the squeeze ends and a breakout begins)'

Getting accurate scan returns for this would be dynamite, unfortunately my scan setup attempts return erratic results.
Here's the custom Squeeze code I tried in the TOS scanner;
##
reference BollingerBands()."Upperband"[1] > KeltnerChannels()."Upper_band"[1] or reference BollingerBands
()."lowerband"[1] < KeltnerChannels()."lower_band"[1]

and
reference BollingerBands()."Upperband"[0] < KeltnerChannels()."Upper_band"[0] or reference BollingerBands
()."lowerband"[0] > KeltnerChannels()."lower_band"[0]
##
--------------

Another optional element that would be great to pinpoint in the scan, would be a hammer candlestick that also meets the beginning squeeze condition.

>> The purpose or benefit of this scan search is that when the squeeze begins, one can initiate a butterfly trade that's assured a couple weeks of low range, sideways movement. This equals profits with a butterfly option trade.

Your feedback will be appreciated)
Re: Fun with ThinkScript
August 26, 2016 09:47PM
Hi Trader,

TOS is down for maintenance, so I'll tinker with the Hull and Clouds this weekend when the system comes back on line...
Re: Fun with ThinkScript
August 27, 2016 07:44AM
would you guys happen to know if its possible to add a bubble to a lower study? i tried the "addchartbubble" using highestall(high) but it tries to add it as the upper price, but i may have been doing it wrong too.

i use roberts rising tide on a 30dma and was thinking it'd be kinda cool to see the dates of the top and bottom of the average curve in the study to see when they peak. (i currently have the upper price subgraph hidden so only the lower study shows)



Re: Fun with ThinkScript
August 27, 2016 09:18AM
Quote
mntman
would you guys happen to know if its possible to add a bubble to a lower study? i tried the "addchartbubble" using highestall(high) but it tries to add it as the upper price, but i may have been doing it wrong too.

i use roberts rising tide on a 30dma and was thinking it'd be kinda cool to see the dates of the top and bottom of the average curve in the study to see when they peak. (i currently have the upper price subgraph hidden so only the lower study shows)

Add this to the bottom of the The Rising Tide script:

def LL = condition == LowestAll(condition);
def HH = condition == HighestAll(condition);
AddChartBubble(LL, condition, GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()), Color.WHITE, 0);
AddChartBubble(HH, condition, GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()), Color.WHITE);



- robert


Professional ThinkorSwim indicators for the average Joe



Edited 2 time(s). Last edit at 08/27/2016 09:22AM by robert.
Re: Fun with ThinkScript
August 27, 2016 10:39AM
awesome! thanks robert... once again it seems impossible to stump you. winking smiley

how does this actually work? it seems like the condition would be a loop upon itself? i guess maybe "condition" is the actual curve and all we're doing is telling it the highest or lowest arcs on the curve?

condition == LowestAll(condition)

I'm so used to thinking in price (high or low) that i didn't realize your approach with "condition" was possible. i was incorrectly trying barnumber == highestall(high).



Edited 1 time(s). Last edit at 08/27/2016 10:42AM by mntman.
Re: Fun with ThinkScript
August 27, 2016 02:39PM
Hi Trader,

Is this what you're looking for?

input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

AddCloud(price, HMA, Color.GREEN, Color.RED);

Hope this helps...
Re: Fun with ThinkScript
August 27, 2016 06:45PM
Automated RSI Divergence indicator

After creating the Mechanical MACD Divergence indicator, the natural thing to do would be to make an automated RSI divergence indicator. So, I did.



- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
August 27, 2016 11:44PM
Hi netarchitech,


Thanks for the help and time spent on this one!
Re: Fun with ThinkScript
August 27, 2016 11:55PM
Hi Trader,

You are certainly welcome smiling smiley

Good Luck and Good Trading!
Re: Fun with ThinkScript
August 30, 2016 09:51PM
Robert, TOS sent me this scriptlet and it works;

AddLabel(visible = yes, text = GetSymbol());


As soon as I add colors, it doesn't.

Def X = close >= Open;
AddLabel(visible = yes, text = GetSymbol()),

(if X then color.Yellow
else color.Dark_Red));



Can you fix it? Thanks, JM.
Re: Fun with ThinkScript
August 30, 2016 10:53PM
Hi Ralph53,

Try this:

def x = close >= open;

AddLabel(visible = yes, text = GetSymbol(), if x then Color.YELLOW else Color.DARK_RED);

Hope this helps...



Edited 1 time(s). Last edit at 08/30/2016 10:54PM by netarchitech.
Re: Fun with ThinkScript
August 30, 2016 11:07PM
Thanks you guys are great.
Re: Fun with ThinkScript
August 31, 2016 12:18AM
Here's another one from TOS. I want to assign my own colors and they sent me this scriptlet to do it with;

X.SetDefaultColor(CreateColor(102, 142, 0));

I can't make it work right if I insert it into this script;

X.assignValueColor(if Y
then Color.Yellow

else if Z
then color.Green

else Color.Red);


Does anyone know how to replace 'assignValueColor...' with 'SetDefaultColor...'? Thanks again, JM.
Re: Fun with ThinkScript
August 31, 2016 06:37PM
Ralph53 Wrote:
-------------------------------------------------------
> Here's another one from TOS. I want to assign my
> own colors and they sent me this scriptlet to do
> it with;
>
> X.SetDefaultColor(CreateColor(102, 142, 0));
>
> I can't make it work right if I insert it into
> this script;
>
> X.assignValueColor(if Y
> then Color.Yellow
>
> else if Z
> then color.Green
>
> else Color.Red);
>
> Does anyone know how to replace
> 'assignValueColor...' with 'SetDefaultColor...'?
> Thanks again, JM.


Just replace the color with CreateColor(000, 000, 000), like this....

assignvaluecolor(if X > Z then CreateColor(000, 000, 000)
else if Z > X then CreateColor(222, 222, 222)
else CreateColor(111, 111, 111));

SetDefaultColor is changable, whereas AssignValueColor is not (it's predefined and not adjustable), so I would suggest global colors in their place though, like this.....

defineglobalcolor("Up", CreateColor(000, 000, 000));
defineglobalcolor("Down", CreateColor(111, 111, 111));
defineglobalcolor("Neutral", CreateColor(222, 222, 222));

X.AssignValueColor(
if X > Z
then globalcolor("Up" )
else if Z > X
then globalcolor("Down" )
else globalcolor("Neutral" ));



Edited 2 time(s). Last edit at 08/31/2016 06:42PM by devildriver6.
Re: Fun with ThinkScript
August 31, 2016 09:24PM
Thanks so much.
Re: Fun with ThinkScript
September 03, 2016 12:22AM
Does anyone know if you can alter a script in this way?

def V = Volume < Volume[1]; I need this script to work on all the candles except the first (or present moving candle).


def V1 = Volume >= Volume[1] /4; I need these 2 scripts to work on just the first (moving) candle alone.
def V2 = Volume >= Volume[1] /2;



Thanks, JM.
Sorry, only registered users may post in this forum.

Click here to login