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
September 11, 2014 10:06AM
Robert,

I have been trying to convert some of your code, that I modified, into a column alert but I get a msg that it is too complex for real time. Can you suggest a code modification.

Thanks,

MT

input DI_length = 5;
input ADX_length = 13;
input Strong_Trend = 25;
input ADX_fill = yes;

def DX = if (DIPlus(DI_length) + DIMinus(DI_length) > 0) then 100 * AbsValue(DIPlus(DI_length) - DIMinus(DI_length)) / (DIPlus(DI_length) + DIMinus(DI_length)) else 0;
plot ADX = WildersAverage(DX, ADX_length);
ADX.DefineColor("Stronger", Color.light_green);
ADX.DefineColor("Weaker", Color.red);
ADX.AssignValueColor(if ADX > ADX[1] then ADX.Color("Stronger"winking smiley else ADX.Color("Weaker"winking smiley);
def adx2 = (if ADX > ADX[1] then 1 else 2);

def stronger = if ADX_fill then ADX else Double.NaN;
def weaker = if ADX_fill then if ADX < ADX[1] then ADX else Double.NaN else Double.NaN;


def "DI+" = DIPlus(DI_length);
def "DI-" = DIMinus(DI_length);


def long = if "DI+" > "DI-" and "DI+"[1] < "DI-"[1] then 1 else 0;
def short = if "DI+" < "DI-" and "DI+"[1] > "DI-"[1] then 1 else 0;

def signal1 = if long and adx2 <> adx2[1] and adx <> adx[1] then 1 else if short and adx2 <> adx2[1] and adx <> adx[1] then 2 else 0;


plot dotUp = if signal1 == 1 then low * 0.997 else Double.NaN;
dotUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
dotUp.SetLineWeight(5);
dotUp.SetDefaultColor(Color.WHITE);

plot dotDn = if signal1 == 2 then high * 1.003 else Double.NaN;
dotDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
dotDn.SetLineWeight(5);
dotDn.SetDefaultColor(Color.WHITE);
Re: Fun with ThinkScript
September 11, 2014 10:29AM
mtut,

I'll look it over later, but from a quick once-over, I notice that you've got multiple plots. Scripts that are used in scans and watch list columns are limited to ONE and only ONE plot.



Edited 1 time(s). Last edit at 09/11/2014 10:32AM by robert.
Re: Fun with ThinkScript
September 11, 2014 02:10PM
Mtut,

I shortened your code as much as I could while still generating the same signals.

def DX = if (DIPlus(5) + DIMinus(5) > 0) then 100 * AbsValue(DIPlus(5) - DIMinus(5)) / (DIPlus(5) + DIMinus(5)) else 0; 
def ADX = WildersAverage(DX, 13); 
def ADX2 = ADX > ADX[1];
def DIplus  = DIPlus(5); 
def DIminus = DIMinus(5); 
def long  = DIplus crosses above DIminus and ADX2 <> ADX2[1]; 
def short = DIplus crosses below DIminus and ADX2 <> ADX2[1];

plot dotUp = if long then low * 0.997 else Double.NaN; 
     dotUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); 
     dotUp.SetLineWeight(5); 
     dotUp.SetDefaultColor(color.white); 

plot dotDn = if short then high * 1.003 else Double.NaN; 
     dotDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); 
     dotDn.SetLineWeight(5); 
     dotDn.SetDefaultColor(color.white);

However, when trying to use it in a watch list column, it chokes on the bits circled below. Despite several attempts at reworking it, I've been unable to figure out a workaround.

Re: Fun with ThinkScript
September 11, 2014 07:42PM
Thank you for looking. I will settle on a column that finds the one condition that does not error and then do a visual on the second condition.
Re: Fun with ThinkScript
September 11, 2014 10:39PM
I dont know what I am doing wrong but I am using this as a study on a 1 min chart but seems to give both buy and sell signal on the same bar. I dont know if some has faced this or knows why?


Also I think there are some post which are missing I see that there is a scan available for the "E UP" but I dont see any explanation what and how it works? may be its in another thread can some body point it out?

Thanks,
StrategyNode
Re: Fun with ThinkScript
September 13, 2014 05:46AM
Hi Richard or anyone lese who could help.

