Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!

Advanced

Fun with ThinkScript

Posted by robert 
Overnight/extended hour day candle
March 08, 2016 09:32PM
Looking to see a day candle that shows the overnight movement on a stock before open. I want to see gaps on a day candle before open.
Re: Overnight/extended hour day candle
March 09, 2016 09:14AM
Hopefully someone will be able to help you. The first question they might ask is what trading platform you are using? I am aware of at least 4 that are used in this forum but probably more. A lot of platforms have some type of toggle for general market hours, all sessions, and/or after hours. Once set you will be able to see all trading information for that symbol. No more gaps but be careful. Extended hours can skew the picture without some type of binary event driving the move (e.g., earnings, major announcement, etc.) Good Luck!

NCT
Re: Overnight/extended hour day candle
March 09, 2016 09:19AM
I am using TOS. I can see after hour movement in the shorter time frames, but would like to see a day candle for after hours to better visualize morning gaps.
Re: Overnight/extended hour day candle
March 09, 2016 10:22AM
There are several more qualified folks to give advice on TOS. One workaround I have seen for other platforms is creating a 1440 minute chart and set it to after hours. You are simulating a 24 hour daily chart. Unfortunately after hours ends and pre-market beings at defined times. If the driver behind the gap occurs outside of these sessions you will not be able to eliminate the gap for stocks. Notable exceptions are instruments that trade around the clock (e.g., futures). That said, futures stop trading Friday night and resume again Sunday evening. I have seen gaps on futures Sunday evening due to weekend news. It is uncommon but it can happen. Best of luck!

NCT
JML
Re: Fun with ThinkScript
March 10, 2016 02:39PM
can anyone help with this code?
this displays the daily percentage change as a label on intraday charts and works good.
just would like the label to show green when the %change is positive and red when negative.
Thanks
JML

input length = 1;
def price = close(period = AggregationPeriod.DAY);

assert(length > 0, "'length' must be positive: " + length);
def PercentChg = 100 * (price / price[length]-1);

addlabel(yes, percentchg, color = Color.black);
Re: Fun with ThinkScript
March 11, 2016 07:58AM
Is it possible to make a condition in a script that will show signal on the Chart only when there is signals in multi time frames ?

i.e If my time frame Chart is 10 minutes and there is signal on the 20 minutes , 30 minute and 1 hour in the same time , this script will show these signals as one signal on my time frame ( 10 minutes ) ?
Re: Fun with ThinkScript
March 11, 2016 10:06AM
Im looking for a simple indicator. If its above the open and above the pivot, buy 5 min breaks. If below the open and below the pivot sell 5 min breaks. anyone can help coding this would be great. Or if they know if there is one already? thanks
Re: Fun with ThinkScript
March 11, 2016 06:17PM
JML,

Replace last line with:

AddLabel(yes, percentchg, if percentchg > 0 then Color.GREEN else COLOR.RED);
Re: Fun with ThinkScript
March 11, 2016 06:26PM
SARA,

Yes it's possible to combine them in one signal. For example:

def BuySignal = BuySignal60 and BuySignal30 and BuySignal20 and BuySignal10;
Alert(BuySignal, "Time to go long", Alert.BAR, Sound.Ring)

You can also plot separate labels showing signals on different higher time frames and lower time frame on the lower time frame chart and code them green for buy signal or red for sell signal or gray for neutral. That way you can go long when all are green or short when all are red.
Re: Fun with ThinkScript
March 11, 2016 07:16PM
Rob Miller,

This indicator will do the following:

1. Plot 5 minute opening range high and low.
2. Plot pivot (solid orange line).
3. Plot opening price (medium cyan dashes).
4. Plot fudge factor of ATR distance above and below opening range high and low (small gray dashes).
5. Plot a cloud in light green color filling the opening range.
6. Alert you if price is above opening price and pivot and breaks out above opening range high on higher than average volume.
7. Alert you if price is below opening price and pivot and breaks down below opening range low on higher than average volume.
8. Add a label "UP" in green when #6 is true.
9. Add a label "DN" in red when #7 is true.
10. Add a label "NO" in gray when neither conditions present.

