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
August 22, 2015 10:19PM
Thanks, I noticed the lag you're talking about 2 years ago and sent TOS a screen movie showing them how unusable their Watch List data was. They're continuously working on it because then it was much worse with a 2 to 7 minute lag. I just tested my Watch Lists and they seem to be updating continuously with a 15 second lag - each script is different though. My Watch Lists lag behind the Add Label's by about 8 seconds. The disappointment is TOS Add Label against E-Trade where the lag time varies each time I test it (from about 15 seconds to about 1 minute). It may be the only way they can solve this is with more memory upgrades on their end. I use a Mac and last year they made us upgrade to Mavericks operating system and it made a huge difference.



Edited 1 time(s). Last edit at 08/22/2015 10:22PM by Ralph53.
Re: Fun with ThinkScript
August 22, 2015 10:37PM
I had 2 more questions, Robert.


1) Can you write a Watch List script that will give the exact price value of a stock when this occurs;

StochasticFull().FullK crosses above StochasticFull().FullD[6]


2) I also need a way to compare it to the previous Stochastic crossover like either

X = Stochastic crossover #2 - Stochastic crossover #1

or a list of say the last 5 crossovers

Stochastic crossover #5 = V
Stochastic crossover #4 = W
Stochastic crossover #3 = X
Stochastic crossover #2 = Y
Stochastic crossover #1 = Z

Thanks much.
Re: Fun with ThinkScript
August 24, 2015 06:33PM
Ralph53,

I don’t think I’ll be able to get to this for quite some time. I just found out last Friday that I’ve been accepted into an accelerated programming course. It started today. The first module is cramming a normally 16 week course into only 3. The next 8 week module will be equally demanding, I’m sure. So, I’m going to be too busy for ThinkScript for the time being.

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
August 24, 2015 08:15PM
Good luck.
Re: Fun with ThinkScript
August 25, 2015 09:26AM
Quote
Palmer
Remember the decal idea? How's this? They would be about 8 inches long and 4 inches high. Viny decals. You could put it on your laptop cover, filing cabinet, car window...center of your wife's make-up mirror...spinning smiley sticking its tongue out

Let me know about any adjustments or idea.

Will send you a few of them.


Palmer,

Your stickers arrived today and they look fantastic. Thank you for putting these together and sending them my way.

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
August 26, 2015 09:45AM
Robert,

Have you been able to get the OR script to work on TOS Mobile? It seems the time based functions do not work on the mobile version.
Re: Fun with ThinkScript
August 26, 2015 05:53PM
Quote
jburrowsiv
Robert,

Have you been able to get the OR script to work on TOS Mobile? It seems the time based functions do not work on the mobile version.

I've not used the mobile version.

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
August 28, 2015 07:37PM
Simple question smiling smiley

Is there a way to display the chart time frame on or within the chart window? When I change from a 233 to a 55 chart I'd like to be able to see at a glance which time frame I am currently looking at?

Seems like a simple question anyways. smiling smiley
Re: Fun with ThinkScript
August 28, 2015 09:50PM
Richie the Rick,

Try this code provided by Robert in the past

def nMinutes = GetAggregationPeriod() / 60000;
def Weekly = if nMinutes == 10080 then 1 else Double.NaN;
def Daily = if nMinutes == 1440 then 1 else Double.NaN;
def Intraday = if nMinutes < 1440 then 1 else Double.NaN;

AddLabel(Weekly, "Weekly", color.cyan);
AddLabel(Daily, "Daily", color.cyan);
AddLabel(Intraday, nMinutes, color.cyan);
Re: Fun with ThinkScript
August 28, 2015 10:10PM
Wow!!!

Very nice. Works great! Thanks for finding it MTUT!!! And a big thanks to Robert for providing it!!!!!!!!!!

smiling smiley smiling smiley smiling smiley smiling smiley