I am looking for a simple TOS script to use. Basically when 5wma crosses 12wma would like a green down arrow to appear. and vice versa when 12wma crosses the 5wma would like red up arrow to appear. Finally, I am looking for alert when the 18sma and the 28sma get very close together. an alert such as a buy bubble to pop up when both these are at say 95% touching.

love everything else I have read here.

astirl
Re: Fun with ThinkScript
September 13, 2014 06:30AM
Quote
strategynode
I dont know what I am doing wrong but I am using this as a study on a 1 min chart but seems to give both buy and sell signal on the same bar. I dont know if some has faced this or knows why?

When you say, "I am using this as a study..." what study do you mean? Please post the script you are using and a screenshot of the double signals you are talking about.


Quote
strategynode
Also I think there are some post which are missing I see that there is a scan available for the "E UP" but I dont see any explanation what and how it works? may be its in another thread can some body point it out?

Read the posts by Darcy2. She coined the term "E" charts. Basically it's a triple moving average system.
Re: Fun with ThinkScript
September 13, 2014 06:55AM
Quote
astiril2809
I am looking for a simple TOS script to use. Basically when 5wma crosses 12wma would like a green down arrow to appear. and vice versa when 12wma crosses the 5wma would like red up arrow to appear.

plot wma5 = WMA(close, 5);
plot wma12 = WMA(close, 12);

plot UParrow = wma5 crosses above wma12;
     UParrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
     UParrow.SetDefaultColor(Color.GREEN);
     UParrow.SetLineWeight(3);

plot DNarrow = wma5 crosses below wma12;
     DNarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
     DNarrow.SetDefaultColor(Color.RED);
     DNarrow.SetLineWeight(3);

Quote
astiril2809
Finally, I am looking for alert when the 18sma and the 28sma get very close together. an alert such as a buy bubble to pop up when both these are at say 95% touching.

def ma18 = Average(close, 18);
def ma28 = Average(close, 28);
def near = ma18 between (ma28 * 0.95) and (ma28 * 1.05);

AddLabel(near, "18sma and 28sma are near each other", Color.YELLOW);
Re: Fun with ThinkScript
September 13, 2014 10:24AM
many, many thanks...

may I just ask for couple quick changes after trying it out in tos.

to change the 18sma and 28sma to ema. and if possible to add a dot(yellow) to occur at where the now changed 18 and 28ema's get close together.

regards and just to say thank you for such a speedy response.

