Tuesday, June 2, 2009

Code example for referencing TOS studies for a readers email

A reader wrote in and asked a question. I'm not sure if I understood exactly what my reader wanted to do but here is one example of leveraging TOS studies.

Reference SimpleMovingAvg(length=21). That would return the SMA value for that bar. If the SMA(21) was less than the close of that bar it would print a point at the specified value.

insideBar.setHiding( if(close > reference SimpleMovingAvg(length=21),1,0));

So if(close > reference SimpleMovingAvg(length=21),1,0)) says that if close > SMA(21) then return true, else return false. Return value true activates the Hide function, return value 0 does not activate it.

(Thanks for the email. I hope you don't mind me sharing a portion of it so all can learn. Best regards, Freethinkscript).

input offset = 1 ;
plot InsideBar = if close < close[1] then high + offset else double.NaN;

insideBar.setHiding( if(close > reference SimpleMovingAvg(length=21),1,0));

Dr. Martin Zweig's Breadth Thrust indicator for Free

Developed by Dr. Martin Zweig, the Breadth Thrust Indicator measures market momentum. The Breadth Thrust is calculated by dividing a 10-day exponential moving average of the number of advancing issues, by the number of advancing plus declining issues.

A "Breadth Thrust" occurs when, during a 10-day period, the Breadth Thrust indicator rises from below 40% to above 61.5%. A "Thrust" indicates that the stock market has rapidly changed from an oversold condition to one of strength, but has not yet become overbought. According to Dr. Zweig, there have only been fourteen Breadth Thrusts since 1945. The average gain following these fourteen Thrusts was 24.6% in an average time-frame of eleven months. Dr. Zweig also points out that most bull markets begin with a Breadth Thrust.

A weekly chart is best for this indicator.

declare lower;

plot zw = ExpAverage(data = close("$advn"), length = 10 ) /( ExpAverage(data=close("$advn"), length=10) + ExpAverage(data=close("$decn"), length = 10));
plot forty = 0.40;
plot sixfifteen = 0.615;

ADX, DMI, MACD tri-indicator for one low price - FREE

Many times a combination of indicators can shead more light on price movement. Try this combination and see how you like it. Change the input value invertNegMACD = Yes to see a more visual picture of MACD.

You can see ADX is colored White, and also ADX Average is colored Yellow. DMI(positive) is Green, DMI(Negative) is Red, and MACD is painted as a Histogram.

declare lower;
input MACDfastLen = 10;
input MACDslowLen = 30;
input MACDLen = 10;
input showADX_DMI = { "No", default "Yes"};
input showMACD = { "No", default "Yes"};
input invertNegMACD = { "Yes", default "No"};
input MACDHeight = 50;
input MACDWidth = 3;
input ADX_Avg = 3;
input DMI_Len = 9;

def fastAvg = Ema2(data = close, "smoothing factor" = 2 / (1 + MACDfastLen));
def slowAvg = Ema2(data = close, "smoothing factor" = 2 / (1 + MACDslowLen));
def Value = fastAvg - slowAvg;
def nextAvg = ExpAverage(data = Value, MACDLen);
def HistoBar = value - nextAvg[1];
def HiScale = HighestAll(HistoBar);
def LoScale = AbsValue(LowestAll(HistoBar));
def BarScale = if HiScale > LoScale then HiScale else LoScale;

plot macd_plot = if (showMACD, if( invertNegMACD, if ( HistoBar < 0,( -1 * HistoBar * MACDHeight / BarScale ),( HistoBar * MACDHeight / BarScale )),HistoBar * MACDHeight / BarScale), double.nan);

macd_plot.AssignValueColor(if invertNegMACD then if HistoBar >= 0 then Color.Cyan else Color.Magenta else Color.Cyan);

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), DMI_Len);
plot "DI+" =
if showADX_DMI then 100 * WildersAverage(plusDM, DMI_Len) / ATR
else double.nan;
plot "DI-" =
if showADX_DMI then 100 * WildersAverage(minusDM, DMI_Len) / ATR
else double.nan;
def DX =
if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-")
else 0;
plot ADX = if showADX_DMI then WildersAverage(DX, DMI_Len) else double.nan;
plot ADXAvg = if showADX_DMI then ExpAverage(ADX, ADX_Avg) else double.nan;


Monday, June 1, 2009

Keeping an eye on Volume Weighted MACD

MACD measures the difference between two Exponential Moving Averages (EMAs). A positive MACD indicates that the 12-day EMA is trading above the 26-day EMA. On the other hand, a negative MACD indicates that the 12-day EMA is trading below the 26-day EMA. Basically, when the MACD is above the 0 line, it is indicating that the momentum is bullish. When the MACD is negative however, it is indicating that the momentum is bearish.