Thanks again
R
Re: Fun with ThinkScript
August 28, 2015 10:43PM
This is a great script from an earlier page. Does anyone know how to alter it so that the AddChartBubbles (just the red and green ones) will show the actual price value of the highs and lows instead of the rise or decline from the previous bubble (while leaving the white bubble alone)?

## START CODE
## ZigZagSign TOMO modification, v0.2 written by Linus @Thinkscripter Lounge adapted from Thinkorswim ZigZagSign Script

input price             = close;
input priceH            = high;    # swing high
input priceL            = low;     # swing low
input ATRreversalfactor = 3.2;
def ATR                 = reference ATR(length = 5);
def reversalAmount      = ATRreversalfactor * ATR;
input showlines         = yes;
input displace          = 1;
input showBubbleschange = yes;


def barNumber = BarNumber();
def barCount = HighestAll(If(IsNaN(price), 0, barNumber));

rec state = {default init, undefined, uptrend, downtrend};
rec minMaxPrice;

if (GetValue(state, 1) == GetValue(state.init, 0)) {
    minMaxPrice = price;
    state = state.undefined;
} else if (GetValue(state, 1) == GetValue(state.undefined, 0)) {
    if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {
        state = state.downtrend;
        minMaxPrice = priceL;
    } else if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {
        state = state.uptrend;
        minMaxPrice = priceH;
    } else {
        state = state.undefined;
        minMaxPrice = GetValue(minMaxPrice, 1);
    }
} else if (GetValue(state, 1) == GetValue(state.uptrend, 0)) {
    if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {
        state = state.downtrend;
        minMaxPrice = priceL;
    } else {
        state = state.uptrend;
        minMaxPrice = Max(priceH, GetValue(minMaxPrice, 1));
    }
} else {
    if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {
        state = state.uptrend;
        minMaxPrice = priceH;
    } else {
        state = state.downtrend;
        minMaxPrice = Min(priceL, GetValue(minMaxPrice, 1));
    }
}

def isCalculated = GetValue(state, 0) != GetValue(state, 1) and barNumber >= 1;
def futureDepth =  barCount - barNumber;
def tmpLastPeriodBar;
if (isCalculated) {
    if (futureDepth >= 1 and GetValue(state, 0) == GetValue(state, -1)) {
        tmpLastPeriodBar = fold lastPeriodBarI = 2 to futureDepth + 1 with lastPeriodBarAcc = 1
            while lastPeriodBarAcc > 0
            do if (GetValue(state, 0) != GetValue(state, -lastPeriodBarI))
                then -lastPeriodBarAcc
                else lastPeriodBarAcc + 1;
    } else {
        tmpLastPeriodBar = 0;
    }
} else {
    tmpLastPeriodBar = Double.NaN;
}

def lastPeriodBar = if (!IsNaN(tmpLastPeriodBar)) then -AbsValue(tmpLastPeriodBar) else -futureDepth;

rec currentPriceLevel;
rec currentPoints;
if (state == state.uptrend and isCalculated) {
    currentPriceLevel =
        fold barWithMaxOnPeriodI = lastPeriodBar to 1 with barWithMaxOnPeriodAcc = minMaxPrice
            do Max(barWithMaxOnPeriodAcc, GetValue(minMaxPrice, barWithMaxOnPeriodI));
    currentPoints =
        fold maxPointOnPeriodI = lastPeriodBar to 1 with maxPointOnPeriodAcc = Double.NaN
            while IsNaN(maxPointOnPeriodAcc)
            do if (GetValue(priceH, maxPointOnPeriodI) == currentPriceLevel)
                then maxPointOnPeriodI
                else maxPointOnPeriodAcc;
} else if (state == state.downtrend and isCalculated) {
    currentPriceLevel =
        fold barWithMinOnPeriodI = lastPeriodBar to 1 with barWithMinOnPeriodAcc = minMaxPrice
            do Min(barWithMinOnPeriodAcc, GetValue(minMaxPrice, barWithMinOnPeriodI));
    currentPoints =
        fold minPointOnPeriodI = lastPeriodBar to 1 with minPointOnPeriodAcc = Double.NaN
            while IsNaN(minPointOnPeriodAcc)
            do if (GetValue(priceL, minPointOnPeriodI) == currentPriceLevel)
                then minPointOnPeriodI
                else minPointOnPeriodAcc;
} else if (!isCalculated and (state == state.uptrend or state == state.downtrend)) {
    currentPriceLevel = GetValue(currentPriceLevel, 1);
    currentPoints = GetValue(currentPoints, 1) + 1;
} else {
    currentPoints = 1;
    currentPriceLevel = GetValue(price, currentPoints);
}

