Anda di halaman 1dari 30


Pepotongan garis indikator

Indikator yang selama ini menghasilkan signal akurat adalah stochastic dan MACD

2. Menyentuh level tertentu

Indikator jenis oscilator yang memberikan signal entry dan exit akurat adalah Money flow
index dan william percent range.

3. Perpindahan posisi indikator

Jenis indikator ini sangat sedikit, tapi yang paling akurat adalah parabolic sar
Perlu dijadikan catatan adalah bahwa indikator diatas akan benar-benar menjadi indikator
akurat jika digunakan sesuai kondisi marketnya , serta parameternya bukan lagi
menggunakan parameter default melainkan telah dirubah sesuai dengan kebutuhan kita.

Berikut ini settingan indikator yang bisa membuatnya lebih akurat:

Parameter indikator paling akurat :

I. Stochastic Oscilator
Parameternya adalah K Period =9 , D Period = 3 , Slowing= 5 , Price Field =Close/Close ,
MA method=simple
Signal entrynya adalah ketika terjadi perpotogan di area jenuh

II.Money Flow Index

Parameternya adalah jika yang akan diprediksi adalah jangka pendek artinya hanya 2-3
candle berikutnya gunakan MFI period = 3
Untuk memprediksijangka panjang gunakan period=5
Signal entrynya adalah Buy ketika MFI bernilai 0 , serta sell ketika MFI bernilai 100 .

III. Parabolic sar

Parameternya adalah step =0.02 dan maksimum = 0.2
Signal entrynya adalah Buy ketika titik sar pertama kali muncul di bawah grafik , serta sell
ketika titik sar muncul diatas grafik
Untuk sementara hanya 3 indikator saja

Itulah indikator paling akurat yang bisa anda gunakan untuk menghasilkan prediksi yang
lebih akurat. Selamat mencoba

Simple Moving Average Calculation

A simple moving average is formed by computing the average price of a security over a
specific number of periods. Most moving averages are based on closing prices. A 5-day
simple moving average is the five day sum of closing prices divided by five. As its name
implies, a moving average is an average that moves. Old data is dropped as new data comes
available. This causes the average to move along the time scale. Below is an example of a 5-
day moving average evolving over three days.

Daily Closing Prices: 11,12,13,14,15,16,17

First day of 5-day SMA: (11 + 12 + 13 + 14 + 15) / 5 = 13

Second day of 5-day SMA: (12 + 13 + 14 + 15 + 16) / 5 = 14

Third day of 5-day SMA: (13 + 14 + 15 + 16 + 17) / 5 = 15

The first day of the moving average simply covers the last five days. The second day of the
moving average drops the first data point (11) and adds the new data point (16). The third day
of the moving average continues by dropping the first data point (12) and adding the new data
point (17). In the example above, prices gradually increase from 11 to 17 over a total of seven
days. Notice that the moving average also rises from 13 to 15 over a three day calculation
period. Also notice that each moving average value is just below the last price. For example,
the moving average for day one equals 13 and the last price is 15. Prices the prior four days
were lower and this causes the moving average to lag.

Exponential Moving Average Calculation

Exponential moving averages reduce the lag by applying more weight to recent prices. The
weighting applied to the most recent price depends on the number of periods in the moving
average. There are three steps to calculating an exponential moving average. First, calculate
the simple moving average. An exponential moving average (EMA) has to start somewhere
so a simple moving average is used as the previous period's EMA in the first calculation.
Second, calculate the weighting multiplier. Third, calculate the exponential moving average.
The formula below is for a 10-day EMA.

SMA: 10 period sum / 10

Multiplier: (2 / (Time periods + 1) ) = (2 / (10 + 1) ) = 0.1818 (18.18%)

EMA: {Close - EMA(previous day)} x multiplier + EMA(previous day).

A 10-period exponential moving average applies an 18.18% weighting to the most recent
price. A 10-period EMA can also be called an 18.18% EMA. A 20-period EMA applies a
9.52% weighing to the most recent price (2/(20+1) = .0952). Notice that the weighting for the
shorter time period is more than the weighting for the longer time period. In fact, the
weighting drops by half every time the moving average period doubles.

If you want to us a specific percentage for an EMA, you can use this formula to convert it to
time periods and then enter that value as the EMA's parameter:

Time Period = (2 / Percentage) - 1

3% Example: Time Period = (2 / 0.03) - 1 = 65.67 time periods

Below is a spreadsheet example of a 10-day simple moving average and a 10-day exponential
moving average for Intel. Simple moving averages are straight forward and require little
explanation. The 10-day average simply moves as new prices become available and old
prices drop off. The exponential moving average starts with the simple moving average value
(22.22) in the first calculation. After the first calculation, the normal formula takes over.
Because an EMA begins with a simple moving average, its true value will not be realized
until 20 or so periods later. In other words, the value on the excel spreadsheet may differ
from the chart value because of the short look-back period. This spreadsheet only goes back
30 periods, which means the affect of the simple moving average has had 20 periods to
dissipate. StockCharts goes back at least 250-periods (typically much further) for its
calculations so the effects of the simple moving average in the first calculation have fully

Click here to download this spreadsheet example.

The Lag Factor

The longer the moving average, the more the lag. A 10-day exponential moving average will
hug prices quite closely and turn shortly after prices turn. Short moving averages are like
speed boats - nimble and quick to change. In contrast, a 100-day moving average contains
lots of past data that slows it down. Longer moving averages are like ocean tankers - lethargic
and slow to change. It takes a larger and longer price movement for a 100-day moving
average to change course.
Click on the chart for a live version.