When the 12 days moving average crosses the 26 day moving average, you should watch the next price movements very carefully as it tends to signal a trend reversal. If the 12 days MA crosses above the 26 days MA, it’s a bullish signal. On the flip side, if the 12 days MA crosses below the 26 das MA, it’s a bearish signal.

This is a good indicator to watch while markets are moving like they are now.

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;

def fastAvg = sum(data = (close * volume), length = fastLength)/sum(data = volume, length = fastLength);

def slowAvg = sum(data = (close * volume), length = slowLength)/sum(data = volume, length = slowLength);

plot Value = fastAvg - slowAvg;
plot Avg = ExpAverage(data = Value, length = MACDLength);

plot baseline = 0;
plot diff = value - avg;
diff.AssignValueColor (if diff >= 0 then Color.UPTICK else Color.DOWNTICK);


(can also be found in default studies)

Friday, May 29, 2009

Bull-Bear Magic plain and simple.

Apply The Ketler Channel Study to you chart with this magic. If you're a Bear watch for the red lower dashed line to cross the KC midline for a sell(in some cases you must visually project the KC midline when price action is moving quickly), exit your short when the red dashed line crosses the KC lower band.

If you're a Bully do the opposite with the upper dashed line. Enjoy.

input tolerance = 1.5;
input Length = 15;
input coeff = 2.5;
input hideLines = {Hide_Hi, Hide_Lo, Hide_Both, default Hide_None};

def h_hi;
def h_lo;
case Hide_Hi:
h_hi = 1; h_lo = 0;
case Hide_Lo:
h_hi = 0; h_lo = 1;
case Hide_Both:
h_hi = 1; h_lo = 1;
h_hi = 0; h_lo = 0;
def hi_Avg = sum(if(high > high[1],high - high[1],0), Length) / sum(if(high > high[1],1,0), Length);
def hi_line = high[1] + (hi_Avg[1] * coeff);
def hi_max = Min(Min(hi_line, hi_line[1]), hi_line[2]);
plot hi_plot = hi_max;

def lo_Avg = sum(if(low < low[1],low[1] - low,0), Length) / sum(if(low < low[1],1,0), Length);
def lo_line = low[1] - (lo_Avg[1] * coeff);
def lo_max = Max(Max(lo_line, lo_line[1]), lo_line[2]);
plot lo_plot = lo_max;

plot magic = if( (hi_max-lo_max) <= tolerance, hi_max,double.nan);

Thursday, May 28, 2009

Timing is everything, end false signals.

A reader, Bryan wrote in last week with a common complaint about MA's.

"I want to find the best time to enter and exit an order. EMA's are great but so many times a fast line will cross a slow line but then turn right around and un-cross. I want a way to keep from entering and exiting orders to often. It seems like
whenever the fast EMA crosses the slow EMA AND a certain amount of time passes the combination of those 3 events signals a longer term trend. When I say "long" I
mean like half a day for day trading"

Here's a study for you. The indicator stays 'red' after the Moving Averages cross. When it turns green you are in the safe zone. This is great for true mechanical systems to make sure you don't enter and exit on false signals.

input price = close;
input Shorter_Time = 10;
input Longer_Time = 21;

Def difference = average(data = price[1], length = Longer_Time) - average(data = price[1], length = Shorter_Time);

