Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!

Advanced

Fun with ThinkScript

Posted by robert 
RangeFinder
January 20, 2016 11:24PM
Robert:

I recently purchased your range finder study and I prefer trading the US daily bar. Can you add a timer setting 09:30 to 16:00?

Regards,
Tom
Re: RangeFinder
January 21, 2016 08:40PM
Robert:

Adding the information below did not work to define the daily bar.


input start_time = 0930;
input end_time = 1600;

Any help is appreciated.

Regards,
Tom
Re: Fun with ThinkScript
January 22, 2016 01:15AM
robert Wrote:
-------------------------------------------------------
> > I'm looking for a way to put all optionable
> stocks that have split within the last 4 weeks
> into a watchlist on TOS.
>
>
> Create a scan using the code below then save that
> scan as a watchlist.
>
>
> plot data = geteventOffset(events.split, -1) <
> 21;
>

Hi everyone,

On page 6 this was posted. It works well, but how can I add to it in order prevent getting the 1:5 and 1:10 split info in the scan? I think that is a reverse split isn't it? How can I tell the scan to only return splits that are 2:1 or better, and not the 1:5, or 1:10 stuff? Also what does the "21" mean? Is that going back 21 days?

Thanks
R
Re: Fun with ThinkScript
January 23, 2016 02:21PM
I am needing help with creating an indicator that draws a line at the daily open. I trade on the 15min chart and would like a line showing the daily open on the 15min chart
Re: Fun with ThinkScript
January 25, 2016 02:34PM
Kamadi,

This will plot a horizontal blue dashed line at daily opening price on any time frame. You can change the color or change to solid line inside the code itself. For solid line change "DASHES" to "HORIZONTAL".

def today = GetLastDay() == GetDay();
plot OpenPrice = if !today then Double.NaN else if SecondsTillTime(0930) > 0 then Double.NaN else open(period = "day" );
OpenPrice.SetPaintingStrategy(PaintingStrategy.DASHES);
OpenPrice.SetDefaultColor(Color.BLUE);
OpenPrice.SetLineWeight(2);
Re: Fun with ThinkScript
January 25, 2016 03:28PM
Hi Tanman

Could you please help me for same type of script for
Previous day High,low and close (9:30 to 16:00) and
Globex High and Low (17:00 to 9:29:59 AM)
I want to put horizontal line for it on chart

And help would be much appreciated

Thanks in advance
Re: Fun with ThinkScript
January 25, 2016 03:34PM
input timefrom = 1000;
input pricefrom = ohlc4;
input priceto = ohlc4;
def lastbar = if isnan(close[-1]) and !isnan(close) then barnumber() else lastbar[1];
def linefrom = if getyyyyMMDD()==getyyYYMMDD() and secondsFromTime(timefrom)==0 then 1 else 0;
def lineto = if barnumber()==highestall(lastbar) then 1 else 0;
plot line = if getday()==getlastDay() then if linefrom then pricefrom else if lineto then priceto else double.nan else double.nan;
line.enableApproximation();
line.setdefaultColor(color.white);
line.setlineWeight(3);
Re: Fun with ThinkScript
January 25, 2016 08:37PM
Hi niks.baps,

I couldn't figure out how to draw Globex high separate from regular trading hours (RTH) high, and Globex low separate from RTH low when Globex range is within the RTH range. The following code will give you the high (green dashes) and the low (red dashes) of the previous entire trading day (including Globex and regular trading hours) and also the high (dark green solid), low (dark red solid) and close (blue dashes) of regular trading hours, but if Globex high is < RTH high or Globex low is > RTH low then it won't draw those lines. Change the colors to what you like within the code. To make lines thinner change SetLineWeight to 1. To change dashes to solid lines, change DASHES to HORIZONTAL or change SHORT_DASH to FIRM.

input showOnlyToday = YES;
input Market_Open_Time = 0930;
input Market_Close_Time = 1600;

def isToday = if(GetDay() == GetLastDay(), 1, 0);
def shouldPlot = if(showOnlyToday and isToday, 1, if(!showOnlyToday, 1, 0));
def pastOpen = if((SecondsTillTime(Market_Open_Time) > 0), 0, 1);
def pastClose = if((SecondsTillTime(Market_Close_Time) > 0), 0, 1);
def marketOpen = if(pastOpen and !pastClose, 1, 0);
def firstBar = if (day[1] != day, 1, 0);
def closingBell = if SecondsTillTime(Market_Close_Time)[1] > 0 and SecondsTillTime(Market_Close_Time) <= 0 or (SecondsTillTime(Market_Close_Time)[1] < SecondsTillTime(Market_Close_Time) and SecondsTillTime(Market_Close_Time)[1] > 0) then 1 else 0;

rec regHoursHigh = if(high > regHoursHigh[1] and marketOpen, high, if(marketOpen and !firstBar, regHoursHigh[1], high));
rec regHoursLow = if(low < regHoursLow[1] and marketOpen, low, if(marketOpen and regHoursLow[1] > 0 and !firstBar, regHoursLow[1], low));
rec runningClose = compoundValue(1, if closingbell then close[1] else runningClose[1], close);
rec prevClose = compoundValue(1, if closingBell then runningClose else prevClose[1], close);
rec prevHigh = compoundValue(1, if closingBell then regHoursHigh[1] else prevHigh[1], high);
rec prevLow = compoundValue(1, if closingBell then regHourslow[1] else prevlow[1], low);