plot "ZZ$" = if (barNumber == barCount or barNumber == 1) then if state == state.uptrend then priceH else priceL else if (currentPoints == 0) then currentPriceLevel else Double.NaN;

rec zzSave =  if !IsNaN("ZZ$" ) then if (barNumber == barCount or barNumber == 1) then if IsNaN(barNumber[-1]) and  state == state.uptrend then priceH else priceL else currentPriceLevel else GetValue(zzSave, 1);

def chg = (if barNumber == barCount and currentPoints < 0 then priceH else if barNumber == barCount and currentPoints > 0 then priceL else currentPriceLevel) - GetValue(zzSave, 1);

def isUp = chg >= 0;

#Higher/Lower/Equal High, Higher/Lower/Equal Low
def xxhigh = if zzSave == priceH then Round(high, 2) else Round(xxhigh[1], 2);
def chghigh = Round(Round(high, 2) - Round(xxhigh[1], 2), 2);
def xxlow = if zzSave == priceL then Round(low, 2) else Round(xxlow[1], 2);
def chglow = Round(Round(low, 2) - Round(xxlow[1], 2), 2);


rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ$", 1)) and GetValue(isConf, 1));

"ZZ$".EnableApproximation();
"ZZ$".DefineColor("Up Trend", Color.UPTICK);
"ZZ$".DefineColor("Down Trend", Color.DOWNTICK);
"ZZ$".DefineColor("Undefined", Color.WHITE);
"ZZ$".AssignValueColor(if !isConf then "ZZ$".Color("Undefined" ) else if isUp then "ZZ$".Color("Up Trend" ) else "ZZ$".Color("Down Trend" ));

DefineGlobalColor("Unconfirmed", Color.WHITE);
DefineGlobalColor("Up", Color.UPTICK);
DefineGlobalColor("Down", Color.DOWNTICK);

AddChartBubble(showBubbleschange and !IsNaN("ZZ$" ) and barNumber != 1, if isUp then high else low , Round(chg, 2) , if barCount == barNumber or !isConf then GlobalColor("Unconfirmed" ) else if isUp then GlobalColor("Up" ) else GlobalColor("Down" ), isUp);

## END CODE
Re: Fun with ThinkScript
August 28, 2015 11:01PM
Quote
Ralph53
This is a great script from an earlier page. Does anyone know how to alter it so that the AddChartBubbles (just the red and green ones) will show the actual price value of the highs and lows instead of the rise or decline from the previous bubble (while leaving the white bubble alone)?

I don't have TOS opened at the moment, but this should do the trick.

AddChartBubble(showBubbleschange and !IsNaN("ZZ$" ) and barNumber != 1, if isUp then high else low , Round(if isUp then high else low, 2) , if barCount == barNumber or !isConf then GlobalColor("Unconfirmed" ) else if isUp then GlobalColor("Up" ) else GlobalColor("Down" ), isUp);

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
August 29, 2015 09:49PM
Robert, that works great.

1) How can I make the Autowave line invisible in the previous script?


And 2) How can I get the price value of X below to appear in the Bubble " " ? Thanks.


def X = Highest(open, 12);
def lastbar = HighestAll(if IsNaN(close) then 0 else BarNumber());
plot condition = if BarNumber() <= lastbar - 19 and BarNumber() >= lastbar - 20 then GetValue(X, BarNumber() - lastbar) else Double.NaN;
AddChartBubble(BarNumber() == lastbar - 19, condition, "  ", Color.Yellow, 0);



