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
May 13, 2016 12:16PM
Thank you
Re: Fun with ThinkScript
May 18, 2016 05:52PM
Getting the after hours volume:

In TOS I like to look at the post market movers under the Lovers and Losers tab because there can be events that you may want to 'take part in'. My issue is that I want to see the volume that happens with those stocks but I only want to see the after hours volume. I know about customizing the headers for your watchlists and I want to add the post market volume. So, basically I want to see the total running volume for these stocks that begins at 1500; 3pm CST.

This is what I've got:


def afthours = if secondsfromtime(1500)>=0 then 1 else 0;
def vol = reference VolumeAvg("length"=1);
plot volp = vol;

However, this only gives me the volume for what the timeframe I have chosen for the script and I have to have the chart set for that timeframe. I'd like to have the 1 minute chart up but see the running total volume beginng at 1500 in that watchlist. And if there is no volume with a stock but only a news alert that causes it to be listed in the Lovers and Losers it looks at the volume (for that timeframe) from when the market was still open.

So, how do a running total the volume from 1500 to say 2000?

Thanks
Re: Fun with ThinkScript
May 19, 2016 12:55PM
Hello guys,

New to the forum here.

I was wondering if anyone here is familiar with the TTM scalper alert on TOS. I am looking for a means of having this alert as an audio alert. it is not currently an option. Any insights will be greatly appreciated.
Re: Fun with ThinkScript
May 22, 2016 01:37AM
Can some one check this script for me, I need help by shifting the bubble to the left, basically what I want is 9:30 to 12:00 cloud and I want it to show on 9:30 - 12:00 range but script is starting to draw the cloud from 12:00 and to whatever i have it set




OpenRange {
input ORtime = 5;

def FirstBar = GetDay() != GetDay()[1];
def RangeTime = SecondsFromTime(930) >= 0 and SecondsFromTime(0930) < 60 * ORtime;
def Rhigh = if FirstBar then high else if RangeTime and high > Rhigh[1] then high else Rhigh[1];
def Rlow = if FirstBar then low else if RangeTime and low < Rlow[1] then low else Rlow[1];

plot h = if RangeTime then Double.NaN else Rhigh;
plot l = if RangeTime then Double.NaN else Rlow;
}


def first30 = SecondsFromTime(930) >= 0 and SecondsTillTime(1600) >= 0;
def today = GetLastDay() == GetDay();


plot yHigh = if !today then Double.NaN else high(period = "day" )[1];
yHigh.SetDefaultColor(Color.CYAN);
plot yLow = if !today then Double.NAN else low(period = "day" )[1];
yLow.SetDefaultColor(Color.PINK);
plot h150 = if !Today then Double.NAN else if !first30 then Double.NaN else OpenRange(150).h;
h150.SetDefaultColor(Color.LIGHT_GRAY);
plot l150 = if !today then Double.NAN else if !first30 then Double.NaN else OpenRange(150).l;
l150.SetDefaultColor(Color.LIGHT_GRAY);


plot LowLW = if !today then Double.NaN else low(period = "week" )[1];
LowLW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

AddCloud (h150, l150, Color.LIGHT_GRAY);


[tinypic.com]





Edited 1 time(s). Last edit at 05/22/2016 01:38AM by Dnice638.
Re: Fun with ThinkScript
May 22, 2016 06:25AM
Could someone help me in coding a script that will paint any Candle that has tail more than 50% of the Candle's body (tail candlestick) ? ( e.g. Pin Bar e.t.c.)

So, if the tail located above ----> Red Candle
if the tail located down ----> Green Candle

Is it possible ?






Edited 2 time(s). Last edit at 05/22/2016 09:21AM by SARA.
Re: Fun with ThinkScript
May 23, 2016 07:53PM
Re: Fun with ThinkScript
May 23, 2016 08:11PM
Very nice job
Re: Fun with ThinkScript
May 23, 2016 08:58PM
does that script come with the fib lines? nice to have you back Robert!
Re: Fun with ThinkScript
May 23, 2016 09:30PM
Quote
xilb51x
does that script come with the fib lines? nice to have you back Robert!