plot pc = if shouldPlot then prevClose else Double.NaN;
pc.SetStyle(Curve.SHORT_DASH);
pc.SetDefaultColor(Color.BLUE);
pc.SetLineWeight(2);

plot pl = if shouldPlot then prevLow else Double.NaN;
pl.SetDefaultColor(Color.DARK_RED);
pl.SetLineWeight(2);

plot ph = if shouldPlot then prevHigh else Double.NaN;
ph.SetDefaultColor(Color.DARK_GREEN);
ph.SetLineWeight(2);

plot Yhigh = high(period = "day" )[1];
Yhigh.SetPaintingStrategy(PaintingStrategy.DASHES);
Yhigh.SetDefaultColor(Color.UPTICK);
Yhigh.SetLineWeight(2);

plot Ylow = low(period = "day" )[1];
Ylow.SetPaintingStrategy(PaintingStrategy.DASHES);
Ylow.SetDefaultColor(Color.DOWNTICK);
Ylow.SetLineWeight(2);
Advanced Alerts in TOS?
January 25, 2016 04:28PM
I've been searching various websites trying to setup advanced alerts in TOS. Basically, I have been trading the "e" system with great success but tend to visually miss some trades due to work. I called TOS support and they mentioned their is no way to setup Audio triggers in relation to the visual triggers that are setup already (green and pink on quote sheet for 30,20,10,5,3).
Re: Fun with ThinkScript
January 25, 2016 10:23PM
Hi Tanman

Thanks you so much for this script , While I import this study into TOS I got an error
I have screen shot ,also screen shot of manual drown horizontal line but now sure how to attached with post

Error
Expected Double
No such variable :day at 10:20

thanks you again for looking into it
Re: Fun with ThinkScript
January 26, 2016 01:41PM
Hi niks.bap,

Change this line in the code:

def firstBar = if (day[1] != day, 1, 0);

to

def firstBar = if(GetDay()[1] != GetDay(), 1, 0);
Re: Fun with ThinkScript
January 26, 2016 04:52PM
Hello all,

I've been reading a lot on this thread and have learned so much. Still a noob though and have a question.

If I wanted to scan for some criteria against only the first bar of the day how would I go about that?

So, for example, if I wanted to scan which stocks opened above a certain price point today how would I do that? (I know it's a dumb scan but I'm just interested in how to scan against bar 1.)
Directional Divergence Index ( DDI ) need a THINKORSWIM Script
September 05, 2014 03:52AM
Good Morning .

first of all I want to thank every one in this forum who helps or share any idea in technical analysis . it is really a fantastic place .

here I want a help to find a script for this Indicator ( DDI - Directional Divergence Index) that works on Thinkorswim. I realized that this Indicator gives signals befor MACD ibdicator . it is really great. see the Chart below:



I search for the scrip but I could not find any one works on thinkorswim program.

I found this I do not know if any one can convert it to a script for THINKORSWIM ?

Formula Name:vDDI
Formula Full Name : Directional Divergence Index
Formula Script:
TR : = MAX ( ABS (H - REF ( H , 1 ) ) , ABS ( L - REF ( L , 1 ) ) ) ;
DMZ : = IF ( ( H+L ) < = ( REF ( H,1 ) + REF ( L,1 ) ) , 0 , MAX ( ABS ( H - REF ( H , 1 ) ) , ABS ( L - REF ( L , 1 ) ) ) ) ;
DMF : = IF ( ( H+L ) > = ( REF ( H ,1 ) + REF ( L,1 ) ) , 0, MAX ( ABS ( H - REF ( H , 1 ) ) , ABS ( L - REF ( L, 1 ) ) ) ) ;
DIZ : = SUM ( DMZ , N ) / ( SUM ( DMZ , N ) + SUM ( DMF , N ) ) ;
DIF : = SUM ( DMF , N ) / ( SUM ( DMF , N ) + SUM ( DMZ , N ) ) ;
DDI : DIZ - DIF , COLORSTICK ;
ADDI : SMA ( DDI , N1 , M ) ;
AD : MA ( ADDI , M1 ) ;

I will rey to find another script if this one not clear ..


thankx
Re: Directional Divergence Index ( DDI ) need a THINKORSWIM Script
January 27, 2016 01:15AM
good day
have any one fund the Directional Divergence Index ( DDI ) if some one can help me in tradestations program or THINKORSWIM program.