astirl
Re: Fun with ThinkScript
September 15, 2014 02:29PM
robert Wrote:
-------------------------------------------------------
> > I am looking for a simple TOS script to use.
> Basically when 5wma crosses 12wma would like a
> green down arrow to appear. and vice versa when
> 12wma crosses the 5wma would like red up arrow to
> appear.
>
>
>
> plot wma5 = WMA(close, 5);
> plot wma12 = WMA(close, 12);
>
> plot UParrow = wma5 crosses above wma12;
>
> UParrow.SetPaintingStrategy(PaintingStrategy.BOOLE
> AN_ARROW_UP);
> UParrow.SetDefaultColor(Color.GREEN);
> UParrow.SetLineWeight(3);
>
> plot DNarrow = wma5 crosses below wma12;
>
> DNarrow.SetPaintingStrategy(PaintingStrategy.BOOLE
> AN_ARROW_DOWN);
> DNarrow.SetDefaultColor(Color.RED);
> DNarrow.SetLineWeight(3);
>
>
>
> Finally, I am looking for alert when the 18sma and
> the 28sma get very close together. an alert such
> as a buy bubble to pop up when both these are at
> say 95% touching.
>
>
>
> def ma18 = Average(close, 18);
> def ma28 = Average(close, 28);
> def near = ma18 between (ma28 * 0.95) and (ma28 *
> 1.05);
>
> AddLabel(near, "18sma and 28sma are near each
> other", Color.YELLOW);
>


Hi Robert

Thank you for the scrip, see above post. The only problem is that the label 18 and 28 are near is being displayed all the time. Is there any way this can be changed so that it only appears when the lines are almost touching.

Thank you for your time, it is really appreciated.

astirl2809
Re: Fun with ThinkScript
September 16, 2014 01:57AM
Robert Thanks for pointing me in the direction of darcy's post that was very helpful.

Also the study I was refering to was the ADX study in page 4 or 5 i belive but There two versions of the post and the second one is the correct one.

I have a new question for you or any body who has a answer to this:

Is there any way to create a new alert for a watch list (static) ? or a custom column in the watchlist panel?

Example: Stock A which is in my watchlist has news and I get a alert about

If not do you guys know of a solution which can do that?



Edited 1 time(s). Last edit at 09/16/2014 01:59AM by strategynode.
Re: Fun with ThinkScript
September 16, 2014 10:38AM
Quote
astirl
many, many thanks...

may I just ask for couple quick changes after trying it out in tos.

to change the 18sma and 28sma to ema. and if possible to add a dot(yellow) to occur at where the now changed 18 and 28ema's get close together.

regards and just to say thank you for such a speedy response.

astirl

If you want EMA instead of SMA, just change Average in the script to ExpAverage instead.

Quote

Thank you for the scrip, see above post. The only problem is that the label 18 and 28 are near is being displayed all the time. Is there any way this can be changed so that it only appears when the lines are almost touching.

You asked for an indication when the two moving averages are within 5% of each other. That's probably a little too wide. For a $100 stock that's $5 on either side of the moving average. You'll have to adjust the range to suit your needs. Adjust the range on this line of code: def near = ma18 between (ma28 * 0.95) and (ma28 * 1.05);

If you want a 3% range then use, between 0.97 and 1.03; 1% would use 0.99 and 1.01. Play with the values until you get what you want.
Re: Fun with ThinkScript
September 16, 2014 10:44AM
strategynode, I don't believe it is possible to script news alerts.
Re: Fun with ThinkScript
September 16, 2014 02:40PM
Thats what I thought. Thanks Robert!
Re: Fun with ThinkScript
September 17, 2014 01:14AM
Hi Robert,
I was wondering if there is any way to add the following indicator into this buy and sell signal code already in this thread:

Existing Code:


# stochslow
def SlowD = StochasticFull(80, 30, 2, 2, hlc3, hlc3, hlc3, 3, "EMA" ).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
def MFIup = MoneyFlowIndex(length = 1).MoneyFlowIndex crosses above 20;
def MFIdn = MoneyFlowIndex(length = 1).MoneyFlowIndex crosses below 80;

# RMI
def emaInc = ExpAverage(Max(close - close[5], 0), 5);
def emaDec = ExpAverage(Max(close[5] - close, 0), 5);
def RMI = if emaDec == 0 then 0 else 100 - 100 / (1 + emaInc / emaDec);
def RMIob = RMI >= 75;
def RMIos = RMI <= 25;


# Signals
plot signalUP = SlowDup and CCIup and MFIup and RMIos;
     signalUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
     signalUP.SetLineWeight(3);
     signalUP.SetDefaultColor(Color.GREEN);
plot signalDN = SlowDdn and CCIdn and MFIdn and RMIob;
     signalDN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
     signalDN.SetLineWeight(3);
     signalDN.SetDefaultColor(Color.RED);

New Indicator I wish to add - The Spearman Indicator (its Already in tos) - the buy signal is when the spearman line crosses spearmanaverage from below and the sell would be the opposite.

#
# TD Ameritrade IP Company, Inc. (c) 2013-2014
#

declare lower;

input price = close;
input length = 10;
input averageLength = 3;
input over_bought = 80;
input over_sold = -80;

assert(length >= 2, "'length' must be greater than or equal to 2: " + length);

def sumSqr = fold i = 0 to length with sum do
sum + Sqr((length - i) - fold j = 0 to length with rank
do rank + if GetValue(price, i, length - 1) > GetValue(price, length - j - 1) or GetValue(price, i) == GetValue(price, length - j - 1) and i <= length - j - 1 then 1 else 0);

plot Spearman = 100 * (1 - 6 * sumSqr / (length * (Sqr(length) - 1)));
plot SpearmanAverage = Average(Spearman, averageLength);
plot OverBought = over_bought;
plot ZeroLine = 0;
plot OverSold = over_sold;

Spearman.SetDefaultColor(GetColor(9));
SpearmanAverage.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(5));
OverSold.SetDefaultColor(GetColor(5));