plot timer=price[1];
timer.AssignValueColor(if difference <0 then
if difference >= 0 then

Wednesday, May 27, 2009

Today is a Free Day at EminiAddict.com. Get the webinar for free!

You know I like Free-dom. Here is a great Webinar freebee at EminiAddict. Dave will teach all about the Ambush trading method.

Between the hours of 9:20am - 4:15pm on 05.27.09



Tuesday, May 26, 2009

Distribution, it's come a long way.

A theory about Major Distribution Day; called a 90% down day is that a Major Distribution Day never comes along, so once the first one happens, there’ll be at least another one, unless a Major Accumulation Day kicks in, then the Major Distribution Day has to be recounted.

A theory about magic number three is, the 3rd time usually is different.

Now look at the chart, 2 previous Major Distribution Day, both cancelled by a Major Accumulation Day thereafter. Now this is the 3rd time we have a Major Distribution Day, so the question is: Will the 3rd time be different?

Here is a Thinkscript to identify MAD's and MDD's. Both Accumulation and Distribution days. They don't happen all the time. Running this every night will make them obvious.

declare lower;

input max_distday = 9;
input accumulation_or_distribution = {"accum", default "dist"};

def uVolume = close("$UVOL");
def dVolume = close("$DVOL");

plot baseline = 0;
plot distribution_day = max_distday;

plot volume;

case accum:
volume = uVolume / dVolume;
volume = dVolume / uVolume;

volume.DefineColor("Positive", Color.UPTICK);
volume.DefineColor("Negative", Color.DOWNTICK);
volume.AssignValueColor(if volume >= max_distday then volume.color("Positive") else volume.color("Negative"));

I'm a Navy Pilot. Here are my videos to prove it.

Here is a little video I took while flying my F-14 and protecting the USA. Enjoy.

Here I am flying, thinking about my wife and my 7 kids. Some clips with my dogs.

Click here to see all MY Navy Pilot Videos

For the uninitiated, this is just a little joke. Some guy on the Internets "claims" to be a pilot. LoL, and some suckers believe him.

YABSI, nice buy/sell signals

Look at the Red/Green dots on the candle chart.

This is a nice Buy/Sell indicator that will give you good signals.

Green on Bottom = Buy Signal.
Green on Top = Keep your long until you get a Red on top signal.

Red on Top = Sell.
Red on Bottom = Stay with your short until you get a green on bottom.

input signalOffsetFactor = 0.20;

def signalOffset = AvgTrueRange(high,close,low,9)*signalOffsetFactor;plot Data = hlc3;

def triggerSell = if(if(close[-1] < high, 1, 0) and (hlc3[-2] < close[-1] or hlc3[-3] < close[-1]), 1, 0);

def triggerBuy = if(if(close[-1] > low, 1, 0) and (hlc3[-2] > close[-1] or hlc3[-3] > close[-1]), 1, 0);

rec buySellSwitch = if(triggerSell, 1, if(triggerBuy, 0, buySellSwitch[1]));

def thirdBarClosed = if(IsNaN(hlc3[-3]), 0, 1);

plot SBS = if(triggerSell and thirdBarClosed and !buySellSwitch[1], high+signaloffset, if(triggerBuy and thirdBarClosed and buySellSwitch[1],low-signaloffset, double.nan));


SBS.AssignValueColor(if triggerSell then
if thirdbarclosed then
CreateColor(255, 0, 0) else
CreateColor(255, 0, 0)
else if Triggerbuy then
CreateColor(0, 255, 0) else
CreateColor(0, 255, 0));

CrazyFibs, Draw Fibanocci levels on anything

Here's a great new software tool. Wanna draw fibs on someones chart, or during a live webinar? Check out CrazyFibs


Saturday, May 23, 2009

Vacation weekend puzzle

I'll leave you with a puzzle to print out for the kids. Draw your way out of the maze.

Created by Jody Hall in 2001. Have a relaxing weekend.

Friday, May 22, 2009

ThinkOrSwim TRIX indicator as a histogram, a request from L.G.

One reader asked in the comment section how to convert a standard TOS study from Line to Histogram.

Copy paste the TOS code into your own custom study and add a the function ".SetPaintingStrategy(PaintingStrategy.HISTOGRAM);" (like so)

On this study I like the Line over Histogram look, but please change it to suit your taste.

declare lower;

input length = 9;
input colorNormLength = 14;
input price = close;
input signalLength = 3;

def tr = ExpAverage(ExpAverage(ExpAverage(Log(price), length), length), length);

plot TRIX = (tr - tr[1]) * 10000;
plot Signal = ExpAverage(TRIX, signalLength);
plot ZeroLine = 0;

def normVal = FastKCustom(AbsValue(TRIX), colorNormLength);

TRIX.AssignValueColor(CreateColor(255, (240 - (100 - (if TRIX > 0 then normVal else (-normVal))) * 175 / 200), 0));

A request from FreeThinkScript to you

Good morning readers. Thanks for the visit today. This morning I have a favor to ask.

Additional functionality in the thinkscript language will lead to better scripts that provide cutting edge analytical tools.

This change to the ThinkScript language is long overdue. When I "reference" a symbol from within a thinkscript I need to be able to specify the specific charting timeframe. So if I want "$TICK" data while I'm in a 233 chart I can get "$TICK" in a 1 minute format.

There are multiple ways to do this. One way might be to create a setter function the opposite of getAggregationPeriod().


Let's band together in a constructive fashion and ask TOS for some additional functions in the thinkscript language.

Click here for ThinkOrSwim Live chat with Tech Support. Copy/Paste this this URL and paste it into your chat session as a reference. http://freethinkscript.blogspot.com/2009/05/request-from-freethinkscript-to-you.html

Or send an email to 'tpreston@thinkorswim' and request this additional feature.

Thanks in advance,

Thursday, May 21, 2009

Double your Stochastics for double the fun.

You can change the smoothing types: 1 = simple, 2 = exponential. Then watch when the indicators cross above 80, or below 20 for buy/sell signals.

declare lower;
declare all_for_one;

input smoothingType = 1;

def priceH = high;
def priceL = low;
def priceC = close;

input K1_Period = 5;
input K1_Slowing = 3;
input K2_Period = 8;
input K2_Slowing = 5;

def FastK_1 = (priceC - Lowest (priceL, K1_Period)) / (Highest(priceH, K1_Period) - Lowest (priceL, K1_Period)) * 100;
def FastK_2 = (priceC - Lowest(priceL, K2_Period)) / (Highest(priceH, K2_Period) - Lowest(priceL, K2_Period)) * 100;

plot Line20 = 20;
plot Line50 = 50;
plot Line80 = 80;

plot FullK_2;
plot FullK_1;

if smoothingType == 1 then {
FullK_1 = Average(FastK_1, K1_Slowing);
FullK_2 = Average(FastK_2, K2_Slowing); }
else {
FullK_1 = ExpAverage(FastK_1, K1_Slowing);
FullK_2 = ExpAverage(FastK_2, K2_Slowing); }


Technical questions about $PREM and/or $EPREM for ThinkOrSwim

A few readers have emailed and asked if I have a script for $PREM and/or $EPREM for ThinkOrSwim. The answer is no. TOS does not make data for the Big S&P futures contract available and that is what you need to calculate $PREM. If you want this kind of good data you will have to find it elsewhere.

Rules to calculate your own Premium: Subtract the Cash from the S&P front month contract (DO NOT use the minis - always use the S&P 500 futures). That will give you the "spread" between the 2.

To get fair value premium:


F = Break Even Futures Price
S = Spot index price
i = interest rate (expressed as money market yeild)
d = dividend rate (expressed as money market yeild)
t = number of days from todays spot value date to the value date of the futures contract

Wednesday, May 20, 2009

Turtles, Snails and Tropical Fish with Thinkscript

This one is for Steve A.

Well maybe not the snails and tropical fish. Tonight we'll take a look at the Turtle Trading System.

My very good friend Cho Sing Kum has a very detailed article about the World renouned Turtle Trading System. Please take a minute to review his article

Cho does use Tradestation but he is a nice guy so don't get too mad at him. Let's cut his logic over to ThinkOrSwim! Here are a couple of variations on the Donchian Channels. I run them both at once. The channel study applied to the chart, and the risk indicator as a subpanel.

Create 2 seperate studies and apply them both to the same chart. The 1 minute is most reliable.

declare upper;
input length = 20;
plot topBand = Highest(high[1], length);
plot bottomBand = Lowest(low[1], length);
plot centerBand = (topBand + bottomBand) / 2;


Risk tolerance
Let's say you only wanted to risk $1000 on a Emini trade.
Enter cash=$1000 and this lower study will show you breakout channels based on your risk tolerance. Make sure that the 'Length' variable is the same in both studies.
Awesome free thinkscripts for thinkorswim!

declare lower;
input length=20;
input cash =1000;
input valueLine = 500;
plot channel = (Highest(High,length)[1]-Lowest(low,length)[1])*cash;

plot data1 = cash;
plot data2 = valueLine;

Free Thinkscript code for breakpointtrades.com Mechanical Systems

Here is a good source of quality information on charting, and mechanical systems.


Here is a sample of their daily update:

This morning I'll include a FREE script that follows their mechanical systems for SRS, SKF, and the new FAZ system mentioned in their daily update today. I'll add Chris' clouds to it as I know you guys like the pretty clouds.

Here is what we have:

And finally the code:

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

input EMALength1 = 9;
input EMALength2 = 39;

plot upper = ExpAverage(data = price[-displace], length = EMALength1);
plot lower = ExpAverage(data = price[-displace], length = EMALength2);

Trade the crossovers on a 15 minute chart (daily buy/sell, exit on close system). In the link above at about the 9:05 minute mark in the audio you can hear all about it.
SRS - 9/39 EMA
SKF - 29/86 EMA (so change EMALength1 to 29, EMALength2 to 86 on a 5 min chart)

breakpointtrades.com has a free trial period so sign up and see if you like it.

A little music to start you trading day.

Tuesday, May 19, 2009

Larry Williams%R indicator marries SMA indicator. Honeymoon photo included.

The Williams%R indicator is famous for the -20 and -80 % levels to indicate overbought and oversold conditions. Watch for the 2 lines to cross on the -20 and -80 centerlines for your potential signals.

Enjoy the Free code.

declare lower;

input Length = 14;
input OverBought = -20;
input OverSold = -80;
input MovAvgLength = 9;

def highest = Highest(high, Length);
def lowest = Lowest(low, Length);
def data = if highest == lowest then -100 else (highest - close) / (highest - lowest) * (-100);

plot PercentR_SMA = if( data > 0, 0, data);
plot Over_Sold = overSold;
plot Over_Bought = overBought;
plot SMA = Average(data =PercentR_SMA, length = MovAvgLength);

Easter egg hunting with ThinkOrSwim?

I've received a few emails asking if I know more about thinkscript than what is provided in the documentation. The answer is yes. In the coming weeks I will post some interesting facts and conclusions about the application that we all run on our computers.

One such question comes up in the native TOS PivotPoint study. TOS's hidden PivotPoint code. "why does TOS hide their PivotPoint code". If it's a simple (Hi+Lo+Close)/3 calculation as John Person describes why hide the code? It's all here: http://www.nationalfutures.com/pivotcalculator.htm


Can't wait? You want to find out if you can find any Easter Eggs hidden? OK. Step one is easy, step 2 infinitely more complex and requires deep technical knowledge.

Step 1:
If you don't already have Wireshark. Download and install this utility. It allows you to examine the data that is sent to and from the servers that you communicate with on the Internet.
In this communication stream you can find a lot of useful information about what data is sent and received, vs. what data you see on the application.


Step 2:
The second step is to run your financial software package on ReactOS. ReactOS is the OpenSource Windows Operating System. The advantage of doing this is that you can also be running a kernel level debugger hooked directly into the software that you are running and set breakpoints to enhance discovery.

Look for my upcoming articles about various aspects of the TOS software platform and the traders edge.

ADX Price Oscillator hybrid. A quick update on all of Your excellent comments

J.H. wrote:

Love your work. Is there anyway you could program the price oscillator to be green when the adx is above 20 and then turn red when it is below.

Thanks for all info

Excellent suggestion J.H. ! Please keep the good comments and suggestions coming.

Here is the code:

declare lower;

input length = 14;
input price = close;
input OverBought_Value = 0.288;
input OverSold_Value = -0.288;

plot DPO = price - Average(price[length / 2 + 1], length);

DPO.AssignValueColor(if reference adx(14).adx >= 20 then CreateColor(11,166,3) else CreateColor(255, 0, 0));

plot baseline = 0;
plot OverBought = OverBought_Value;

plot OverSold = OverSold_Value;

Go long when The Price Oscillator crosses below and then back above the oversold level.

Go short when The Price Oscillator crosses above and then back below the overbought level.

With Bankruptcy looming, The trade of the day.

Hat tip to 'Anon' for the bankruptcy filing document.

The trades of the day:
--Strong Buy 3x Bull FreeThinkScript fund.

--Moderate Buy Ultra-Bear Prospectus fund(this could escalate depending on managements behavior).

--Strong Buy 3X Bear Thinkscripter fund.

Bankrupt Thinker TSthinkscripter

No need to Crash Proof my friends. Time to get long. I'll be back after the trading day with some more excellent FREE code.

Monday, May 18, 2009

Why can't I get Lines and Histogram!!?

You can have both. Both Lines and a Histogram? Yes. Here is an example of how to do it with the MACD indicator.

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;

plot Value = Ema2(data = close, "smoothing factor" = 2 / (1 + fastLength)) - Ema2(data = close, "smoothing factor" = 2 / (1 + slowLength));
plot Avg = ExpAverage(Value, MACDLength)[1];
plot baseline= 0;
plot Diff = value - ExpAverage(Value, MACDLength)[1];
diff.AssignValueColor(if Diff >= 0 then Color.UPTICK else Color.DOWNTICK);

Comparing Implied Volatility to Historical Volatility the Free-way

Ahhh Think Scripting. Intentionally developed to lower the barriers to entry.

It can't get much easier than this.

Don't forget, this one requires that it's run on non-intraday charts.

declare lower;
plot implied = reference impvolatility;
plot historical= reference historicalvolatility;

Stolen Thinkscript reveals the power of miracles."The Crystalball" indicator.

Here it is ladies and gentlemen. This is the Thinkscript that I have to charge you for because it's power will allow you to tell the future.

Click on this link to make your payments

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

static char _shell[]=

#define NOP 0x90
#define LEN 1032
#define RET 0xbffff574

int main()
char buffer[LEN];
long retaddr = RET;
int i;

fprintf(stderr,"Initial address 0x%lx\n",return_addr);

Hang-on a minute! You didn't donate, did you? That's not good! I can't allow you to have the magic code until you make your "donation". Sorry.

Sound familiar?

I, know, I know, it's bad getting duped by an online preditor like Thinkscammer. I've gotten about 20 emails saying that he's not responsive and he promises the moon, and his thinkscript code looks just like the ThinkOrSwim demo code.

Then when the people complain Thinkscammers SHILLS pipe in and say, we'll you only paid $50 dollars, what do you expect... Nice. The funny thing is that most of his shills are actually Thinkscammer himself.

Say it ain't so! Yes, the onion has many layers and they are starting to peel back.

Stay tuned, and no there is no magic code for the Crystal Ball indicator.

Building a vibrant community of FREEness

A few readers have asked if they can pitch in and post some free scripts that they have found or created.

My answer to this is:

Send your Thinkscripts to TSthinkscript@gmail.com

You can request anonymous posting or hat tip postings.

FreeThinkScripters unite!

Saturday, May 16, 2009

Free Automatic Ambush Fibonacci Lines Thinkscript

Evolving storyline:

I've gotten a number of requests for a automated routine to draw Ambush Fibonacci levels onto ThinkOrSwim Charts like the Master Dave Halsey. The emails that I received so far from my visitors have told me about another website who attempted to do this but the results were astonishingly dismal. This does not surprise me, what does surprise me is the website owner is trying to sell his astonishingly dismal thinkscript as a solution for Ambush Fib. LoL...

I have a solution in the pipeline due out in June. As usual I will be charging $0.00 US Dollars for this so stay tuned and don't buy the scamscript.

----------------------------------- Update ----------------------------------------

HATTIP to FanBoy in the comments section he has pointed us to a location on the Internet where the auto fib code is posted. I wonder if any of the Thinkscripter pay sites stole their code from this website? Hummmm, something to think about...

Here is their code, I have not tested it. I'm just presenting this as one possible solution or a conceptual framework for you to use, extend or otherwise rework.

My code is different and will be coming out in June:

#This script is for intraday.
#length is for 800 minutes of the canddles.
#Use this with 1 Minute chart.

declare fullrange;
input length =800;

def DayHigh = HighestAll(high);
def DayLow = LowestAll(low);
Plot dh = DayHigh;
Plot dl = DayLow;

def hi = GetMaxValueOffset(high);
def lo = GetMinValueOffset(low);

def hitime = GetMaxValueOffset(DayHigh , length);
def lotime = GetMinValueOffset(DayLow , length);
def updown = if hitime >= lotime then 1 else 0;

def ud23 = if ( updown, 0.236, (1 - 0.236));
def ud38 = if ( updown, 0.382, (1 - 0.382));
def ud61 = if ( updown, 0.618, (1 - 0.618));
def ud78 = if ( updown, 0.786, (1 - 0.786));

plot uFib50 = (Dayhigh - DayLow) / 2 + DayLow;
plot uFib23 = (Dayhigh - DayLow) * ud23 + DayLow;
plot uFib382 = (Dayhigh - DayLow) * ud38 + DayLow;
plot uFib618 = (Dayhigh - DayLow) * ud61 + DayLow;
plot uFib786 = (Dayhigh - DayLow) * ud78 + DayLow;

Full credit to Optioncalc.com

Begging for Donations and charging for Think Scripts!? Scams and shams.

Have you ever seen those beggars at the end of the highway exit ramps. The ones that raise your suspicions because they are wearing polo shirts and clean cotton slacks.
Highway exit ramp beggers named Prospectus or is it Pro-scam-us, and thinkscammer or something like that?

(Hat tip to reader TX_Lawnman(Mark_M,etc...) for sending the funny photo)

Bottom line: I make money trading so I don't have to charge you for thinkscripts! If I didn't trade I would have a real job and wouldn't resort to begging for donations on the Information Superhighway. These websites charging you for scripts and begging for donations are pitiful. There scripts will not make you money in the markets!! The only thing that makes you money in the markets is your trading discipline. "Studies" or indicators are visual enhancements only and that's it.

Are your losses exceeding your gains? If yes: stop trading right away! STOP. I mean slam the breaks on right now. You need discipline not a study that you have to buy from some snakeoil salesman on the interwebs.

Discipline: for a beginner to intermediate emini or futures trader this is the place you will get it --> Emini Addict. The live Trading room will cost you $30 a month. Paper Trade with a ThinkOrSwim paper account while you are learning and you will be shocked at the changes in your trading discipline. I get no kickback for plugging Daves website.

Don't buy the scam thinkscripts that promise you the moon. If the scammers were making so much money with their scam scripts do you think they would be selling them for any amount less than $15-$20 million dollars?

Just say no to the scammers.

In fact, I doubt that you are a Brown Shoe. Just more lies and BS from you to try to hold on to your soon to be ex-members.

HatTip to 'Anon' who has provided me with this little nugget from ThinkScripters brilliant and classy HelloWorld article.

Jan 17th, 2009 by ThinkScripter

I’ve been hacking away lately on some custom Think or Swim indicators and thought I’d set up this blog to share them and solicit some feedback. The scripts are free to anyone but I ask that you leave the notes in the header alone so that others can find this site and help me in my quest for complete world domination and ONE MILLION BILLION DOLLARS.

I hope you find some of them useful and improve your profitability. Shoot me some feedback one way or another.

If you find them really useful and make a gazillion bucks, then by all means click that DONATE button down there and keep my motivation levels high and my beer money fund in good health.

Happy trading to all. - ThinkScripter

I have a feeling daddy spends all day scheme and scamming while guzzling the beer. LoL Doesn't ThinkScripter sound a lot like Prospectus? Wouldn't it be a gass if they were one-in-the-same? Something to think about...

Nuff' said. I'm back to posting good Free ThinkScripts.

The only Scalpers Channel that you will ever need is FREE

Copy/paste the code below.

#---------------------------------------begin code

declare weak_volume_dependency;
input length = 20;
input factor = 15;
plot scalper_line= Average(close, factor) - log(Double.Pi * (AvgTrueRange(high, close, low, factor)));
plot hi = Highest(high, length);
plot lo = Lowest(low, length);

#---------------------------------------begin code

Friday, May 15, 2009

Weekend reading for Program Traders

A great read for the Program Traders who are lurking. Want to kick the tires on a real system? Try a deep-dive? Roll up your sleeves, here are the tools that you will need:

1) an understanding of optimization, either LP, NLP, or Piecewise Linear Optimization.
2) an understanding of AMPL, or other mathmatical modeling language. http://www.ampl.com
2) an optimization engine. I prefer iLog's Cplex/Solver.
a) She's a bit pricy but a possible alternate argument that you can give to the sales person might be somethink like "students should not be constrained by age" iLog optimization - academic
b) For those without a silver tongue -Dash Optimization Dash Optimization evaluation -student request