Thanks
Hani
Re: Directional Divergence Index ( DDI ) need a THINKORSWIM Script
January 27, 2016 04:58AM
Quote
hanimusa
> good day
> have any one fund the Directional Divergence Index
> ( DDI ) if some one can help me in tradestations
> program or THINKORSWIM program.
> Thanks
> Hani
hanimusa, I have no idea what kind of code that DDI is written in. But, I took a try at interpreting what I think it means. I then ran it on TOS and it seems useful. BUT, I don't believe there is a way to create histogram bars for a custom study in TOS (I'm pretty sure histogram bars are limited to TOS canned studies). Best I could do is add Cloud. I have the TOS code in bold, and the old code normal. Just copy it all and load it as it is. Hope it's at least a step in the right direction.
~EDIT~ I also have no idea what the relevance of "TR" is, since it's not called again in the original code. But I included a couple of pointless defs for it anyway.
declare lower;
input span1 = 12;
input span2 = 26;
#TR : = MAX ( ABS (H - REF ( H , 1 ) ) , ABS ( L - REF ( L , 1 ) ) ) ;
def TR = absvalue(high-high[1]);
def TR2 = absvalue(low-low[1]);
#DMZ : = IF ( ( H+L ) < = ( REF ( H,1 ) + REF ( L,1 ) ) , 0 , MAX ( ABS ( H - REF #( H , 1 ) ) ,
#ABS ( L - REF ( L , 1 ) ) ) ) ;
def DMZ = if (high+low) <= (high[1]+low[1]) then 0 else absvalue(high-high[1]) and absvalue(low-low[1]);
#DMF : = IF ( ( H+L ) > = ( REF ( H ,1 ) + REF ( L,1 ) ) , 0, MAX ( ABS ( H - REF #( H , 1 ) ) ,
#ABS ( L - REF ( L, 1 ) ) ) ) ;
def DMF = if (high+low) >= (high[1]+low[1]) then 0 else absvalue(high-high[1]) and absvalue(low-low[1]);
#DIZ : = SUM ( DMZ , N ) / ( SUM ( DMZ , N ) + SUM ( DMF , N ) ) ;
def DIZ = (sum(DMZ,span1)/sum(DMZ,span2) )+ sum(DMF,span1);
#DIF : = SUM ( DMF , N ) / ( SUM ( DMF , N ) + SUM ( DMZ , N ) ) ; 
def DIF = (sum(DMF,span1)/sum(DMF,span2) )+ sum(DMZ,span1);
#DDI : DIZ - DIF , COLORSTICK ;
def DDI = DIZ-DIF;
#ADDI : SMA ( DDI , N1 , M ) ;
plot ADDI = average(DDI,span1);
#AD : MA ( ADDI , M1 ) ;
plot AD = average(ADDI,span2);
addcloud(ADDI,AD,color.plum,color.magenta);

Gamblers roll the dice; Traders load the dice.



Edited 2 time(s). Last edit at 01/27/2016 05:15AM by baffled1.
Re: Fun with ThinkScript
January 27, 2016 02:23PM
Tanman

thank you so much for the code. I really appreciate the work you do. I have one more request. I am new to coding with thinkscript. I would like a code that does the following

Price color changes to Red when these conditions are met: Price is below 18 ema, 3ema crosses below 6ema, and MacD 6-18-9 histogram cross below zero as well as rsi 14 crosses below 50

Price changes blue when: Price above 18ema, 3ema crosses above 6ema, MacD 6-18-9 histogram crosses above zero, and rsi above 50

If neither is true then the rest is colored grey

Also if you can turn it into a scannable script as well will be nice
Re: Fun with ThinkScript
January 27, 2016 07:26PM
Kamadi,

Here is the script. What exactly do you want to scan for? Do you want to scan for all stocks in which current daily bar just changed in color? Otherwise if you just scan for stocks in uptrend versus stocks in downtrend then you will also get those stocks which are in an extended trend already. I played around a bit and noticed that when color changes from gray or red to blue after a red trend and gray or blue to red after a blue trend, you can trade at close and next day or in few days there is high percentage of move in same color direction!

def EMA3 = ExpAverage(close, 3);
def EMA6 = ExpAverage(close, 6);
def EMA18 = ExpAverage(close, 18);
def Diff = MACD(6, 18, 9, AverageType.EXPONENTIAL).Diff;
def NetChgAvg = MovingAverage(AverageType.WILDERS, close - close[1], 14);
def TotChgAvg = MovingAverage(AverageType.WILDERS, AbsValue(close - close[1]), 14);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def Above18EMA = close > EMA18;
def Below18EMA = close < EMA18;
def EMAAbove = EMA3 > EMA6;
def EMABelow = EMA3 < EMA6;
def DiffAbove = Diff > 0;
def DiffBelow = Diff < 0;
def RSIAbove = RSI > 50;
def RSIBelow = RSI < 50;
def UP = Above18EMA and EMAAbove and DiffAbove and RSIAbove;
def DN = Below18EMA and EMABelow and DiffBelow and RSIBelow;

assignpricecolor(if UP then color.BLUE else if DN then color.RED else color.GRAY);



Edited 2 time(s). Last edit at 01/27/2016 07:31PM by tanman.
Re: Fun with ThinkScript
January 27, 2016 10:40PM
Thank you so much Tanman for the script spinning smiley sticking its tongue out
Re: Fun with ThinkScript
January 28, 2016 02:38AM
Tanman,

You are Incredible!!!!!!!!!!!!!!!!!!! I really appreciate the time you took to create that script for me. and yes I would like a scan that shows all stocks that have just changed colors
Re: Fun with ThinkScript
January 28, 2016 01:51PM
Kamadi and niks.baps, You are welcome!

Kamadi,

Here are the scan scripts. The first script is for change of color to blue and second scan is for change of color to red. Add them separately as 2 different scans, because each scan script can have only one plot line.

# scan for uptrend
def EMA3 = ExpAverage(close, 3);
def EMA6 = ExpAverage(close, 6);
def EMA18 = ExpAverage(close, 18);
def Diff = MACD(6, 18, 9, AverageType.EXPONENTIAL).Diff;
def NetChgAvg = MovingAverage(AverageType.WILDERS, close - close[1], 14);
def TotChgAvg = MovingAverage(AverageType.WILDERS, AbsValue(close - close[1]), 14);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def Above18EMA = close > EMA18;
def Below18EMA = close < EMA18;
def EMAAbove = EMA3 > EMA6;
def EMABelow = EMA3 < EMA6;
def DiffAbove = Diff > 0;
def DiffBelow = Diff < 0;
def RSIAbove = RSI > 50;
def RSIBelow = RSI < 50;
def UP = Above18EMA and EMAAbove and DiffAbove and RSIAbove;

