Re: Fun with ThinkScript July 10, 2014 05:29PM |
Registered: 10 years ago Posts: 615 |
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.
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.
def VIX = close("VIX" );
Re: Fun with ThinkScript July 10, 2014 10:03PM |
Registered: 10 years ago Posts: 143 |
Re: Fun with ThinkScript July 11, 2014 02:14AM |
Registered: 10 years ago Posts: 615 |
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?
Re: Fun with ThinkScript July 11, 2014 12:35PM |
Registered: 9 years ago Posts: 13 |
Re: Fun with ThinkScript July 11, 2014 04:45PM |
Registered: 9 years ago Posts: 8 |
#VIX label def VIX = close("VIX" ); AddLabel(VIX < 13 , "VIX: " + VIX , Color.UPTICK); AddLabel(VIX > 13 , "VIX: " + VIX , Color.DOWNTICK);
Re: Fun with ThinkScript July 12, 2014 03:31PM |
Registered: 9 years ago Posts: 9 |
Re: Fun with ThinkScript July 12, 2014 03:50PM |
Registered: 10 years ago Posts: 615 |
Re: Fun with ThinkScript July 12, 2014 04:06PM |
Registered: 9 years ago Posts: 9 |
Re: Fun with ThinkScript July 12, 2014 04:10PM |
Registered: 10 years ago Posts: 615 |
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?
# 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 |
Registered: 10 years ago Posts: 615 |
Re: Fun with ThinkScript July 12, 2014 09:40PM |
Registered: 9 years ago Posts: 13 |
Re: Fun with ThinkScript July 14, 2014 10:21AM |
Registered: 9 years ago Posts: 13 |
Re: Fun with ThinkScript July 14, 2014 04:08PM |
Registered: 9 years ago Posts: 13 |
Re: Fun with ThinkScript July 14, 2014 05:50PM |
Registered: 10 years ago Posts: 615 |
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???
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 |
Registered: 9 years ago Posts: 13 |
Re: Fun with ThinkScript July 14, 2014 08:37PM |
Registered: 9 years ago Posts: 1 |
Re: Fun with ThinkScript July 18, 2014 01:17PM |
Registered: 10 years ago Posts: 143 |
Re: Fun with ThinkScript July 18, 2014 05:47PM |
Registered: 10 years ago Posts: 615 |
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?
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();
def dayHigh = high(period = "day" ); def dayLow = low(period = "day" );
Re: Fun with ThinkScript July 18, 2014 06:44PM |
Registered: 10 years ago Posts: 143 |
Re: Fun with ThinkScript July 18, 2014 07:56PM |
Registered: 10 years ago Posts: 615 |
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.
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);
Re: Fun with ThinkScript July 18, 2014 08:13PM |
Registered: 10 years ago Posts: 143 |
Re: Fun with ThinkScript July 20, 2014 12:53PM |
Registered: 9 years ago Posts: 17 |
Re: Fun with ThinkScript July 20, 2014 02:21PM |
Registered: 9 years ago Posts: 4 |
Quote
#Start
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] + volume(period = "DAY"[12] + volume(period = "DAY"[13] + volume(period = "DAY"[14] + volume(period = "DAY"[15] + volume(period = "DAY"[16] + volume(period = "DAY"[17] + volume(period = "DAY"[18] + volume(period = "DAY"[19] + volume(period = "DAY"[20] + volume(period = "DAY"[21] + volume(period = "DAY"[22] + volume(period = "DAY"[23] + volume(period = "DAY"[24] + volume(period = "DAY"[25] + volume(period = "DAY"[26] + volume(period = "DAY"[27] + volume(period = "DAY"[28] + volume(period = "DAY"[29] + volume(period = "DAY"[30] + volume(period = "DAY"[31] + volume(period = "DAY"[32] + volume(period = "DAY"[33] + volume(period = "DAY"[34] + volume(period = "DAY"[35] + volume(period = "DAY"[36] + volume(period = "DAY"[37] + volume(period = "DAY"[38] + volume(period = "DAY"[39] + volume(period = "DAY"[40] + volume(period = "DAY"[41] + volume(period = "DAY"[42] + volume(period = "DAY"[43] + volume(period = "DAY"[44] + volume(period = "DAY"[45] + volume(period = "DAY"[46] + volume(period = "DAY"[47] + volume(period = "DAY"[48] + volume(period = "DAY"[49] + volume(period = "DAY"[50] + volume(period = "DAY"[51] + volume(period = "DAY"[52] + volume(period = "DAY"[53] + volume(period = "DAY"[54] + volume(period = "DAY"[55] + volume(period = "DAY"[56] + volume(period = "DAY"[57] + volume(period = "DAY"[58] + volume(period = "DAY"[59] + volume(period = "DAY"[60]) / 60;
def volumepercentage = (volume(period = "DAY" / sixtydayavgvol) * 100;
plot VolDay = volume(period=”DAY”);
plot sixtydayavgvolplot = sixtydayavgvol;
AddLabel(yes, Concat("Average Volume Difference: ", Concat(Round(volumepercentage, 0), "%"), 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"[1], length = 60);
sixtydayavgvol.SetLineWeight(3);
#Finish
Re: Fun with ThinkScript July 20, 2014 07:58PM |
Registered: 10 years ago Posts: 615 |
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.
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] ...
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.
Re: Fun with ThinkScript July 20, 2014 11:07PM |
Registered: 9 years ago Posts: 4 |
Re: Fun with ThinkScript July 21, 2014 04:58AM |
Registered: 10 years ago Posts: 615 |
Quote
SuperChief9
That car was a 1957 Pontiac SuperChief which I restored and still have today
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?
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);
Re: Fun with ThinkScript July 21, 2014 12:04PM |
Registered: 11 years ago Posts: 106 |
Re: Fun with ThinkScript July 21, 2014 12:33PM |
Registered: 10 years ago Posts: 615 |
Quote
NMR
Hi Robert:
How easy would it be to make a modification to the DM study using this as the base:
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?
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 |
Registered: 9 years ago Posts: 4 |
Re: Fun with ThinkScript July 21, 2014 05:36PM |
Registered: 11 years ago Posts: 106 |