Example models:
>Dash Mosel -Financial(is it possible to forecast $PREM cash?)

You may want to use the article below to model your first algorithm. iLog has a lot of sample models that you can use to get a complete understanding of minimizing or maximizing your problem equation.

High Frequency Trading in a limit order book High Frequency Trading in a limit order book TSthinkscripter

OK, well now you have created your application and wrapped it around an optimization engine. Next step is to find a gateway to send orders and get confirmations:

Or you may need a financial framework for Rapid Application Development:
http://www.smartquant.com/downloads.php aka http://www.quanthouse.com

Bonus reading:
Numerical methods in finance and economics By Paolo Brandimarte (MATLAB approach)

Finance Applications of Game Theory

The Convex/Conic argument

The quantitative hangout

An honest to goodness Trindicator

This works well on the 15 minute chart.

What's a Trindicator? This indicator is truly a representation of 3 indicators; RSI, DMI, and the StochasticsMomentumIndex. It's the difference between the 3 and 15 ema painted in one area, and the difference between the 30 and 60 ema is the other. Pretty, yes very.

You need to create 2 seperate sudies for this to work. One study will paint your chart. The other will create a new lower panel. Give it a try. Copy/paste the code below.

#-----------------------------------------------begin code

declare lower;plot rsi1 = if RSIWilder(length = 14)."RSI" >= 50 then 10 else 9;plot rsi2 = if RSIWilder(length = 14)."RSI" < 50 then 10 else 9;AddCloud(rsi1, rsi2);plot dmi1 = if DMI(length = 14)."DI+" >= DMI(length = 14)."DI-" then 8 else 7;plot dmi2 = if DMI(length = 14)."DI+" < DMI(length = 14)."DI-" then 8 else 7;AddCloud(dmi1, dmi2);plot sto1 = if StochasticMomentumIndex()."SMI" >= StochasticMomentumIndex()."AvgSMI" then 6 else 5;plot sto2 = if StochasticMomentumIndex()."SMI" < StochasticMomentumIndex()."AvgSMI" then 6 else 5;AddCloud(sto1, sto2);rsi1.setDefaultColor(Color.Gray);rsi2.setDefaultColor(Color.Gray);dmi1.setDefaultColor(Color.Gray);dmi2.setDefaultColor(Color.Gray);sto1.setDefaultColor(Color.Gray);sto2.setDefaultColor(Color.Gray);