plot result = !UP[1] and UP;



# scan for downtrend
def EMA3 = ExpAverage(close, 3);
def EMA6 = ExpAverage(close, 6);
def EMA18 = ExpAverage(close, 18);
def Diff = MACD(6, 18, 9, AverageType.EXPONENTIAL).Diff;
def NetChgAvg = MovingAverage(AverageType.WILDERS, close - close[1], 14);
def TotChgAvg = MovingAverage(AverageType.WILDERS, AbsValue(close - close[1]), 14);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def Above18EMA = close > EMA18;
def Below18EMA = close < EMA18;
def EMAAbove = EMA3 > EMA6;
def EMABelow = EMA3 < EMA6;
def DiffAbove = Diff > 0;
def DiffBelow = Diff < 0;
def RSIAbove = RSI > 50;
def RSIBelow = RSI < 50;
def DN = Below18EMA and EMABelow and DiffBelow and RSIBelow;

plot result = !DN[1] and DN;
Re: Fun with ThinkScript
January 28, 2016 01:52PM
Kamadi,

I'm still learning thinkscript but you can add the below code to the bottom and it would work as a scan

def gray = if up[1] or dn[1] then 0 else 1;

plot scan = if up or dn and gray then 1 else 0;
Re: Fun with ThinkScript
January 28, 2016 01:53PM
haha nevermind lol we posted at same time and his is waaaaaayyyyy better than mine
Re: Fun with ThinkScript
January 28, 2016 03:23PM
TANMAN is an incredible coder. hot smiley

Gamblers roll the dice; Traders load the dice.
Re: Fun with ThinkScript
January 28, 2016 05:42PM
Thanks baffled1 and brazilianpillar! I learned everything from ROBERT and he is 100 times better. Robert is the grandmaster of thinkscript and an amazing day trader! Wonder what happened to him and how he is doing.
Re: Fun with ThinkScript
January 28, 2016 11:46PM
Hello all and thanks to all who have contributed via scripts and information in this forum. I just decided last week to try my hand in trading. I play around in investopedia and have done ok and decided last Thursday to open a thinkorswim account. I have literally spent all possible hours I have outside of my day job to research and study. I ordered a couple of books I am reading and have watched countless hours of online videos.

With all that being said, I always find most of my searches coming back to this very forum. I have tried so many chart setups and countless indicators on my paper money account in thinkorswim and at this point I am vastly overwhelmed. At this point I am only interested in starting out with options / all symbols / 1-3 dollar stocks.

Before giving up on reading this, please understand I am not here to steal others time and money they put into learning. I am and will do the same thing. What I am looking for is suggestions on best setups or at least a starting point. I will explain what I am doing so far below.

For scans I have dozans but came acorss this one tonight and will try in the morning

From Tanman

# scan for uptrend
def EMA3 = ExpAverage(close, 3);
def EMA6 = ExpAverage(close, 6);
def EMA18 = ExpAverage(close, 18);
def Diff = MACD(6, 18, 9, AverageType.EXPONENTIAL).Diff;
def NetChgAvg = MovingAverage(AverageType.WILDERS, close - close[1], 14);
def TotChgAvg = MovingAverage(AverageType.WILDERS, AbsValue(close - close[1]), 14);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def Above18EMA = close > EMA18;
def Below18EMA = close < EMA18;
def EMAAbove = EMA3 > EMA6;
def EMABelow = EMA3 < EMA6;
def DiffAbove = Diff > 0;
def DiffBelow = Diff < 0;
def RSIAbove = RSI > 50;
def RSIBelow = RSI < 50;
def UP = Above18EMA and EMAAbove and DiffAbove and RSIAbove;

plot result = !UP[1] and UP;



# scan for downtrend
def EMA3 = ExpAverage(close, 3);
def EMA6 = ExpAverage(close, 6);
def EMA18 = ExpAverage(close, 18);
def Diff = MACD(6, 18, 9, AverageType.EXPONENTIAL).Diff;
def NetChgAvg = MovingAverage(AverageType.WILDERS, close - close[1], 14);
def TotChgAvg = MovingAverage(AverageType.WILDERS, AbsValue(close - close[1]), 14);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def Above18EMA = close > EMA18;
def Below18EMA = close < EMA18;
def EMAAbove = EMA3 > EMA6;
def EMABelow = EMA3 < EMA6;
def DiffAbove = Diff > 0;
def DiffBelow = Diff < 0;
def RSIAbove = RSI > 50;
def RSIBelow = RSI < 50;
def DN = Below18EMA and EMABelow and DiffBelow and RSIBelow;

plot result = !DN[1] and DN;



I am currently using the below studies

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

I have 4 charts setup for the below with the Intraday 20 day custom 55 / 34 / 21 / 13

The Edge

#The Edge
#Robert Payne

#Plot 8 period moving average
plot MA8 = Average(close, 8);
MA8.SetDefaultColor(Color.YELLOW);
MA8.SetLineWeight(2);