Thanks,
StrategyNode



Edited 1 time(s). Last edit at 09/17/2014 01:15AM by strategynode.
Re: Fun with ThinkScript
September 17, 2014 02:11AM
Quote
strategynode
New Indicator I wish to add - The Spearman Indicator (its Already in tos) - the buy signal is when the spearman line crosses spearmanaverage from below and the sell would be the opposite.

input price = close;
input length = 10;
input averageLength = 3;
input over_bought = 80;
input over_sold = -80;

assert(length >= 2, "'length' must be greater than or equal to 2: " + length);

def sumSqr = fold i = 0 to length with sum do
sum + Sqr((length - i) - fold j = 0 to length with rank
do rank + if GetValue(price, i, length - 1) > GetValue(price, length - j - 1) or GetValue(price, i) == GetValue(price, length - j - 1) and i <= length - j - 1 then 1 else 0);

def Spearman = 100 * (1 - 6 * sumSqr / (length * (Sqr(length) - 1)));
def SpearmanAverage = Average(Spearman, averageLength);
plot SpearmanUP = Spearman crosses above SpearmanAverage;
     SpearmanUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
     SpearmanUP.SetLineWeight(3);
     SpearmanUP.SetDefaultColor(Color.GREEN);
plot SpearmanDN = Spearman crosses below SpearmanAverage;
     SpearmanDN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
     SpearmanDN.SetLineWeight(3);
     SpearmanDN.SetDefaultColor(Color.RED);
Re: Fun with ThinkScript
September 17, 2014 02:12AM
It is time for someone else to pick up the scripting challenge.

I would suggest:

1) Work your way through the tutorials provided by the ThinkScript team.

2) The official ThinkScript manual lists all the functions and gives some examples

3) The ThinkScript user group on Yahoo is an excellent resource.

4) Look back through the multitude of scripts I've posted in this thread. You should be able to find something similar to whatever you are trying to accomplish. Then just modify it to meet your needs.



Edited 1 time(s). Last edit at 09/17/2014 02:27AM by robert.
Re: Fun with ThinkScript
September 17, 2014 02:17AM
I am sorry to ask for one last thing, I wanted to combine this indicator with the existing indicators.

# stochslow
def SlowD = StochasticFull(80, 30, 2, 2, hlc3, hlc3, hlc3, 3, "EMA" ).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
def MFIup = MoneyFlowIndex(length = 1).MoneyFlowIndex crosses above 20;
def MFIdn = MoneyFlowIndex(length = 1).MoneyFlowIndex crosses below 80;

# RMI
def emaInc = ExpAverage(Max(close - close[5], 0), 5);
def emaDec = ExpAverage(Max(close[5] - close, 0), 5);
def RMI = if emaDec == 0 then 0 else 100 - 100 / (1 + emaInc / emaDec);
def RMIob = RMI >= 75;
def RMIos = RMI <= 25;


# Signals
plot signalUP = SlowDup and CCIup and MFIup and RMIos;
     signalUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
     signalUP.SetLineWeight(3);
     signalUP.SetDefaultColor(Color.GREEN);
plot signalDN = SlowDdn and CCIdn and MFIdn and RMIob;
     signalDN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
     signalDN.SetLineWeight(3);
     signalDN.SetDefaultColor(Color.RED);
Re: Fun with ThinkScript
September 17, 2014 04:14AM
robert Wrote:
-------------------------------------------------------
> > many, many thanks...
>
> may I just ask for couple quick changes after
> trying it out in tos.
>
> to change the 18sma and 28sma to ema. and if
> possible to add a dot(yellow) to occur at where
> the now changed 18 and 28ema's get close together.
>
>
> regards and just to say thank you for such a
> speedy response.
>
> astirl
>
>
> If you want EMA instead of SMA, just change
> Average in the script to ExpAverage instead.
>
> Thank you for the scrip, see above post. The only
> problem is that the label 18 and 28 are near is
> being displayed all the time. Is there any way
> this can be changed so that it only appears when
> the lines are almost touching.
>
> You asked for an indication when the two moving
> averages are within 5% of each other. That's
> probably a little too wide. For a $100 stock
> that's $5 on either side of the moving average.
> You'll have to adjust the range to suit your
> needs. Adjust the range on this line of code:
> def near = ma18 between (ma28 * 0.95) and (ma28 *
> 1.05);
>
> If you want a 3% range then use, between 0.97 and
> 1.03; 1% would use 0.99 and 1.01. Play with the
> values until you get what you want.


