Saturday, April 16, 2016

Widget THINKSCRIPT - BBC (flawed but current)

#bbcsignal but flawed because it gives NaN many times...except for during market hours. wanted to fix it but couldn't

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

def X = TotalSum (close - close [1]) / (ATR(10, AverageType.WILDERS));

def PPA = TotalSum (close - close [1]) / (ATR(10, AverageType.WILDERS));

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

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;

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

def BullTRUE = if vsbull ==1 then 1 else 0;
def PPABullTrue = if PPAhistbull ==1 then 1 else 0;
def Bull2x = if vsbull ==1 and ppahistbull ==1 then 2 else 0;
def Bear2x = if vsbear ==1 and ppahistbear ==1 then -2 else 0;

def score = Bear2x+Bull2x;
plot S = score;

s.AssignValueColor(if bull2x== 2 then color.green else if bear2x ==-2 then Color.red else color.dark_gray);

No comments:

Post a Comment