I day trade breakouts with very similar conditions and based on my years of experience, I added the volume condition because when breakout is on higher than average volume it is less likely to be a fake breakout. Additionally, after breakout when price is still less than ATR distance from breakout high/low it is more likely to reverse and cause fake breakout. After breakout once price candle closes beyond ATR distance then it is more likely to be a real breakout. Please look at SPY today with this indicator. Price broke out above 5 minute opening range high when it was above opening price and above pivot but failed to close above ATR distance (on both 1 minute and 5 minute charts), so it reversed and went back down. Later when price broke out and went above ATR distance from opening range high, then it ripped and never came back below opening range high.

If you don't want the fudge factor plotted or want volume condition removed or make other changes, let me know. Hope this helps:



#Plot opening range high / low and fudge factor
script OpenRange {
input ORtime = 5;

def FirstBar = SecondsFromTime(0930) >= 0 and SecondsFromTime(0930) < 60;
def RangeTime = SecondsFromTime(0930) >= 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 or SecondsTillTime(0930) > 0 then Double.NaN else Rhigh;
plot l = if RangeTime or SecondsTillTime(0930) > 0 then Double.NaN else Rlow;
}

def today = GetLastDay() == GetDay();
def ATR = WildersAverage(TrueRange(high, close, low), 6);

plot h5 = if !today then Double.NaN else OpenRange(5).h;
h5.SetDefaultColor(Color.LIGHT_GRAY);
plot FFh5 = h5 + ATR;
FFh5.SetStyle(Curve.SHORT_DASH);
FFh5.AssignValueColor(Color.LIGHT_GRAY);
plot l5 = if !today then Double.NaN else OpenRange(5).l;
l5.SetDefaultColor(Color.PINK);
plot FFl5 = l5 - ATR;
FFl5.SetStyle(Curve.SHORT_DASH);
FFl5.AssignValueColor(Color.LIGHT_GRAY);

AddCloud(h5, l5, Color.LIGHT_GREEN);

#Plot pivot
plot Pivot = if !today then Double.NaN else (high(period = "day" )[1] + low(period = "day" )[1] + close(period = "day" )[1]) / 3;
Pivot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Pivot.SetDefaultColor(Color.ORANGE);
Pivot.SetLineWeight(2);

#Plot open price
plot OpenPrice = if !today or SecondsTillTime(0930) > 0 then Double.NaN else open(period = "day" );
OpenPrice.SetStyle(Curve.MEDIUM_DASH);
OpenPrice.SetDefaultColor(Color.CYAN);
OpenPrice.SetLineWeight(2);

#Define signals
def AvgVol = Average(volume, 6);
def VolUP = volume > AvgVol;
def bull = close[2] <= h5 and close[1] > h5 and close[1] > open(period = "day" ) and close[1] > Pivot and VolUP[1];
def bear = close[2] >= l5 and close[1] < l5 and close[1] < open(period = "day" ) and close[1] < Pivot and VolUP[1];
def Above = close[1] > h5 and close[1] > open(period = "day" ) and close[1] > Pivot;
def Below = close[1] < l5 and close[1] < open(period = "day" ) and close[1] < Pivot;
def Neut = !Above and !Below;

#Trigger alerts
Alert(bull, GetSymbolPart() + " above 5 minute opening range on higher volume", Alert.BAR, Sound.Ring);
Alert(bear, GetSymbolPart() + " below 5 minute opening range on higher volume", Alert.BAR, Sound.Ring);

#Add labels
AddLabel(Neut, "NO", Color.LIGHT_GRAY);
AddLabel(Above, "UP", Color.GREEN);
AddLabel(Below, "DN", Color.RED);



Edited 2 time(s). Last edit at 03/11/2016 11:43PM by tanman.
Re: Fun with ThinkScript
March 12, 2016 04:25AM
tanman Wrote:
-------------------------------------------------------
> SARA,
>
> Yes it's possible to combine them in one signal.
> For example:
>
> def BuySignal = BuySignal60 and BuySignal30 and
> BuySignal20 and BuySignal10;
> Alert(BuySignal, "Time to go long", Alert.BAR,
> Sound.Ring)
>
> You can also plot separate labels showing signals
> on different higher time frames and lower time
> frame on the lower time frame chart and code them
> green for buy signal or red for sell signal or
> gray for neutral. That way you can go long when
> all are green or short when all are red.


