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
February 20, 2017 11:43AM
BTW, is there any script that would show on the chart (e.g. top right corner ) P/L status on the open position?
Re: Fun with ThinkScript
February 20, 2017 02:19PM
Can I turn this indicator into a strategy
Re: Fun with ThinkScript
February 20, 2017 02:52PM
This should be a fairly simple request:

The thinkscript below adds a horizontal line on the chart to mark last week's closing price. Can anyone please tell me how to make an addition where I can have a visible text label above the horizontal line to say "LWC"? Thanks a million in advance.

----------------------------------------------------------------------------------------

declare upper;

def Today = if GetLastDay() == GetDay() then 1 else 0;
def DrawHighs = if (close < high(period="Week" )[1] AND close > low(period="Week" )[1]) OR high(period="Week" ) > high(period="Week" )[1] then 1 else 0;
def DrawLows = if (close < high(period="Week" )[1] AND close > low(period="Week" )[1]) OR low(period="Week" ) < low(period="Week" )[1] then 1 else 0;

plot yClose = if Today then close(period = "Week" )[1] else Double.NaN;
yClose.SetDefaultColor(Color.LIGHT_GRAY);
yClose.SetLineWeight(1);
yClose.SetStyle(Curve.MEDIUM_DASH);
Re: Fun with ThinkScript
February 22, 2017 09:09AM
Robert, What color swatches (numbers) are you using for your chart color? I like it, but am unable to match it. Thank you
Re: Fun with ThinkScript
February 22, 2017 09:39AM
Ok fellow traders...been a while since I've posted but I have a code that was done for Ambibroker (AFL) that I'd like to get coded for TOS...

The code basically highlights on the chart when the Bollinger Bands are in a Squeeze...so those of you that use the BB squeeze as a trade strategy may find this helpful.. See pic of chart here - [s21.postimg.org]

If anyone can help code it for TOS it would be greatly appreciated!

The Ambibroker Code is below:

Length = 14;
Price = EMA(Close, Length);
  
// Keltner
kLength = Length;
kN = 1.5;
kATR = ATR(kLength);
kUpper = Price + kN * kATR;
kLower = Price - kN * kATR;
  
// Bollinger
bbLength = Length;
bbN = 2;
bbStDevValues = StDev(Close, bbLength);
bbUpper = Price + bbN * bbStDevValues;
bbLower = Price - bbN * bbStDevValues;
  
IsBBSqueeze = bbUpper <= kUpper AND bbLower >= kLower;
 
