Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!

Advanced

Fun with ThinkScript

Posted by robert 
Re: Fun with ThinkScript
September 22, 2016 01:52PM
In this ‘AddLabel’ does anyone know how to script it so that what it says in the label area changes from C1 to C2 or C3 or C4) as the color changes (C1 to C2 to C3 or C4), .


def C1 = Close < Open("period" = AggregationPeriod.DAY) -.25;
def C2 = Close < Open("period" = AggregationPeriod.DAY) -.50;
def C3 = Close < Open("period" = AggregationPeriod.DAY) -.75;
def C4 = Close < Open("period" = AggregationPeriod.DAY) - 1.00;

AddLabel(yes , " " + (C1 or C2 or C3 or C4),

(if C1
then color.Yellow

else if C2
then color.Green

else if C3
then color.Dark_Green

else if C4
then color.Dark_Red

else color.Black));


Can this be done? Thanks, JM.
Re: Fun with ThinkScript
September 23, 2016 03:34AM
Can someone please help me with this thinkscript. I am wanting a scan code that scans the first daily bar of a weekly macd zeroline crossover on mondays I've tried coding it and the scans come after the fact. Scans won't show up until Friday when I'm wanting them to show on Monday. An example would be

Weekly Macd 12-26-9 from one bar ago is less than zero
Weekly macd 12-26-9 crosses above zero

Then when I run the scan on Monday it shows the first daily bar when the weekly macd crossed above zero
Re: Fun with ThinkScript
September 23, 2016 08:00AM
TOS sent me this yesterday to add to the script;

def label = if C4
then 4

else if C3
then 3

else if C2
then 2

else if C1
then 1

else double.nan;


It only seems to work with numbers. Does anyone know how to add letters or words to the AddLabel?



Edited 3 time(s). Last edit at 09/24/2016 09:24PM by Ralph53.
Re: Fun with ThinkScript
September 26, 2016 07:25AM
Hi Ralph53,

How 'bout something like this?
AddLabel(yes,
if long then "GO LONG" else
if short then "GO SHORT" else
if exit then "EXIT TRADE" else
"NO TRADE",

if long then Color.UPTICK else 
if short then Color.DOWNTICK else 
if exit then Color.YELLOW 
else Color.GRAY);

AddLabel(yes, "LONG STOP: " + STOPlong, 
if long then Color.UPTICK 
else Color.GRAY);

AddLabel(yes, "SHORT STOP: " + STOPshort, 
if short then Color.DOWNTICK 
else Color.GRAY);

Hope this helps...
Re: Fun with ThinkScript
September 26, 2016 12:35PM
Thanks.
Re: Fun with ThinkScript
September 27, 2016 04:14PM
HI All,

It is indeed exciting to find this forum and thread. And thanks Robert for being so generous with your contributions.

I would appreciate some help.

I have the output of a band pass filter. I have this programed and it is working well. Lets call the output array Wave.

I am trying to 'count' the number of bars between the successive highs and (and also for the lows) of the output. The output wave is fairly smooth, so determining the highs and lows should be easy, as the slope of the output changes. Perhaps like:

HighWave = Wave < Wave[1] and Wave[1] >= Wave[2]; # Location of Highs
LowWave = Wave > Wave[1] and Wave[1] <= Wave[2]; # Location of Lows

But now, I don't see how to compute the number of bars between successive highs and also for the Lows using TS built in functions. Anyone know how to do this? In English, what I want to do is:

DeltaHigh = index or location of HighWave when it is TRUE - index or location of HighWave when it was last TRUE.

and similarly for DeltaLow.

Once I have the number(s), I would like to 'print' the number near each high and low. This does not seem to be possible with ThinkScript. If not possible, perhaps I could put the numbers for the last two Highs in the Label with addLabel, and then the last two Lows in another Label.

Thanks for your help.

Charles
Re: Fun with ThinkScript
September 27, 2016 10:43PM
Can anyone help me setting the same parameters that I have in Etrade..

I have some scanner settings in my Etrade Pro.
I couldn't find how to set the same setttings in TOS.

Can somebody help me please..



Edited 1 time(s). Last edit at 09/27/2016 10:48PM by pravinraj.vincent@gmail.com.
Re: Fun with ThinkScript
September 27, 2016 11:53PM
Quote
charles
I would appreciate some help.

I am trying to 'count' the number of bars between the successive highs and (and also for the lows) of the output.

But now, I don't see how to compute the number of bars between successive highs and also for the Lows using TS built in functions. Anyone know how to do this?

Once I have the number(s), I would like to 'print' the number near each high and low. This does not seem to be possible with ThinkScript. If not possible, perhaps I could put the numbers for the last two Highs in the Label with addLabel, and then the last two Lows in another Label.

It's relatively easy to do. Take a look at this post

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
September 28, 2016 03:39PM
Hello everyone. Could Someone please help me code this script. Been at it for weeks.