Thank you Tanman . I'll try that code .cool smiley
JML
Re: Fun with ThinkScript
March 12, 2016 08:47AM
tanman Wrote:
-------------------------------------------------------
> Rob Miller,
>
> This indicator will do the following:
>
> 1. Plot 5 minute opening range high and low.
> 2. Plot pivot (solid orange line).
> 3. Plot opening price (medium cyan dashes).
> 4. Plot fudge factor of ATR distance above and
> below opening range high and low (small gray
> dashes).
> 5. Plot a cloud in light green color filling the
> opening range.
> 6. Alert you if price is above opening price and
> pivot and breaks out above opening range high on
> higher than average volume.
> 7. Alert you if price is below opening price and
> pivot and breaks down below opening range low on
> higher than average volume.
> 8. Add a label "UP" in green when #6 is true.
> 9. Add a label "DN" in red when #7 is true.
> 10. Add a label "NO" in gray when neither
> conditions present.
>
> I day trade breakouts with very similar conditions
> and based on my years of experience, I added the
> volume condition because when breakout is on
> higher than average volume it is less likely to be
> a fake breakout. Additionally, after breakout when
> price is still less than ATR distance from
> breakout high/low it is more likely to reverse and
> cause fake breakout. After breakout once price
> candle closes beyond ATR distance then it is more
> likely to be a real breakout. Please look at SPY
> today with this indicator. Price broke out above 5
> minute opening range high when it was above
> opening price and above pivot but failed to close
> above ATR distance (on both 1 minute and 5 minute
> charts), so it reversed and went back down. Later
> when price broke out and went above ATR distance
> from opening range high, then it ripped and never
> came back below opening range high.
>
> If you don't want the fudge factor plotted or want
> volume condition removed or make other changes,
> let me know. Hope this helps:
>
>
>
> #Plot opening range high / low and fudge factor
> script OpenRange {
> input ORtime = 5;
>
> def FirstBar = SecondsFromTime(0930) >= 0 and
> SecondsFromTime(0930) < 60;
> def RangeTime = SecondsFromTime(0930) >= 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 or SecondsTillTime(0930)
> > 0 then Double.NaN else Rhigh;
> plot l = if RangeTime or SecondsTillTime(0930)
> > 0 then Double.NaN else Rlow;
> }
>
> def today = GetLastDay() == GetDay();
> def ATR = WildersAverage(TrueRange(high, close,
> low), 6);
>
> plot h5 = if !today then Double.NaN else
> OpenRange(5).h;
> h5.SetDefaultColor(Color.LIGHT_GRAY);
> plot FFh5 = h5 + ATR;
> FFh5.SetStyle(Curve.SHORT_DASH);
> FFh5.AssignValueColor(Color.LIGHT_GRAY);
> plot l5 = if !today then Double.NaN else
> OpenRange(5).l;
> l5.SetDefaultColor(Color.PINK);
> plot FFl5 = l5 - ATR;
> FFl5.SetStyle(Curve.SHORT_DASH);
> FFl5.AssignValueColor(Color.LIGHT_GRAY);
>
> AddCloud(h5, l5, Color.LIGHT_GREEN);
>
> #Plot pivot
> plot Pivot = if !today then Double.NaN else
> (high(period = "day" )[1] + low(period = "day"
> )[1] + close(period = "day" )[1]) / 3;
> Pivot.SetPaintingStrategy(PaintingStrategy.HORIZON
> TAL);
> Pivot.SetDefaultColor(Color.ORANGE);
> Pivot.SetLineWeight(2);
>
> #Plot open price
> plot OpenPrice = if !today or
> SecondsTillTime(0930) > 0 then Double.NaN else
> open(period = "day" );
> OpenPrice.SetStyle(Curve.MEDIUM_DASH);
> OpenPrice.SetDefaultColor(Color.CYAN);
> OpenPrice.SetLineWeight(2);
>
> #Define signals
> def AvgVol = Average(volume, 6);
> def VolUP = volume > AvgVol;
> def bull = close[2] <= h5 and close[1] > h5 and
> close[1] > open(period = "day" ) and close[1] >
> Pivot and VolUP[1];
> def bear = close[2] >= l5 and close[1] < l5 and
> close[1] < open(period = "day" ) and close[1] <
> Pivot and VolUP[1];
> def Above = close[1] > h5 and close[1] >
> open(period = "day" ) and close[1] > Pivot;
> def Below = close[1] < l5 and close[1] <
> open(period = "day" ) and close[1] < Pivot;
> def Neut = !Above and !Below;
>
> #Trigger alerts
> Alert(bull, GetSymbolPart() + " above 5 minute
> opening range on higher volume", Alert.BAR,
> Sound.Ring);
> Alert(bear, GetSymbolPart() + " below 5 minute
> opening range on higher volume", Alert.BAR,
> Sound.Ring);
>
> #Add labels
> AddLabel(Neut, "NO", Color.LIGHT_GRAY);
> AddLabel(Above, "UP", Color.GREEN);
> AddLabel(Below, "DN", Color.RED);