The chart above shows the S&P 500 ETF with a 10-day EMA closely following prices and a
100-day SMA grinding higher. Even with the January-February decline, the 100-day SMA
held the course and did not turn down. The 50-day SMA fits somewhere between the 10 and
100 day moving averages when it comes to the lag factor.

Simple vs Exponential Moving Averages

Even though there are clear differences between simple moving averages and exponential
moving averages, one is not necessarily better than the other. Exponential moving averages
have less lag and are therefore more sensitive to recent prices - and recent price changes.
Exponential moving averages will turn before simple moving averages. Simple moving
averages, on the other hand, represent a true average of prices for the entire time period. As
such, simple moving averages may be better suited to identify support or resistance levels.

Moving average preference depends on objectives, analytical style and time horizon.
Chartists should experiment with both types of moving averages as well as different
timeframes to find the best fit. The chart below shows IBM with the 50-day SMA in red and
the 50-day EMA in green. Both peaked in late January, but the decline in the EMA was
sharper than the decline in the SMA. The EMA turned up in mid February, but the SMA
continued lower until the end of March. Notice that the SMA turned up over a month after the
Lengths and Timeframes
The length of the moving average depends on the analytical objectives. Short moving
averages (5-20 periods) are best suited for short-term trends and trading. Chartists interested
in medium-term trends would opt for longer moving averages that might extend 20-60
periods. Long-term investors will prefer moving averages with 100 or more periods.

Some moving average lengths are more popular than others. The 200-day moving average is
perhaps the most popular. Because of its length, this is clearly a long-term moving average.
Next, the 50-day moving average is quite popular for the medium-term trend. Many chartists
use the 50-day and 200-day moving averages together. Short-term, a 10-day moving average
was quite popular in the past because it was easy to calculate. One simply added the numbers
and moved the decimal point.

Trend Identification
The same signals can be generated using simple or exponential moving averages. As noted
above, the preference depends on each individual. These examples below will use both
simple and exponential moving averages. The term “moving average” applies to both simple
and exponential moving averages.

The direction of the moving average conveys important information about prices. A rising
moving average shows that prices are generally increasing. A falling moving average
indicates that prices, on average, are falling. A rising long-term moving average reflects a
long-term uptrend. A falling long-term moving average reflects a long-term downtrend.
The chart above shows 3M (MMM) with a 150-day exponential moving average. This
example shows just how well moving averages work when the trend is strong. The 150-day
EMA turned down in November 2007 and again in January 2008. Notice that it took a 15%
decline to reverse the direction of this moving average. These lagging indicators identify
trend reversals as they occur (at best) or after they occur (at worst). MMM continued lower
into March 2009 and then surged 40-50%. Notice that the 150-day EMA did not turn up until
after this surge. Once it did, however, MMM continued higher the next 12 months. Moving
averages work brilliantly in strong trends.

Double Crossovers
Two moving averages can be used together to generate crossover signals. In Technical
Analysis of the Financial Markets, John Murphy calls this the “double crossover method”.
Double crossovers involve one relatively short moving average and one relatively long
moving average. As with all moving averages, the general length of the moving average
defines the timeframe for the system. A system using a 5-day EMA and 35-day EMA would
be deemed short-term. A system using a 50-day SMA and 200-day SMA would be deemed
medium-term, perhaps even long-term.

A bullish crossover occurs when the shorter moving average crosses above the longer moving
average. This is also known as a golden cross. A bearish crossover occurs when the shorter
moving average crosses below the longer moving average. This is known as a dead cross.

Moving average crossovers produce relatively late signals. After all, the system employs two
lagging indicators. The longer the moving average periods, the greater the lag in the signals.
These signals work great when a good trend takes hold. However, a moving average
crossover system will produce lots of whipsaws in the absence of a strong trend.

There is also a triple crossover method that involves three moving averages. Again, a signal
is generated when the shortest moving average crosses the two longer moving averages. A
simple triple crossover system might involve 5-day, 10-day and 20-day moving averages.
The chart above shows Home Depot (HD) with a 10-day EMA (green dotted line) and 50-day
EMA (red line). The black line is the daily close. Using a moving average crossover would
have resulted in three whipsaws before catching a good trade. The 10-day EMA broke below
the 50-day EMA in late October (1), but this did not last long as the 10-day moved back
above in mid November (2). This cross lasted longer, but the next bearish crossover in
January (3) occurred near late November price levels, resulting in another whipsaw. This
bearish cross did not last long as the 10-day EMA moved back above the 50-day a few days
later (4). After three bad signals, the fourth signal foreshadowed a strong move as the stock
advanced over 20%.

There are two takeaways here. First, crossovers are prone to whipsaw. A price or time filter
can be applied to help prevent whipsaws. Traders might require the crossover to last 3 days
before acting or require the 10-day EMA to move above/below the 50-day EMA by a certain
amount before acting. Second, MACD can be used to identify and quantify these crossovers.
MACD (10,50,1) will show a line representing the difference between the two exponential
moving averages. MACD turns positive during a golden cross and negative during a dead
cross. The Percentage Price Oscillator (PPO) can be used the same way to show percentage
differences. Note that MACD and the PPO are based on exponential moving averages and
will not match up with simple moving averages.
This chart shows Oracle (ORCL) with the 50-day EMA, 200-day EMA and
MACD(50,200,1). There were four moving average crossovers over a 2 1/2 year period. The
first three resulted in whipsaws or bad trades. A sustained trend began with the fourth
crossover as ORCL advanced to the mid 20s. Once again, moving average crossovers work
great when the trend is strong, but produce losses in the absence of a trend.