Thanks. I'm not fully back, though. At least, I cannot be as active as I used to be because life has changed quite a bit since last year and I don't have the time I used to have.


The auto-fibonacci levels are a part of the Basic Market Structure script

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
May 24, 2016 12:37PM
SARA Yeah it's easy to do, what type of signal on those candle do you want to see?
Re: Fun with ThinkScript
May 24, 2016 07:53PM
Now that I've done an auto-trend line, I believe my next project will be automatic fibonacci fans.

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
May 25, 2016 08:01AM
I want to detect that type of candle,
I don't want any candle that has two long tails in the same candle ( Doji ) only to detect pin bar (hammer , hanging man) candles.
Re: Fun with ThinkScript
May 25, 2016 12:27PM
excellent work robert... im really enjoying the auto trend lines script this week! works great for tech analysis when combined with your support/resistance lines and the pivot2 labels in your basic market structure. its saving me a lot of time from manually drawing the trend lines now.

question: is it possible to create a column script to label the cross up and downs signals for a watchlist? i tried but tos is saying the script was too complicated. do you think its due the "switch" statement in the beginning?
Re: Fun with ThinkScript
May 25, 2016 01:49PM
I am trying to setup an alert that will notify me every time the DI_ADX_TREND-INDICATOR goes from weak to strong. can someone tell me if what I have in the code section is the most efficient way to do this.




declare lower;
input DI_length = 5;
input ADX_length = 13;
input Strong_Trend = 25;

def DX = if (diplus(di_length) + diminus(di_length) > 0) then 100 * AbsValue(diplus(di_length) - diminus(di_length)) / (diplus(di_length) + diminus(di_length)) else 0;
plot ADX = WildersAverage(DX, adx_length);ADX.DefineColor("Stronger", Color.green);
ADX.DefineColor("Weaker", Color.blue);
ADX.AssignValueColor(if ADX > ADX[1] then ADX.Color("Stronger" ) else ADX.Color("Weaker" ));
ADX.SetPaintingStrategy(PaintingStrategy.LINE);
ADX.SetStyle(Curve.SHORT_DASH);

AddCloud(ADX, 0, ADX.Color("stronger" ));
def weaker = if ADX < ADX[1] then ADX else Double.NaN;
AddCloud(weaker, 0, ADX.Color("weaker" ));

plot "DI+" = DIPlus(DI_length);
"DI+".SetDefaultColor(Color.RED);
"DI+".SetLineWeight(2);

plot "DI-" = DIMinus(DI_length);
"DI-".SetDefaultColor(Color.GREEN);
"DI-".SetLineWeight(2);

plot StrongTrend = Strong_Trend;
StrongTrend.SetDefaultColor(Color.black);
strongTrend.setlineWeight(2);

def Strong = if ADX > ADX[1] then ADX else Double.NaN;
alert(Strong, getsymbol() + "ADX Stronger", alert.bar, sound.bell);
Re: Fun with ThinkScript
May 25, 2016 01:55PM
Quote
mntman
excellent work robert... im really enjoying the auto trend lines script this week! works great for tech analysis when combined with your support/resistance lines and the pivot2 labels in your basic market structure. its saving me a lot of time from manually drawing the trend lines now.

Thank you for the kind words. It's always great to hear feedback from users who are happy with my scripts.


Quote
mntman
question: is it possible to create a column script to label the cross up and downs signals for a watchlist? i tried but tos is saying the script was too complicated. do you think its due the "switch" statement in the beginning?

This script is far too complex to be used in the watchlist since it includes loops and recursive variables—neither of which are supported by the watchlist (or scanner for that matter).

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
May 25, 2016 02:03PM
Quote
TexasJohn
I am trying to setup an alert that will notify me every time the DI_ADX_TREND-INDICATOR goes from weak to strong. can someone tell me if what I have in the code section is the most efficient way to do this.