Tanman,

Thanks for sharing this study and your strategy, awesome to say the least!!
One thing you can add if possible... to where we can go back and look at this setup on previous days, noticed it only shows on actual day.
Thanks
JML
Re: Fun with ThinkScript
March 12, 2016 08:56AM
Tanman, I haven't had a chance to look at this code yet in ToS, but I know a floor trader that does something very similar and is VERY successful with it. Have you had a chance to go back and look at it for success rate?

Thanks for sharing the code
Re: Fun with ThinkScript
March 12, 2016 10:38AM
JML, Rob Miller,

This will show up on all previous days as well. I also added a label which displays the ATR. Please read my following post for more tips.


#Plot opening range high / low and fudge factor
script OpenRange {
input ORtime = 5;

def FirstBar = SecondsFromTime(0930) >= 0 and SecondsFromTime(0930) < 60;
def RangeTime = SecondsFromTime(0930) >= 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 or SecondsTillTime(0930) > 0 then Double.NaN else Rhigh;
plot l = if RangeTime or SecondsTillTime(0930) > 0 then Double.NaN else Rlow;
}

def ATR = WildersAverage(TrueRange(high, close, low), 6);

plot h5 = OpenRange(5).h;
h5.SetDefaultColor(Color.LIGHT_GRAY);
plot FFh5 = h5 + ATR;
FFh5.SetStyle(Curve.SHORT_DASH);
FFh5.AssignValueColor(Color.LIGHT_GRAY);
plot l5 = OpenRange(5).l;
l5.SetDefaultColor(Color.PINK);
plot FFl5 = l5 - ATR;
FFl5.SetStyle(Curve.SHORT_DASH);
FFl5.AssignValueColor(Color.LIGHT_GRAY);

AddCloud(h5, l5, Color.LIGHT_GREEN);

#Plot pivot
plot Pivot = (high(period = "day" )[1] + low(period = "day" )[1] + close(period = "day" )[1]) / 3;
Pivot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Pivot.SetDefaultColor(Color.ORANGE);
Pivot.SetLineWeight(2);

#Plot open price
plot OpenPrice = if SecondsTillTime(0930) > 0 then Double.NaN else open(period = "day" );
OpenPrice.SetStyle(Curve.MEDIUM_DASH);
OpenPrice.SetDefaultColor(Color.CYAN);
OpenPrice.SetLineWeight(2);

#Define signals
def AvgVol = Average(volume, 6);
def VolUP = volume > AvgVol;
def bull = close[2] <= h5 and close[1] > h5 and close[1] > open(period = "day" ) and close[1] > Pivot and VolUP[1];
def bear = close[2] >= l5 and close[1] < l5 and close[1] < open(period = "day" ) and close[1] < Pivot and VolUP[1];
def Above = close[1] > h5 and close[1] > open(period = "day" ) and close[1] > Pivot;
def Below = close[1] < l5 and close[1] < open(period = "day" ) and close[1] < Pivot;
def Neut = !Above and !Below;

#Trigger alerts
Alert(bull, GetSymbolPart() + " above 5 minute opening range on higher volume", Alert.BAR, Sound.Ring);
Alert(bear, GetSymbolPart() + " below 5 minute opening range on higher volume", Alert.BAR, Sound.Ring);

