Archive for the ‘ TradeStation Code ’ Category

BB Squeeze Indicator for TradeStation (TTM Squeeze concept)

Hey Traders,

here is an excellent indicator using Bollinger band and Keltner channel “SQUEEZE”

Inputs: {————————————————}
Price(Close),
Length(20), { Length for Average True Range (ATR) & Std. Deviation (SD) Calcs }
nK(1.5), { Keltner Channel ATRs from Average }
nBB(2), { Bollinger Band Std. Devs. from Average }
AlertLine( 1 ), { BBS_Index level at which to issue alerts }
NormalColor( Red ), { Normal color for BBS_Ind }
AlertlColor( Blue ); { Color for BBS_Ind below alert line }

Variables: {———————————————}
ATR(0), { Average True Range }
SDev(0), { Standard Deviation }
BBS_Ind(0), { Bollinger Band Squeeze Indicator }
alertTextID(-1),
Denom(0),
LHMult(0);

if ( barnumber=1 ) then
Begin
If minmove <> 0 then
LHMult = pricescale/minmove;
end;

if barnumber = 1 and alertTextID = -1 then
alertTextID = Text_New(date,time,0,”dummy”);

{– Calculate BB Squeeze Indicator ———————-}
ATR = AvgTrueRange(Length);
SDev = StandardDev(Price, Length, 1);

Denom = (nK*ATR);
If Denom <> 0 then
BBS_Ind = (nBB * SDev) /Denom;

If BBS_Ind < Alertline then
SetPlotColor(1, NormalColor)
else
SetPlotColor(1, AlertlColor);

{– Plot the Index & Alert Line ————————-}
Plot1(0, “BBS_Ind”);

{– Plot delta of price from Donchian mid line ———-}
value2 = LinearRegValue(price-((Highest(H, Length)+Lowest(L, Length))/2
+ xAverage(c,Length))/2,Length,0);

var:color(0); color = yellow;

if value2 > 0 then
if value2 > value2[1] then
color = green
else
color = darkgreen;

if value2 < 0 then
if value2 < value2[1] then color = red
else
color = darkred;

Plot3(value2*LHMult, “NickmNxtMove”, color);
{plot3(value2,”BB Squeeze”,color);}

{– Issue Alert when the Squeeze is On ——————}
if BBS_Ind crosses below AlertLine
and Text_GetTime(alertTextID) <> time then
begin
text_setLocation(alertTextID, date, time, 0);
Alert(”BB Squeeze Alert”);
end;

{– Issue Alert when the Squeeze Releases —————}
if BBS_Ind crosses above AlertLine
and Text_GetTime(alertTextID) <> time then
begin
text_setLocation(alertTextID, date, time, 0);
Alert(”BB Squeeze Is Over”);
end;

Heikin Ashi Oscillator (HACO) for TradeStation

Excellent indicator displaying Heikin Ashi trend as well as the strength of the trend:

inputs:
Avg( 34 );
variables:
TMA1(0),
TMA2(0),
Diff(0),
ZlHa(0),
ZlCl(0),
ZlDif(0) ;
{CrossOver formula}
TMA1= Tema(haC,avg);
TMA2= Tema(TMA1,avg);
Diff= TMA1 - TMA2;
ZlHa= TMA1 + Diff;
TMA1= Tema((H+L)/2,avg);
TMA2= Tema(TMA1,avg);
Diff= TMA1 - TMA2;
ZlCl= TMA1 + Diff;
ZlDif=ZlCl-ZlHa;
Plot1( ZlDif,”ZlDif”);
Plot2(0,”Zero Line”);

Binary Heikin Ashi Crossover for TradeStation

Hey Traders,

this binary heikin ashi code will be displayed in a subgraph with either 1 for uptrend or 0 for downtrend, excellent if you want to look at original style candles and still use the heikin ashi trend tool:

{HACO}
inputs:
Avg( 34 ),
AvgDn( 34 );

variables:
TMA1g(0),
TMA2g(0),
Diffg(0),
ZlHag(0),
ZlClg(0),
ZlDifg(0),
TMA1r(0),
TMA2r(0),
Diffr(0),
ZlHar(0),
ZlClr(0),
ZlDifr(0),