Price Crossovers
Moving averages can also be used to generate signals with simple price crossovers. A bullish
signal is generated when prices move above the moving average. A bearish signal is
generated when prices move below the moving average. Price crossovers can be combined to
trade within the bigger trend. The longer moving average sets the tone for the bigger trend
and the shorter moving average is used to generate the signals. One would look for bullish
price crosses only when prices are already above the longer moving average. This would be
trading in harmony with the bigger trend. For example, if price is above the 200-day moving
average, chartists would only focus on signals when price moves above the 50-day moving
average. Obviously, a move below the 50-day moving average would precede such a signal,
but such bearish crosses would be ignored because the bigger trend is up. A bearish cross
would simply suggest a pullback within a bigger uptrend. A cross back above the 50-day
moving average would signal an upturn in prices and continuation of the bigger uptrend.

The next chart shows Emerson Electric (EMR) with the 50-day EMA and 200-day EMA. The
stock moved above and held above the 200-day moving average in August. There were dips
below the 50-day EMA in early November and again in early February. Prices quickly moved
back above the 50-day EMA to provide bullish signals (green arrows) in harmony with the
bigger uptrend. MACD(1,50,1) is shown in the indicator window to confirm price crosses
above or below the 50-day EMA. The 1-day EMA equals the closing price. MACD(1,50,1) is
positive when the close is above the 50-day EMA and negative when the close is below the
50-day EMA.

Support and Resistance

Moving averages can also act as support in an uptrend and resistance in a downtrend. A
short-term uptrend might find support near the 20-day simple moving average, which is also
used in Bollinger Bands. A long-term uptrend might find support near the 200-day simple
moving average, which is the most popular long-term moving average. If fact, the 200-day
moving average may offer support or resistance simply because it is so widely used. It is
almost like a self-fulfilling prophecy.
The chart above shows the NY Composite with the 200-day simple moving average from mid
2004 until the end of 2008. The 200-day provided support numerous times during the
advance. Once the trend reversed with a double top support break, the 200-day moving
average acted as resistance around 9500.

Do not expect exact support and resistance levels from moving averages, especially longer
moving averages. Markets are driven by emotion, which makes them prone to overshoots.
Instead of exact levels, moving averages can be used to identify support or resistance zones.

The advantages of using moving averages need to be weighed against the disadvantages.
Moving averages are trend following, or lagging, indicators that will always be a step behind.
This is not necessarily a bad thing though. After all, the trend is your friend and it is best to
trade in the direction of the trend. Moving averages insure that a trader is in line with the
current trend. Even though the trend is your friend, securities spend a great deal of time in
trading ranges, which render moving averages ineffective. Once in a trend, moving averages
will keep you in, but also give late signals. Don't expect to sell at the top and buy at the
bottom using moving averages. As with most technical analysis tools, moving averages
should not be used on their own, but in conjunction with other complementary tools. Chartists
can use moving averages to define the overall trend and then use RSI to define overbought or
oversold levels.

Adding Moving Averages to StockCharts Charts

Moving averages are available as a price overlay feature on the SharpCharts workbench.
Using the Overlays drop-down menu, users can choose either a simple moving average or an
exponential moving average. The first parameter is used to set the number of time periods.
An optional parameter can be added to specify which price field should be used in the
calculations - “O” for the Open, “H” for the High, “L” for the Low, and “C” for the Close. A
comma is used to separate parameters.

Another optional parameter can be added to shift the moving averages to the left (past) or
right (future). A negative number (-10) would shift the moving average to the left 10 periods.
A positive number (10) would shift the moving average to the right 10 periods.

Multiple moving averages can be overlaid the price plot by simply adding another overlay
line to the workbench. StockCharts members can change the colors and style to differentiate
between multiple moving averages. After selecting an indicator, open “Advanced Options”
by clicking the little green triangle.

“Advanced Options” can also be used to add a moving average overlay to other technical
indicators like RSI, CCI, and Volume.

Click here for a live chart with several different moving averages.

Using Moving Averages with StockCharts Scans

Here are some sample scans that StockCharts members can use to scan for various moving
average situations:

Bullish Moving Average Cross: This scans looks for stocks with a rising 150-day simple
moving average and a bullish cross of the 5-day EMA and 35-day EMA. The 150-day
moving average is rising as long as it is trading above its level five days ago. A bullish cross
occurs when the 5-day EMA moves above the 35-day EMA on above average volume.
Simple Moving Average Calculation
Sebuah rata-rata bergerak sederhana dibentuk dengan menghitung harga rata-rata keamanan di
atas jumlah tertentu periode. Kebanyakan rata-rata bergerak didasarkan pada harga penutupan. A 5-
hari simple moving average adalah lima hari jumlah harga penutupan dibagi lima. Seperti namanya,
rata-rata bergerak adalah rata-rata yang bergerak. Data lama dijatuhkan sebagai data baru datang
tersedia. Hal ini menyebabkan rata-rata bergerak sepanjang skala waktu. Di bawah ini adalah contoh
dari 5-day moving average berkembang selama tiga hari.

Daily Closing Prices: 11,12,13,14,15,16,17

First day of 5-day SMA: (11 + 12 + 13 + 14 + 15) / 5 = 13

Second day of 5-day SMA: (12 + 13 + 14 + 15 + 16) / 5 = 14

Third day of 5-day SMA: (13 + 14 + 15 + 16 + 17) / 5 = 15