#Add labels
AddLabel(Neut, "NO", Color.LIGHT_GRAY);
AddLabel(Above, "UP", Color.GREEN);
AddLabel(Below, "DN", Color.RED);
AddLabel(yes, Round(ATR, 2), Color.LIGHT_GRAY);
JML
Re: Fun with ThinkScript
March 12, 2016 11:31AM
tanman Wrote:
-------------------------------------------------------
> JML, Rob Miller,
>
> This will show up on all previous days as well. I
> also added a label which displays the ATR. Please
> read my following post for more tips.
>
>
> #Plot opening range high / low and fudge factor
> script OpenRange {
> input ORtime = 5;
>
> def FirstBar = SecondsFromTime(0930) >= 0 and
> SecondsFromTime(0930) < 60;
> def RangeTime = SecondsFromTime(0930) >= 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 or SecondsTillTime(0930) > 0
> then Double.NaN else Rhigh;
> plot l = if RangeTime or SecondsTillTime(0930) > 0
> then Double.NaN else Rlow;
> }
>
> def ATR = WildersAverage(TrueRange(high, close,
> low), 6);
>
> plot h5 = OpenRange(5).h;
> h5.SetDefaultColor(Color.LIGHT_GRAY);
> plot FFh5 = h5 + ATR;
> FFh5.SetStyle(Curve.SHORT_DASH);
> FFh5.AssignValueColor(Color.LIGHT_GRAY);
> plot l5 = OpenRange(5).l;
> l5.SetDefaultColor(Color.PINK);
> plot FFl5 = l5 - ATR;
> FFl5.SetStyle(Curve.SHORT_DASH);
> FFl5.AssignValueColor(Color.LIGHT_GRAY);
>
> AddCloud(h5, l5, Color.LIGHT_GREEN);
>
> #Plot pivot
> plot Pivot = (high(period = "day" )[1] +
> low(period = "day" )[1] + close(period = "day"
> )[1]) / 3;
> Pivot.SetPaintingStrategy(PaintingStrategy.HORIZON
> TAL);
> Pivot.SetDefaultColor(Color.ORANGE);
> Pivot.SetLineWeight(2);
>
> #Plot open price
> plot OpenPrice = if SecondsTillTime(0930) > 0 then
> Double.NaN else open(period = "day" );
> OpenPrice.SetStyle(Curve.MEDIUM_DASH);
> OpenPrice.SetDefaultColor(Color.CYAN);
> OpenPrice.SetLineWeight(2);
>
> #Define signals
> def AvgVol = Average(volume, 6);
> def VolUP = volume > AvgVol;
> def bull = close[2] <= h5 and close[1] > h5 and
> close[1] > open(period = "day" ) and close[1] >
> Pivot and VolUP[1];
> def bear = close[2] >= l5 and close[1] < l5 and
> close[1] < open(period = "day" ) and close[1] <
> Pivot and VolUP[1];
> def Above = close[1] > h5 and close[1] >
> open(period = "day" ) and close[1] > Pivot;
> def Below = close[1] < l5 and close[1] <
> open(period = "day" ) and close[1] < Pivot;
> def Neut = !Above and !Below;
>
> #Trigger alerts
> Alert(bull, GetSymbolPart() + " above 5 minute
> opening range on higher volume", Alert.BAR,
> Sound.Ring);
> Alert(bear, GetSymbolPart() + " below 5 minute
> opening range on higher volume", Alert.BAR,
> Sound.Ring);
>
> #Add labels
> AddLabel(Neut, "NO", Color.LIGHT_GRAY);
> AddLabel(Above, "UP", Color.GREEN);
> AddLabel(Below, "DN", Color.RED);
> AddLabel(yes, Round(ATR, 2), Color.LIGHT_GRAY);

Tanman,
Thanks for making the change. Where are your following tips? Any of your advise is helpful.
I read your strategy in the original post, was that it?
What instruments do you trade with this? How successful have you been?
I trade mainly the ZB, so I changed the times to 8:20 EST, seems to give good signals.
Thanks
JML
Re: Fun with ThinkScript
March 12, 2016 11:51AM
You're great at coding. Any chance of coding this as a thinkscript strategy that way we could actually see the signals and P/L at the bottom? Thanks
Re: Fun with ThinkScript
March 12, 2016 01:04PM
Rob Miller,