keep1r(false),
keep2r(false),
keep3r(false),
keepingr(false),
keepallr(false),
keep1g(false),
keep2g(false),
keep3g(false),
keepingg(false),
keepallg(false),
utr(false),
dtr(false),
upw(false),
dnw(false),
result(” “);
{CrossOver formula}
TMA1g= Tema(haC,avg);
TMA2g= Tema(TMA1g,avg);
Diffg= TMA1g - TMA2g;
ZlHag= TMA1g + Diffg;
TMA1g= Tema((H+L)/2,avg);
TMA2g= Tema(TMA1g,avg);
Diffg= TMA1g - TMA2g;
ZlClg= TMA1g + Diffg;
ZlDifg=ZlClg-ZlHag;

keep1g=(haC>=haOpen or haC[1]>=haOpen[1]);
keep2g=ZlDifg>=0;
keepingg=(keep1g OR keep2g);
keepallg=keepingg OR (keepingg[1] AND (Close >=Open) OR Close >=Close[1]);
keep3g=(AbsValue(Close-Open)<(High-Low)*.35 AND High>=Low[1]);
utr=Keepallg OR (keepallg[1] AND keep3g);

{CrossOver formula}
TMA1r= Tema(haC,avgdn);
TMA2r= Tema(TMA1r,avgdn);
Diffr= TMA1r - TMA2r;
ZlHar= TMA1r + Diffr;
TMA1r= Tema((H+L)/2,avgdn);
TMA2r= Tema(TMA1r,avgdn);
Diffr= TMA1r - TMA2r;
ZlClr= TMA1r + Diffr;
ZlDifr=ZlClr-ZlHar;

keep1r=haC<haOpen or haC[1]<haOpen[1] ;
keep2r=ZlDifr<0;
keep3r=AbsValue(Close -Open )<(High-Low)*.35 AND Low<= High[1];
keepingr=keep1r and keep2r;
keepallr=keepingr OR (keepingr[1] AND (Close<Open) OR Close<Close[1]);
dtr= Keepallr OR (keepallr[1] AND keep3r);

upw=dtr=false AND dtr[1]=false AND utr;
dnw=utr=false AND utr[1]=false AND dtr;

if upw then
plot1(1,”HACO”)
else if dnw then
plot1(-1,”HACO”)
else
plot1(plot1[1],”HACO”);

Heikin Ashi Paintbars for TradeStation

Hey Traders,

here is code for Heikin Ashi candlesticks, excellent tool for determining market trends

inputs:
HollowColor( White ),
UpTrendColor( DarkGreen ),
DnTrendcolor( Red ),
Avg( 34 ) ;

variables:
GreenBar( false ),
MyHaC(0),
MyHaOpen(0),
color(0),
colorW(0),
TMA1(0),
TMA2(0),
Diff(0),
ZlHa(0),
ZlCl(0),
ZlDif(0),
keep1r(false),
keep2r(false),
keep3r(false),
keepingr(false),
keepallr(false),
keep1g(false),
keep2g(false),
keep3g(false),
keepingg(false),
keepallg(false),
utr(false),
dtr(false),
upw(false),
dnw(false),
result(” “);
{CrossOver formula}
TMA1= Tema(haC,avg);
TMA2= Tema(TMA1,avg);
Diff= TMA1 - TMA2;
ZlHa= TMA1 + Diff;
TMA1= Tema((H+L)/2,avg);
TMA2= Tema(TMA1,avg);
Diff= TMA1 - TMA2;
ZlCl= TMA1 + Diff;
ZlDif=ZlCl-ZlHa;

keep1g=(haC>=haOpen or haC[1]>=haOpen[1]);
keep2g=ZlDif>=0;
keepingg=(keep1g OR keep2g);
keepallg=keepingg OR (keepingg[1] AND (Close >=Open) OR Close >=Close[1]);
keep3g=(AbsValue(Close-Open)<(High-Low)*.35 AND High>=Low[1]);
utr=Keepallg OR (keepallg[1] AND keep3g);

keep1r=haC<haOpen or haC[1]<haOpen[1] ;
keep2r=ZlDif<0;
keep3r=AbsValue(Close -Open )<(High-Low)*.35 AND Low<= High[1];
keepingr=keep1r and keep2r;
keepallr=keepingr OR (keepingr[1] AND (Close<Open) OR Close<Close[1]);
dtr= Keepallr OR (keepallr[1] AND keep3r);