def Strong = if ADX > ADX[1] then ADX else Double.NaN;
alert(Strong, getsymbol() + "ADX Stronger", alert.bar, sound.bell);


John,

As currently written, the alert will sound for every bar that has and ADX value that is higher than the preceding one. From your description above, I believe that you are only wanting it to signal when the value changes from weak (ADX is sloping down) to strong (ADX is now sloping up).

Try this instead.

alert(Strong AND weaker[1], getsymbol() + "ADX Stronger", alert.bar, sound.bell);

This will alert when this bar is stronger but the previous one was weaker.

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
May 25, 2016 02:53PM
Thank you Robert....

Have a couple of lattes on me
Re: Fun with ThinkScript
May 25, 2016 07:06PM
Quote
xilb51x
hello, just bought your auto trend lines, is it possible to also view the old trend lines?

That isn't possible as originally coded. I am working on adding that functionality now, though. However, it will require a serious change in methodology.

Quote
TexasJohn
Have a couple of lattes on me

Thank you very much! No lattes today, though. You bought curry for lunch. smiling smiley

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
May 25, 2016 09:19PM
Quote
This script is far too complex to be used in the watchlist
thats what i was afraid of... wishful thinking winking smiley

robert i was playing with your autotrendlines and added a set of shorter term trend lines for my personal preference of swing trading (3 to 20 days). i like the ones you have now off the p2pivots, but felt the p1s might provide myself with more trade signals. if you felt there may be enough traders interested then i thought respectfully you may wish to consider adding this option if you were currently already working on a version 2. (although this option may not appeal really to day traders as much?) i did the same for your basicmarketstructure fibs, i added a p2 range just like your p3 range so i have the option of both shorter or intermediate time frame fibs with a simple toggle now. just my personal thoughts in case you were curious about user feedbacks so far. grinning smiley both excellent scripts... couldn't be more pleased





Edited 2 time(s). Last edit at 05/25/2016 09:30PM by mntman.
Re: Fun with ThinkScript
May 26, 2016 06:04AM
Getting the after hours volume:

In TOS I like to look at the post market movers under the Lovers and Losers tab because there can be events that you may want to 'take part in'. My issue is that I want to see the volume that happens with those stocks but I only want to see the after hours volume. I know about customizing the headers for your watchlists and I want to add the post market volume. So, basically I want to see the total running volume for these stocks that begins at 1500; 3pm CST.

This is what I've got:


def afthours = if secondsfromtime(1500)>=0 then 1 else 0;
def vol = reference VolumeAvg("length"=1);
plot volp = vol;

However, this only gives me the volume for what the timeframe I have chosen for the script and I have to have the chart set for that timeframe. I'd like to have the 1 minute chart up but see the running total volume beginng at 1500 in that watchlist. And if there is no volume with a stock but only a news alert that causes it to be listed in the Lovers and Losers it looks at the volume (for that timeframe) from when the market was still open.

So, how do a running total the volume from 1500 to say 2000?

Thanks
Re: Fun with ThinkScript
May 27, 2016 05:49PM
So I'm working on a Watchlist column. I'd like to have the watchlist column show the date that the stock had a split within the last 43 days. I can get the script to show today's date but it won't show the date that the stock split in the last 43 days. The reason I stopped at 43 is because any more than that the the script gives an error of being to complex.

I've been working on this for weeks now and I seem to be at a stand still.

Where have I gone wrong??? I just know it has to be something simple that I'm overlooking.