Thank you for the kind words. I have thought about coding a strategy but that is complicated and beyond my coding skills currently. If you read my older posts you will find that I had zero coding skills not too long ago and learned how to code from Robert's scripts. I am still learning and consider myself an amateur at coding. Robert is the guru of thinkscript and maybe he can come up with a strategy script.

I will discuss my complete rules shortly, but what do you use for stop loss and exit, because that is an important part of coding a strategy?

I can try to code a strategy if the stop loss and exit rules are simple enough, but can't guarantee it.
Re: Fun with ThinkScript
March 12, 2016 01:25PM
I like small stops, 8-10 ticks on the ES so I can get back in if needed. After you hit 4points profit you would automatically move your stop to break even. With more than one contract you would hold for bigger moves. The theory is if you can get 4 points a day on average then every once and while you would get a gap and go day. The days it goes bid and never slows down.

I'm trying to get consistent base hits daily, then there are times you would hit home runs. With the extra contract and break even stop.
The guy I follow on Twitter does something similar and I'm trying to mimick his style because he is so successful. He uses only the pivot and daily charts, with weekly monthly for bigger moves. If it's above the pivot in an uptrend, he waits for the daily candle to go from red to green then it's A long entry. If stopped out, re enter when it goes green again. Try this 3 times to catch the daily move. I was trying to use the script you provided and others I've tried for better entries.
Re: Fun with ThinkScript
March 12, 2016 01:53PM
Rob Miller, JML,

Please see my following post in another thread for my recommended rules for breakout trading:

[www.researchtrade.com]
Re: Fun with ThinkScript
March 12, 2016 02:14PM
Rob Miller,

That seems like a good strategy but difficult to code. Your final exit is still not clear which is essential to code the strategy.

I think 8-10 tick stop in /ES is risky. The 5 minute ATR can be greater than that. This way you can be stopped out in a normal fluctuation which then reverses after an expected ATR move and resumes previous direction but without you. More reasonable would be ATR x 2 stop loss (about 16 ticks) or stop loss beyond most recent swing high/low but that would require account size of at least 25K for risk to be less than 1%.

What if price reverses from 4 points after you move stop loss to break even and you get stopped out for zero profit even when you had an ATR x 2 move? I think more prudent would be to always trade with at least 2 contracts and scale out of one contract at 4 points and then move stop loss to break even because then you lock in a profit and let the rest ride. This, however, would require at least 40K account for risk to be less than 1%.

This is why smaller accounts are at a disadvantage because almost all successful trading strategies require bigger account size! The most common reason for blowing out accounts is trading with smaller account size than is necessary for a successful strategy.
Re: Fun with ThinkScript
March 12, 2016 02:40PM
Yes, I would agree would agree with that. I will read your recommend rules for breakout trading. Thanks for posting them
JML
Re: Fun with ThinkScript
March 12, 2016 02:55PM
tanman Wrote:
-------------------------------------------------------
> Rob Miller, JML,
>
> Please see my following post in another thread for
> my recommended rules for breakout trading:
>
> [www.researchtrade.com]
> ,6313#msg-6313


Thanks!!
JML
JML
Re: Fun with ThinkScript
March 12, 2016 03:15PM
Hey Tanman,

Have you figured out good setting for TOS low/high memory settings that you set from the log on screen?

Just trying to tweak my performance.

I presently use an I5 2.2 g processor with 8 meg of ram- windows 10.

Thanks
Jml
Re: Fun with ThinkScript
March 12, 2016 03:54PM
JML,

The best way is to open 2 separate accounts on TOS and set each to 1024/4096 min/max memory settings. Then divide your charts into the 2 accounts and log in both accounts simultaneously. You can also use one only for charting and second only or trading. This way memory is divided in both accounts and max memory usage I see in each remains < 3 Gigs and TOS doesn't freeze or slow down a lot, even though I have multiple detached windows open at same time with multiple charts in each window.