#Trend Signal
def TrendUp = if close > MA8 then 1 else Double.NaN;
def TrendDn = if close < MA8 then 1 else Double.NaN;
AddLabel(TrendUp, "UP", Color.GREEN);
AddLabel(TrendDn, "DN", Color.RED);

#Net Signal
def NSup = if close - close(period = "day" )[1] > 0 then 1 else Double.NaN;
def NSdn = if close - close(period = "day" )[1] <= 0 then 1 else Double.NaN;
AddLabel(NSup, "NS", Color.GREEN);
AddLabel(NSdn, "NS", Color.RED);

#Open Signal
def OSup = if close - open(period = "day" ) > 0 then 1 else Double.NaN;
def OSdn = if close - open(period = "day" ) < 0 then 1 else Double.NaN;
AddLabel(OSup, "OS", Color.GREEN);
AddLabel(OSdn, "OS", Color.RED);

#High / Low Signal
def Higher = if close > high(period = "day" )[1] then 1 else Double.NaN;
def Lower = if close < low(period = "day" )[1] then 1 else Double.NaN;
def Neutral = if close <= high(period="day" )[1] and close >= low(period="day" )[1] then 1 else Double.NaN;
AddLabel(Higher, "H/L", Color.GREEN);
AddLabel(Lower, "H/L", Color.RED);
AddLabel(Neutral, "H/L", Color.GRAY);

#Out of Bounds
def sDev = StDev(close, 21);
def MidLine = Average(close, 21);
def UpperBand = MidLine + 2 * sDev;
def LowerBand = MidLine - 2 * sDev;
def CloseAbove = if close > UpperBand then 1 else Double.NaN;
def CloseBelow = if close < LowerBand then 1 else Double.NaN;
AddLabel(CloseAbove, round(close - UpperBand,2), Color.WHITE);
AddLabel(CloseBelow, round(close - LowerBand,2), Color.WHITE);


----------------------------------------AND-----------------------------------------------

Break Points

declare upper;
input price = close;
input displace = 0;

input EMALength1 = 9;
input EMALength2 = 39;

plot upper = ExpAverage(data = price[-displace], length = EMALength1);
upper.SetDefaultColor(Color.RED);
plot lower = ExpAverage(data = price[-displace], length = EMALength2);
lower.SetDefaultColor(Color.BLUE);
AddCloud(upper,lower);

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

For the 5th chart I have it set at Intraday 20 day 5 min that includes the below studies.


# SJ_ADX_DMI_TrendStrengthLabels
#
# Directional Movement System measures the ability of bulls and 
# bears to move price outside the previous day's trading range.

declare upper;

input length = 14;