Hari pertama rata-rata bergerak sederhana meliputi lima hari terakhir. Hari kedua rata-rata
bergerak turun titik data yang pertama (11) dan menambahkan titik data baru (16). Hari
ketiga rata-rata bergerak terus dengan menjatuhkan titik data yang pertama (12) dan
menambahkan titik data baru (17). Dalam contoh di atas, harga secara bertahap meningkatkan
11-17 atas total tujuh hari. Perhatikan bahwa rata-rata bergerak juga naik 13-15 selama tiga
hari perhitungan. Juga perhatikan bahwa setiap nilai rata-rata bergerak adalah tepat di bawah
harga terakhir. Sebagai contoh, rata-rata bergerak untuk satu hari sama dengan 13 dan harga
terakhir adalah 15. Harga sebelum empat hari lebih rendah dan ini menyebabkan rata-rata
bergerak lag.

Exponential Moving Average Calculation

Eksponensial moving averages mengurangi lag dengan menerapkan bobot lebih untuk harga
baru-baru ini. Bobot diterapkan harga terbaru tergantung pada jumlah periode rata-rata
bergerak. Ada tiga langkah untuk menghitung rata-rata bergerak eksponensial sebuah.
Pertama, menghitung rata-rata bergerak sederhana. Sebuah exponential moving average
(EMA) harus dimulai di suatu tempat sehingga rata-rata bergerak sederhana digunakan
sebagai EMA periode sebelumnya dalam perhitungan pertama. Kedua, menghitung multiplier
pembobotan. Ketiga, menghitung rata-rata bergerak eksponensial. Rumus di bawah ini untuk
EMA 10-hari.

SMA: 10 period sum / 10

Multiplier: (2 / (Time periods + 1) ) = (2 / (10 + 1) ) = 0.1818 (18.18%)

EMA: {Close - EMA(previous day)} x multiplier + EMA(previous day).

Masa-10 eksponensial moving average menerapkan suatu 18,18% bobot dengan harga terbaru.
Masa-10 EMA juga bisa disebut 18,18% EMA. Masa-20 EMA menerapkan 9.52% berat dengan harga
terbaru (2 / (20 + 1) = 0,0952). Perhatikan bahwa pembobotan untuk periode waktu yang lebih
pendek lebih dari pembobotan untuk periode waktu yang lebih lama. Bahkan, bobot turun setengah
setiap kali moving average periode ganda.

Jika Anda ingin kami persentase tertentu untuk EMA, Anda dapat menggunakan rumus ini untuk
mengubahnya menjadi periode waktu dan kemudian masukkan nilai itu sebagai parameter EMA:

Time Period = (2 / Percentage) - 1

3% Example: Time Period = (2 / 0.03) - 1 = 65.67 time periods

Di bawah ini adalah contoh spreadsheet dari 10-hari rata-rata bergerak sederhana dan 10-hari
exponential moving average untuk Intel. Simple moving average yang lurus ke depan dan
memerlukan sedikit penjelasan. 10-hari rata-rata hanya bergerak karena harga baru menjadi
tersedia dan harga lama drop off. Eksponensial moving average dimulai dengan nilai rata-rata
bergerak sederhana (22,22) dalam perhitungan pertama. Setelah perhitungan pertama, rumus
yang normal mengambil alih. Karena sebuah EMA dimulai dengan simple moving average,
nilai sebenarnya tidak akan terwujud sampai 20 atau lebih periode kemudian. Dengan kata
lain, nilai pada spreadsheet excel mungkin berbeda dari nilai grafik karena masa melihat-
kembali singkat. Spreadsheet ini hanya kembali 30 periode, yang berarti pengaruh rata-rata
bergerak sederhana memiliki periode 20 menghilang. StockCharts kembali setidaknya 250-
periode (biasanya lebih jauh) untuk perhitungan sehingga efek dari rata-rata bergerak
sederhana dalam perhitungan pertama telah sepenuhnya hilang.
Menambahkan Moving Averages untuk StockCharts Charts
Moving average yang tersedia sebagai fitur overlay harga pada SharpCharts meja kerja.
Menggunakan menu drop-down Overlay, pengguna dapat memilih simple moving average
atau rata-rata bergerak eksponensial. Parameter pertama digunakan untuk mengatur jumlah
periode waktu.

Parameter opsional dapat ditambahkan untuk menentukan harga lapangan harus digunakan
dalam perhitungan - "O" Terbuka, "H" untuk High, "L" untuk Low, dan "C" untuk Tutup.
Sebuah koma digunakan untuk parameter terpisah.

Parameter opsional lain dapat ditambahkan untuk menggeser rata-rata bergerak ke kiri (masa
lalu) atau kanan (masa depan). Sejumlah negatif (-10) akan menggeser rata-rata bergerak ke
kiri 10 periode tersebut. Sejumlah positif (10) akan menggeser moving average ke kanan 10

Beberapa moving average dapat dilakukan overlay plot harga dengan hanya menambahkan
baris overlay lain untuk meja kerja. Anggota StockCharts dapat mengubah warna dan gaya
untuk membedakan antara beberapa moving average. Setelah memilih indikator, terbuka
"Advanced Options" dengan mengklik segitiga hijau kecil.

input accelerationFactor = 0.02;

input accelerationLimit = 0.2;

assert(accelerationFactor > 0, "'acceleration factor' must be positive: " + accelerationFactor);

assert(accelerationLimit >= accelerationFactor, "'acceleration limit' (" + accelerationLimit +
") must be greater than or equal to 'acceleration factor' (" + accelerationFactor + ")");

def state = {default init, long, short};

def extreme;
def SAR;
def acc;