The second way which I haven't tried is to duplicate the thinkorswim folder wherever it is located, and link each to a separate desktop icon and then you can run 2 copies of TOS simultaneously without having to open 2 separate accounts.
JML
Re: Fun with ThinkScript
March 12, 2016 04:56PM
tanman Wrote:
-------------------------------------------------------
> JML,
>
> The best way is to open 2 separate accounts on TOS
> and set each to 1024/4096 min/max memory settings.
> Then divide your charts into the 2 accounts and
> log in both accounts simultaneously. You can also
> use one only for charting and second only or
> trading. This way memory is divided in both
> accounts and max memory usage I see in each
> remains < 3 Gigs and TOS doesn't freeze or slow
> down a lot, even though I have multiple detached
> windows open at same time with multiple charts in
> each window.
>
> The second way which I haven't tried is to
> duplicate the thinkorswim folder wherever it is
> located, and link each to a separate desktop icon
> and then you can run 2 copies of TOS
> simultaneously without having to open 2 separate
> accounts.

I found this online and it seems to have improved things, if it dint work, will try your idea, thanks!!
JML

min mem 1024 and max 6484

settings for thinkorswim.vmoptions file

-Xmx6484m
-Xms1024m
-Djava.util.Arrays.useLegacyMergeSort=true
-classpath/p launcher-first.jar
-Djava.net.preferIPv4Stack=true
-Dsun.java2d.xrender=True
-XX:-UseConcMarkSweepGC
-Dsun.java2d.noddraw=true
-Dsun.awt.disableMixing=true
-Dawt.useSystemAAFontSettings=lcd_hrgb
-Dsun.net.http.allowRestrictedHeaders=true
-XX:MaxPermSize=256m
Re: Fun with ThinkScript
March 14, 2016 12:09PM
tanman Wrote:
-------------------------------------------------------
> SARA,
>
> Yes it's possible to combine them in one signal.
> For example:
>
> def BuySignal = BuySignal60 and BuySignal30 and
> BuySignal20 and BuySignal10;
> Alert(BuySignal, "Time to go long", Alert.BAR,
> Sound.Ring)
>
> You can also plot separate labels showing signals
> on different higher time frames and lower time
> frame on the lower time frame chart and code them
> green for buy signal or red for sell signal or
> gray for neutral. That way you can go long when
> all are green or short when all are red.


I couldn't do it as I want .. could you please help me in coding this script as described before ..

-----------------------------


input Aggregate = {Five_Min, ten_min, Fifteen_min, twenty_min, thirty_min, Hourly, Two_Hours, Three_Hours, Four_Hours, default Daily, Weekly, Monthly} ;

def Agg = if Aggregate == Aggregate.Hourly then AggregationPeriod.HOUR else
if Aggregate == Aggregate.Five_Min then AggregationPeriod.FIVE_MIN else
if Aggregate == Aggregate.ten_min then AggregationPeriod.TEN_MIN else
if Aggregate == Aggregate.Fifteen_min then AggregationPeriod.FIFTEEN_MIN else
if Aggregate == Aggregate.twenty_min then AggregationPeriod.TWENTY_MIN else
if Aggregate == Aggregate.thirty_min then AggregationPeriod.THIRTY_MIN else
if Aggregate == Aggregate.Two_Hours then AggregationPeriod.TWO_HOURS else
if Aggregate == Aggregate.Four_Hours then AggregationPeriod.FOUR_HOURS else
if Aggregate == Aggregate.Daily then AggregationPeriod.DAY else 
if Aggregate == Aggregate.Weekly then AggregationPeriod.WEEK else 
if Aggregate == Aggregate.Monthly then AggregationPeriod.MONTH else AggregationPeriod.MIN; 


# macd

DEF Value = MACD(2, 5, 2, "weighted" ).Value;
DEF Avg = MACD(2, 5, 2, "weighted" ).Avg;
def MACDup = Value > Avg;
def MACDdn = Value < Avg;



# stochslow

#def SlowDdn = SlowD crosses ABOVE 80
def SlowD = StochasticFull(80, 30, 2, 2, hlc3(period = Agg), hlc3(period = Agg), hlc3(period = Agg), 3, "weighted" ).FullD;
def SlowDup = SlowD  CROSSES ABOVE 30;
def SlowDdn = SlowD  crosses BELOW  80;

# CCI

