Saturday, April 16, 2016

THINKSCRIPT - BBCsignal (flawed but current)

#BBCsignal with 2 signals only but FLAWED because different values from StockWidget...could not fix it

declare lower;

input vsstock = "spx";
input MAlength = 50;
input averageType = AverageType.EXPONENTIAL;
input lineweight = 2;

input atraveragetype = averageType.WILDERS;
input atrlength = 10;

#Price as ATR indicator (study of the real move of the stock) because the most important move is the move size vs how it moved recently...percentage and dollar amount is an incomplete picture

def X = TotalSum (close - close [1]) / (ATR(atrlength, atraveragetype));

def PPA = TotalSum (close - close [1]) / (ATR(atrlength, atraveragetype));

def PPAMA = MovingAverage (averageType, X, MAlength);

def PPAhistBull = PPA > PPAMA;
def PPAhistBear = PPA < PPAMA;


#Stock vs SPX (study of relative strength vs SPX) because only want to buy strong stocks who can lead

def StockvsMA = ((close() - MovingAverage(averageType, close(), MAlength)) / MovingAverage(averageType, close(), MAlength));
def SPYvsMA = ((close(vsstock) - MovingAverage(averageType, close(vsstock), MAlength)) / MovingAverage(averageType, close(vsstock), MAlength));

def VSbull = StockvsMA > SPYvsMA;
def VSbear = StockvsMA < SPYvsMA;


#plot BBC indicator

plot BBCsignal = if VSbull + PPAhistBull == 2 then 1 else if VSbear + PPAhistBear == 2 then -1 else 0;

plot zeroline = 0;



BBCsignal.SetPaintingStrategy(paintingstrategy=PaintingStrategy.line_vs_POINTS);

BBCsignal.AssignValueColor(if BBCsignal == 1 then Color.GREEN else if BBCsignal == -1 then Color.RED else Color.white);

zeroline.SetDefaultColor(Color.light_gray);
zeroline.SetLineWeight(1);
BBCsignal.SetLineWeight(lineweight);

No comments:

Post a Comment