1. SMA, this is the default ATR provided by MultiCharts.
2. EMA, exponential average of true range.
3. Smoothed true range, this is the original ATR as described by Wells Wilder and it uses the built-in function DirMovement which has the calculation.
I also added a delay in the plotting so it wont plot the wrong values in the beginning.
Code: Select all
inputs:
Type ( 1 ), //1=SMA 2=EMA 3=SMMA
ATRLength( 14 ),
AlertLength( 14 ) ;
variables:
ATR( 0 ), var0( 0 ), var1( 0 ), var2( 0 ), var3( 0 ), var4( 0 ), var5( 0 ) ;
Value1 = DirMovement( H, L, C, ATRLength, var0, var1, var2, var3, var4, var5 ) ;
if Type = 1 then ATR = AvgTrueRange( ATRLength ) ;
if Type = 2 then ATR = XAverage( TrueRange, ATRLength ) ;
if Type = 3 then ATR = var5 ;
if ATR[ATRLength+1] <> 0 then Plot1( ATR, "ATR" ) ;
condition1 = HighestBar( ATR, AlertLength ) = 0 ;
if condition1 then
Alert( "Indicator at high" )
else
begin
condition1 = LowestBar( ATR, AlertLength ) = 0 ;
if condition1 then
Alert( "Indicator at low" ) ;
end;