def CCI = CCI(7);
def CCIup = CCI crosses above -100;
def CCIdn = CCI crosses below 100;

# MFI

#crosses above 30
#crosses BELOW 80
def MFIup = MoneyFlowIndex(length = 1).MoneyFlowIndex crosses ABOVE 30;
def MFIdn = MoneyFlowIndex(length = 1).MoneyFlowIndex crosses BELOW 80;



#ADX 

input ADXlength = 14; 
input averageType = AverageType.WILDERS; 
DEF ADX = DMI(ADXlength, averageType).ADX; 



#Signals
plot BuySignal = MFIup and SlowDup and MACDup and CCIup and ADX >= 30; 
Alert(BuySignal, "Time to go LONG", Alert.BAR, Sound.Ring);


plot SellSignal =  MFIdn and SlowDdn and MACDdn and CCIdn  and ADX >= 30 ;
Alert(SellSignal, "Time to go SHORT", Alert.BAR, Sound.Ring);

Re: Fun with ThinkScript
March 14, 2016 04:05PM
SARA,

That is because it is almost impossible for all of them to be crossing at same exact time. If you change crosses above to just > and crosses below to just < then it might start giving you alerts. I'll try to work on the exact lines of script and see what's wrong.

Additionally, you will have to write each time frame's signal separately and then combine all of them together instead of the different inputs.



Edited 1 time(s). Last edit at 03/14/2016 04:08PM by tanman.
Re: Fun with ThinkScript
March 14, 2016 05:44PM
SARA,

You will have to view script of each study in ToS and then change high, low, close etc. in the script to aggregation period that you want, for example change high to high(period = "hour" ) for 60 minute time frame. Then write signal for each study in the specific time frame and combine them for that time frame, for example:

BuySignal60 = MACD60up and slowD60up and CCI60up and MFI60up and ADX60 >= 30;

Then do the same for BuySignal30 and BuySignal20 and BuySignal10 etc. and then combine them all into one BuySignal.

Change all "crosses above" to > and "crosses below" to <.

Hope that helps.
YTD,MTD, and WTD percentage change in a label.
March 15, 2016 10:05AM
Hello ,

I am new to this forum and new to think script. I am trying to build a study that has a label at the bottom of the chart that will display year to date percentage change, month to date percentage change and week to date percentage change. Cosmetic would be labels are green when positive and red when negative. If anyone would help me do this I would be grateful. I have the following so far but don't seem to get the right percentages for some reason.

input price = close;
input show_label = yes;
def entryprice = price;

####################
# Percent_Change_Year_To_Date

def YearClose = if GetYear() != GetYear()[1] then open else yearclose[1];
def YTDnetchange = ((entryprice - YearClose) / YearClose) ;
plot YearValue = YTDnetchange;
YearValue.Hide();
AddLabel(show_label, "YTD: " + AsPercent(YearValue), if YearValue > 0 then Color.Dark_GREEN else Color.RED);


####################
# Percent_Change_Month_To_Date

def MonthClose = if GetLastMonth() == GetMonth() then close(GetSymbol(), period = AggregationPeriod.MONTH)[1] else Double.NaN;
def MTDnetchange = ((entryprice - MonthClose) / MonthClose) ;
plot MonthValue = MTDnetchange;
MonthValue.Hide();
AddLabel(show_label, "MTD: " + AsPercent(MonthValue), if MonthValue > 0 then Color.DarK_GREEN else Color.RED);

####################
# Percent_Change_Week_To_Date
def WeekClose = if GetLastWeek() == GetWeek() then close(GetSymbol(), period = AggregationPeriod.WEEK)[1] else Double.NaN;
def WTDnetchange = ((entryprice - WeekClose) / WeekClose) ;
plot WeekValue = WTDnetchange;
WeekValue.Hide();
AddLabel(show_label, "WTD: " + AsPercent(WeekValue), if WeekValue > 0 then Color.DARK_GREEN else Color.RED);
Re: Fun with ThinkScript
March 15, 2016 02:20PM
Tom D,

Try changing def yearclose line to following:

def YearClose = if GetYear() != GetYear()[1] then close[1] else yearclose[1];
Sorry, only registered users may post in this forum.

Click here to login