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
March 18, 2014 08:09AM
Quote
Tan
Wow, the code works great! Thank you so much. You're the best smiling smiley

You're welcome.

Quote
Tan
Can you help me with a few other things? Is it possible also for the entry price to be displayed in the alert message?

Replace the #Trigger alerts section with the following code:

#Trigger alerts
Alert(AboveYhigh and !AboveYhigh[1], Concat(GetSymbolPart(), Concat(" above yesterday's high.  Entry Price:  ", Round(Yhigh + ATR, 2))), Alert.BAR, Sound.Chimes);
Alert(AbovePivot and !AbovePivot[1], Concat(GetSymbolPart(), Concat(" above pivot point.  Entry Price:  ", Round(Pivot + ATR, 2))), Alert.BAR, Sound.Chimes);
Alert(AboveORHigh and !AboveORHigh[1], Concat(GetSymbolPart(), Concat(" above opening range high.  Entry Price:  ", Round(ORHigh + ATR, 2))), Alert.BAR, Sound.Chimes);
Alert(BelowYlow and !BelowYlow[1], Concat(GetSymbolPart(), Concat(" below yesterday's low.  Entry Price:  ", Round(Ylow - ATR, 2))), Alert.BAR, Sound.Chimes);
Alert(BelowPivot and !BelowPivot[1], Concat(GetSymbolPart(), Concat(" below pivot point.  Entry Price:  ", Round(Pivot - ATR, 2))), Alert.BAR, Sound.Chimes);
Alert(BelowORLow and !BelowORLow[1], Concat(GetSymbolPart(), Concat(" below opening range low.  Entry Price:  ", Round(ORLow - ATR, 2))), Alert.BAR, Sound.Chimes);

Quote
Tan
I want to add a label which displays current 2 minute ATR on upper chart next to the ADX label. The lower studies get cut off when I open 2 charts horizontally and I cannot see the ATR.

At the very bottom, replace the last two AddLabel entries with the following code. Also, I added a little formatting bonus to paint the opening range that I think you'll like.

AddLabel(ADXred, Concat("SPY ADX:  ", Round(AltSymbolADX,2)), Color.PINK);
AddLabel(ADXgreen, Concat("SPY ADX:  ", Round(AltSymbolADX,2)), Color.UPTICK);
AddLabel(yes, Concat("ATR:  ", Round(ATR, 2)), Color.LIME);
AddCloud(OpenRangeHigh, OpenRangeLow, Color.LIGHT_GRAY);

By the way, the SPY ADX is currently being calculated on a 2 minute time period since you are using a 2 minute chart. However, if you would rather know the SPY's daily ADX value then in the #Display SPY ADX value in a box section replace these three lines with the following code.

def h = high(symbol);
def l = low(symbol);
def c = close(symbol);

def h = high(symbol, Period="Day" );
def l = low(symbol, Period="Day" );
def c = close(symbol, Period="Day" );

Quote
Tan
Is it possible to build custom watch list columns for previous day range, open range, and pivot point which show green or red color in front of the symbol when long or short entries are triggered?

It is possible, however, unless ThinkOrSwim has recently fixed their program, I don't think you'll be very happy with the results. Custom watchlist columns tend to be unreliable during the first 20 or 30 minutes of the day as the servers don't keep up with the data. During the opening few minutes of the day the custom columns will either display "loading data..." or they will display the last calculated data from yesterday. So, you may not get the results you expect but here's the code if you want to try.

For the previous day's high / low use the following with a Daily aggregation period:

plot HL = if close > high[1] then 1 else if close < low[1] then -1 else 0;
AssignBackgroundColor(if HL > 0 then Color.UPTICK else if HL < 0 then Color.DOWNTICK else Color.DARK_GRAY);
HL.AssignValueColor(if HL > 0 then Color.UPTICK else if HL < 0 then Color.DOWNTICK else Color.DARK_GRAY);

For the pivot point use the following with a Daily aggregation period:

def pivot = (high[1] + low[1] + close[1]) / 3;
plot pp = if open > pivot and close < pivot then -1 else if open < pivot and close > pivot then 1 else 0;
AssignBackgroundColor(if pp > 0 then Color.UPTICK else if pp < 0 then Color.DOWNTICK else Color.DARK_GRAY);
pp.AssignValueColor(if pp > 0 then Color.UPTICK else if pp < 0 then Color.DOWNTICK else Color.DARK_GRAY);

For the opening range use the following code with a 5 minute aggregation period:

def mybarcount = RoundUp(SecondsFromTime(0930) / 300, 0);
def orHigh = GetValue(high, mybarcount);
def orLow = GetValue(low, mybarcount);

plot signal = if close > orHigh then 1 else if close < orLow then -1 else 0;
AssignBackgroundColor(if signal == 1 then Color.Uptick else if signal == -1 then Color.Downtick else Color.DARK_GRAY);
signal.AssignValueColor(if signal == 1 then Color.Uptick else if signal == -1 then Color.Downtick else Color.DARK_GRAY);

Re: Fun with ThinkScript
March 18, 2014 04:46PM
Robert,

I am extremely grateful and thankful for your help. The open range cloud is a beautiful touch and exactly what I needed! You are right; it takes some time for the watch list columns to load but it might be helpful after the first half hour of trading.

One minor issue: Before market open, while I'm looking at the pre market chart, the open range high and low alerts keep getting triggered very frequently even though there is no 5 minute open range formed yet!

Tan
Re: Fun with ThinkScript
March 18, 2014 05:09PM
Quote
Tan
One minor issue: Before market open, while I'm looking at the pre market chart, the open range high and low alerts keep getting triggered very frequently even though there is no 5 minute open range formed yet!

See if this helps.

#Trigger alerts
Alert(SecondsFromTime(0930) > 0 and AboveYhigh and !AboveYhigh[1], Concat(GetSymbolPart(), Concat(" above yesterday's high.  Entry Price:  ", Round(Yhigh + ATR, 2))), Alert.BAR, Sound.Chimes);
Alert(SecondsFromTime(0930) > 0 and AbovePivot and !AbovePivot[1], Concat(GetSymbolPart(), Concat(" above pivot point.  Entry Price:  ", Round(Pivot + ATR, 2))), Alert.BAR, Sound.Chimes);
Alert(SecondsFromTime(0930) > 0 and AboveORHigh and !AboveORHigh[1], Concat(GetSymbolPart(), Concat(" above opening range high.  Entry Price:  ", Round(ORHigh + ATR, 2))), Alert.BAR, Sound.Chimes);
Alert(SecondsFromTime(0930) > 0 and BelowYlow and !BelowYlow[1], Concat(GetSymbolPart(), Concat(" below yesterday's low.  Entry Price:  ", Round(Ylow - ATR, 2))), Alert.BAR, Sound.Chimes);
Alert(SecondsFromTime(0930) > 0 and BelowPivot and !BelowPivot[1], Concat(GetSymbolPart(), Concat(" below pivot point.  Entry Price:  ", Round(Pivot - ATR, 2))), Alert.BAR, Sound.Chimes);
Alert(SecondsFromTime(0930) > 0 and BelowORLow and !BelowORLow[1], Concat(GetSymbolPart(), Concat(" below opening range low.  Entry Price:  ", Round(ORLow - ATR, 2))), Alert.BAR, Sound.Chimes);
Re: Fun with ThinkScript
March 18, 2014 05:23PM
Robert,
First I want to say thank-you ....for the autowave
I do have a question ???? How hard would it be to add an alarm, say ring for a green bubble and a bell for a red bubble on the autowave script.

Thanks again,
Re: Fun with ThinkScript
March 18, 2014 06:43PM
I wanted a quick way to compare the current close with the previous few bars without having to always drag the crosshair around the screen so I whipped up this little bit of code. The length of the line is adjustable in the settings. Perhaps one of you will also find it useful.


input lineLength = 4;
def barNumber = BarNumber();
def barCount = HighestAll(If(IsNaN(close), 0, barNumber));
def closeLine = if barNumber == 1 then Double.NaN else if barNumber == barCount - lineLength then close[-lineLength] else if barNumber == barCount then Double.NaN else closeLine[1];
plot data = closeLine;
data.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
March 18, 2014 07:45PM
removed

- robert


Professional ThinkorSwim indicators for the average Joe



Edited 1 time(s). Last edit at 05/14/2016 05:07PM by robert.
Re: Fun with ThinkScript
March 18, 2014 08:19PM
Quote
GameOver
How hard would it be to add an alarm, say ring for a green bubble and a bell for a red bubble on the autowave script.

Add the following lines to the bottom of the autowave code.

