SuperTrend in EasyLanguage is a stateful study — carry the final bands and the line
from bar to bar with [1] references. See
the explainer for the logic.
What you’ll need
- TradeStation or MultiCharts
- The EasyLanguage / PowerLanguage Editor, new Indicator
The source
{ AlgoGen SuperTrend — TradeStation / MultiCharts }
inputs:
AtrLen( 10 ),
Mult( 3.0 );
variables:
HL2( 0 ), UB( 0 ), LB( 0 ), FU( 0 ), FL( 0 ), ST( 0 );
HL2 = ( High + Low ) / 2;
UB = HL2 + Mult * AvgTrueRange( AtrLen );
LB = HL2 - Mult * AvgTrueRange( AtrLen );
{ Band-locking: bands only ratchet toward price }
if UB < FU[1] or Close[1] > FU[1] then FU = UB else FU = FU[1];
if LB > FL[1] or Close[1] < FL[1] then FL = LB else FL = FL[1];
{ Flip the active band when price closes through it }
if ST[1] = FU[1] then begin
if Close > FU then ST = FL else ST = FU;
end
else begin
if Close < FL then ST = FU else ST = FL;
end;
Plot1( ST, "SuperTrend" );
if ST = FL then SetPlotColor( 1, Green ) else SetPlotColor( 1, Red );
AvgTrueRange supplies volatility; the FU/FL band-locking with [1] references
is the ratchet; and the flip block switches the active band — the colour-coded line
from the output chart.
A stop-and-reverse strategy
{ Add to the study above, in a Strategy }
if ST = FL and ST[1] = FU[1] then Buy next bar at market; { flipped up }
if ST = FU and ST[1] = FL[1] then SellShort next bar at market; { flipped down }
The Strategy Performance Report will show the trend-follower’s usual profile — and why a range filter helps.
Gotchas
[1]everywhere. The bands and line all reference their prior-bar values; miss a[1]and the state machine breaks.- Band-locking is essential. Without the ratchet conditions, the line flips every bar. This mirrors the Python logic exactly.
- Multiplier dial. Bigger multiplier = wider bands, fewer flips; test per market.
Same indicator elsewhere: Python, MQL5, Pine Script, NinjaScript. Then backtest it in AlgoGen.
This post is educational, not financial advice. Indicators describe the past; they don’t predict the future. Backtest anything before you risk real money on it.
Sources and further reading
- What is EasyLanguage? (TradeStation)