Proportion = (kUpper - kLower) / (bbUpper - bbLower);
BBBreakout = Cross(1,Proportion);
Periods = Param("BBPeriods", 14, 2, 300, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style"winking smiley;
bbtop=BBandTop( C, Periods, Width );
bbbot=BBandBot( C, Periods, Width );
Plot(bbtop, "", Color, Style );
Plot(bbbot , "", Color, Style );
 
sqeezcolor=ColorRGB(194,220,218);
 
PlotOHLC( bbtop,bbtop, bbbot,bbbot, "",IIf(IsBBSqueeze,colorYellow,colorWhite), styleCloud|styleNoRescale,  Null, Null, Null, -1 );
Plot(Close,"Close",colorGreen,styleCandle);
 
Filter = BBBreakout;
 
AddColumn(BBBreakout, "BB Breakout", 1, colorWhite, IIf(BBBreakout==1, colorRed, colorWhite));
//set default sorting to Date/time in descending order in results window
SetSortColumns(-2);
Re: Fun with ThinkScript
February 22, 2017 12:47PM
Quote
rob miller
Robert, What color swatches (numbers) are you using for your chart color? I like it, but am unable to match it. Thank you

Uptick, Downtick, and Background colors are as follows:



- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
February 22, 2017 02:21PM
Quote
MoneyMachine8253
Beautiful coding I hope to get as good as you one day. I was wondering if you could make me a code that for strangely that plots intraday high and low throughout the trading day.


def today = GetDay() == GetLastDay();
plot dailyHigh = if !today then Double.NaN else high(period = "day" );
plot dailyLow = if !today then Double.NaN else low(period = "day" );

Quote

Also one for extended hours as well

That one is already available here.

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
February 22, 2017 02:29PM
TAMPMAN -- Here's one for BB squeeze on TOS...


input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input KCfactor = 1.50;
input averageType = AverageType.SIMPLE;
input ShowLabels = yes;


def shift = KCfactor * MovingAverage(averageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, close, length);
def Avg = average;

plot Upper_KCBand = average + shift;
plot Lower_KCBand = average - shift;
Upper_KCBand.setdefaultColor(color.cyan);
Upper_KCBand.setstyle(curve.SHORT_DASH);
Lower_KCBand.setdefaultColor(color.cyan);
Lower_KCBand.setstyle(curve.SHORT_DASH);

def sDev = StDev(close, length);

plot MidLine = MovingAverage(averageType, close, length);
plot LowerBand = MidLine + Num_Dev_Dn * sDev;
plot UpperBand = MidLine + Num_Dev_up * sDev;

MidLine.SetDefaultColor(Color.YELLOW);
MidLine.SetLineWeight(2);
MidLine.SetStyle(Curve.MEDIUM_DASH);
LowerBand.SetDefaultColor(Color.WHITE);
UpperBand.SetDefaultColor(Color.WHITE);


def squeezeON = if Upper_KCBand >= UpperBand and Lower_KCBand <= LowerBand then 1 else 0;

def SqU = if Upper_KCBand >= UpperBand and Lower_KCBand <= LowerBand then Upper_KCBand else Double.NaN;
def SqL = if Upper_KCBand >= UpperBand and Lower_KCBand <= LowerBand then Lower_KCBand else Double.NaN;

AddCloud(SqU, SqL, Color.BLUE, Color.CURRENT);

AddLabel(ShowLabels, if squeezeON == 1 then "Squeeze" else "",
if squeezeON == 1
then Color.BLUE
else Color.DARK_GRAY);



Edited 3 time(s). Last edit at 02/22/2017 02:30PM by devildriver6.
Re: Fun with ThinkScript
February 22, 2017 03:11PM
Quote
SMcTrader
This should be a fairly simple request:

The thinkscript below adds a horizontal line on the chart to mark last week's closing price. Can anyone please tell me how to make an addition where I can have a visible text label above the horizontal line to say "LWC"? Thanks a million in advance.

plot closeLastWeek = close(period = "week" )[1];
     closeLastWeek.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
     closeLastWeek.SetDefaultColor(Color.YELLOW);
     closeLastWeek.SetLineWeight(2);
AddChartBubble(BarNumber() == HighestAll(BarNumber()), closeLastWeek, "LWC", Color.YELLOW, if close > closeLastWeek then 0 else 1);



- robert


Professional ThinkorSwim indicators for the average Joe



Edited 1 time(s). Last edit at 02/22/2017 03:23PM by robert.
Re: Fun with ThinkScript
February 22, 2017 05:17PM
@DevilDriver...Thanks but since you didn't post a chart as an example I'm not sure it's what I was looking for... I already have the squeeze code for TOS... I wanted the script to highlight the squeeze on the chart like I showed on the sample chart I posted the link for... [s21.postimg.org]



Edited 3 time(s). Last edit at 02/22/2017 05:23PM by Tampman.
Re: Fun with ThinkScript
February 22, 2017 05:23PM
You mean like the big blue clouds are doing in the script I posted?

Didn't have time to post a chart, but I'm fairly certain it's what you're looking for.

If not, let me know. smiling smiley



Edited 1 time(s). Last edit at 02/22/2017 05:26PM by devildriver6.
Re: Fun with ThinkScript
February 22, 2017 05:25PM
LOL... well haven't had a chance to paste the script to see what exactly to it looks like.... but was looking for the highlight of the squeeze area as shown in the chart I posted.. if your script does that then I am very grateful for your help... will check when I get home...and load the code.



Edited 2 time(s). Last edit at 02/22/2017 05:27PM by Tampman.
Re: Fun with ThinkScript
February 22, 2017 05:27PM
Tampman - yeah, it paints a cloud from beginning to end of the squeeze from the upper to lower Keltner channel.... I'd post a chart now, but I'm mobile at the moment.
Re: Fun with ThinkScript
February 22, 2017 05:31PM
OK....cool... will check and let you know but sounds perfect!
Re: Fun with ThinkScript
February 22, 2017 06:04PM
Tampman -

Below is the code for one of the first thinkscripts I cobbled together for a bollinger squeeze...

def price = close;
def displace = 0;
def length = 20;
def length2 = 14;
def factor = 1.5;

input averageType = {default sMA, eMA};
def averageType2 = AverageType.WILDERS;

def num_Dev_Up = 2.0;
def num_Dev_Dn = -2.0;

#def shift = factor * Average(TrueRange(high,  close,  low),  length);
def shift = factor * MovingAverage(averageType2, TrueRange(high, close, low), length2);


def average;
switch (averageType) {
case sMA:
    average = Average(price, length);
case eMA:
    average = ExpAverage(price, length);
}

def sDev = StDev(data = price[-displace], length = length);

def MidLine = MovingAverage(averageType, data = price[-displace], length = length);

plot bbUpperBand = MidLine + num_Dev_Up * sDev;
     bbUpperBand.setDefaultColor(GetColor(3));
     bbUpperBand.hideTitle();

plot bbLowerBand = MidLine + num_Dev_Dn * sDev;
     bbLowerBand.setDefaultColor(GetColor(3));
     bbLowerBand.hideTitle();

def Avg = MovingAverage(averageType, data = price[-displace], length = length);

plot kcUpperBand = Avg + shift[-displace];
     kcUpperBand.setDefaultColor(GetColor(7));
     kcUpperBand.hideTitle();
     
plot kcLowerBand = Avg - shift[-displace];
     kcLowerBand.setDefaultColor(GetColor(7));
     kcLowerBand.hideTitle();

addCloud(bbUpperBand, kcUpperBand, color.DARK_GRAY, color.UPTICK);
addCloud(bbLowerBand, kcLowerBand, color.UPTICK, color.DARK_GRAY);

Hope this helps smiling smiley
Re: Fun with ThinkScript
February 22, 2017 06:37PM
@netarchitect... Cool Thanks!
Re: Fun with ThinkScript
February 22, 2017 09:13PM
@DevilDriver... Thanks Looks great!
Re: Fun with ThinkScript
February 23, 2017 06:40PM
Can someone please give me the reversal scanner for ThinkOrSwim! i love the concept and i dont want to spend that much money for a scanner so could someone please be so generous and give me itsmiling smiley
Thanks!
Re: Fun with ThinkScript
February 28, 2017 03:17PM
1. delete vmoptions.bak
2. -Dsun.java2d.d3d=false
add this line to the end of vmoptions file (not same as bak file)
and overwrite original file

3d acceleration and direct draw .... bye bye



Edited 2 time(s). Last edit at 02/28/2017 03:22PM by elovemer.
Re: Fun with ThinkScript
February 28, 2017 10:30PM
@Elovemer -

This is what I currently have in vmoptions:
-Xmx8192m
-Xms4096m
-Djava.util.Arrays.useLegacyMergeSort=true
-classpath/p launcher-first.jar
-Dawt.useSystemAAFontSettings=lcd_hrgb
-Dsun.net.http.allowRestrictedHeaders=true
-XX:MaxPermSize=256m
Any suggestions to further optimize these settings?

Thanks in advance smiling smiley
Re: Fun with ThinkScript
February 28, 2017 11:38PM
here is an example .
=========================
-Xms32m
-Xmx768m
-Dsun.java2d.d3d=false

-XX:MaxPermSize=256m
===========================

disabling 3d acceleration and direct draw is described as a performance upgrade for 32 bit machines with lower ram ..... however there is no reason why these would not put a lag on high end machines with high ram.

java ensures that the platform can't be left open no matter how much ram a machine has. it will eventually run out of memory.
---------------------------------------

add the line as stated. if it doesn't work for you, then delete the bak file again and go back to your old saved vmoptions file and restart again.

you also might consider having a platform open for order entry with no charts or saved study sets. and have another platform open for charting.
------------------------------------

by the way... on order entry page if you want a chart......
but you don't want your chart to move around every time you want to modify an order....use the quick chart gadget on the left side for your chart. when the order entry dialog pops up and down, it won't resize your chart. Funny how TOS gives no priority to making order entry easy.



Edited 3 time(s). Last edit at 03/01/2017 12:14AM by elovemer.
Re: Fun with ThinkScript
February 28, 2017 11:57PM
@Elovemer -

Thanks for the swift late night reply. I really appreciate it...

I'll give it a go and report back if there's anything noteworthy to report, that is smiling smiley
Re: Fun with ThinkScript
March 01, 2017 05:56PM
This is what mine has.

It loads fast and switches from symbol to symbol really fast now. smiling smiley

-Xmx768m
-Xms32m
-Djava.util.Arrays.useLegacyMergeSort=true
-classpath/p launcher-first.jar
-Dawt.useSystemAAFontSettings=lcd_hrgb
-Dsun.net.http.allowRestrictedHeaders=true
-Dsun.java2d.d3d=false
-XX:MaxPermSize=256m

I'm running 4GB memory so I'd like TOS to have as small a footprint as possible. Even with it set this way TOS runs at 750MB. By comparison Alchemcharts runs at 135MB.



Edited 1 time(s). Last edit at 03/01/2017 06:01PM by RichieRick.
Re: Fun with ThinkScript
March 01, 2017 09:36PM
Hi Robert,

Please kindly help me to correct below coding. I don't think TOS has standard ZIG function. thanks in advance.

Def A= ZIG(close,6);
Def BSignal = A>A[1] and A[1]<A[2];
Plot Buy = if BSignal = 1, else 0;
Def B= ZIG(close,10);
Def SSignal = B<B[1] and B[1]>B[2];
Plot Sell = if SSginal = 1, else 0;
Def C=PEAKBARS(2,15,1)<10;
Def D=IF(C=1,2,0);
Def SS= IF(D=2,2,0);
Def MS=IF(SS>SS[1],2,0);
Plot MSell= if MS=2, else 0;



Edited 2 time(s). Last edit at 03/02/2017 12:55AM by anky7544.
Re: Fun with ThinkScript
March 02, 2017 01:54AM
RichieRick Wrote:
-------------------------------------------------------
> This is what mine has.
>
> It loads fast and switches from symbol to symbol
> really fast now. smiling smiley
>
> -Xmx768m
> -Xms32m
> -Djava.util.Arrays.useLegacyMergeSort=true
> -classpath/p launcher-first.jar
> -Dawt.useSystemAAFontSettings=lcd_hrgb
> -Dsun.net.http.allowRestrictedHeaders=true
> -Dsun.java2d.d3d=false
> -XX:MaxPermSize=256m
>
> I'm running 4GB memory so I'd like TOS to have as
> small a footprint as possible. Even with it set
> this way TOS runs at 750MB. By comparison
> Alchemcharts runs at 135MB.


Where would I go to adjust this??
Re: Fun with ThinkScript
March 02, 2017 07:17AM
@devildriver6 -

The thinkorswim.vmoptions file path is C:\Users\USER\AppData\Local\thinkorswim...

Rename the thinkorswim.vmoptions file extension to thinkorswim.vmoptions.old before saving the new configuration smiling smiley

Hope this helps...
Re: Fun with ThinkScript
March 02, 2017 07:19AM
by the way ... if you want a fixed-range price chart.... the only way i have found to do it is to use " fit studies " .

write a study for the range of price you want... then click "fit studies" .
that way if you show only the current day, you will always have the same range of prices shown on the chart.
otherwise, one bar may take up the same space on your chart as 78 bars for a 5 minute one day chart

this keeps your scaling constant as long as price lies in the range you have programmed and therefore the price bars are not constantly being distorted in size according to how much price history is being shown.

when nothing is happening, price looks big when it is really not (range-wise that is). when things are moving, price starts to looks very small when it is actually much bigger than normal. so when there is big news... you get a tiny 5min bar which is actually 10 points in range.
this distortion is the reverse of what is needed... constancy .

a huge problem with TOS is scaling. there are free programs out there that have much better scaling than TOS does. good scaling avoids the squash effect that happens when you zoom in.

simple things ... are the best indicators.
Re: Fun with ThinkScript
March 02, 2017 07:31AM
Quote
elovemer
simple things ... are the best indicators.

Good point...With all the blinking lights and gadgetry, it can be difficult to see the forest for the trees...Information overload...

For me...Price, Volume, a little VSA and a couple of homebaked "indicators" work pretty well, but I've been peeling the onion for years now to get to where I am as a trader/investor...
Re: Fun with ThinkScript
March 02, 2017 08:21AM
elovemer Wrote:
-------------------------------------------------------
> by the way ... if you want a fixed-range price
> chart.... the only way i have found to do it is to
> use " fit studies " .
>
> write a study for the range of price you want...
> then click "fit studies" .
> that way if you show only the current day, you
> will always have the same range of prices shown on
> the chart.
> otherwise, one bar may take up the same space on
> your chart as 78 bars for a 5 minute one day
> chart
>
> this keeps your scaling constant as long as price
> lies in the range you have programmed and
> therefore the price bars are not constantly being
> distorted in size according to how much price
> history is being shown.
>
> when nothing is happening, price looks big
> when it is really not (range-wise that is). when
> things are moving, price starts to looks very
> small when it is actually much bigger than normal.
> so when there is big news... you get a tiny 5min
> bar which is actually 10 points in range.
> this distortion is the reverse of what is
> needed... constancy .
>
> a huge problem with TOS is scaling. there are
> free programs out there that have much better
> scaling than TOS does. good scaling avoids the
> squash effect that happens when you zoom in.
>
> simple things ... are the best indicators.

It would be much better if the "fit studies" option only performed that action on the visible candles within the chart window instead of the full length based on the time you selected. For example, if I pull up a daily chart, and select 1 year of data,it will look different than when I select 3 months of data because it applies the "fit studies" to the entire time frame instead of the visible area of the chart window. It kind of annoying. smiling smiley
Re: Fun with ThinkScript
March 04, 2017 10:03AM
Windows XP no long fully supports thinkorswim, support will be completely removed in a future release.
For now, some features such as myTrade and chat profiles and video playback will be unavailable.
Please consider upgrading to the minimum supported operating system to ensure uninterrupted access to thinkorswim.

--------------------------

Translation: TOS cares nothing about actual trading. Creating a Facebook of trading is more profitable.


Note: Bull**** like direct 3d acceleration and direct draw are perfect examples of things that do nothing but slow down a platform which cannot even support the weight of its own java base. TOS doesn't care as long as the Facebook thing can grow.
Sorry, only registered users may post in this forum.

Click here to login