Alert(!IsNaN("ZZ$" ) and barNumber != 1 and isUp, Concat(GetSymbolPart(), " at new swing high." ), Alert.BAR, Sound.Ring);
Alert(!IsNaN("ZZ$" ) and barNumber != 1 and !isUp, Concat(GetSymbolPart(), " at new swing low." ), Alert.BAR, Sound.Bell);
Re: Fun with ThinkScript
March 18, 2014 09:01PM
Robert,
Thanks, now I can run the group of charts and wait for the sound then look at the message board and wait for the other indicators. Bamm ...way toooooo cool
Awesome
Thanks again
Re: Fun with ThinkScript
March 20, 2014 11:46AM
Robert, hands down on that script! simply amazing!!!thumbs up
Is it possible to assign the 3 session colors (with the highest volume for each session) to the histogram ?
Thank you!!!
Re: Fun with ThinkScript
March 20, 2014 02:55PM
removed

- robert


Professional ThinkorSwim indicators for the average Joe



Edited 1 time(s). Last edit at 05/14/2016 05:08PM by robert.
Re: Fun with ThinkScript
March 20, 2014 03:21PM
I tip my hat off to you seƱor!
Thank you so very mucho!
Re: Fun with ThinkScript
March 20, 2014 07:27PM
Hello Robert,
How do you get the baby blue square that is posted with the edge squares that has the time frame in it?

again thanks, this is good stuff
Re: Fun with ThinkScript
March 20, 2014 08:16PM
Quote
GameOver
Hello Robert,
How do you get the baby blue square that is posted with the edge squares that has the time frame in it?

again thanks, this is good stuff

Here you go. Change the blue color under settings if you want.

#Display Chart Time Frame 
DefineGlobalColor("time", CreateColor(148, 214, 232));
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", GlobalColor("time" ));
AddLabel(Daily, "Daily", GlobalColor("time" ));
AddLabel(Intraday, concat(nMinutes, " Minute" ), GlobalColor("time" ));
Re: Fun with ThinkScript
March 20, 2014 09:26PM
Thanks Robert,
I could not get the color to change but after thinking about it , I changed it to be fixed to red for intraday, blue for daily, and dark green for weekly

your the bomb. as Gary would say this is like breathing to you. or putting on socks
Re: Fun with ThinkScript
March 21, 2014 02:23AM
Quote
GameOver
your the bomb. as Gary would say this is like breathing to you. or putting on socks

Thanks. I find that statement a little funny, though, because while I am getting better, this is certainly not like breathing for me. I am not a programmer by any stretch of the imagination.

When I started using ThinkOrSwim a few months ago, I learned that it allowed one to add functionality via ThinkScript. The first thing I wanted to do was try to make an indicator that would automatically flag a FP / HRFP; so through a lot of experimentation, googling, and repeated readings of the ThinkScript manual page I managed to cobble together some code to do that. Every once in a while I get an idea then it's more trial and error until I get it to work.

I've enjoyed trying to fulfill the requests several of you have made of late because it gives me the opportunity to learn something new. It took me the better part of the day this past weekend trying to figure out the code that TanMan first asked for. But, I was then able to apply some of what I learned doing his code when I wrote the code for the volume box support / resistance zones a few days ago.

I'm passionate about learning to trade for a living so I enjoy piecing together these little indicators which will make it easier for me to trade.
Re: Fun with ThinkScript
March 21, 2014 09:22AM
For those who would like to learn more about the ORBO.

A research base on the 10 o'clock system
[www.wpi.edu]

The 10 o'clock system
[wealthv.com]
Re: Fun with ThinkScript
March 21, 2014 10:30AM
Robert,
Thanks, I am trying to make zones in the upper chart that just turn from red to green using the StochRSI using just one line ,,,,but all I can get is a ribbon cloud which smashes the chart

declare upper;

input RSI_length = 14;
input over_bought = 80;
input over_sold = 20;
input RSI_choice = {default "RSI Wilder", "RSI EMA"};
input RSI_price = close;
input KPeriod = 14;
input DPeriod = 3;
input slowing_period = 1;
input smoothingType = {Default SMA, EMA};

def RSI;
switch (rsi_choice) {
case "RSI EMA":
RSI = RSI_EMA(price = RSI_price, length = RSI_length);
case "RSI Wilder":
RSI = RSIWilder(price = RSI_price, length = RSI_length);
}

def FullK = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI, RSI, RSI, slowing_period, smoothingType).FullK;
plot FullD = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI, RSI, RSI, slowing_period, smoothingType).FullD;

###FullK.SetDefaultColor(GetColor(5));
FullD.SetDefaultColor(GetColor(0));
plot highbar1 = FullD;
plot lowbar1 =FullD[1];