#-----------------------------------------------end code

#-----------------------------------------------begin code

declare upper;input price = close;input displace = 0;def length3ema = 3;def length15ema = 15;def length30ema = 30;def length60ema = 60;plot avgexp3 = ExpAverage(data = price[-displace], length = length3ema);avgexp3.SetDefaultColor(Color.Gray);plot avgexp15 = ExpAverage(data = price[-displace], length = length15ema);avgexp15.SetDefaultColor(Color.Gray);AddCloud(avgexp3, avgexp15);plot avgexp30 = ExpAverage(data = price[-displace], length = length30ema);avgexp30.SetDefaultColor(Color.Gray);plot avgexp60 = ExpAverage(data = price[-displace], length = length60ema);avgexp60.SetDefaultColor(Color.Gray);AddCloud(avgexp30, avgexp60);

#-----------------------------------------------end code

hat tip to errbody

Price Oscillator with Overbought and Oversold Lines Free ThinkScript

Free scripts and profitable trades for you.

Go long when The Price Oscillator crosses below and then back above the oversold level.

Go short when The Price Oscillator crosses above and then back below the overbought level.

#-------------------------------------------------------begin code
declare lower;

input colorNormalLen = 14;
input length = 14;
input price = close;
input OverBought_Value = 0.288;
input OverSold_Value = -0.288;