switch (state[1]) {
case init:
state = state.long;
acc = accelerationFactor;
extreme = high;
SAR = low;
case short:
if (SAR[1] < high)
then {
state = state.long;
acc = accelerationFactor;
extreme = high;
SAR = extreme[1];
} else {
state = state.short;
if (low < extreme[1])
then {
acc = min(acc[1] + accelerationFactor, accelerationLimit);
extreme = low;
} else {
acc = acc[1];
extreme = extreme[1];
SAR = max(max(high, high[1]), SAR[1] + acc * (extreme - SAR[1]));
case long:
if (SAR[1] > low)
then {
state = state.short;
acc = accelerationFactor;
extreme = low;
SAR = extreme[1];
} else {
state = state.long;
if (high > extreme[1])
then {
acc = min(acc[1] + accelerationFactor, accelerationLimit);
extreme = high;
} else {
acc = acc[1];
extreme = extreme[1];
SAR = min(min(low, low[1]), SAR[1] + acc * (extreme - SAR[1]));

plot parSAR = SAR;

Indicator sugianto
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));

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);
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),
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),
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;
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

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


#Created by tradescripter
#Last Update May 20, 2011
#Green arrows pointing down are price highs.
#Red arrows pointing up are price lows
#Price highs and lows are determined by a few different methods.
#One method is to assume a price high or low if the length of the bar is greater than the
#bar length, plus one standard deviation. In other words, if there is an unusually big price
#move on one bar, a price high or low is assumed.
#A price high and a price low may not be a trend peak or bottom.
#Many of the price high and low signals are one bar early. Take that into account.
#As soon as you get an signal, you must decide whether it's trend peak/bottom or not
#If you think it's not the end of a trend place an exit order to take profit just over the current
#or under the current low. If you don't get a fill almost immediately on the next bar, you
#adjust your exit to a smaller profit within seconds, or use a market order to take profit.
#If the price high or low is a trend peak or bottom, the price probably won't go higher for a
#or lower for the bottom. So you must decide on a strategy for taking profits.
#Whether you take profit immediately on a signal, or wait for the next bar, either way you
will loose out on some
#profit. You must decide when it's better to take profit, at the signal, or just after the signal.

#There is often a price high when the price first hits a prior high after being under the high
#for a while. That potential price high is shown by a magenta arrow down over the high of
the bar.
#A potential price low, bowncing off support of a prior low, is a blue arrow.

#Stop losses are shown by squares. The stop losses turn out to also be points of price highs
#and lows. A long stop loss is show by a red square. The long stop loss is often a price low
#You must use your discretion on how to trade it.
#A price high signal, and a stop loss signal often occur on the same bar. That may be a
#confirmation that the price is at a high. You must use your discretion.

#Prior highs and low are also shown The prior highs and lows are the "Stepped" horizontal
#So you can keep track of recent prior highs and lows.

#I have not back-tested this study. I have no idea if it is any good or not.

input length=10;

def o=open;
def c=close;
def h=high;
def l=low;

def hh=h>h[1];
def ll=l<l[1];

def ClsUp=c>o;
def ClsDwn=c<o;

def BarLngth=h-l;
def AvgBarLngth=average(BarLngth,20);
def Threshhold=AvgBarLngth+StDev(BarLngth,20);

def ClsHigher=c>c[1];
def ClsLower=c<c[1];

def HiestHi=highest(close[3],length);
def LwestLw=lowest(close[3],length);

rec LastHi=if HiestHi>HiestHi[1] then HiestHi[1] else LastHi[1];

rec LastLw=if LwestLw<LwestLw[1] then LwestLw[1] else LastLw[1];
def ClsOvrHi=close>HiestHi;
def ClsUndrLw=close<LwestLw;

def ClsUndrLastHi=close<LastHi;
def ClsOvrLastLw=close>LastLw;

def Hi1 = !ClsOvrHi[2] and ClsOvrHi[1] and ClsOvrHi and ClsHigher;

def Hi2 = BarLngth>Threshhold and ClsUp;

def Lw1 = !ClsUndrLw[2] and ClsUndrLw[1] and ClsUndrLw and ClsLower;

def Lw2 = BarLngth>Threshhold and ClsDwn;

def HiSig=Hi1 or Hi2;

def LwSig=Lw1 or Lw2;

def LwOvrSupport=l>LwestLw;
def HiUndrSupport=h<HiestHi;

plot PriceHigh = if HiSig then high else double.nan;


plot PriceLow = if LwSig then low else double.nan;


def BreaksSpprt=LwOvrSupport[3] and LwOvrSupport[2] and LwOvrSupport[1] and

def BreaksRzist=HiUndrSupport[3] and HiUndrSupport[2] and HiUndrSupport[1] and

plot FirstSupportBreak=if BreaksSpprt then l else double.nan;


plot FirstResistanceBreak=if BreaksRzist then h else double.nan;


plot HighestHigh=HiestHi;

plot LowestLow=LwestLw;

plot LastHigh=LastHi;
plot LastLow=LastLw;

plot LongStopLossHit=if !ClsUndrLastHi[1] and ClsUndrLastHi then l else double.nan;


plot ShortStopLossHit=if !ClsOvrLastLw[1] and ClsOvrLastLw then h else double.nan;;



#Previous Day Script

#Justin Williams , @infinitycap, waterfronttrader

#09/20/11: Now works on all chart time periods.

#04/08/12: Changed both previous day line colors and made the open line dynamically
#04/13/12: Gave both previous day lines new colors so they don't blend with the open line &
made the open line dashed. Also changed open time for people who use chart on /es.

input ShowPreviousDay = YES;

input ShowDayOpen = YES;

def MarketOpenTime = 0930;