def eventday = GetEventOffset(Events.SPLIT, -1);
def splitdate = if eventday then GetYYYYMMDD() else if
eventday[-1] then GetYYYYMMDD()[-1] else if
eventday[-2] then GetYYYYMMDD()[-2] else if
eventday[-3] then GetYYYYMMDD()[-3] else if
eventday[-4] then GetYYYYMMDD()[-4] else if
eventday[-5] then GetYYYYMMDD()[-5] else if
eventday[-6] then GetYYYYMMDD()[-6] else if
eventday[-7] then GetYYYYMMDD()[-7] else if
eventday[-8] then GetYYYYMMDD()[-8] else if
eventday[-9] then GetYYYYMMDD()[-9] else if
eventday[-10] then GetYYYYMMDD()[-10] else if
eventday[-11] then GetYYYYMMDD()[-11] else if
eventday[-12] then GetYYYYMMDD()[-12] else if
eventday[-13] then GetYYYYMMDD()[-13] else if
eventday[-14] then GetYYYYMMDD()[-14] else if
eventday[-15] then GetYYYYMMDD()[-15] else if
eventday[-16] then GetYYYYMMDD()[-16] else if
eventday[-17] then GetYYYYMMDD()[-17] else if
eventday[-18] then GetYYYYMMDD()[-18] else if
eventday[-19] then GetYYYYMMDD()[-19] else if
eventday[-20] then GetYYYYMMDD()[-20] else if
eventday[-21] then GetYYYYMMDD()[-21] else if
eventday[-22] then GetYYYYMMDD()[-22] else if
eventday[-23] then GetYYYYMMDD()[-23] else if
eventday[-24] then GetYYYYMMDD()[-24] else if
eventday[-25] then GetYYYYMMDD()[-25] else if
eventday[-26] then GetYYYYMMDD()[-26] else if
eventday[-27] then GetYYYYMMDD()[-27] else if
eventday[-28] then GetYYYYMMDD()[-28] else if
eventday[-29] then GetYYYYMMDD()[-29] else if
eventday[-30] then GetYYYYMMDD()[-30] else if
eventday[-31] then GetYYYYMMDD()[-31] else if
eventday[-32] then GetYYYYMMDD()[-32] else if
eventday[-33] then GetYYYYMMDD()[-33] else if
eventday[-34] then GetYYYYMMDD()[-34] else if
eventday[-35] then GetYYYYMMDD()[-35] else if
eventday[-36] then GetYYYYMMDD()[-36] else if
eventday[-37] then GetYYYYMMDD()[-37] else if
eventday[-38] then GetYYYYMMDD()[-38] else if
eventday[-39] then GetYYYYMMDD()[-39] else if
eventday[-40] then GetYYYYMMDD()[-40] else if
eventday[-41] then GetYYYYMMDD()[-41] else if
eventday[-42] then GetYYYYMMDD()[-42] else if
eventday[-43] then GetYYYYMMDD()[-43]
else Double.NaN;

def date = splitdate;
def year = RoundDown(date / 10000, 0);
def month = RoundDown((date - (year * 10000)) / 100, 0);
def day = RoundDown((date - (year * 10000) - (month * 100)), 0);

AddLabel(yes, if !IsNaN(date) then month + "/" + (if day < 10 then "0" else "" ) + day else "" );

## End



Edited 1 time(s). Last edit at 05/27/2016 07:17PM by RichieRick.
Re: Fun with ThinkScript
May 27, 2016 08:03PM
Quote
RichieRick
So I'm working on a Watchlist column. I'd like to have the watchlist column show the date that the stock had a split within the last 43 days. I can get the script to show today's date but it won't show the date that the stock split in the last 43 days. The reason I stopped at 43 is because any more than that the the script gives an error of being to complex.

I've been working on this for weeks now and I seem to be at a stand still.

Where have I gone wrong??? I just know it has to be something simple that I'm overlooking.

# +----------------------------------------+
# |       Display date of last split       |
# |              Robert Payne              |
# |          rrpayne.blogspot.com          |
# +----------------------------------------+

# +----------------------------------------+
# |    How long ago did the split occur?   |
# +----------------------------------------+
def lookback = GetEventOffset(Events.SPLIT, -1);
# +----------------------------------------+
# |     What was the date of the split?    |
# +----------------------------------------+
def sDay = GetValue(GetDayOfMonth(GetYYYYMMDD()), lookback);
def sMonth = GetValue(GetMonth(), lookback);
def sYear = GetValue(GetYear(), lookback) - 2000;
# +----------------------------------------+
# |           Display the date.            |
# +----------------------------------------+
AddLabel(yes, if IsNaN(GetValue(close, lookback)) then "Data not available" else sMonth + "/" + sDay + "/" + "20" + sYear, Color.YELLOW);

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
May 27, 2016 08:08PM
Quote
Palmer
So, how do a running total the volume from 1500 to say 2000?