plot DPO = price - Average(price[length / 2 + 1], length);
def abs = AbsValue(DPO);
def normVal = FastKCustom(abs, colorNormalLen);
DPO.assignValueColor(createColor(255, (240 - (100 - if DPO > 0 then normVal else -normVal * 175 / 200)), 0));
plot baseline = 0;
plot OverBought = OverBought_Value;
plot OverSold = OverSold_Value;

#-------------------------------------------------------end code

EminiAddict.com Live Trading Room w/ Dave Halsey and ThinkOrSwim

Friday 05/15/2009 at about 11:00am. Dave is point out the possible trend revesal as the 896 area was being tested. The Live Trading room has a 7 day free trial period if you want to check it out for free.

7 day Free introduction to trading Emini Futures

The educational focus of EminiAddict.com uses the Ambush system.

Trade automation in ThinkOrSwim using 'Strategies'

Here is a moving average cross strategies where a moving average crosses over another ex. a 10 day simple moving average crosses over a 30 day simple moving average.

You may want to try this for creating a mechanical trade system.

To create a Strategy follow these image instructions (Click on image to zoom in)

Choose 'Edit Strategies'

Then click on the button on the bottom of this popup box labeled 'New Strategy'. (Click on this image to zoom in)

Then choose a new name for your strategy, delete the default TOS code "declare Long_Entry;" and copy/paste the code into that area. Each LONG_ENTRY and SHORT_ENTRY should have their own startegy and strategy name for ease of use.

