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
July 10, 2014 05:29PM
Quote
Exgamer
Hey all. I just wanted to add my thanks to Robert for all the great stuff you shared, I'm using much of it for my day trading and it's improved my ToS experience.

Thanks for the feedback. I'm glad to hear that you are finding something useful in this tread.

Quote
Exgamer
I've been trying to figure out the scripting language and although I've been successful modifying working scripts, I'm stuck trying to create my own, if it's even possible.

What I'd like to add is the current VIX price as a chart label to my upper chart with colors ie: VIX > 12 RED, < 12 GREEN or something.

Thanks for any help.

This is a very easy script. I'll get you started in the right direction. If you have questions, ask and I'll help. If you get it figured out, please post so others may benefit as well. If you get too stuck, let me know.

Ok, to get started...

I'm assuming that you are wanting to display a label of the VIX's value on a different chart (i.e. if you are looking at a chart of TSLA, you want to be able to display the VIX's value in a label on THAT same chart).

The first thing that must be done is to lookup the VIX's value. This will be accomplished by slightly modifying the "close" function. Normally, "close" will return the value of the currently displayed ticker symbol, but it may be used to lookup a different symbol as well; like so:

def VIX = close("VIX" );

Note that the ticker symbol must be enclosed in quotes.

Now that you know the value of the VIX, you just need to add your colored labels. You are going to need two "AddLabel" statements--one for each of your conditions (VIX > 12 and VIX < 12). Read about the use of the AddLabel function here.
Re: Fun with ThinkScript
July 10, 2014 10:03PM
Hi Robert,

Thinkscript always tells me there has to be "plot" in the script. Wouldn't it be better to have

plot VIX = close("VIX" );

instead of

def VIX = close("VIX" );

because the subsequent two lines of AddLabel won't have any "plot" in it?
Just trying to learn from the guru smiling smiley

Tan
Re: Fun with ThinkScript
July 11, 2014 02:14AM
Quote
tanman
Thinkscript always tells me there has to be "plot" in the script. Wouldn't it be better to have

plot VIX = close("VIX" );

instead of

def VIX = close("VIX" );

because the subsequent two lines of AddLabel won't have any "plot" in it?

Good question, Tan. Each script should display something in the end. Normally, that "something" is displayed via a plot function, but the AddLabel function is a valid method of displaying "something" as well.

As a learning experiment, try it both ways. Both will yield the desired effect of having the value of the VIX displayed at the top of the chart, but notice the difference.

Re: Fun with ThinkScript
July 11, 2014 12:35PM
I'm trying to write a strategy that would enter at 10am CST and exit at 1pm CST. For simplicity at 10am the close has to be above the 10-period MA on a 15 minute chart. Can someone give me an example?
Re: Fun with ThinkScript
July 11, 2014 04:45PM
Thank you Robert; Tanman, your contributions were also well received. Turns out I almost had it, just needed that confirmation from you I was headed in the right direction. Here's the basic version. I'll attempt to add alerts, etc tonight.

Thanks again.

#VIX label
def VIX = close("VIX" );

AddLabel(VIX < 13 , "VIX: " + VIX , Color.UPTICK);
AddLabel(VIX > 13 , "VIX: " + VIX , Color.DOWNTICK);
Mel
Re: Fun with ThinkScript
July 12, 2014 03:31PM
Hi Everyone,

I'm trying to script a double EMA crossover with a daily time frame using it with an intra-day chart. All I want to plot is a vertical line when this happens either up or down.

def EMA1 = expAverage((close(period = "day" )),3);
def EMA2 = expAverage((close(period = "day" )),5);

Not sure if this is possible with TOS. Any help or clues to get started would be much appreciated.

Thx,

Madison



Edited 4 time(s). Last edit at 07/12/2014 03:47PM by Mel.
Re: Fun with ThinkScript
July 12, 2014 03:50PM
Mel
Re: Fun with ThinkScript
July 12, 2014 04:06PM
Thanks Robert, that's perfect. I just needed to add (close(period = "day" ) and it works great.

thx again,

Madison



Edited 1 time(s). Last edit at 07/12/2014 04:07PM by Mel.
Re: Fun with ThinkScript
July 12, 2014 04:10PM
Quote
donmat
I'm trying to write a strategy that would enter at 10am CST and exit at 1pm CST. For simplicity at 10am the close has to be above the 10-period MA on a 15 minute chart. Can someone give me an example?

This should get you pointed in right direction.

# define the 10-period moving average
def MA10 = Average(close, 10);

# define the 10:00 a.m. bar
def Bar10am = SecondsFromTime(1000) >= 0 and SecondsTillTime(1015) > 0;

# determine whether or not the close is above the 10MA at 10:00 a.m.
plot Signal = close > MA10 and Bar10am;
	Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
	Signal.SetDefaultColor(Color.GREEN);
	Signal.SetLineWeight(4);
Re: Fun with ThinkScript
July 12, 2014 04:11PM
Quote
Madison
Thanks Robert, that's perfect. I just needed to add (close(period = "day" ) and it works great.

Happy to have helped.
Re: Fun with ThinkScript
July 12, 2014 09:40PM
Thank you robert.
Re: Fun with ThinkScript
July 14, 2014 10:21AM
Is it possible in TOS to create a fixed Stop loss order in a strategy that would exit at the current bar and not the open of the next bar?
Re: Fun with ThinkScript
July 14, 2014 04:08PM
This seems to be what I want.

def Bar1PM = SecondsFromTime(1345) >= 0 and SecondsTillTime(1400) > 0;
input stop = 5;
input target = 10;

def entry = entryPrice();
def exit = if (high >= (entry + target) or low <= (entry - stop)) then 1 else 0;
def exitPrice = if (high >= (entry + target)) then (entry + target) else (entry - stop);

AddOrder(OrderType.SELL_TO_CLOSE,exit, exitprice, tickColor = Color.WHITE, arrowColor = Color.WHITE);

So now if the target or stop is not met, I want to exit at 1pm. Still don't know how to include the Bar1pm???
Re: Fun with ThinkScript
July 14, 2014 05:50PM
Quote
donmat
So now if the target or stop is not met, I want to exit at 1pm. Still don't know how to include the Bar1pm???

I've never messed with the automated orders, so I'm just spitballing here, but see if this logic makes sense for your situation.

input stop = 5;
input target = 10;

def StoppedOut = low <= (entry - stop);
def TargetMet = high >= (entry + target);
def Sell1pm = SecondsFromTime(1300) >= 0 and SecondsFromTime(1300) < 60;
def Price1pm = if Sell1pm then close[1] else double.nan;
def exit = StoppedOut or TargetMet or Sell1pm;
def exitPrice = if StoppedOut then entry - stop else if TargetMet then entry + target else Price1pm;

AddOrder(OrderType.SELL_TO_CLOSE, exit, exitPrice, tickColor = Color.WHITE, arrowColor = Color.WHITE);
Re: Fun with ThinkScript
July 14, 2014 07:40PM
Here's the one that finally worked. Thanks for your help.


input stop = 5;
input target = 10;
def entry = EntryPrice();
def StoppedOut = low <= (entry - stop);
def TargetMet = high >= (entry + target);
def Sell1pm = SecondsFromTime(1345) >= 0 and SecondsFromTime(1400) <0 ;

def Price1pm = if Sell1pm then close else Double.NaN;
def exit = StoppedOut or TargetMet or Sell1pm;
def exitPrice = if StoppedOut then entry - stop else if TargetMet then entry + target else Price1pm;

AddOrder(OrderType.SELL_TO_CLOSE, exit, exitPrice, tickcolor = Color.WHITE, arrowcolor = Color.WHITE);
Re: Fun with ThinkScript
July 14, 2014 08:37PM
Robert,

Great stuff, I appreciate all of your time and energy on this forum. Have you scripted anything like a Gartley pattern before? I've seen the ZigZag set of scripts to get started, but I'm falling woefully short. This script would draw connecting lines at 5 different swing points that would form the shape of an M or W and would have the following conditions:
    [*] Swing Points: X (swing low), A (high), B (low), C (high), D (low)
    [*] A>C, C>B, B>D, and D>X
    [*] AB is about a 0.618 retracement of XA
    [*] BC is about a 0.618 - 0.786 retracement of AB
    [*] CD is about a 0.786 retracement of XA
    [*] Would be able to set the strength of the swing point by defining the number of bars to either side of the high/low
    [*] Set a tolerance level to the retracement level (0.618 - Tolerance%)

I guess this study would be more beneficial if it could project the CD line prior to those bars happening thereby projecting where the D point would be. So I guess you would only have four of the five swing points. I would also have a second line drawn in as an alternate CD that would be equal in length to the AB leg (AB=CD).

Best Regards,

Mike
Re: Fun with ThinkScript
July 18, 2014 01:17PM
Hi Robert,

Something very strange is happening. When I use the following code to plot intraday high or low, sometimes it works great and sometimes it doesn't work at all. For example it is not working in AAPL and SPY today, but is working in TWTR and AMZN!

#Plot intraday high and intraday low
def dayHigh = if GetDay() != GetDay()[1] and high > high[-1] and high > high[-2] and high > high[-3] then high else if close > dayHigh[1] and high >= high[-1] and high >= high[-2] and high >= high[-3] then high else dayHigh[1];
def dayLow = if GetDay() != GetDay()[1] and low < low[-1] and low < low[-2] and low < low[-3] then low else if close < dayLow[1] and low <= low[-1] and low <= low[-2] and low <= low[-3] then low else dayLow[1];
def today = GetLastDay() == GetDay();

plot DH = if !today then Double.NaN else dayHigh;
DH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DH.SetDefaultColor(Color.UPTICK);
plot DL = if !today then Double.NaN else dayLow;
DL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DL.SetDefaultColor(Color.DOWNTICK);

Can you figure out what's going on? Thanks.

Tan
Re: Fun with ThinkScript
July 18, 2014 05:47PM
Quote
mtl2302
Robert,

Great stuff, I appreciate all of your time and energy on this forum. Have you scripted anything like a Gartley pattern before?

Welcome, Mike. No, I've never even heard of a Gartley pattern. My codes are simple affairs and I'm afraid that is beyond my current skill set.

Quote
Tan
When I use the following code to plot intraday high or low, sometimes it works great and sometimes it doesn't work at all. For example it is not working in AAPL and SPY today, but is working in TWTR and AMZN!

#Plot intraday high and intraday low
def dayHigh = if GetDay() != GetDay()[1] and high > high[-1] and high > high[-2] and high > high[-3] then high else if close > dayHigh[1] and high >= high[-1] and high >= high[-2] and high >= high[-3] then high else dayHigh[1];
def dayLow = if GetDay() != GetDay()[1] and low < low[-1] and low < low[-2] and low < low[-3] then low else if close < dayLow[1] and low <= low[-1] and low <= low[-2] and low <= low[-3] then low else dayLow[1];
def today = GetLastDay() == GetDay();

Tan,

If all you want to do is plot the intraday high and low, then keep the code simple.

def dayHigh = high(period = "day" );
def dayLow = low(period = "day" );
Re: Fun with ThinkScript
July 18, 2014 06:44PM
Robert,

If I do that it plots all the successive highs when price is moving up and each bar is higher than the last one. I am trying to plot only the intraday high which has 3 bars following it which are lower so that it plots only the significant intraday highs which act as resistance and can give a good breakout trade when stock price is above open high and previous day high. Usually it is a cup pattern breakout. What is strange is that the script I compiled works perfectly for the same stock one day but doesn't another day and I can't figure out why confused smiley

Tan
Re: Fun with ThinkScript
July 18, 2014 07:56PM
Quote
tanman
I am trying to plot only the intraday high which has 3 bars following it which are lower so that it plots only the significant intraday highs which act as resistance and can give a good breakout trade when stock price is above open high and previous day high.

Ah. Gotcha. I believe this'll do what you want.



def h3 = high > Highest(high[-3], 3);
def highLevel = if GetDay() != GetDay()[1] then high else if h3 and high > highLevel[1] then high else highLevel[1];

def l3 = low < Lowest(low[-3], 3);
def lowLevel = if GetDay() != GetDay()[1] then low else if l3 and low < lowLevel[1] then low else lowLevel[1];

plot HL = highLevel;
     HL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
     HL.SetDefaultColor(Color.UPTICK);
plot LL = lowLevel;
     LL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
     LL.SetDefaultColor(Color.DOWNTICK);

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
July 18, 2014 08:13PM
Wow what a cool logic! That's brilliant smiling smiley Thank you very much.
Re: Fun with ThinkScript
July 20, 2014 12:53PM
Hey Gents,

Looking for the following strat coded:
(anything in [ ] is user defined)

ADX[length]
ADX[threshold]
EMA[length]

Long entry: If ADX[length] > ADX[thresh] and Close < EMA[length] close, then a BUY signal is generated on price chart (arrow maybe?)
Short entry: If ADX[length] > ADX[thresh] and Close > EMA[length] close, then a SELL signal is generated on price chart (arrow maybe?)

Your work here is GREATLY appreciated guys, Rob.

Gaterz
Re: Fun with ThinkScript
July 20, 2014 02:21PM
Hi Robert,
I've been reading through this forum for a few hours and I must say thank you so much for all your hard work. I am doing my best to code and learning as I go along. I came across some code that I know can be done easier and I have some thoughts I'd like to add. I originally wanted 60 day volume average plotted against the current trading day's volume and give a percentage as well. btw- I previewed this several times to see if I could figure out how to have the text editor not turn any of the code into a smiley face, but failed miserably. The code I found online was this:
Quote


#Start
def sixtydayavgvol = (volume(period = "DAY"winking smiley[1] + volume(period = "DAY"winking smiley[2] + volume(period = "DAY"winking smiley[3] + volume(period = "DAY"winking smiley[4] + volume(period = "DAY"winking smiley[5] + volume(period = "DAY"winking smiley[6] + volume(period = "DAY"winking smiley[7] + volume(period = "DAY"winking smiley[8] + volume(period = "DAY"winking smiley[9] + volume(period = "DAY"winking smiley[10] + volume(period = "DAY"winking smiley[11] + volume(period = "DAY"winking smiley[12] + volume(period = "DAY"winking smiley[13] + volume(period = "DAY"winking smiley[14] + volume(period = "DAY"winking smiley[15] + volume(period = "DAY"winking smiley[16] + volume(period = "DAY"winking smiley[17] + volume(period = "DAY"winking smiley[18] + volume(period = "DAY"winking smiley[19] + volume(period = "DAY"winking smiley[20] + volume(period = "DAY"winking smiley[21] + volume(period = "DAY"winking smiley[22] + volume(period = "DAY"winking smiley[23] + volume(period = "DAY"winking smiley[24] + volume(period = "DAY"winking smiley[25] + volume(period = "DAY"winking smiley[26] + volume(period = "DAY"winking smiley[27] + volume(period = "DAY"winking smiley[28] + volume(period = "DAY"winking smiley[29] + volume(period = "DAY"winking smiley[30] + volume(period = "DAY"winking smiley[31] + volume(period = "DAY"winking smiley[32] + volume(period = "DAY"winking smiley[33] + volume(period = "DAY"winking smiley[34] + volume(period = "DAY"winking smiley[35] + volume(period = "DAY"winking smiley[36] + volume(period = "DAY"winking smiley[37] + volume(period = "DAY"winking smiley[38] + volume(period = "DAY"winking smiley[39] + volume(period = "DAY"winking smiley[40] + volume(period = "DAY"winking smiley[41] + volume(period = "DAY"winking smiley[42] + volume(period = "DAY"winking smiley[43] + volume(period = "DAY"winking smiley[44] + volume(period = "DAY"winking smiley[45] + volume(period = "DAY"winking smiley[46] + volume(period = "DAY"winking smiley[47] + volume(period = "DAY"winking smiley[48] + volume(period = "DAY"winking smiley[49] + volume(period = "DAY"winking smiley[50] + volume(period = "DAY"winking smiley[51] + volume(period = "DAY"winking smiley[52] + volume(period = "DAY"winking smiley[53] + volume(period = "DAY"winking smiley[54] + volume(period = "DAY"winking smiley[55] + volume(period = "DAY"winking smiley[56] + volume(period = "DAY"winking smiley[57] + volume(period = "DAY"winking smiley[58] + volume(period = "DAY"winking smiley[59] + volume(period = "DAY"winking smiley[60]) / 60;

def volumepercentage = (volume(period = "DAY"winking smiley / sixtydayavgvol) * 100;

plot VolDay = volume(period=”DAY”);
plot sixtydayavgvolplot = sixtydayavgvol;

AddLabel(yes, Concat("Average Volume Difference: ", Concat(Round(volumepercentage, 0), "%"winking smiley), if volumepercentage >= 100 then Color.UPTICK else Color.DOWNTICK);
#END

This seems so unnecessary, so I tried something like this:

#Start
plot Vol = volume(period=”DAY”);
plot sixtydayavgvol = simplemovingavg(price = volume(period="DAY"winking smiley[1], length = 60);
sixtydayavgvol.SetLineWeight(3);
#Finish

I am trying to make equivalent to the long, complicated version above and keeping apples to apples I don't want to include the current day's volume in the 60 day average script, so I believe I put the [1] in the right place. I would like to take this a step further and take the volume from the 60 day average, but only from 9:35am to 15:55pm in all past 60 days and average that only. I want the new script to disregard all other volume that doesn't fall into that timeframe. Then as well as plotting the current day's volume starting at 9:35am and ending at 15:55pm. The percentage indicator is nice as well.
Re: Fun with ThinkScript
July 20, 2014 07:58PM
Welcome, SuperChief9 (military? -- I'm retired Navy)

Quote
SuperChief9
btw- I previewed this several times to see if I could figure out how to have the text editor not turn any of the code into a smiley face, but failed miserably.

Yeah, the smileys can be a bit of a pain. You have to put an extra space between the quotation mark at the end of period="day" and the following close parenthesis to avoid getting automatic smileys.

def sixtydayavgvol = (volume(period = "DAY" )[1] + volume(period = "DAY" )[2] + volume(period = "DAY" )[3] + volume(period = "DAY" )[4] + volume(period = "DAY" )[5] + volume(period = "DAY" )[6] + volume(period = "DAY" )[7] + volume(period = "DAY" )[8] + volume(period = "DAY" )[9] + volume(period = "DAY" )[10] + volume(period = "DAY" )[11] ...

Whew! That's certainly one way of calculating a 60 day average. smiling smiley Your new code looks great, but could be shortened a little bit if you wanted.

plot SixtyDayAvgVol = Average(Volume(period = "day" )[1], 60);

Quote
SuperChief9
I would like to take this a step further and take the volume from the 60 day average, but only from 9:35am to 15:55pm in all past 60 days and average that only. I want the new script to disregard all other volume that doesn't fall into that timeframe. Then as well as plotting the current day's volume starting at 9:35am and ending at 15:55pm.

I thought about your idea for a while today and had a few ideas, but came to the conclusion that it's not really feasible given the limitations of thinkscript. Reading between the lines, though, and I believe what you are trying to do is get a better volume average without having it skewed by the excessively high spikes at open / close of the day. If you haven't already seen it, you might take a look at the script I posted here: [www.researchtrade.com]



Edited 1 time(s). Last edit at 07/20/2014 08:01PM by robert.
Re: Fun with ThinkScript
July 20, 2014 11:07PM
Hi Robert,

Thank you again- you really are extremely kind for helping not only me out, but everyone on the forum. I sincerely appreciate it. I was never in the military- as an adolescent I went to work for a large farm where we harvested mostly tobacco and tomatoes (along with many other veggies on a small scale). I worked there many years and when I got into my late teens I made a side-comment about how beautiful one of the old vehicles was in one of their sheds. The farmers perked up and asked if I wanted to purchase it (they said they were trying to sell it for years). I did and worked that summer paying it off. That car was a 1957 Pontiac SuperChief which I restored and still have today. The farmers were so meticulous about how they kept all their mechanical affairs- they had the original receipt, the original 1957 registration on the windshield, a near perfect car manual, and the car was in excellent shape (only about 45k miles on it). There wasn't even one hole in the interior and even the headliner was in tact. I couldn't believe how well the chrome polished up.

This was a farm along the Connecticut River where I used to find many arrowheads in the soil as I worked (Pontiac's symbol is an arrowhead) and even the farm Billy Joel shot his River of Dreams video on. Everyone I know was in the video, but of course after all the years I worked there in which I never missed a season and never took time off- that particular year I was off for several weeks doing an Outward Bound in Oregon. Because of that I was the only one not in the video! Everyone on the farm got to meet him along with Christie Brinklely and their daughter and they all had free food while they were there do to the catering truck. When I got back not one person mentioned it. An entire week went by until I finally had to ask why a giant Billy Joel sign was in the barn! It will always be a very special place to me. My dad I went back to visit randomly one time and when we got there we immediately saw a bald eagle fly over and around us. A bit off topic- I digress. It's a story I don't mind reminiscencing.

I spent many hours this weekend coding and reading this forum and I'm familar with the volume script you sent a link to. Although I may find a use for it at some point- that's not currently what I'm trying to accomplish. My sense tells me that historical volume from a specific time from a previous day isn't that important because of the randomness of the market, but I'll never say never until proper backtesting. Not only am I trying to wipe out any spike via morning and afternoon bell- but more importantly I'm trying to wipe out any pre-market and after-market volume. I never hold overnight and I think gaps are a suckers game. I don't want any premarket or postmarket data clouding up my intraday chart. With that said- there must be something that can be done.

In TOS you can go back 20 years on the daily chart, 180 days on the hourly chart, and 20 days on the five minute chart. I'm looking for a 60 day volume average with the crust cut off. Let me bounce a couple things off you. Could this be done with a 20 day volume average since that's how far back the 5 minute goes? It seems like it could be done and if so- I would definitely give that a shot because I still think there would be a lot of value in it. Let's say I jump to the hourly chart and keep the time from 9:30am to 15:30pm (I'm not sure if it's wise to leave off the last hour because it's only a half hour anyway and I'm not sure how TOS calculates an hour chart with only a half hour left, but perhaps it wouldn't matter going right to 16:00pm)- could the volume be calculated without including any extending hours (yesterdays post-market and the current days pre-market)? If that's possible I could get the 60 day volume average and perhaps the opening and closing bell spike probably wouldn't matter that much. I tend to think it's the extending hours volume that would be the worst culprit, but that could be easily figured out if we could get the five minute chart to work with a 20 day volume average. I could play with starting at 9:35am to 15:55pm and then trying 9:40am to 15:50pm, then 9:45am 15:45pm, etc.

If both these scenarios could be done the five minute script would most likely answer if there was any issue with the hourly script. I'm really looking forward to your feedback on this.


Peace,
Andrew



Edited 1 time(s). Last edit at 07/20/2014 11:23PM by SuperChief9.
Re: Fun with ThinkScript
July 21, 2014 04:58AM
Quote
SuperChief9
That car was a 1957 Pontiac SuperChief which I restored and still have today

Great story, Andrew. I never even thought about a car. I asked if you were military because one of the many chiefs that I knew while in the service called himself "super chief."

Quote
SuperChief9
In TOS you can go back 20 years on the daily chart, 180 days on the hourly chart, and 20 days on the five minute chart. I'm looking for a 60 day volume average with the crust cut off. Let me bounce a couple things off you. Could this be done with a 20 day volume average since that's how far back the 5 minute goes?

Ok. I stated that it wouldn't work within the confines of the thinkscript limitations because you were specifically asking for a 60 day average. Because you want to ignore the volume of the first and last 5 minutes of the day, you are relegated to using this script on a 5 minute chart; which, as you are aware, is limited to only 20 days. If you are willing to work within those confines, then I believe it can be done. However, since the volume for "today" will not be included, then the maximum average that can be calculated will be reduced to 19 days because that is the extent of the available data. It's not an ideal solution.

I propose summing the volume for every candle except for any of "today's" candles or the first or last candle of any previous day then dividing that sum by 19 to get a 19 day average without the opening / closing bell spike.

As written, if used on a 5 min chart, this script will skip the first and last 5 minutes of the day. If used on a 10 min chart, then it will skip the first and last 10 minutes of the day, etc.

declare lower;

def Today = GetDay() == GetLastDay();

# define the first and last bar of the day
def Bfl = GetDay() != GetDay()[1] or GetDay() != GetDay()[-1];

# sum the volume for every candle except for any of "today's" candles or the first or last candle of any previous day
def SumVol = if Today or Bfl then SumVol[1] else SumVol[1] + volume;

# plot the modified 19 day average volume
plot AvgVol = if Today then SumVol / 19 else Double.NaN;

# plot the standard 19 day average volume for comparison
plot AvgVol2 = Average(volume(period = "day" )[1], 19);
AvgVol2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);



Edited 1 time(s). Last edit at 07/21/2014 04:59AM by robert.
NMR
Re: Fun with ThinkScript
July 21, 2014 12:04PM
Hi Robert:

How easy would it be to make a modification to the DM study using this as the base:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# DI Indicator with Trigger Line
declare lower;

input DI_length = XXX;

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 trigger = 8.5;
trigger.SetDefaultColor(Color.BLACK);
trigger.SetLineWeight(2);

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

what I would like is to be able to assign the background color to "color.gray" if the +DI or the =DI is under my plot trigger setting... (like 8.5) I'm not sure how to set up the definitions for that... I know the code for the "assignbackgroundcolor" to be:

assignbackgroubdcolor(if condition == 1 then color.gray else color.curent): ( think)

Also- is there a way to set up a text or email alert from the study- or is that only accomplished via a scan?

I can explain what I am doing more if it needed- just let me know.

Thank you in advance!!!
Re: Fun with ThinkScript
July 21, 2014 12:33PM
Quote
NMR
Hi Robert:

How easy would it be to make a modification to the DM study using this as the base:

Pretty easy. Add this to the bottom:

def DE = "DI+" < trigger or "DI-" < trigger;
AssignBackgroundColor(if DE then Color.GRAY else Color.CURRENT);

Quote
NMR
Also- is there a way to set up a text or email alert from the study- or is that only accomplished via a scan?

by the way, I don't have TOS open right now, so am just typing this response from memory. If it doesn't work, let me know and I'll revisit it later.

def DEtrigger = "DI+" crosses above trigger or "DI-" crosses above trigger;
Alert(DEtrigger, getsymbol() + " has triggered the DE.", alert.bar, sound.bell);
Re: Fun with ThinkScript
July 21, 2014 04:00PM
Hi Robert:

I am brand new to this site and have been going through all of your coding....I have to say your skills are awesome!!! With that in mind, I was wondering if you might could assist me in a problem I am having? I am trying to put put some dots at the top and bottom of my upper chart using the following:

def LongLevel = HighestAll (high) * 1.02;
def ShortLevel = LowestAll(low) * .98;
def DispDiff = LongLevel - ShortLevel;

However, on some charts it scrunches the candles down to a point where the chart is not useful. Do you know of any way I could position my output on these certain areas of the screen without affect the integrity of the chart?

Thanks in advance!

Scott
NMR
Re: Fun with ThinkScript
July 21, 2014 05:36PM
Robert- thank you very much !!!!
Sorry, only registered users may post in this forum.

Click here to login