Hi Robert. Perhaps last easy one for me. No more asks....

Just a simple code added in that gives blue arrow when 5 woman and 12 AMA crosses over the 18 ema and 28ema

Regards.....and thank you
Re: Fun with ThinkScript
September 17, 2014 06:03AM
Quote
strategynode
I am sorry to ask for one last thing, I wanted to combine this indicator with the existing indicators.

[www.researchtrade.com]

I added the up and down signals to the Spearman code for you as requested. Now all that is left for you to do is copy and paste that code into the other, multi-indicator code you were wanting to use, then you need to look at how that code is structured and change the plot SignalUP and SignalDN lines to incorporate the new SpearmanUP and SpearmanDN signals.

[www.researchtrade.com]

Quote
Astiril
Hi Robert. Perhaps last easy one for me. No more asks....

Just a simple code added in that gives blue arrow when 5 woman and 12 AMA crosses over the 18 ema and 28ema

Regards.....and thank you

[www.researchtrade.com]

I've already written code for you that signals one moving average crossing the other. A very short review of that code will demonstrate to you how to add the arrow to your EMA crossover code.



Edited 1 time(s). Last edit at 09/17/2014 06:10AM by robert.
Re: Fun with ThinkScript
September 17, 2014 05:40PM
Hello all,

I am new here and this seems to be the place to get some help. I am looking for a way to modify the default Money Flow Index that comes with TOS. As a day trader, the default MFI is useful but not very accurate for giving signals for reversal points. Is there any way to change it according to the number of trades in a day of the stock say like 500 trades and take into account block volume size? This would give a more accurate signal of when money is leaving the stock and when there is weakness or when big money is coming into a stock showing strength. Basically i'm looking for it to be more accurate when it flashes red so I know exactly where to start shorting weakness and green so I start buying.

Any help appreciated, thanks.
Re: Fun with ThinkScript
September 17, 2014 05:47PM
Alex, I don't believe that'll be possible. Look here [tlc.thinkorswim.com] for a list of fundamentals that thinkscript has access to.
Re: Fun with ThinkScript
September 17, 2014 06:24PM
Ok. Well are you aware of any modified or tweaked version of the Money Flow Index for Thinkorswim?
Re: Fun with ThinkScript
September 17, 2014 06:28PM
Or any settings that can be changed to improve the MFI formula
Re: Fun with ThinkScript
September 17, 2014 07:07PM
Sorry for all the questions. Since this cannot work for the moneyflowindex is there a way to identify block trades from the underlying stock in TOS?
Re: Fun with ThinkScript
September 17, 2014 07:20PM
Alex, I don't know the answers to your question. Doesn't mean that there isn't one, or that someone else doesn't know, just that I don't. Good luck in you search.
Dan
Re: Fun with ThinkScript
September 17, 2014 10:26PM
Alex,

Are you finding as many block trades out there as in the past? I have noticed that there will be a rapid barrage of orders for 100-500 shares that, when taken in total, equal a block trade, which is stated as at least 10,000 shares or a value of greater than $200,000 according to NASDAQ rules. I seem to remember reading an article that program trading now uses this method to trade large blocks of stock without entering them as block trades. Also, hasn't a lot of what formerly traded as block trades moved to so called "dark pools?"
Re: Fun with ThinkScript
September 19, 2014 12:39AM
Hi Robert,

I am new to the forum and have read all of your thread. All I can say is WOW!!!! It’s very helpful. THANK YOU for your time and effort.I am using a lot of your code!

Is there a way to add a label to a daily and weekly chart that shows the percent above/below the 50day/10week SMA(Being able to change these SMA numbers as needed), with a grey colored label if within +/- % of SMA(Being able to separately adjust the positive and negative percent sides),Light to dark shades of Red Color below 4 different adjustable percent on negative side, But on the upside it will be light to dark Green color above 4 different adjustable percentages UNTIL it goes X percent (Will need to manually change X %) above the 50Day SMA/10Week SMA and at that point and above it will be black label with white letters.(I would like this black and white so it will make it stand out and also I want to see how the code would look for this. So I can modify another think script I have. I can modify script a little, but writing is a different story.) (So that is 2 grey, 4 red, 4 green and 1 Black label color/percent changes)