Heading to dinner, so no time for a complete answer this evening. You need to use a self-referencing variable to maintain a running total.

Something along the lines of this (not an actual line of code)

def CumulativeVolume = if {bar@1500} then volume else CumulativeVolume[1] + volume;

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
May 27, 2016 09:35PM
I'm using roberts reversal areas as my swing targets after breakouts. I'm still fairly new to thinkscript, but my understanding is currently his script has a previous peak extend as a dashed line to the start of the next peak. i would like to modify this where the previous peak only extends for me when todays close comes within 1/2% of that peak level... otherwise it would remain unextended.

i referenced roberts other post about when a price is inRange of a set percentage. ive added definitions for inRange and percentage but can't seem to get it to work. would anyone have advice where I'm going wrong please?

as i have it now the previous peak is not extending like i intended:
# continue the previous peak as a dashed line
def percent = 0.5;
def inRange = close between (peak*(1-percent/100)) and (peak*(1+percent/100));
def oldpeak = if BarNumber() < magnitude then Double.NaN else if peak and inRange then peakvalue[1] else oldpeak[1];
plot oldpeakline = oldpeak;
     oldpeakline.SetPaintingStrategy(PaintingStrategy.DASHES);
     oldpeakline.SetDefaultColor(Color.light_green);




Edited 3 time(s). Last edit at 05/30/2016 01:44PM by mntman.
Re: Fun with ThinkScript
May 30, 2016 11:24AM
robert Wrote:
-------------------------------------------------------
> > These are all great!!
>
> Now get to work on an AutoWave for TOS!!!
>
>
> QCharts AutoWave on top -- ThinkOrSwim with
> modified ZigZag on bottom
>
> [i.imgur.com]
>
> I did not write this code, I only modified it
> slightly. Thanks to TCB and Dan for providing
> QCharts screenshots to compare the values. This
> is as close to the AutoWave as I've found.
>
>
> ## 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 = ATRWilder("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
>


Welcome back, Robert! I use this code a lot on my charts. But Is there any way to make this code into a "scan" ?
Re: Fun with ThinkScript
May 30, 2016 11:41AM
Quote
DynaMike
Welcome back, Robert!

Thanks.


Quote
DynaMike
Welcome back, Robert! I use this code a lot on my charts. But Is there any way to make this code into a "scan" ?

Nope. It is far to complex. That script uses several loops (fold statements) to look at what happens after the current bar. See this post for an explanation as to why the scan cannot "look into the future".

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
May 30, 2016 07:12PM
Quote
mntman
i would like to modify this where the previous peak only extends for me when todays close comes within 1/2% of that peak level... otherwise it would remain unextended.
def inRange = close between (peak*(1-percent/100)) and (peak*(1+percent/100));

i'm thinking my problem lies with the definition of "close". i was thinking that close with no brackets would be understood as todays close, but after doing some reading I'm curious now if the script is interpreting it as a cumulative close of all the bars currently shown on the chart?

would i need to somehow define todays close by using a barNumber() function maybe?



Edited 1 time(s). Last edit at 05/30/2016 07:28PM by mntman.
HELP
May 30, 2016 08:42PM
HI TO EVERYONE ON THIS GREAT AND FUN FORUM... I WILL LIKE TO KNOW IF SOMEONE CAN HELP ME TO CREATE A SCRIPT FOR TOS.. I'VE USING MULTI TIME FRAME FOR MACD,12,26,9.. HERE IS THE SCRIPT THE ONE IM USING NOW, I WILL LIKE TO CHANGE FOR REMKO BARS FOR INTRADAY TO TRADE THE FUTURE.. CAN SOMEONE HELP ME CREATE THE SCRIPT? THANKS ....HERE IS THE SCRIPT ON THE SCRIPT IM USING NOW IS WORK GREAT FOR 60,15,5 MINUTES FOR THE FUTURES.