###highbar1.AssignValueColor(if highbar1 > lowbar1 then Color.DARK_RED else Color.MAGENTA);
###lowbar1.AssignValueColor(if highbar1 < lowbar1 then Color.DARK_green else Color.PINK);
###AddCloud(lowbar1, highbar1, Color.RED, Color.green);
highBar1.assignValueColor(if highBar1>lowBar1 then color.dark_red else color.green);
lowBar1.assignValueColor(if highBar1>lowBar1 then color.dark_red else color.green);
addCloud(lowBar1, highBar1);

also not sure how to post a picture
Re: Fun with ThinkScript
March 21, 2014 10:53AM
Quote
GameOver
also not sure how to post a picture





Re: Fun with ThinkScript
March 21, 2014 11:01AM
Quote
GameOver
I am trying to make zones in the upper chart that just turn from red to green using the StochRSI using just one line ,,,,but all I can get is a ribbon cloud which smashes the chart

I don't think I understand what you are trying to accomplish. If you can better describe what you want, I'll try to help you figure it out.
Re: Fun with ThinkScript
March 21, 2014 11:18AM
Re: Fun with ThinkScript
March 21, 2014 11:20AM
Re: Fun with ThinkScript
March 21, 2014 11:24AM
This was thinkscripter free code for trading hours (zones). I was trying to use it but I am missing something

# TS_TRADEZONES
# [www.thinkscripter.com]
# thinkscripter@gmail.com
# Last Update 30 JUN 2009

input zoneStart = 1500;
input zoneEnd = 1615;
input type = {default NOTRADE, REVERSAL};
plot highBar;
plot lowBar;

switch (type){

case NOTRADE:
highBar = if secondsTillTime(zoneStart) <= 0 and secondsTillTime(zoneEnd) >= 0 then highestAll(high) else double.nan;
lowBar = if secondsTillTime(zoneStart) <= 0 and secondsTillTime(zoneEnd) >= 0 then lowestAll(low) else double.nan;
case REVERSAL:
lowBar = if secondsTillTime(zoneStart) <= 0 and secondsTillTime(zoneEnd) >= 0 then highestAll(high) else double.nan;
highBar = if secondsTillTime(zoneStart) <= 0 and secondsTillTime(zoneEnd) >= 0 then lowestAll(low) else double.nan;
}
highBar.assignValueColor(if highBar>lowBar then color.dark_red else color.green);
lowBar.assignValueColor(if highBar>lowBar then color.dark_red else color.green);
addCloud(lowBar, highBar);
Re: Fun with ThinkScript
March 21, 2014 11:28AM
GameOver,

I still don't know what you want to accomplish. How does the StochRSI play into it? Do you want a red box when StochRSI is overbought (>80) or what?
Re: Fun with ThinkScript
March 21, 2014 11:36AM
no when line changes positive to negative. / negative to postive.
like wave < wave[1] .....red zone
wave > wave[1] ......light green zone
Re: Fun with ThinkScript
March 21, 2014 11:38AM
just trying to use the fullD line of StochRSI to create the colored zones
Re: Fun with ThinkScript
March 21, 2014 11:55AM
Re: Fun with ThinkScript
March 21, 2014 11:58AM
Hope you get a laugh ..... puts a new meaning to it's a art thing.....not a chart thing
Re: Fun with ThinkScript
March 21, 2014 12:33PM
Quote
GameOver
just trying to use the fullD line of StochRSI to create the colored zones

..... puts a new meaning to it's a art thing

cute. smiling smiley

I think this is what you are asking for.



def RSI = RSIWilder(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.light_green);
addcloud(value1,neg,color.pink);

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
March 21, 2014 01:05PM
Yea!!!!
wow Robert, you made that look simple
thanks
OK back to the thinkscript manual 4 me ... LOL
Re: Fun with ThinkScript
April 11, 2014 09:25AM
Thanks for all your hard work in helping us with Thinkscript, it is such a blessingsmiling smiley

You may have already written this script, but is there a Thinkscript available that will alert me ONLY when the the following four conditions occur at he EXACT same time on one timeframe when the candle closes (per Darcy's super helpful setup conditions)?

- FP or HRFP

- "E" formed (5MA & 10MA both cross 20MA)

- Money flow going in the same direction of moving average line (but not above or below 70/30)

- ADX turning up and above 25


Not even sure if this is even possible, just thought I'd ask. PLEASE don't even worry about it if it's too much to mess with.

Thanks & God Blesssmiling smiley
Sorry, only registered users may post in this forum.

Click here to login