Also is there a way to take the purchase date and the purchase price of a stock (or starting date and price of the stock at the START of this Bull Market run) (I will manually enter price and date in code?) as the starting point and take the highest price to the right side of chart/date given (Is it possible for the present high to automatically change when/if a NEW high price number is reached?)to make a chart label with percent off the stocks high price vs your Stock buying price/date. Also if possible put a Modified Fibonacci Retracements type horizontal lines labeled with the percent down numbers and stock prices AT that percent down number on each line on the chart at 5% to 10% increments. Zero percent labeled line at the stock new high to 100 percent labeled line at stock buy price. Like 5% increments from 0 to 50% and 10% increments from 50 to 100%. This would be used in a multiple charting grid when looking to quickly visually scan charts from watch/scan tab lists to get a feel for the percent change of the correction/consolidation basing patterns in that stock vs its stock buy price and date (or bull cycle starting period price and date).I was thinking you may only need the starting date not the starting price, because all you need is the stock high price to the right side of chart from the stock date used? But you would need the starting price for the Modified Fibonacci Retracement. I think I read that a date could not be entered in think script? If this is true how about manually counting bar/periods backwards to the point in time(date) needed and making a dot/vertical line as a reference point for the calculations? I guess there would have to be a automated negative one period added to the number every trading day to keep the time period(date) right?

Another Daily chart label: 50 day SMA of VOLUME times Current Stock price = Number of Dollars that exchange hands that day (Rounded in millions IF POSSIBLE: Like 1.12 billion would be labeled 1,120 million.) One light and one dark Green Label for 2 different prices above X dollars and one light and one dark Red for the 2 different price below X dollars.

Finally last one how about a chart label that shows the stock PERCENT gain/loss FROM the purchase date and price TO CURRENT price. Also using 3 positive and 3 negative percent adjustable number changes. The 7 chart labels would/could be in a single continuous row. So 1 label would have the percent the stock has gained/lost from initial buy point and 3 different (shades of green) stock price numbers labels (X) percent POSITIVE apart from initial buy point and 3 different (shades of red) stock price numbers labels (X) percent NEGATIVE apart from initial buy point. This 3 positive and 3 negative adjustable percent positions/colors will be the places/used for additional buy points or stop loss orders FROM the initial buy point. If horizontal lines could be added to the chart and/or shaded to match the label colors that would be very helpful towards showing possible support/resistance at the multiple price levels. This would also have your pregame plan setup before you even buy the stock. So set it up in advance and wait for your buy limit order to trip. Then the game plan is already in place. If multiple stocks trip at once like during the first hour of trading. Your mind/psychology will stay straight and clear. Just follow the preset game plan.

I think of investing as a three headed monster.

1st Mechanical edge. (Fundamentals, Charts, Chart Indicators)

2nd Psychology of the market and yourself.

3rd Money Management. (Percent of portfolio per stock, Stop setting/changing, additional buy entry points etc.)

The above thinkscripts WILL make the Money management side a lot easier. This will help with that day to day grind of the percentage math of setting /changing stop, exiting an extended position, additional buy entry points, etc.

Also by running your portfolio off of percentages, your psychology and your mechanical edge can stay the same whether you have 10,000 or 10,000,000 to invest. Things like Percent of portfolio used per stock (50 day MA of Volume times Current Stock price = $XX million or more exchange hands per day) this size of stock is needed on the bigger portfolio size accounts (to prevent them from being trapped in the stock AS BAD in major down turns in the market), Setting Stop loss percentages, Percent OFF of MAX gains to SELL a long term hold stock. I will allow the percentage off long term hold True market leader stock price high to get BIGGER the farther away I get from my initial buy point. (This is why a trailing stop will NOT work for me on long term TRUE market leaders.) Making the percent OFF OF highs bigger as I get farther from initial buy point prevents me from getting stopped out as easy in correction/consolidation the farther away the stock gets from my initial buy point in TRUE market leading stocks that are in basing patterns. I am mainly a swing trader, but I will hold a large percentage of my initial buy of a TRUE market leader ONLY through the FULL bull cycle if possible. My TRUE shorter term swing trade ONLY stocks are sold completely different. They are sold at their PERCEIVED extreme highs like channel top break through, breaking below the 10 day MA if it has been above it for month(s), climate tops, Multiple COMBINED Charting Indicators at extremes, etc. This is the point that I PERCEIVE (True or NOT) is the start of a correction/consolidation basing patterns in that stock and/or market in general. I wait till what I PERCEIVE is the building of the bottom of the Base and buy back in use a limit buy order. Set a small percent stop lose in case my Perceived bottom pattern price is wrong. And reward the stock by buying more IF it moves upward. So money management by percentage rules means a lot to me.

