Friday, September 23, 2011

TOS code with 10 SMA , Choice of SMA and EMA and Clouds




#########################################################
## BigbullandBigBear LLC
## Date: 22nd Sept 2011
#########################################################

input price       = close;
input ColoredCloud = yes;
input ColoredFill = yes;
input BreakArrows = yes;
input displace    =  0;
input length      = 10;

def lastBar = if (IsNaN(close), 1, 0);

input AverageType = {default SMA, EMA};
def MA;
switch (AverageType) {
case SMA:
    MA = Average(close, Length);
   
case EMA:
    MA = ExpAverage(close, Length);
 
}

def MAStatus =
  if close >MA then 2    
  else
    if close < MA then -2  
    else 0    ;                          

rec BreakStatus = compoundValue(1,
  if BreakStatus[1] == maStatus or maStatus == 0 then BreakStatus[1]
  else
    if mastatus == 2 then 2
    else -2, 0);

plot UpperBand = MA*1.01;
UpperBand.AssignValueColor (
    if !Coloredcloud then Color.White
    else
      if BreakStatus[0] == 2 then Color.Green
      else Color.Red);
UpperBand.SetLineWeight(1);

plot LowerBand = MA*.99;
LowerBand.AssignValueColor (
    if !Coloredcloud then Color.White
    else
      if BreakStatus[0] == 2 then Color.Green
      else Color.Red);
LowerBand.SetLineWeight(1);

# Breakout/down arrows.
plot BreakOutArrow =
  if BreakArrows then
    if BreakStatus[0] == BreakStatus[1] then double.NAN
    else if BreakStatus[0] == 2 then
      close else double.NAN
  else double.NAN;
BreakOutArrow.SetPaintingStrategy(PaintingStrategy.Arrow_Up);
BreakOutArrow.SetDefaultColor(Color.Green);
BreakOutArrow.SetLineWeight(3);

plot BreakDownArrow =
  if BreakArrows then
    if BreakStatus[0] == BreakStatus[1] then double.NAN
    else if BreakStatus[0] == -2 then
      close else double.NAN
else double.NAN;
BreakDownArrow.SetPaintingStrategy(PaintingStrategy.Arrow_Down);
BreakDownArrow.SetDefaultColor(Color.Red);
BreakDownArrow.SetLineWeight(3);

# colored clouds
plot GreenUpper = if ColoredFill and BreakSTatus[0] == 2 then
  UpperBand else double.NAN;
GreenUpper.SetDefaultColor(CreateColor(0,100,0));
plot GreenLower = if ColoredFill and BreakStatus[0] == 2 then
  LowerBand else double.NAN;
GreenLower.SetDefaultColor(CreateColor(0,100,0));
AddCloud (GreenUpper, GreenLower,CreateColor(0,100,0), color.red);

plot RedUpper = if ColoredFill and BreakSTatus[0] == -2 then
  UpperBand else double.NAN;
RedUpper.SetDefaultColor(CreateColor(200,0,0));
plot RedLower = if ColoredFill and BreakStatus[0] == -2 then
  LowerBand else double.NAN;
RedLower.SetDefaultColor(CreateColor(200,0,0));
AddCloud (RedUpper, RedLower, CreateColor(200,0,0), color.green);

1 comments:

Tommy said...

I find your "Clouds," very good, THANK YOU for sharing!

Post a Comment