def hiDiff = high - high[1];
def loDiff = low[1] - low;

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 ATR = WildersAverage(TrueRange(high, close, low), length);
def "DI+" = 100 * WildersAverage(plusDM, length) / ATR;
def "DI-" = 100 * WildersAverage(minusDM, length) / ATR;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-"winking smiley / ("DI+" + "DI-"winking smiley else 0;
def ADX = WildersAverage(DX, length);
#
# ============================================================
# TREND DIRECTION
# ============================================================ 
# Bullish Trend
def BullishCondition =  "DI+" > "DI-"; 
# Bearish Trend
def BearishCondition =  "DI-" > "DI+";
# ============================================================
# TREND STRENGTH
# ============================================================ 
# Range Bound & No Trend
def ConditionA = ADX > 0 && ADX < 20;
# Absent or Weak Trend
def ConditionB = ADX > 20 && ADX < 25;
# Strong Trend
def ConditionC = ADX > 25 && ADX < 50;
# Very Strong Trend
def ConditionD = ADX > 50 && ADX < 75;
# Extremely Strong Trend
def ConditionE = ADX > 75 && ADX < 100;
# ============================================================ 
# ************************************************************
# addChartLabel(visible, value, textLabel, color)
AddLabel(yes, Concat( ADX,  Concat(
if ConditionA then " Range Bound " else 
if ConditionB then " Weak " else 
if ConditionC then " Strong " else 
if ConditionD then " Very Strong " else 
if ConditionE then " Extremely Strong " else 
" No Strength ", 
if BullishCondition then "Bullish Trend" else 
if BearishCondition then "Bearish Trend" else 
"& No Trend"winking smiley),  
if ConditionA && BullishCondition then Color.LIME else 
if ConditionA && BearishCondition then Color.MAGENTA else
if ConditionB && BullishCondition then Color.LIGHT_GREEN else 
if ConditionB && BearishCondition then Color.PINK else
if ConditionC && BullishCondition then Color.GREEN else 
if ConditionC && BearishCondition then Color.RED else
if ConditionD && BullishCondition then Color.DARK_GREEN else 
if ConditionD && BearishCondition then Color.DARK_RED else
if ConditionE && BullishCondition then Color.YELLOW else 
if ConditionE && BearishCondition then Color.PLUM else
Color.WHITE);

plot null = Double.NaN;



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

Momentum

# macd
def Value = MACD(2, 5, 2, "EMA" ).Value;
def Avg = MACD(2, 5, 2, "EMA" ).Avg;
def MACDup = Value > Avg;
def MACDdn = Value <= Avg;

# 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 = MACDup and SlowDup and CCIup and MFIup and RMIos;
signalUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signalUP.SetLineWeight(3);
signalUP.SetDefaultColor(Color.LIGHT_GREEN);
plot signalDN = MACDdn and SlowDdn and CCIdn and MFIdn and RMIob;
signalDN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signalDN.SetLineWeight(3);
signalDN.SetDefaultColor(Color.PINK);

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

ECharts V3

# E-Charts v3

declare upper;
input short_average = 5;
input medium_average = 10;
input long_average = 20;
input average_type = {default "SMA", "EMA"};
input showArrows = yes;

def MA1;
def MA2;
def MA3;
switch (average_type) {
case "SMA":
MA1 = Average(close, short_average);
MA2 = Average(close, medium_average);
MA3 = Average(close, long_average);
case "EMA":
MA1 = ExpAverage(close, short_average);
MA2 = ExpAverage(close, medium_average);
MA3 = ExpAverage(close, long_average);
}

# define e-signal and crossover point
def Eup = MA1 > MA2 && MA2 > MA3;
def Edn = MA1 < MA2 && MA2 < MA3;

def CrossUp = close > MA1 && Eup && !Eup[1];
def CrossDn = close < MA1 && Edn && !Edn[1];

# Define up and down signals
def higherHigh = close > Highest(Max(open, close), 3)[1];
def lowerLow = close < Lowest(Min(open, close), 3)[1];
def SignalUp = if (CrossUp && higherHigh)
then 1
else if (CrossUp[1] && higherHigh && !higherHigh[1])
then 1
else if (CrossUp[2] && higherHigh && !higherHigh[1] && !higherHigh[2])
then 1
else Double.NaN;
def SignalDn = if (CrossDn && lowerLow)
then 1
else if (CrossDn[1] && lowerLow && !lowerLow[1])
then 1
else if (CrossDn[2] && lowerLow && !lowerLow[1] && !lowerLow[2])
then 1
else Double.NaN;

# Plot the moving average lines
plot ln1 = MA1;
ln1.SetDefaultColor(CreateColor(145, 210, 144));
ln1.SetLineWeight(2);
plot ln2 = MA2;
ln2.SetDefaultColor(CreateColor(111, 183, 214));
ln2.SetLineWeight(2);
plot ln3 = MA3;
ln3.SetDefaultColor(CreateColor(249, 140, 182));
ln3.SetLineWeight(2);

# Show an arrow
plot ArrowUp = if SignalUp and showArrows then low * 0.997 else Double.NaN;
ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowUp.SetLineWeight(4);
ArrowUp.SetDefaultColor(Color.YELLOW);
plot ArrowDn = if SignalDn and showArrows then high * 1.003 else Double.NaN;
ArrowDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowDn.SetLineWeight(4);
ArrowDn.SetDefaultColor(Color.CYAN);

# Add label for Eup or Edn
AddLabel(Eup, "E Up", CreateColor(134, 202, 93));
AddLabel(Edn, "E Dn", CreateColor(232, 148, 157));

# Calculate Meter Values
def sl1 = ma1 > ma1[1];
def sl2 = ma2 > ma2[1];
def sl3 = ma3 > ma3[1];
def p1 = close > ma1;
def p2 = close > ma2;
def p3 = close > ma3;
def u1 = 2 * (close > open);
def u2 = 2 * (close > high[1]);
def d1 = 2 * (close < open);
def d2 = 2 * (close < low[1]);

def UPstr = sl1 + sl2 + sl3 + p1 + p2 + p3 + u1 + u2;
def DNstr = !sl1 + !sl2 + !sl3 + !p1 +!p2 + !p3 + d1 + d2;

# Add Strength Meter
AddLabel(Eup or Edn, " ", if Eup and UPstr >= 3 then CreateColor(128, 199, 94) else if Edn and DNstr >= 3 then CreateColor(232, 143, 153) else CreateColor(177,177,166));
AddLabel(Eup or Edn, " ", if Eup and UPstr >= 6 then CreateColor(99, 197, 72) else if Edn and DNstr >= 6 then CreateColor(238, 123, 136) else CreateColor(177,177,166));
AddLabel(Eup or Edn, " ", if Eup and UPstr >= 8 then CreateColor(65, 195, 50) else if Edn and DNstr >= 8 then CreateColor(245, 101, 117) else CreateColor(177,177,166));
AddLabel(Eup or Edn, " ", if Eup and UPstr == 10 then CreateColor(41, 192, 36) else if Edn and DNstr == 10 then CreateColor(249, 81, 101) else CreateColor(177,177,166));


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

I guess the biggest question I have is do I have to many indicators setup, am I trying to over analyze the stocks?

I know even with indicators, it is still a semi guessing game and nothing is guaranteed but is there one of the above or another indicator that should be my starting point and whatever it is, what is the best way to read it. I watched so many videos and so many people have different styles I can not figure out the best one. I know it will end up being whatever style I feel most comfortable with but without a starting point, I cant even make that decision.

My ultimate goal is to start out with trading small stocks and build momentum from there, it will take me months if not a couple of years. I know there are paid for sites out there with forums and people that give advice but they are all so sketchy. People have started out like me so I know it is possible, I just need to find the right group and keep educating myself.


I would be grateful for any help from anyone.

FYI, if I have not included the proper thanks to the individuals from the scripts above that might be outside this forum, please let me know, I have visited so many sites over the last week and have just thrown in scripts without keeping track of where I got them.



Edited 1 time(s). Last edit at 01/28/2016 11:50PM by bughatti.
Re: Fun with ThinkScript
January 29, 2016 01:58AM
Quote
bughatti
...What I am looking for is
> suggestions on best setups or at least a starting
> point...
> I guess the biggest question I have is do I have
> to many indicators setup, am I trying to over
> analyze the stocks?...
> I know even with indicators, it is still a semi
> guessing game and nothing is guaranteed but is
> there one of the above or another indicator that
> should be my starting point and whatever it is,
> what is the best way to read it....
bughatti, you've come to the right place, as there are many expert options traders here. I hope they'll share with you. I'm not an expert in that area, but I traded options (Long only) during a most difficult period, 2008-2009. So here's my two cents. Yes, that's too many indicators. As you know- and it's easy to forget- there are only three things important to trading options: Timing, Direction, and Speed. Speed translates as beta, or volatility. Time decay (theta) can be readily forecasted and, though it's important, if you get TDS right, then theta's irrelevant. I don't know which combination of your studies is best for realizing TDS but you sound diligent so I know you'll figure it out.

Once you're ahead of the game some, you might consider "gambling" a LITTLE of your surplus on what I call "sleepers", which can explode at perfectly unreasonable multiples without warning. I say this because sooner or later you'll notice them and maybe try them yourself but the key is to set a take-profit at some reasonable level because the moves happen really fast. Just for example, treasury ETFs like TLT and IEF can do this on contracts a bit out of the money. But as I say, it's risky almost "gambling". A strangle on them just before an auction might be good, or just before a Fed rate decision (hahaha) grinning smiley could work, but only in terms of forecasting high beta, not direction.

Good luck to you.

Gamblers roll the dice; Traders load the dice.
Re: Directional Divergence Index ( DDI ) need a THINKORSWIM Script
January 29, 2016 04:18PM
baffled1 Wrote:
-------------------------------------------------------
> > > good day
> > have any one fund the Directional Divergence
> Index
> > ( DDI ) if some one can help me in
> tradestations
> > program or THINKORSWIM program.
> > Thanks
> > Hani
>
> hanimusa, I have no idea what kind of code that
> DDI is written in. But, I took a try at
> interpreting what I think it means. I then ran it
> on TOS and it seems useful. BUT, I don't believe
> there is a way to create histogram bars for a
> custom study in TOS (I'm pretty sure histogram
> bars are limited to TOS canned studies). Best I
> could do is add Cloud. I have the TOS code in
> bold, and the old code normal. Just copy it all
> and load it as it is. Hope it's at least a step in
> the right direction.
> ~EDIT~ I also have no idea what the relevance of
> "TR" is, since it's not called again in the
> original code. But I included a couple of
> pointless defs for it anyway.
>
> declare lower;
> input span1 = 12;
> input span2 = 26;
> #TR : = MAX ( ABS (H - REF ( H , 1 ) ) , ABS ( L -
> REF ( L , 1 ) ) ) ;
> def TR = absvalue(high-high[1]);
> def TR2 = absvalue(low-low[1]);
> #DMZ : = IF ( ( H+L ) < = ( REF ( H,1 ) + REF (
> L,1 ) ) , 0 , MAX ( ABS ( H - REF #( H , 1 ) ) ,
> #ABS ( L - REF ( L , 1 ) ) ) ) ;
> def DMZ = if (high+low) <= (high[1]+low[1]) then 0
> else absvalue(high-high[1]) and
> absvalue(low-low[1]);
> #DMF : = IF ( ( H+L ) > = ( REF ( H ,1 ) + REF (
> L,1 ) ) , 0, MAX ( ABS ( H - REF #( H , 1 ) ) ,
> #ABS ( L - REF ( L, 1 ) ) ) ) ;
> def DMF = if (high+low) >= (high[1]+low[1]) then 0
> else absvalue(high-high[1]) and
> absvalue(low-low[1]);
> #DIZ : = SUM ( DMZ , N ) / ( SUM ( DMZ , N ) + SUM
> ( DMF , N ) ) ;
> def DIZ = (sum(DMZ,span1)/sum(DMZ,span2) )+
> sum(DMF,span1);
> #DIF : = SUM ( DMF , N ) / ( SUM ( DMF , N ) + SUM
> ( DMZ , N ) ) ;
> def DIF = (sum(DMF,span1)/sum(DMF,span2) )+
> sum(DMZ,span1);
> #DDI : DIZ - DIF , COLORSTICK ;
> def DDI = DIZ-DIF;
> #ADDI : SMA ( DDI , N1 , M ) ;
> plot ADDI = average(DDI,span1);
> #AD : MA ( ADDI , M1 ) ;
> plot AD = average(ADDI,span2);
> addcloud(ADDI,AD,color.plum,color.magenta);
>