Thanks in advance for your help and all you have done for the forum!

Mark
Re: Fun with ThinkScript
September 19, 2014 05:18AM
Quote
makp451
Hi Robert,

I am new to the forum and have read all of your thread. All I can say is WOW!!!! It’s very helpful. THANK YOU for your time and effort.I am using a lot of your code!

You're welcome. I'm glad you've found some of it useful.

Quote
makp451
Is there a way to add a label to a daily and weekly chart that shows the percent above/below the 50day/10week SMA ...

<paraphrase>I'd also like to add a multitude of other labels. How would I do that?<end paraphrase>

The "AddLabel" function uses the following format:

AddLabel(input 1, input 2, input 3);

where:

[input 1] determines when the label will be displayed.
    If you want the label to always be displayed then substitute "yes" for input 1.
    AddLabel(yes, input 2, input 3);

    If you only want the label to be displayed when a certain condition is met, then substitute that condition for input 1.
    AddLabel(close > high(period = "day" )[1], input 2, input 3); will only show the label when the close is above yesterday's high.
[input 2] determines what the label will display.
    AddLabel(yes, "I'm a little teapot.", input 3); will always (yes) show the message "I'm a little teapot."

    The label can display multiple bits of information by utilizing the "+" symbol. For example, if the variable PctChg were defined as today's percentage change in price then that variable could be combined with the text "Percent Change: " like so:
    AddLabel(yes, "Percent Change: " + PctChg, input 3); which may display "Percent Change: 13.6"
[input 3] determines what color the label will be.
    AddLabel(yes, high(period = "day" ), Color.LIME); will display today's high price in a LIME colored label.

    "If .. then" statements may also be used to determine the label's color based on differing conditions.
    AddLabel(yes, NetChange, if NetChange > 0 then Color.GREEN else Color.RED); will display the stock's net change in price in a green label if the change is positive and in a red label if the change is negative--assuming that the variable NetChange was previously defined as close - close(period = "day" )[1]
So...as a more realistic example, if you want to display the RSI in a label with various colors based on different conditions, then you might use code similar to this:

def RSI = RSIWilder(length = 14).RSI;

AddLabel(yes, "RSI: " + Round(RSI, 2), if RSI > 70 then Color.PINK else if RSI < 30 then Color.LIGHT_GREEN else Color.YELLOW);
Re: Fun with ThinkScript
September 19, 2014 03:18PM
Hi Robert,

Thanks for the info.

ThinkScript manual stuff needs more examples for me. I have been looking at other script for ideas on my chart labels.

I struggle with things like script structure and order of operations like input, def then addlabel.

Main question below:

Chart Label for a daily chart that shows the percent change above/below the 50day SMA.

Would percent proportion formula have to have a true/false statement in it? One formula for positive percent change and one formula for negative percent change for math formulas and green vs red color changes to work together?

If stock close price is HIGHER that SMA price (positive percent number) then True use def PositveSMA= formula.

If stock close price is LOWER that SMA price(negative percent number) then False use def NegativeSMA= formula.

What I am wondering is if negative numbers effect the multiple shades of red and need a separate formula/ addlabel?

Is there a good way/place for more examples about order of operations in the thinkscript math formulas.

Would you have some percent proportion examples?


Thanks again for the help,

Mark



Edited 1 time(s). Last edit at 09/19/2014 04:00PM by makp451.
Sorry, only registered users may post in this forum.

Click here to login