upw=dtr=false AND dtr[1]=false AND utr;
dnw=utr=false AND utr[1]=false AND dtr;

if upw then
result = “GreenBar”
else if dnw = false then
result = “RedBar” ;

if Result = “GreenBar” then
begin
ColorW = UpTrendColor ;
if Close > Close[1] and Open < Close then
Color = UpTrendColor
else
Color = HollowColor ;
if  Close < Close[1] and Open > Close then
Color = UpTrendColor
else
Color = HollowColor ;
end
else
begin
ColorW = DnTrendColor ;
if Close < Close[1] and Open > Close then
Color = DnTrendColor
else
Color = HollowColor ;
if  Close > Close[1] and Open < Close then
Color = DnTrendColor
else
Color = HollowColor ;
end ;

{ Outlined Candles by Solidus
https://www.tradestation.com/Discussions/Topic.aspx?Topic_ID=67474}
inputs:
WICKwidth( 1 ),
BODYwidth( 3 );

variables:
BodySize(iff(bodywidth=2, 1, iff(bodywidth>4, 4, bodywidth) )),
Outline(iff(bodysize=0, 2, iff(bodysize=1, 3, iff(bodysize=3, 4, 5)))  );

plot1(c,”c outline a”,colorW,0,outline);
plot2(c,”c outline b”);
plot3(o,”o outline a”,colorW,0,outline);
plot4(o,”o outline b”);

Plot5(c,”C”,color,0,bodysize);
Plot6(o,”O”);

Plot7(c,”C outline”,colorW,0,outline);
Plot8(o,”O outline”);

plot9(h,”H”,colorW,0,WICKwidth);
plot10(l,”L”);

Market Delta Code for Trade Station

This market delta code will only analyze price action data from the data displayed on you screen, so to go further back in time adjust your chart setting accordingly.

inputs:
Threshold1( 150 ),
Threshold2( 300 ),
Threshold3( 600 ),
DisplayDelta( false ),
Type( 1 ), // 1 = Use Upticks/Downticks, 2 = Use Bid/Ask
BidAskArraySz( 1000 );

variables:
TickSize( MinMove / PriceScale ),
PriceAtIndex( Open ),
BaseIndex( BidAskArraySz/2 ),
Red1(RGB(255,185,185)),
Red2(RGB(255,128,128)),
Red3(RGB(255,0,0)),
Red4(RGB(128,0,0)),
Green1(RGB(210,255,210)),
Green2(RGB(125,255,125)),
Green3(RGB(0,255,0)),
Green4(RGB(0,128,0)),
i( 0 );

variables:
intrabarpersist Price( 0 ),
intrabarpersist MyVol( 0 ),
intrabarpersist VolTmp( 0 ),
intrabarpersist LastTick( 0 ),
intrabarpersist MyCurrentBar( 0 ),
intrabarpersist Index( 0 ),
intrabarpersist BidAskDelta( 0 ),
intrabarpersist xDelta( 0 ),
intrabarpersist TextString(”"),
intrabarpersist MyUpTicks( 0 ),
intrabarpersist MyDownTicks( 0 );

Arrays:
intrabarpersist Bid[](0),
intrabarpersist Ask[](0);

Array_SetMaxIndex( Bid, BidAskArraySz );
Array_SetMaxIndex( Ask, BidAskArraySz );

if (Type = 1 or Type = 2) and LastBarOnChart and BarType < 2 then
begin
MyVol = Ticks;
PriceAtIndex = Open;

if CurrentBar > MyCurrentBar then
begin
VolTmp = 0;
MyCurrentBar = CurrentBar;
MyUpTicks = 0;
MyDownTicks = 0;

for i = 0 to BidAskArraySz - 1
begin
Bid[i] = 0;
Ask[i] = 0;
end;
end;

Index = BaseIndex + (Close - PriceAtIndex) / TickSize;

if InsideBid < InsideAsk then
begin
if Type = 1 then
begin
// Use Upticks/Downticks
if DownTicks <> MyDownTicks then
Bid[Index] = Bid[Index] + MyVol - VolTmp
else if UpTicks <> MyUpTicks then
Ask[Index] = Ask[Index] + MyVol - VolTmp
else
begin
if Close <= LastTick then
Bid[Index] = Bid[Index] + MyVol - VolTmp
else
Ask[Index] = Ask[Index] + MyVol - VolTmp;
end;
end
else
begin
// Use Bid/Ask
// Warning: TradeStation provides snapshot of bid/ask
if Close <= InsideBid then
Bid[Index] = Bid[Index] + MyVol - VolTmp
else if Close >= InsideAsk then
Ask[Index] = Ask[Index] + MyVol - VolTmp
else
begin
// Last tick was between bid/ask
if Close <= LastTick then
Bid[Index] = Bid[Index] + MyVol - VolTmp
else
Ask[Index] = Ask[Index] + MyVol - VolTmp;
end;
end;
end;

MyUpTicks = UpTicks;
MyDownTicks = DownTicks;
VolTmp = MyVol;
LastTick = Close;

xDelta = 0;
Price = Low;

while Price <= High
begin
Index = BaseIndex + (Price - PriceAtIndex) / TickSize;
TextString = NumToStr(Bid[Index],0) + ” x ” + NumToStr(Ask[Index],0);
Value99 = Text_New(Date, Time, 0, ” “);
Text_SetString(Value99, TextString);
Text_SetLocation(Value99, Date, Time, Price);
Text_SetStyle(Value99, 1, 1);

BidAskDelta = Ask[Index] - Bid[Index];
if BidAskDelta > Threshold3 then
Text_SetColor(Value99, Green4)
else if BidAskDelta > Threshold2 then
Text_SetColor(Value99, Green3)
else if BidAskDelta > Threshold1 then
Text_SetColor(Value99, Green2)
else if BidAskDelta >= 0 then
Text_SetColor(Value99, Green1)
else if BidAskDelta < -Threshold3 then
Text_SetColor(Value99, Red4)
else if BidAskDelta < -Threshold2 then
Text_SetColor(Value99, Red3)
else if BidAskDelta < -Threshold1 then
Text_SetColor(Value99, Red2)
else
Text_SetColor(Value99, Red1);

xDelta = xDelta + BidAskDelta;

Price = Price + TickSize;
end;

if DisplayDelta = true then
begin
Value99 = Text_New(Date, Time, 0, ” “);
Text_SetString(Value99, NumToStr(xDelta, 0 ));
Text_SetLocation(Value99, Date, Time, Low - TickSize);
Text_SetStyle(Value99, 1, 1);

if xDelta >= 0 then
Text_SetColor(Value99, Green)
else
Text_SetColor(Value99, Red);
end;
end;

Enjoy

Heikin-Ashi, Free “TTM TREND” Indicator Code for TradeStation

Hey Traders,

you might have noticed that on most of my charts I use for analysis Candle Colors are not standard green for up candles, red for down candles, That is because I am using a paid version of TTM Trend indicators of TradeStation which essentially is Heikin Ashi modified bars. Heikin-Ashi is very useful in determining current trend and seeing trend changes.

If you would like to use Heikin Ashi paint bad study on your TradeStation platform, use simple EasyLanguage Code below:

{ Heikin Ashi PaintBarStudy
Heikin-Ashi technique for visualization
of trend }
inputs: UpColor( RGB(0,255,0)),DnColor( RGB(255,0,0) ), help(”www.TazaTek.com”);
vars: haClose(0),haOpen(0),haHigh(0),haLow(0),
color(0);
if BarNumber = 1 then
begin
haOpen = open;
haClose = (O+H+L+C)/4;
haHigh = MaxList( high, haOpen, haClose);
haLow = MinList( low, haOpen,haClose);
end;
if BarNumber > 1 then
begin
haClose = (O+H+L+C)/4;
haOpen = (haOpen [1] + haClose [1])/2 ;
haHigh = MaxList(High, haOpen, haClose) ;
haLow = MinList(Low, haOpen, haClose) ;
if haClose > haOpen then
color = UpColor
else
color = DnColor;
plotPB(haOpen,haClose,”Ignore-ME-”,color);
SetPlotWidth(1,4);
SetPlotColor(1,color);
end;

I will be posting more heiken-ashi/ttm trend based strategies once I get to completing “Trading Strategies” section of the blog

Enjoy