declare lower;
input midTermPeriod = {"1 min", "3 min", "5 min", "15 min", "30 min", "60 min", "120 min", "Daily", default "Weekly", "Monthly"};
input longTermPeriod = {"3 min", "5 min", "15 min", "30 min", "60 min", "120 min", "Daily", "Weekly", default "Monthly"};

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;

input midTermFastLength = 12;
input midTermSlowLength = 26;
input midTermMACDLength = 9;

input longTermFastLength = 12;
input longTermSlowLength = 26;
input longTermMACDLength = 9;

def middleAggregation;

switch (midTermPeriod) {
case "1 min":
middleAggregation = AggregationPeriod.MIN;
case "3 min":
middleAggregation = AggregationPeriod.THREE_MIN;
case "5 min":
middleAggregation = AggregationPeriod.FIVE_MIN;
case "15 min":
middleAggregation = AggregationPeriod.FIFTEEN_MIN;
case "30 min":
middleAggregation = AggregationPeriod.THIRTY_MIN;
case "60 min":
middleAggregation = AggregationPeriod.HOUR;
case "120 min":
middleAggregation = AggregationPeriod.TWO_HOURS;
case "Daily":
middleAggregation = AggregationPeriod.DAY;
case "Weekly":
middleAggregation = AggregationPeriod.WEEK;
case "Monthly":
middleAggregation = AggregationPeriod.MONTH;
}

def highestAggregation;
switch (longTermPeriod) {
case "3 min":
highestAggregation = AggregationPeriod.THREE_MIN;
case "5 min":
highestAggregation = AggregationPeriod.FIVE_MIN;
case "15 min":
highestAggregation = AggregationPeriod.FIFTEEN_MIN;
case "30 min":
highestAggregation = AggregationPeriod.THIRTY_MIN;
case "60 min":
highestAggregation = AggregationPeriod.HOUR;
case "120 min":
highestAggregation = AggregationPeriod.TWO_HOURS;
case "Daily":
highestAggregation = AggregationPeriod.DAY;
case "Weekly":
highestAggregation = AggregationPeriod.WEEK;
case "Monthly":
highestAggregation = AggregationPeriod.MONTH;
}

DefineGlobalColor("UpTrend", color.GREEN);
DefineGlobalColor("DownTrend", color.RED);
DefineGlobalColor("NoTrend", color.LIGHT_GRAY);

def timeFrame = getAggregationPeriod();
def testTimeFrames = if timeFrame < middleAggregation and middleAggregation < highestAggregation then yes else no;

AddLabel(yes, if testTimeFrames then "Time Frames Are Correct" else "Time Frames Are Wrong", if testTimeFrames then color.GREEN else color.RED);

# This section is for the chart level MACD
def fastAvg = ExpAverage(close, fastLength);
def slowAvg = ExpAverage(close, slowLength);

plot Value = fastAvg - slowAvg;
Value.SetDefaultColor(color.CYAN);
plot Avg = ExpAverage(Value, MACDLength);
Avg.SetDefaultColor(color.YELLOW);
plot Diff = (value - avg)*3;

# This section is for the medium term MACD
def midTermFastAvg = ExpAverage(close(period = middleAggregation) , midTermFastLength);
def midTermSlowAvg = ExpAverage(close(period = middleAggregation) , midTermSlowLength);

def midTermValue = midTermFastAvg - midTermSlowAvg;
def midTermAvg = ExpAverage(midTermValue, midTermMACDLength);
plot midTermDiff = (midTermValue - midTermAvg)*3;
midTermDiff.Hide();
midTermDiff.HideBubble();

# This section is for the long term MACD
def longTermFastAvg = ExpAverage(close(period = highestAggregation) , longTermFastLength);
def longTermSlowAvg = ExpAverage(close(period = highestAggregation) , longTermSlowLength);

