Re: Fun with ThinkScript June 16, 2015 11:03PM |
Registered: 8 years ago Posts: 59 |
Re: Fun with ThinkScript June 20, 2015 09:57PM |
Registered: 9 years ago Posts: 7 |
Re: Fun with ThinkScript June 21, 2015 12:13AM |
Registered: 10 years ago Posts: 615 |
Quote
az
I am using a script to display a label with price change of SPX on a daily chart, but I am not able to display the same price change of SPX on an intraday chart. It shows an error: "Two different secondary periods can't be used with one variable". I tried to change the aggregation period, but the error persists.
All I am trying to do is to have a label that would display the price change of SPX on an intraday chart between last day close and current time, regardless of the time frame of the chart.
Can you please suggest a fix? Thank you.
def Net1 = Round(close(sym1, period = "day" ) - close(sym1, period = "day" )[1], 1);
Re: Fun with ThinkScript June 21, 2015 01:14AM |
Registered: 9 years ago Posts: 7 |
Re: Fun with ThinkScript June 22, 2015 09:56AM |
Registered: 8 years ago Posts: 59 |
Re: Fun with ThinkScript June 22, 2015 11:15AM |
Registered: 8 years ago Posts: 26 |
Quote
Robert
My wife and I are in the process of packing the house in preparation for our move, so I don't really have time for any scripting right now.
#Define opening range high / low input OpenRangeMinutes = 5; input MarketOpenTime = 0930; input ShowTodayOnly = yes; def Today = if GetDay() == GetLastDay() then 1 else 0; def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0; def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0; def ORHigh = if FirstMinute then high else if OpenRangeTime and high > ORHigh[1] then high else ORHigh[1]; def ORLow = if FirstMinute then low else if OpenRangeTime and low < ORLow[1] then low else ORLow[1]; #define yesterday's high / low def Yhigh = high(period = "day" )[1]; def Ylow = low(period = "day" )[1]; #define pivot def Pivot = (high(period = "day" )[1] + low(period = "day" )[1] + close(period = "day" )[1]) / 3; #Calculate 2 min ATR input ATRLength = 14; def ATR = WildersAverage(TrueRange(high, close, low), ATRLength); #Define long signals def AboveYhigh = close >= Yhigh + ATR; def AbovePivot = close >= Pivot + ATR; def AboveORHigh = close >= ORHigh + ATR; #Define short signals def BelowYlow = close <= Ylow - ATR; def BelowPivot = close <= Pivot - ATR; def BelowORLow = close <= ORLow - ATR; #Define Open range long price def crossORhigh = AboveOrHigh and close[1]< ORhigh + ATR; def ATRHigh = if FirstMinute then ATR else if OpenRangeTime and high > ORHigh[1] then ATR else ATRHigh[1]; def ORLongPrice = ORHigh + ATRHigh; #Define Open range sell price def crossORLow = BelowORLow and close[1]> ORLow - ATR; def ATRLow = if FirstMinute then ATR else if OpenRangeTime and low < ORLow[1] then ATR else ATRLOw[1]; def ORshortPrice = ORLow - ATRLow; #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); #Display SPX ADX value in a box input symbol = "SPX"; input ADX_length = 14; def h = high(symbol); def l = low(symbol); def c = close(symbol); def hiDiff = h - h[1]; def loDiff = l[1] - l; def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0; def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0; def ATR2 = WildersAverage(TrueRange(h, c, l), ADX_length); def "DI+" = 100 * WildersAverage(plusDM, ADX_length) / ATR2; def "DI-" = 100 * WildersAverage(minusDM, ADX_length) / ATR2; def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-" ) / ("DI+" + "DI-" ) else 0; def AltSymbolADX = WildersAverage(DX, ADX_length); def ADXred = if AltSymbolADX < 20 then 1 else 0; def ADXgreen = if AltSymbolADX >= 20 then 1 else 0; #Buy Order Input Tradesize = 2; addOrder(OrderType.BUY_TO_OPEN, crossORhigh and ADXgreen, ORLongPrice, Tradesize, tickColor = GetColor(1), arrowColor = GetColor(1)); #Sell to close def ORLongtarget = if crossORhigh then ORLongPrice +2*ATR else ORLongtarget[1]; def ORLongtarget2 = if crossORhigh then ORLongPrice +5*ATR else ORLongtarget2[1]; def ORLongStop = if crossORhigh then ORLongPrice - 2*ATR else ORLongStop[1]; addOrder(OrderType.SELL_TO_CLOSE, close >= ORLongtarget, ORLongtarget, Tradesize/2, tickColor = GetColor(6), arrowColor = GetColor(6)); addOrder(OrderType.SELL_TO_CLOSE, close >= ORLongtarget2, ORLongtarget2, Tradesize/2, tickColor = GetColor(6), arrowColor = GetColor(6)); addOrder(OrderType.SELL_TO_CLOSE, close >= ORLongtarget, ORLongPrice, Tradesize/2, tickColor = GetColor(5), arrowColor = GetColor(5)); addOrder(OrderType.SELL_TO_CLOSE, close <= ORLongStop, ORLongStop, Tradesize, tickColor = GetColor(5), arrowColor = GetColor(5)); addOrder(OrderType.SELL_TO_CLOSE, secondsTillTime(1600)<1, close, Tradesize or Tradesize/2, tickColor = GetColor(5), arrowColor = GetColor(5));
Re: Fun with ThinkScript June 22, 2015 10:14PM |
Registered: 8 years ago Posts: 26 |
Re: Fun with ThinkScript June 23, 2015 06:42AM |
Registered: 10 years ago Posts: 615 |
Quote
howo3579
I’m having trouble to sell close based on Tan’s strategy:
½ position when close is 2*ATR above entry price.
½ position when close is 5*ATR above entry price.
½ position when close is at entry price if it didn’t hit 5*ATR above.
full position when close is 2*ATR below entry price.
Full position or remaining ½ when no matter what when time is 1 min before market close.
Re: Request June 26, 2015 07:23PM |
Registered: 10 years ago Posts: 615 |
Quote
Tampman
Can you provide a TOS code for 5 indicator studies: RSI w/BB's; MFI w/BB's,.. %b(RSI);, %b(MFI); and %b(CCI).. BB setting at length 50 and Dev 2.1, 2.1 for all.
Much appreciated...
Jim
Re: Request June 27, 2015 09:19AM |
Registered: 9 years ago Posts: 53 |
Re: Request June 27, 2015 10:49AM |
Registered: 10 years ago Posts: 615 |
Quote
Palmer
Is it possibe to the previous day's 1 minute chart? I wan't to look at yesterdays 1 minute data from the market open through the first 15 minutes on a 1 min chart:
Condition1 RSI(14) > 80
I can define the conditions no problem, thanks to you, but I need to see how to reference yesterday's (if possible) 1 minute data.
def yClose = close[390];
def RSI = reference RSI(14).rsi; def yRSI = RSI[390];
Re: Request June 27, 2015 10:57AM |
Registered: 8 years ago Posts: 61 |
Re: Request June 27, 2015 11:26AM |
Registered: 9 years ago Posts: 53 |
Re: Request June 27, 2015 11:39AM |
Registered: 10 years ago Posts: 615 |
Quote
Tampman
Robert: Thank you so much... but I forgot to ask for the CCI w/BB's... if you could provide that one too and it to the others it would great! Will await for that one to be added ..and will pay for all 6 when done..Thanks again!! You are awesome!!
Re: Request June 27, 2015 11:45AM |
Registered: 10 years ago Posts: 615 |
Quote
Palmer
Thanks my friend....I left out the word 'scan' after is it possible to ....
Will do my best to 'take it from here'.
plot MA50 = average(close, 50); plot MA200 = average(close, 200);
def MA50 = average(close, 50); def MA200 = average(close, 200); plot Signal = MA50 crosses above MA200;
Re: Request June 27, 2015 12:17PM |
Registered: 8 years ago Posts: 61 |
Re: Fun with ThinkScript June 27, 2015 05:50PM |
Registered: 8 years ago Posts: 59 |
Re: Fun with ThinkScript June 28, 2015 05:24AM |
Registered: 10 years ago Posts: 615 |
Quote
Ralph53
Robert; is there any way to alter the line length of this script so it's 3 candles long? Thanks again.
def Low10 = Low +.10;
def lastbar = HighestAll(if IsNaN(close) then 5 else BarNumber());
plot condition = if BarNumber() < lastbar then GetValue(Low10, BarNumber() - lastbar) else Double.NaN;
condition.SetLineWeight(1);
input lineLength = 3; def Low10 = low + .10; def lastbar = HighestAll(if IsNaN(close) then 5 else BarNumber()); def condition = if BarNumber() < lastbar then GetValue(Low10, BarNumber() - lastbar) else Double.NaN; plot line = if BarNumber() >= lastbar - lineLength then condition else Double.NaN;
Re: Fun with ThinkScript June 28, 2015 06:03PM |
Registered: 8 years ago Posts: 7 |
Re: Fun with ThinkScript June 28, 2015 06:56PM |
Registered: 10 years ago Posts: 615 |
Quote
KevinR
Robert,
First, I would like to thank you for this thread. I have learned a lot on thinkscripting from it.
Quote
KevinR
I have a request which I have had trouble with:
For any given indicator that features a discontinuous plot of up/down arrows, how would you make an additional plot that "connects the dots" (arrows) with straight line segments?
# ----- define a valley as any point which is lower than the three preceding lows and the three following lows def Valley = low < Lowest(low[1], 3) and low < Lowest(low[-3], 3); # ----- mark each valley with an up arrow ----- plot ArrowUP = Valley; ArrowUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); ArrowUP.SetDefaultColor(Color.WHITE); ArrowUP.SetLineWeight(4); # ----- draw a straight line connecting each valley ----- plot line = if ArrowUP then low else Double.NaN; line.EnableApproximation(); line.SetDefaultColor(Color.LIME); line.SetLineWeight(2);
Re: Fun with ThinkScript June 28, 2015 07:43PM |
Registered: 8 years ago Posts: 7 |
Re: Fun with ThinkScript June 28, 2015 11:36PM |
Registered: 8 years ago Posts: 59 |
Re: Fun with ThinkScript June 29, 2015 12:58AM |
Registered: 8 years ago Posts: 26 |
declare lower; # 4H StochRSI 40 Xover and Daily StochRSI trend input RSI_length = 14; input over_bought = 80; input over_sold = 20; input cross_over = 40; input RSI_average_type = AverageType.WILDERS; def RSI_price_4H = close (period = AggregationPeriod.FOUR_HOURS); def RSI_price_Daily = close (period = AggregationPeriod.DAY); input KPeriod = 14; input DPeriod = 3; input slowing_period = 1; input averageType = AverageType.SIMPLE; def RSI_4H = RSI(price = RSI_price_4H, length = RSI_length, averageType = RSI_average_type); def FullK_4H = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI_4H, RSI_4H, RSI_4H, slowing_period, averageType).FullK; def FullD_4H = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI_4H, RSI_4H, RSI_4H, slowing_period, averageType).FullD; def RSI_Daily = RSI(price = RSI_price_Daily, length = RSI_length, averageType = RSI_average_type); def FullK_Daily = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI_Daily, RSI_Daily, RSI_Daily, slowing_period, averageType).FullK; def FullD_Daily = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI_Daily, RSI_Daily, RSI_Daily, slowing_period, averageType).FullD; def C1 = if FullK_4H > 40 then 3 else -3; def C4 = if (FullK_Daily >= FullK_Daily[1] and FullK_Daily[1] > FullK_Daily[2]) then 1 else if (FullK_Daily <= FullK_Daily[1] and FullK_Daily[1] < FullK_Daily[2]) then -1 else 0; # 4H and Daily MACD trend input fastLength = 12; input slowLength = 26; input MACDLength = 9; input averageType2 = AverageType.EXPONENTIAL; def Value_4H = MovingAverage(averageType2, close(period = AggregationPeriod.FOUR_HOURS), fastLength) - MovingAverage(averageType2, close, slowLength); def Avg_4H = MovingAverage(averageType2, Value_4H, MACDLength); def Diff_4H = Value_4H - Avg_4H; def Value_Daily = MovingAverage(averageType2, close(period = AggregationPeriod.DAY), fastLength) - MovingAverage(averageType2, close, slowLength); def Avg_Daily = MovingAverage(averageType2, Value_Daily, MACDLength); def Diff_Daily = Value_Daily - Avg_Daily; def C2 = if (Value_4H >= Value_4H[1] and Value_4H[1] > Value_4H[2]) then 1 else if (Value_4H <= Value_4H[1] and Value_4H[1] < Value_4H[2]) then -1 else 0; def C5 = if (Value_Daily >= Value_Daily[1] and Value_Daily[1] > Value_Daily[2]) then 2 else if (Value_Daily <= Value_Daily[1] and Value_Daily[1] < Value_Daily[2]) then -2 else 0; def C6 = if (Diff_Daily >= Diff_Daily[1] and Diff_Daily[1] > Diff_Daily[2]) then 2 else if (Diff_Daily <= Diff_Daily[1] and Diff_Daily[1] < Diff_Daily[2]) then -2 else 0; plot C = C1 + C2 + C4 + C5 + C6; # Draw vertical line to indicate call and put signals def triggerup = if FullK_4H >= 40 and FullK_4H[1] < 40 and C >= 3 then 1 else 0; def unload = if triggerup then 0 else if C > -2 then unload[1] else 1; def unloadc = if unload and unload[1] == 0 then 1 else 0; def triggerdown = if FullK_4H <= 40 and FullK_4H[1] > 40 and C <= -3 then 1 else 0; def cover = if triggerdown then 0 else if C < 2 then cover[1] else 1; def coverc = if cover and cover[1] == 0 then 1 else 0; AddVerticalLine(triggerup, "Up", Color.UPTICK); AddVerticalLine(triggerdown, "Down", Color.DOWNTICK); AddVerticalLine(unloadc, "unload", Color.LIGHT_GREEN); AddVerticalLine(coverc, "cover", Color.LIGHT_RED);
Re: Fun with ThinkScript June 29, 2015 04:27AM |
Registered: 10 years ago Posts: 615 |
Quote
Ralph53
Robert, I posted this last week and I don't know if you answered it yet? This line script you gave me starts 10 candles back and works great. How can I add this description of it ' - 5 ' somewhere on the line (preferably at its beginning - 10th bar back) so I know what it is? Thanks so much.
# 5 Cents Below Open # def OpenNeg5 = (open("period" = AggregationPeriod.DAY) - .05); def lastbar = HighestAll(if IsNaN(close) then 0 else BarNumber()); plot condition = if BarNumber() <= lastbar - 10 then GetValue(OpenNeg5, BarNumber() - lastbar) else Double.NaN; AddChartBubble(BarNumber() == lastbar - 10, condition, "-5", Color.CYAN, 0);
Re: Fun with ThinkScript June 29, 2015 05:40AM |
Registered: 10 years ago Posts: 615 |
Quote
howo3579
One thing I have problem with is 4 hour chart with after hour turn on. The plot is all jacked up and discontinuous and back test report only gave me a few trades even though I knew it should've triggered trade more frequently.
plot line = close(period = "day" ); line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Quote
howo3579
The message is "the subgragh doesn't have enough space" I have no idea what that means. If Robert or any of you know how to fix it please share.
Re: Fun with ThinkScript June 29, 2015 07:24AM |
Registered: 8 years ago Posts: 7 |
Re: Fun with ThinkScript June 29, 2015 07:51AM |
Registered: 9 years ago Posts: 53 |
Re: Fun with ThinkScript June 29, 2015 08:56AM |
Registered: 8 years ago Posts: 26 |
Re: Fun with ThinkScript June 29, 2015 09:22AM |
Registered: 10 years ago Posts: 615 |
Quote
howo3579
Instead of letting the close shift from previous day close to following day's close, how do we ask TOS to use the previous day close until 9:30am (9:00 for future) and then it can start actively return close live again?
plot line = close(period = "day" ); line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
def premarket = SecondsTillTime(0930) > 0; plot line = if premarket then close(period = "day" )[1] else close(period = "day" ); line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Quote
howo3579
The rollover line message is exactly what I got. What is this rollover lines?