Thanks a lot baffled1 for yor reply and help

Directional Divergence Index ( DDI ) looks like MACD, but the difference between MACD AND DDI IS
MACD 26,12,9

DDI has 4 periods
period 13
period 30
period 10
period 5

kindly look to the pic



so could you please help me with the formela for DDI

Hani
Re: Directional Divergence Index ( DDI ) need a THINKORSWIM Script
January 29, 2016 06:48PM
Quote
hanimusa
> Thanks a lot baffled1 for yor reply and help

> Directional Divergence Index ( DDI ) looks like
> MACD, but the difference between MACD AND DDI IS
> MACD 26,12,9
>
> DDI has 4 periods
> period 13
> period 30
> period 10
> period 5
>
> kindly look to the pic
> [www.google.com]
_KAhVEuBQKHYXVCp8QjRwIBw&url=http%3A%2F%2Fwww.researchtrade.com%2Fforum%2Fread.php%3F7%2C3877&psig=AFQjCNG7Pb0ZKt3LLzlCgSlY3E2DL-wBcQ&ust=1454186789689981
so could you please help me with the formela for DDI
Hani
Hanimusa, glad I could help a little. There's no pic (and it might not help that much anyway). I have been unable to find a clear description of DDI anyplace, so it's very hard to code what I don't understand. Your description helps but it's still not perfectly clear. Are those "periods" EMAs? Which ones to subtract from which ones? Is only one of them the signal line? If you can clarify these points I'm sure this code can be written (even by an amateur like me). This link explains how MACD is set up so you see what I mean
http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:moving_average_convergence_divergence_macd
We're getting there, I think!

