thinkScript

# Dual Moving Averages with clouds and cross arrows 

#Labels added by SFL 

#TOS Title = CloudBetween2MovingAverages 

#hint:Cloud usage between two moving averages 

 

declare upper; 

 

#  Input Code 

input price = close;#hint close:Select the price of choice 

input fastLength = 8;#hint fastLength:The fast average length 

input fastAvgType = AverageType.SIMPLE;#hint fastAvgType:Select the average type 

input slowLength = 20;#hint slowLength:The slow average length 

input slowAvgType = AverageType.SIMPLE; #hint slowAvgType:Select the average type 

input Show_Crosses = YES;#hint Show_Crosses:Toggles crossing arrows ON/OFF 

 

#  Moving Average Plot Code 

plot FastMva = MovingAverage( fastAvgType, price, fastLength ); 

plot SlowMva = MovingAverage( slowAvgType, price, slowLength ); 

 

#  Cloud Code 

AddCloud( FastMva, SlowMva, Color.YELLOW, Color.RED ); 

 

#  Crossing Code 

def CrossUp =  if Crosses(FastMva, SlowMva, CrossingDirection.above) then 1 else 0; 

Plot UpArrow = If CrossUp && Show_Crosses then low else double.nan; 

UpArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); 

UpArrow.SetLineWeight(3); 

UpArrow.SetDefaultColor(Color.GREEN); 

 

def CrossDown =  if Crosses(FastMva, SlowMva, CrossingDirection.below) then 1 else 0; 

Plot DownArrow = If CrossDown && Show_Crosses then high else double.nan; 

DownArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); 

DownArrow.SetLineWeight(3); 

DownArrow.SetDefaultColor(Color.RED); 

#  Label Code 

#AddLabel(Show_Crosses,”Cross = UP ARROW”,color.PINK); 

 

addlabel(1,”Slow MA(” +  slowLength  + “) is ” +  (If fastAvgType == AverageType.EXPONENTIAL then “Exponential average”  

else if  fastAvgType == AverageType.Hull then “Hull average”  

else if fastAvgType == AverageType.simple then “Simple average” 

else if fastAvgType == AverageType.wilders then “Wilders average” 

else if fastAvgType == AverageType.weighted then “Weighted average” 

else “”)   ,color.cyan); 

 

addlabel(1,”Fast MA(” +  fastLength  + “) is ” +  (If slowAvgType == AverageType.EXPONENTIAL then “Exponential average”  

else if  slowAvgType == AverageType.Hull then “Hull average”  

else if slowAvgType == AverageType.simple then “Simple average” 

else if slowAvgType == AverageType.wilders then “Wilders average” 

else if slowAvgType == AverageType.weighted then “Weighted average” 

else “”)   ,color.pink); 

# end 

Leave a Reply