Edited 2 time(s). Last edit at 08/31/2015 01:40PM by Ralph53.
Re: Fun with ThinkScript
August 31, 2015 11:39AM
I've been trying to work with the following scan code. Unfortunately, there appears to be a 3 bar/candle delay built into the logic (see "hlc3[-3]" bold/underlined references)...

Given my limited thinkscripting abilities, I am able to grasp and understand certain basic aspects of the code. However, I am currently unable to make the necessary changes in order to draw the signal on the current or just completed bar/candle. Is it possible?

input signalOffsetFactor = 0.20;

def signalOffset = Average(TrueRange(high, close, low), 9) * signalOffsetFactor;

def triggerSell = If(If(close[-1] < high, 1, 0) and (hlc3[-2] < close[-1] or hlc3[-3] < close[-1]), 1, 0);

def triggerBuy = If(If(close[-1] > low, 1, 0) and (hlc3[-2] > close[-1] or hlc3[-3] > close[-1]), 1, 0);

rec buySellSwitch = If(triggerSell, 1, If(triggerBuy, 0, buySellSwitch[1]));

def thirdBarClosed = If(IsNaN(hlc3[-3]), 0, 1);

plot BS_Long = If(triggerBuy and thirdBarClosed and buySellSwitch[1], low - signalOffset, Double.NaN);
     BS_Long.SetStyle(Curve.FIRM);
     BS_Long.SetPaintingStrategy(PaintingStrategy.POINTS);
     BS_Long.SetLineWeight(5);
     BS_Long.AssignValueColor(CreateColor(153, 255, 153));
Thanks in advance for any assistance/guidance in this endeavor. It is certainly appreciated smiling smiley



Edited 1 time(s). Last edit at 08/31/2015 01:28PM by netarchitech.
Re: Fun with ThinkScript
September 04, 2015 02:11PM
Lots of talk lately concerning the chart bubbles in TOS smiling smiley

For the Autowave we use in TOS, is there a way to put the chartbubble or the data on the center of the Autowave line just like it is in Qcharts?
Re: Fun with ThinkScript
September 06, 2015 04:41AM
I want to create a scan for which I don't seem to find any of my required criteria on ToS.

I am interested in running a scan based on options prices /premium looking for a decrease in price between 48 - 55 % from previous day close and another scan looking for an increase in prices from previous day close of 190 -204%.

How would I accomplish this?
Thanks
Re: Fun with ThinkScript
September 06, 2015 02:45PM
Hi Robert and anyone else who is great at thinkscript,
oops, my bad.
I ask a question about scanning for change in option prices on ToS before reading the thread on ToS not enabled for these kinds of scan.

Robert, coffee is on me. You truly have a servant heart to help people, maybe form years of service in the military. Cheers mate.

I do need help on scripting for a scan on optionable weekly stocks with vol greater than 500,000, minimum of 9 consecutive of lower closes or higher closes and a change in price direction. I am essentially looking for trend reversal based on price action. I am imagining this will be a study filter on ToS?

I am also interested in creating what I call the slingshot rubber band effect on Bollinger band by looking for when price action is greater than 2 standard deviation, plus and minus. Have it as a watchlist and on the chart.

BTW, the code for the autowave was so helpful as I always struggled with doing Elliott wave counts. Thanks ever so much.
Re: Fun with ThinkScript
September 06, 2015 04:26PM
Quote
gblinc2
Robert, coffee is on me. You truly have a servant heart to help people, maybe form years of service in the military. Cheers mate.

Thank you. That's very kind of you and is much appreciated.



I'm not ignoring anyone (well, I guess I am since I'm not answering questions.) It's just that I'm in an accelerated programming course right now (my first ever) and am a little swamped with the amount of work being thrown at me. Remind me of some of your requests in about a month. Hopefully, I'll have the time to knock out some thinkscript then.

- robert


Professional ThinkorSwim indicators for the average Joe