Gamblers roll the dice; Traders load the dice.
Re: Fun with ThinkScript
January 29, 2016 08:45PM
bughatti,

This post is a bit off-topic but I think it is extremely important for someone who has just started to learn how to trade equities. I would STRONGLY recommend not to trade options. I have been there and done that. After years of reading 20+ books on options, attending seminars, watching videos etc. and practical option trading experience and losing thousands of dollars in option trading, I have learned this the hard way.

By now I think I am a master at options and I still won't consider trading options except maybe 2 strategies. One of those strategies (delta 5 naked strangle, which Karen the super trader used to make $40 million from $800,000 in a few years) requires a lot of money to be successfully employed (at least $150,000 so you can get a portfolio margin account). Karen started with $100,000 and slowly built it up and then exploded once her friends let her manage a combined account of $800,000. That strategy can be very safe (with 95% odds in your favor) if you know what you are doing and are a master at adjusting your position if the trade turns against you and with proper money management (including getting out with a small loss at the right time). Risk to reward ratio is very bad (5% of the time you can lose big bucks), but this can be overcome with trade adjustment and proper money management.

The other strategy is a calendar spread put on 3-4 weeks before earnings of selected stocks and getting out a week before earnings or earlier if target profit percentage hit, because the increase in volatility in that time period occurs with almost 100% certainty. Both Volatility or Vega and Time or Theta are in your favor and can even overcome Delta! Gamma is not that important because you never hold until expiration. You have to know which stocks are good candidates (with almost EKG like rhythmic and large implied volatility waves and with heavily traded weekly options) and have to be very careful about which expiration date to sell (the expiration right before earnings), which one to buy (the expiration right after earnings), the proper strike price based on short term technical analysis, never holding till expiration, ALWAYS getting out before earnings, and how to adjust the position if trade starts going against you. This strategy when used properly can have a very high percentage win rate and good risk to reward ratio.

Other option strategies including iron condors, credit spreads, debit spreads, strangles, straddles, butterflies and regular call or put buying can be EXTREMELY dangerous. As baffled1 has VERY APTLY stated, you have to be right in TIME, DIRECTION and SPEED in order to win at regular call and put buying, debit spreads and buying butterflies, which is almost impossible to accomplish. Another factor is VOLATILITY or VEGA. You can be right about TIME (Theta), DIRECTION (Delta) and SPEED (Gamma), and STILL LOSE if VEGA goes against you. VEGA is one of the most important characteristic of options about which most option traders are COMPLETELY clueless, and most of the time it is not predictable (except in the magic 4-8 weeks before earnings which gives calendar spreads in that time an edge). This is why 90% of regular call and put buyers lose.

There are other insurmountable problems with options also. The deck is stacked against you because of the high bid/ask spread. You are losing a large percentage of your trade size (could be hundreds of dollars) immediately after entering a position and then have an uphill struggle just to overcome that bid/ask spread disadvantage.

It is also very difficult to set up an exact stop loss point. Conditional stop loss orders based on price of underlying unfortunately do not take Theta, Vega and Gamma into account.

Even if you are right about every other thing, the wrong Delta of an option can turn the trade into a loss sometimes. In one of my previous posts on this forum, I practically demonstrated how selecting the right delta can amplify the win percent by 5 times sometimes and vice versa a wrong delta can be disastrous. This is because of the S shaped delta curve of options which most option traders are clueless about:

[sfb649.wiwi.hu-berlin.de]

I would urge you to consider learning how to trade stocks or futures instead, in which a consistently winning trading strategy with an edge can be successfully employed, overcoming the odds stacked against you, by entering only in low probability risk positions (inevitable consequence of human psychology of traders). You will need a bit more money but start saving right away to build up the trading nest egg, while you learn the intricacies of trading. The usual learning curve of equity trading is about 2 years and requires a lot of hard work, dedication, determination and the right mindset. Always have a written trading plan, master all aspects of money management, have an iron discipline, and learn to overcome your emotions of fear, greed and gut feelings. The holy grail of trading is Patience, Discipline and Money Management ........ and staying away from options and also Forex! No offense to Forex traders spinning smiley sticking its tongue out
Re: Fun with ThinkScript
January 29, 2016 11:15PM
Baffled1 & Tanman,thanks for the kind words. As I do not want to saturate this thread outside of its purpose, I will start a new thread and hope I can continue to get inputs.

continued thread
[www.researchtrade.com]
Sorry, only registered users may post in this forum.

Click here to login