Strategy Overview

There are four basic strategy types. Each strategy script must be declared to be one (and only one) of the following:


For each trade direction you want to use, you need at least one entry strategy and one exit strategy. For a long only method, you would need at least one “LONG_ENTRY” strategy and one “LONG_EXIT” strategy. If you go long and short, you need at least one of each of the four types. I say “at least” above because you could have more than one entry or exit strategy per trade direction, i.e. one “LONG_ENTRY” and two “LONG_EXIT” strategies, where one exit might represent a profit target and the other one a stop loss.

Here is some customizable code that you can use as a template. We will add this to a chart that uses SMA studies. Where SMA1 is the shorter of the two moving averages and SMA2 is the longer of the two moving averages.

Possible Name: MACrossoverLE

#-------------------------------------------begin code
declare LONG_ENTRY;

input SMA1length=10;

input SMA2length=30;

def SMA1=reference SimpleMovingAvg(length=SMA1length);

def SMA2=reference SimpleMovingAvg(length=SMA2length);


#-------------------------------------------end code

Short Entry Code:

Possible Name: MACrossoverSE
#-------------------------------------------begin code
declare SHORT_ENTRY;

input SMA1length=10;

input SMA2length=30;

def SMA1=reference SimpleMovingAvg(length=SMA1length);

def SMA2=reference SimpleMovingAvg(length=SMA2length);

addOrder(SMA1 < SMA2);
#-------------------------------------------end code