Edited 1 time(s). Last edit at 09/06/2015 04:33PM by robert.
Re: Fun with ThinkScript
September 06, 2015 06:10PM
This is for baffled1, optiontrader101 and tampman.
On the Mostafa Belkhayat center of gravity study, how would you create a scan from that to create a list of tradable watchlist?

This place is a wealth of information. I feel like a kid in a candy store.
Thanks in advance
Re: Fun with ThinkScript
September 06, 2015 06:25PM
One day at a time. I trust that after the programming class, the information you impart will take us from wanna bes to wall street billionare ballers.
Enjoy School.
Re: Fun with ThinkScript
September 06, 2015 07:38PM
Robert,

Good luck and all the best with your advanced programming class. Since I haven't been around these parts in a while, I've been catching up and read that you recently moved. I certainly hope it all went smoothly...

I look forward to hopefully seeing you back around here in a month or so smiling smiley
Re: Fun with ThinkScript
September 08, 2015 09:14PM
gblinc2 Wrote:
-------------------------------------------------------
> This is for baffled1, optiontrader101 and tampman.
>
> On the Mostafa Belkhayat center of gravity study,
> how would you create a scan from that to create a
> list of tradable watchlist?
>
> This place is a wealth of information. I feel like
> a kid in a candy store.
> Thanks in advance
gblinc2, that's very challenging, which I guess is why nobody replied yet. I had to look it up and it's an interesting regression analysis,
with part of it the Golden Mean. So first step is to figure out what he's doing from the internet descriptions then convert that to TS. Maybe somebody else will work it out before I do, but I'll be giving it a try. Haven't worked with this stuff since my spreadsheet days. Thanks for the challenge.
Robert- good luck with class! You deserve to do well!!
Re: Fun with ThinkScript
September 09, 2015 12:02AM
Thanks, I am so happy to have woken the mad scientist in you.smiling bouncing smiley
I went back to look at the thinkscript for the chart and I am thinking the input portion of the script regarding the price being used , which is the closed price and the length of -50 and width of 60 will be part of that algorithm for the scan.

I am so appreciative that you are taking up this challenge.
Thanks
Re: Fun with ThinkScript
September 09, 2015 01:31PM
Quote
gblinc2
> I went back to look at the thinkscript for the chart and I am thinking the input portion of the
script regarding the price being used , which is the closed price and the length of -50 and width
of 60 will be part of that algorithm for the scan.
-------------------------------------------------------
Okay, gblinc2, I know what you mean. But one issue with the Evil Algo has always been width-shifting, and I read on another forum that the Mostafa Belkhayat COG has the same issue. I manually accomodate this in the Evil Algo so it usually works for me but it can be annoying and lock me in a trade longer than I want. So starting from brass tacks, I propose to eliminate time-dependent width, so the plot remains stable. In other words, a more simplistic approach. And whattaya know, it does seem to work... Thank you again spinning smiley sticking its tongue out but I'll probably keep tinkering. Please let me know what your tinkering turns up, okay? Believe it or not (I was shocked), but the default lengths of "1", i.e., no averaging at all, seem to produce best results. So price rocks back and forth between upperlim and lowerlim, which is really what we want to see. When you run this code, the plot is actually forecasting the upper/lower limit of the CURRENT bar as a stable plot. EDIT: Ah, forgot to mention, the "1.001618" and "0.001618" values are for EURUSD H1 but for stocks or other forex the zeroes to right of decimal would probably have to be moved right or left, and ditto for other EURUSD timeframes... Yep, just tried "1.01618" and "0.01618" on EURUSD Daily and it reads modestly okay.
input length1 = 1;
input length2 = 1;
def upperlim = ((high[1]+low[1]+close[1])/3)*1.001618;
def lowerlim = ((high[1]+low[1]+close[1])/3)-((high[1]+low[1]+close[1])/3)*0.001618;
plot upperlimmax = average(upperlim,length1);
plot lowerlimmax = average(lowerlim,length2);