1.) using Weekly MacD Multiple TimeFrame on a daily chart I would like an arrow to plot on the daily chart when the weekly MTF Histogram crosses above zero
2.) and also turn it into a scan
declare lower;

input fastLength = 6;
input slowLength = 30;
input MACDLength = 5;
input averageType = AverageType.EXPONENTIAL;
input period1 = AggregationPeriod.WEEK;

def Value1 =  ExpAverage(close(period = period1), fastLength) -  ExpAverage(close(period = period1), slowLength);
def Avg1   = ExpAverage(ExpAverage(close(period = period1), fastLength) -  ExpAverage(close(period = period1), slowLength), MACDLength);
plot Diff = Value1 - Avg1;
plot ZeroLine = 0;

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.DefineColor("Positive and Up above zero", Color.blue);
Diff.DefineColor("Negative and Down below zero", Color.blue);
##################################################################
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.Color("Positive and Up"winking smiley else Diff.Color("Positive and Down"winking smiley else if Diff < Diff[1] then Diff.Color("Negative and Down"winking smiley else Diff.Color("Negative and Up"winking smiley);
ZeroLine.SetDefaultColor(GetColor(0));



Edited 1 time(s). Last edit at 09/28/2016 03:42PM by Kamadi.
Re: Fun with ThinkScript
September 28, 2016 05:44PM
Thanks Robert for your example on your blog, answering my 'plead' for help. It was most helpful. You certainly demonstrated that a job that is hard for a novice is easy for a pro.

I was able to determine the peaks (and troughs) of the Wave output from the Band Pass Filter using your example.

The Down/Up arrows did not work. These only 'print' at the high and low of the price, regardless of the waveform of interest used in the input list. I can easily do without the arrows.

The AddChartBubble function worked well. Just what I needed. Thanks again so much.

Below is a screen capture of the relevant portion of my screen, after using your help.

Bottom chart is the test script used to add your suggestions. It has just one Band Pass Filter. Middle chart is what I had before your help.

Thanks again, Charles

KM
Add Label (Net change or market change) in TOS
October 06, 2016 10:21PM
Friends,

I use addlabel study in TOS to have some quotes on the top portion of my chart......But instead of the current full quote, I just want the netchange or marketchange (For example: instead of showing "SPY: 215", I want to display the current change like - "SPY: +2.22" or "SPY: -0.75"......

Can anyone advise how to update the code?

My current code is:

input symbol1 = "SPY";
def close1 = close(symbol1);
AddLabel(yes, Concat(symbol1, Concat(" : ", close1)), if close1 > close1[1] then Color.DARK_GREEN else Color.RED);
Re: Add Label (Net change or market change) in TOS
October 07, 2016 05:46AM
input symbol1 = "SPY"; 
def close1 = close(symbol1); 
AddLabel(yes, Concat(symbol1, Concat(" : ", close1 - close1[1])), if close1 > close1[1] then Color.DARK_GREEN else Color.RED);

- robert


Professional ThinkorSwim indicators for the average Joe
KM
Re: Add Label (Net change or market change) in TOS
October 07, 2016 06:23AM
I don't see any additions? Did you add something? Advise.
Re: Add Label (Net change or market change) in TOS
October 07, 2016 06:38AM
It's slightly different... look again...
KM
Re: Add Label (Net change or market change) in TOS
October 07, 2016 07:12AM
Thanks.

I see the change from full quote to the net change, BUT instead of showing the net change from previous day close, it's changing from previous tick (Say, the S&P futures is now -5.50, it's showing 0......and when the futures change to -6, it shows -0.50.....not sure why it's using the -5.50 as benchmark).

I was looking to see it show -5.50 (change from previous day close), like it shows in the watchlist - net change column

Will try and see for stocks once market opens.
KM
Re: Add Label (Net change or market change) in TOS
October 07, 2016 08:45AM
It's not working right.

AMZN, for example, is now +0.85 net change from yesterday, but the study is showing 0.802.....

The S&P futures is -5.75, the study shows -3.75

Advise, where it's getting wrong?
Re: Add Label (Net change or market change) in TOS
October 07, 2016 08:54AM
if you want daily values, use this instead:

def close1 = close(symbol1, period = "day" );

- robert


Professional ThinkorSwim indicators for the average Joe
KM
Re: Add Label (Net change or market change) in TOS
October 07, 2016 09:02AM
Now it's showing 0 as value, confused.

I wanted the same value as the net change for the day (+/-)
Re: Add Label (Net change or market change) in TOS
October 07, 2016 12:37PM
Rob:

How about just show both current price and daily change i.e., SPY $215, +$1.32.... etc..
Re: Add Label (Net change or market change) in TOS
October 08, 2016 08:47AM
Quote
Tampman
How about just show both current price and daily change i.e., SPY $215, +$1.32.... etc..

something like this?



def sym = close("SPY", period="day" );
def symCh = sym - sym[1];
def pos = if symCh > 0 then 1 else 0;

addLabel(yes, "SPY $" + sym + ", $" + symCh, if pos then color.light_green else color.pink);
KM
Re: Fun with ThinkScript
October 08, 2016 05:06PM
Right, thanks.
Re: Fun with ThinkScript
October 08, 2016 11:58PM
Hi Robert. Great stuff on here, I'm glad I found it! I've created a SMI crossover from the TOS moving average crossover. Unfortunately, the arrow shows up every time the lines cross and disappears when they uncross. It's especially annoying if there's sound along with it. Is there any way to see the arrow only once right when the candle closes? I've been looking for months...

~Scott


#wizard input: length1
#wizard text: -period
#wizard input: averageType1
#wizard text: crosses
#wizard input: crossingType
#wizard input: length2
#wizard text: -period
#wizard input: averageType2
#wizard text: Price:
#wizard input: price
#All except current



input price = close;
input percentDLength = 3;
input percentKLength = 5;
input crossingType = {default above, below};

def min_low = lowest(low, percentKLength);
def max_high = highest(high, percentKLength);
def rel_diff = close - (max_high + min_low)/2;
def diff = max_high - min_low;

def avgrel = expaverage(expaverage(rel_diff, percentDLength), percentDLength);
def avgdiff = expaverage(expaverage(diff, percentDLength), percentDLength);

def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;


def AvgSMI = expaverage(smi, percentDLength);


plot signal = crosses(smi, avgsmi, crossingType == CrossingType.above);

signal.DefineColor("Above", GetColor(6));
signal.DefineColor("Below", GetColor(7));
signal.AssignValueColor(if crossingType == CrossingType.above then signal.color("Above"winking smiley else signal.color("Below"winking smiley);

signal.SetPaintingStrategy(if crossingType == CrossingType.above
Re: Fun with ThinkScript
October 09, 2016 01:33AM
Is there any way for the BID and ASK to float like in the left hand top corner of the price window or perhaps near the latest candle?
Re: Fun with ThinkScript
October 09, 2016 01:30PM
It's finally here! This indicator duplicates the QCharts AutoWave ZigZag feature.



- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
October 09, 2016 02:21PM
Hi Robert,

Seems we had a few conversations in the part concerning the Autowave. Last we discussed it, I was convinced that there was something about the autowave in TOS that wasn't quite right. While it was very very close on some time frames it was off in other time frames. I began to notice that the further back in time you would go the move there seemed to be issues with the autowave. Also I noticed that the time frame one would use on their charts had an effect on the accuracy of the autowave. Like for example using the daily set to 1 year would on some charts produce different results than say the same chart but set to 5 or 10 years of data. So did you go back and rebuild your autowave and correct the issues?
Re: Fun with ThinkScript
October 09, 2016 03:35PM
RR,

Yes, this indicator was re-written from the ground up using a completely different algorithm than the one you are discussing. I have compared it to about a dozen or so charts (different time frames, different symbols, different length settings) and all are a match to the QCharts version. I believe this is the only one available for TOS that duplicates the QCharts AutoWave ZigZag.

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Add Label (Net change or market change) in TOS
October 09, 2016 10:27PM
Perfect!!
Re: Fun with ThinkScript
October 10, 2016 11:10PM
I need [close - the highest of these 3 [Present candle Max(High), Second candle Max(Open or close) or Third candle Max(Open or close)].

This works for the first 2 candles;

def X = close - Max((High), Max((Open[1]), (close[1])));


I tried this but it doesn't work for 3;

def X = close - Max((High), Max((Open[1]), (close[1])), Max((Open[2]), (close[2])));



Can anyone help make this work for 3 candles? Thanks.




Edited 1 time(s). Last edit at 10/10/2016 11:14PM by Ralph53.
Re: Fun with ThinkScript
October 11, 2016 12:48AM
Quote
ACWE
Is there any way for the BID and ASK to float like in the left hand top corner of the price window or perhaps near the latest candle?

i was going to see if i could create this but best i can tell it appears that this is not available in TOS chart studies, and only available thru market watch or orders.

Quote
Bid
Returns current value of bid price for current symbol. This function is only available in thinkScript® integration features: Custom Quotes, Study Alerts, and Conditional Orders.

http://tlc.thinkorswim.com/center/charting/thinkscript/reference/Functions/Fundamentals/bid.html
Re: Fun with ThinkScript
October 11, 2016 12:50AM
Robert,

can you help me ?

i have never liked the fact that TOS does not allow for custom bar spacing. i wrote an indicator which plots solid block candles while skipping a space between each one. The effect is that you get double the spacing between bars. It looks beautiful but ....

since my programming is not good, I made it too repetitive. so it uses up too much memory and loads down TOS.

if i post the script here could you recommend a revision which would make it lighter so that it could be used without bogging down TOS ?

thanks



robert Wrote:
-------------------------------------------------------
Sorry, only registered users may post in this forum.

Click here to login