def MarketCloseTime = 1600;
def Day = getDay();
def Previous = getLastDay();
def Today = if(Day == Previous and secondsFromTime(MarketOpenTime) >= 0, 1, 0);
def Current = if(Today, 1, 0);

def PreviousOpen = if((secondsTillTime(MarketOpenTime) > 0), 0, 1);

def PreviousClose = if((secondsTillTime(MarketCloseTime) > 0), 0, 1);
def MarketOpen = if(PreviousOpen and !PreviousClose, 1, 0);
def closeByPeriod = close(period = “DAY”)[-1];

def closingBell = if secondsTillTime(MarketCloseTime)[1] > 0 and

secondsTillTime(MarketCloseTime) <= 0 or
(secondsTillTime(MarketCloseTime)[1] < secondsTillTime(MarketCloseTime)
and secondsTillTime(MarketCloseTime)[1] > 0) then 1 else 0;

def PrevHigh = high(period = "Day")[1];

def PrevLow = low(period = "Day")[1];
def TodayOpen = open(period = "Day");

plot PrLow;
plot PrHigh;
plot DayOpen;
if !IsNaN(close(period = “DAY”)[-1])
then {

PrLow = Double.NaN;
PrHigh = Double.NaN;
DayOpen = Double.NaN;

} else {

PrLow = if marketOpen and today and Current and ShowPreviousDay then prevLow else
PrHigh = if marketOpen and today and Current and ShowPreviousDay then prevHigh else
DayOpen = if marketOpen and today and Current and ShowDayOpen then TodayOpen
else double.nan;

DayOpen.AssignValueColor(if TodayOpen - close >= 0 then else;

# Billy Bob's Better Gap Indicator
input Detect_Gaps_By = {default "percent", "dollars"};
input Min_Gap_Size = 1.0;
input NumberOfGapsToTrack = {default "3", "2", "1"};
input ShowGapIndicatorBubbles = yes;
input show_gap_mid_line = yes;
input show_half_gap_move_up = yes;
input show_half_gap_move_down = yes;
input show_full_gap_move_up = yes;
input show_full_gap_move_down = yes;

# Decide how many simultaneous gaps to track

def show_gap2;
def show_gap3;
switch (numberOfGapsToTrack) {
case "3":
show_gap2 = yes;
show_gap3 = yes;
case "2":
show_gap2 = yes;
show_gap3 = no;
case "1":
show_gap2 = no;
show_gap3 = no;

# Declare Global Colors

DefineGlobalColor("gap top", CreateColor(165, 138, 193));
DefineGlobalColor("gap bottom", CreateColor(165, 138, 193));
DefineGlobalColor("gap middle", CreateColor(155, 206, 225));
DefineGlobalColor("gap half up", CreateColor(134, 202, 93));
DefineGlobalColor("gap full up", CreateColor(224, 243, 177));
DefineGlobalColor("gap half down", CreateColor(250, 141, 183));
DefineGlobalColor("gap full down", CreateColor(253, 222, 238));

# Define Candle Body

def bodyTop = Max(open, close);
def bodyBottom = Min(open, close);

# Define Gap Lines

def GapTop = Max(bodyBottom, bodyBottom[1]);
def GapBottom = Min(bodyTop, bodyTop[1]);
def GapMiddle = if show_gap_mid_line then (GapTop + GapBottom) / 2 else Double.NaN;
def GapHalfUp = if show_half_gap_move_up then GapTop + (GapTop - GapBottom) / 2 else
def GapHalfDown = if show_half_gap_move_down then GapBottom - (GapTop -
GapBottom) / 2 else Double.NaN;
def GapFullUp = if show_full_gap_move_up then GapTop + (GapTop - GapBottom) else
def GapFullDown = if show_full_gap_move_down then GapBottom - (GapTop -
GapBottom) else Double.NaN;

# Define a gap and its direction

def MinGapSize;
switch (Detect_Gaps_By) {
case "percent":
MinGapSize = Min(close[1] * (Min_Gap_Size/100),5);
case "dollars":
MinGapSize = Min_Gap_Size;

def GapUp = bodyBottom - bodyTop[1] >= MinGapSize;

def GapDown = bodyTop - bodyBottom[1] <= -MinGapSize;
def isGap = GapUp or GapDown;

AddChartBubble(ShowGapIndicatorBubbles and GapUp[-1], bodyBottom[-1], bodyBottom[-

1], GlobalColor("gap half up" ), no);
AddChartBubble(ShowGapIndicatorBubbles and GapUp[-1], bodyTop, bodyTop,
GlobalColor("gap half up" ));

AddChartBubble(ShowGapIndicatorBubbles and GapDown[-1], bodyTop[-1], bodyTop[-1],

GlobalColor("gap half down" ));
AddChartBubble(ShowGapIndicatorBubbles and GapDown[-1], bodyBottom, bodyBottom,
GlobalColor("gap half down" ),no);

# Define recursive variables

# Set variables for the first gap
rec gt1 = if isGap then GapTop else gt1[1];
rec gb1 = if isGap then GapBottom else gb1[1];
rec gm1 = if isGap then GapMiddle else gm1[1];
rec ghu1 = if isGap then GapHalfUp else ghu1[1];
rec ghd1 = if isGap then GapHalfDown else ghd1[1];
rec gfu1 = if isGap then GapFullUp else gfu1[1];
rec gfd1 = if isGap then GapFullDown else gfd1[1];

# Set variables for the second gap

rec gt2 = if isGap and gt2[1] <> gt1[1] then gt1[1] else gt2[1];
rec gb2 = if isGap and gb2[1] <> gb1[1] then gb1[1] else gb2[1];
rec gm2 = if isGap and gm2[1] <> gm1[1] then gm1[1] else gm2[1];
rec ghu2 = if isGap and ghu2[1] <> ghu1[1] then ghu1[1] else ghu2[1];
rec ghd2 = if isGap and ghd2[1] <> ghd1[1] then ghd1[1] else ghd2[1];
rec gfu2 = if isGap and gfu2[1] <> gfu1[1] then gfu1[1] else gfu2[1];
rec gfd2 = if isGap and gfd2[1] <> gfd1[1] then gfd1[1] else gfd2[1];

# Set variables for the third gap

rec gt3 = if isGap and gt3[1] <> gt2[1] then gt2[1] else gt3[1];
rec gb3 = if isGap and gb3[1] <> gb2[1] then gb2[1] else gb3[1];
rec gm3 = if isGap and gm3[1] <> gm2[1] then gm2[1] else gm3[1];
rec ghu3 = if isGap and ghu3[1] <> ghu2[1] then ghu2[1] else ghu3[1];
rec ghd3 = if isGap and ghd3[1] <> ghd2[1] then ghd2[1] else ghd3[1];
rec gfu3 = if isGap and gfu3[1] <> gfu2[1] then gfu2[1] else gfu3[1];
rec gfd3 = if isGap and gfd3[1] <> gfd2[1] then gfd2[1] else gfd3[1];

# Plot Gap Lines

# plot the first gap
plot pgt1 = if gt1 == 0 then double.nan else gt1;
plot pgb1 = if gb1 == 0 then double.nan else gb1;
plot pgm1 = if gm1 == 0 then double.nan else gm1;
plot pghu1 = if ghu1 == 0 then double.nan else ghu1;
plot pghd1 = if ghd1 == 0 then double.nan else ghd1;
plot pgfu1 = if gfu1 == 0 then double.nan else gfu1;
plot pgfd1 = if gfd1 == 0 then double.nan else gfd1;



pgt1.AssignValueColor(GlobalColor("gap top" ));

pgb1.AssignValueColor(GlobalColor("gap bottom" ));
pgm1.AssignValueColor(GlobalColor("gap middle" ));
pghu1.AssignValueColor(GlobalColor("gap half up" ));
pghd1.AssignValueColor(GlobalColor("gap half down" ));
pgfu1.AssignValueColor(GlobalColor("gap full up" ));
pgfd1.AssignValueColor(GlobalColor("gap full down" ));

# Plot the second gap

plot pgt2 = if gt2 == 0 then double.nan else gt2;
plot pgb2 = if gb2 == 0 then double.nan else gb2;
plot pgm2 = if gm2 == 0 then double.nan else gm2;
plot pghu2 = if ghu2 == 0 then double.nan else ghu2;
plot pghd2 = if ghd2 == 0 then double.nan else ghd2;
plot pgfu2 = if gfu2 == 0 then double.nan else gfu2;
plot pgfd2 = if gfd2 == 0 then double.nan else gfd2;



pgt2.AssignValueColor(GlobalColor("gap top" ));

pgb2.AssignValueColor(GlobalColor("gap bottom" ));
pgm2.AssignValueColor(GlobalColor("gap middle" ));
pghu2.AssignValueColor(GlobalColor("gap half up" ));
pghd2.AssignValueColor(GlobalColor("gap half down" ));
pgfu2.AssignValueColor(GlobalColor("gap full up" ));
pgfd2.AssignValueColor(GlobalColor("gap full down" ));

pgt2.sethiding(if show_gap2 then 0 else 1);

pgb2.sethiding(if show_gap2 then 0 else 1);
pgm2.sethiding(if show_gap2 then 0 else 1);
pghu2.sethiding(if show_gap2 then 0 else 1);
pghd2.sethiding(if show_gap2 then 0 else 1);
pgfu2.sethiding(if show_gap2 then 0 else 1);
pgfd2.sethiding(if show_gap2 then 0 else 1);
# Plot the third gap
plot pgt3 = if gt3 == 0 then double.nan else gt3;
plot pgb3 = if gb3 == 0 then double.nan else gb3;
plot pgm3 = if gm3 == 0 then double.nan else gm3;
plot pghu3 = if ghu3 == 0 then double.nan else ghu3;
plot pghd3 = if ghd3 == 0 then double.nan else ghd3;
plot pgfu3 = if gfu3 == 0 then double.nan else gfu3;
plot pgfd3 = if gfd3 == 0 then double.nan else gfd3;



pgt3.AssignValueColor(GlobalColor("gap top" ));

pgb3.AssignValueColor(GlobalColor("gap bottom" ));
pgm3.AssignValueColor(GlobalColor("gap middle" ));
pghu3.AssignValueColor(GlobalColor("gap half up" ));
pghd3.AssignValueColor(GlobalColor("gap half down" ));
pgfu3.AssignValueColor(GlobalColor("gap full up" ));
pgfd3.AssignValueColor(GlobalColor("gap full down" ));

pgt3.sethiding(if show_gap3 then 0 else 1);

pgb3.sethiding(if show_gap3 then 0 else 1);
pgm3.sethiding(if show_gap3 then 0 else 1);
pghu3.sethiding(if show_gap3 then 0 else 1);
pghd3.sethiding(if show_gap3 then 0 else 1);
pgfu3.sethiding(if show_gap3 then 0 else 1);
pgfd3.sethiding(if show_gap3 then 0 else 1);

###delete this line when pasting into thing or swim###

input ThermoLookBackBars = 50;

input PlotType = {default AdaptiveMovingAverages, Standard};

def HighLowScore = 1000 * ((high - high[1]) / (high[1]) +

(low - low[1]) / low[1]);

#######ATR TrailingStop Code

input trailType = {default modified, unmodified};
input ATRPeriod = 5;
input ATRFactor = 3.5;
input firstTrade = {default long, short};

def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));

def HRef = if low <= high[1]
then high - close[1]
else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
then close[1] - low
else (close[1] - low) - 0.5 * (low[1] - high);
def ATRMod = ExpAverage(Max(HiLo, Max(HRef, LRef)), 2 * ATRPeriod - 1);

def loss;
switch (trailType) {
case modified:
loss = ATRFactor * ATRMod;
case unmodified:
loss = ATRFactor * AvgTrueRange(high, close, low, ATRPeriod);

rec state = {default init, long, short};

rec trail;
switch (state[1]) {
case init:
if (!IsNaN(loss)) {
switch (firstTrade) {
case long:
state = state.long;
trail = close - loss;
case short:
state = state.short;
trail = close + loss;
} else {
state = state.init;
trail = Double.NaN;
case long:
if (close > trail[1]) {
state = state.long;
trail = Max(trail[1], close - loss);
else {
state = state.short;
trail = close + loss;
case short:
if (close < trail[1]) {
state = state.short;
trail = Min(trail[1], close + loss);
else {
state = state.long;
trail = close - loss;

def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);

def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);

plot TrailingStop = trail;

####End ATR Trailing Stop Code

def A = Highest(high[1], ThermoLookBackBars);

def B = Lowest(low[1], ThermoLookBackBars);

def FiftyTwoWeekHigh = A;

def FiftyTwoWeekLow = B;

def FiftyTwoWeekScore = 10 * (((high

- FiftyTwoWeekHigh) / FiftyTwoWeekHigh) +
((low - FiftyTwoWeekLow) / FiftyTwoWeekLow));

def ThermoScore = ExpAverage(HighLowScore + FiftyTwoWeekScore,


input FastLengthShort = 5;
input SlowLengthShort = 15;
input EffRatioShort = 10;
input FastLengthLong = 10;
input SlowLengthLong = 25;
input EffRatioLong = 5;

def AMA = MovAvgAdaptive(ThermoScore, FastLengthShort, SlowLengthShort,

def AMA2 = MovAvgAdaptive(ThermoScore, FastLengthLong, SlowLengthLong,

plot Line1;
plot Line2;

switch (PlotType) {
case AdaptiveMovingAverages:
Line1 = AMA;
Line2 = AMA2;
case Standard:
Line1 = ThermoScore;
Line2 = ThermoScore;

def InvisibleLine = close * 0;

plot Line3 = InvisibleLine;

def Buy = Line1 > 0 and Line2 < 0 and state == state.long;
def StrongBuy = Line1 > 0 and Line2 >= 0 and state == state.long;
def Sell = Line1 < 0 and Line2 > 0 and state == state.short;
def StrongSell = Line1 < 0 and Line2 <= 0 and state == state.short;

AssignPriceColor(if Buy then Color.DARK_GREEN else if StrongBuy then Color.GREEN

else if Sell then Color.DARK_RED else if StrongSell then Color.RED else Color.BLUE);

AddLabel(yes, Concat("Current Reading is ", (if Buy then "Up Trend" else if StrongBuy then
"Strong Up Trend" else if Sell then "Down Trend" else if StrongSell then "Strong Down
Trend" else "Neutral")), if Buy then Color.DARK_GREEN else if StrongBuy then
Color.GREEN else if Sell then Color.DARK_RED else if StrongSell then Color.RED else

#######Stochastic Code

declare upper;

input over_bought = 80;

input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 3;
input smoothingType = {default SMA, EMA};

def lowest_k = Lowest(priceL, KPeriod);

def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

def FullK;
def FullD;

switch (smoothingType) {
case SMA:
FullK = Average(FastK, slowing_period);
FullD = Average(FullK, DPeriod);
case EMA:
FullK = ExpAverage(FastK, slowing_period);
FullD = ExpAverage(FullK, DPeriod);

def pricefilterup = if close > close[50] then 1 else 0;

def pricefilterdown = if close < close [50] then 1 else 0;

def OverBoughtAdd = if FullK < over_bought and FullK[1] >= over_bought then 1 else 0;
def OverSoldAdd = if FullK > over_sold and FullK[1] <= over_sold then 1 else 0;

def na = Double.NaN;

#Plot arrows
plot up = if StrongBuy and OverSoldAdd and pricefilterup then low - (3 * TickSize()) else
plot down = if StrongSell and OverBoughtAdd and pricefilterdown then high + (3 *
TickSize()) else na;

###delete this line when pasting into think or swim###

def body = AbsValue(open-close);
def larger = if low[1] > high[-1] and body > body[1] and body > body[2] and
body > body[3] then 1 else 0;
plot wrbhg = if low[1] > high[-1] and body > body[1] and body > body[2]
and body > body[3] then 1 else 0;
alert(larger, "Wide Range Body Hidden Gap",, sound.ding);

def body = AbsValue(open-close);
def larger = if high[1] < low[-1] and body > body[1] and body > body[2] and
body > body[3] then 1 else 0;
plot wrbhg = if high[1] < low[-1] and body > body[1] and body > body[2]
and body > body[3] then 1 else 0;
wrbhg.SetPaintingStrategy (PaintingStrategy.BOOLEAN_ARROW_UP);
alert(larger, "Wide Range Body Hidden Gap",, sound.ding);