Edited 5 time(s). Last edit at 09/09/2015 01:47PM by baffled1.
Re: Fun with ThinkScript
September 09, 2015 10:31PM
Thanks Baffled1.
I tried doing the scan. I had to split it into 2 scans because on scan thinkscript, you can only have one plot.
Out of curiosity, have you or anyone else reading this thread heard of patternsmart or Toslancer? they have cog scans thinkscript for sale
Just wondering if there are any true reviews out there because I commit my hard earned money?
Thankscool smiley
Re: Fun with ThinkScript
September 10, 2015 12:43PM
Greetings,

I'm trying to create a scan that identifies stock breakout candidates where today's open is 2+ standard deviations of the ATR above or below the previous day's close. Here's what I have so far however TOS doesn't like it so I believe I have the incorrect syntax. Any help is much appreciated!

Open > Close[1] + (2*StDev(ATR, 10)) or Open < Close[1] – (2*StDev(ATR, 10))

If the direction and number of standard deviations can be added as columns in the scan results that would be very helpful.

Thanks!
ATR Breakout Scan
September 10, 2015 12:26PM
Greetings,

I'm trying to create a scan that identifies stock breakout candidates where today's open is 2+ standard deviations of the ATR above or below the previous day's close. Here's what I have so far however TOS doesn't like it so I believe I have the incorrect syntax. Any help is much appreciated!

Open > Close[1] + (2*StDev(ATR, 10)) or Open < Close[1] – (2*StDev(ATR, 10))

If the direction and number of standard deviations can be added as columns in the scan results that would be very helpful.

Thanks!
Re: Fun with ThinkScript
September 11, 2015 04:01PM
I try not to throw out the baby with the bathwater. So even though my last post hasn't yielded anything spectacular for me, I noticed that the midline at least defined an upper limit. So I went to work finding the lower limit. Not recommending anybody else try trading this but what I'll probably do next week is look for when price makes a break above or below the cloud, then try to book my trade at the extreme but in the opposite direction. A 500-bar H1 sample is not statistically best but I notice from it the strategy rarely fails.
This is for EURUSD H1 ; values would be different for other issues and periods. Values of "goldmean1" and "goldmean2" are fractions of 1.618, and "midmaxminorval" arrived at by trial and error (so I recommend tinkering only with "midmaxminorval" ).
input length1 = 1;
input length2 = 1;
input goldmean1 = 1.00809;
input goldmean2 = 0.004854;
input midmaxminorval = 2.007;
def upperlim = ((high[1]+low[1]+close[1])/3)*goldmean1;
def lowerlim = ((high[1]+low[1]+close[1])/3)-((high[1]+low[1]+close[1])/3)*goldmean2;
def upperlimmax = average(upperlim,length1);
def lowerlimmax = average(lowerlim,length2);
plot midmax = (upperlimmax+lowerlimmax)/2;
plot midmaxminor = (upperlimmax+lowerlimmax)/midmaxminorval;
AddCloud(midmax,midmaxminor,color.plum,color.plum);
Re: Fun with ThinkScript
September 14, 2015 06:38AM
Hello Robert, after reading a lot of those threads , I've decided to purchase the Champion Reversal Scan then the indicator last Friday, on my watchlist stock appear and disappear when i do a scan and i miss on opportunities to do a trade, I would like to know if it's possible to create a custom column on my watchlist who will alert me by changing to color GREEN for bottom reversal and red for top reversal when the arrow present a possible reversal.
Intraday bull flag in Watchlist in ThinkorSwim
September 14, 2015 03:58PM
Hi Robert (or anybody who can help me out),

I need a watch list column displaying intra-day (5 minute) bull flags. I have the standard Intraday flag provided by thinkorswim for charts. I have tried to port the same code to a watch list column, but I get a msg that essentially says that the code is too complex.

If this is not possible to code, would you have any ideas on how I can quickly and efficiently find which stocks have a bull flag?

Thanks so much for your help!
Sorry, only registered users may post in this forum.

Click here to login