def longTermValue = longTermFastAvg - longTermSlowAvg;
def longTermAvg = ExpAverage(longTermValue, longTermMACDLength);
plot longTermDiff = (longTermValue - longTermAvg)*3;
longTermDiff.Hide();
longTermDiff.HideBubble();


def midTermLower = midTermDiff < midTermDiff[1];
def midTermHigher = midTermDiff > midTermDiff[1];
rec midTermSignal = if midTermLower then yes else if midTermSignal[1] == yes and midTermHigher == no then yes else no;
#plot test = midTermSignal;
def longTermLower = longTermDiff < longTermDiff[1];
def longTermHigher = longTermDiff > longTermDiff[1];
rec longTermSignal = if longTermLower then yes else if longTermSignal[1] == yes and longTermHigher == no then yes else no;

midTermDiff.AssignValueColor(if midTermSignal then color.RED else color.BLUE);
longTermDiff.AssignValueColor(if longTermSignal then color.RED else color.BLUE);

Diff.AssignValueColor(if Diff > Diff[1] and midTermSignal == no and longTermSignal == no then GlobalColor("UpTrend"winking smiley else if Diff < Diff[1] and midTermSignal == yes and longTermSignal == yes then GlobalColor("DownTrend"winking smiley else GlobalColor("NoTrend"winking smiley );
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);

plot zeroLine = if close[-1] > 0 then 0 else Double.Nan;
zeroLine.AssignValueColor(if Diff > Diff[1] and midTermSignal == no and longTermSignal == no then GlobalColor("UpTrend"winking smiley else if Diff < Diff[1] and midTermSignal == yes and longTermSignal == yes then GlobalColor("DownTrend"winking smiley else GlobalColor("NoTrend"winking smiley );
zeroLine.SetPaintingStrategy(PaintingStrategy.POINTS);
zeroLine.SetLineWeight(3);
Re: Fun with ThinkScript
May 30, 2016 10:21PM
robert Wrote:
-------------------------------------------------------

> # +----------------------------------------+
> # | Display date of last split |
> # | Robert Payne |
> # | rrpayne.blogspot.com |
> # +----------------------------------------+
>
> # +----------------------------------------+
> # | How long ago did the split occur? |
> # +----------------------------------------+
> def lookback = GetEventOffset(Events.SPLIT, -1);
> # +----------------------------------------+
> # | What was the date of the split? |
> # +----------------------------------------+
> def sDay = GetValue(GetDayOfMonth(GetYYYYMMDD()),
> lookback);
> def sMonth = GetValue(GetMonth(), lookback);
> def sYear = GetValue(GetYear(), lookback) - 2000;
> # +----------------------------------------+
> # | Display the date. |
> # +----------------------------------------+
> AddLabel(yes, if IsNaN(GetValue(close, lookback))
> then "Data not available" else sMonth + "/" + sDay
> + "/" + "20" + sYear, Color.YELLOW);
>


Hey Robert,

Glad to see you are lurking the boards still. smiling smiley

It's amazing, simply amazing!!! Your five lines of code destroyed my 30 or so lines. And the speed with which you whipped it out. Man that was fast.

I'll get it added and see how it turns out. I'm sure I'll have to mod it just a tiny bit as I'm trying to create 2 scripts. One watch list that scans Pre-split and one that does post-split. I'm also making 2 more watch list columns, one that shows the date of upcoming earnings, and another that shows whether earnings release is before or after market hours.


Thanks for squaring me away!!!
Much appreciated. smiling smiley
Re: Fun with ThinkScript
May 31, 2016 03:52PM
Robert:

Thanks for the help. I'm getting an error from

def CumulativeVolume = if {bar @ begin_time} then volume else CumulativeVolume[1] + volume;

Here is what I have:

input begin_time = 1500;

def afthours = if secondsfromtime(begin_time)>=0 then 1 else 0;

def CumulativeVolume = if {bar @ begin_time} then volume else CumulativeVolume[1] + volume;

plot CumulativeVolume;


Any thoughts?

Will buy you a round winking smiley
Sorry, only registered users may post in this forum.

Click here to login