To set the stage, this is my first post on usethinkscript.com. I have not written a study with thinkscript but have made some simple modifications to several studies that I use. I use Martin Begley's moving average study that changes color as the slope of the moving average changes (see his code below). I am trying to write the script to create a scan to identify stocks where their 50 day moving average has changed from sloping downward (yesterday) to sloping upward (today). Following are my attempts to create this scan. First, I used the Thinkorswim Condition Wizard and came up with the following code which did not work:
SimpleMovingAvg("length" = 50) is greater than SimpleMovingAvg("length" = 50) from -1 bars ago
So, I tried to hand-write the code below and, unfortunately, it did not work either. I would very much appreciate someone's help! Thank you in advance!!!
input length = 50;
input price = close;
input AverageType = SimpleMovingAvg;
def MA = SimpleMovingAvg;
plot MA > MA[1];
##############################################
# Calculate and Plot Moving Average With Colors
# by Martin Begley
###############################################
input length = 50;
input price = close;
input AverageType = {Default Simple, Exponential, Weighted, Wilders, Hull};
def average;
switch (AverageType) {
case Simple:
average = Average(price, length);
case Exponential:
average = ExpAverage(price, length);
case Weighted:
average = wma(price, length);
case Wilders:
average = WildersAverage(price, length);
case Hull:
average = HullMovingAvg(price, length);
}
plot MA = average;
MA.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
MA.SetLineWeight(2);
MA.DefineColor("Up", Color.DARK_GREEN);
MA.DefineColor("Down", Color.RED);
MA.DefineColor("Flat", Color.GRAY);
MA.AssignValueColor(if MA[0] > MA[1] then MA.Color("Up") else if MA[0] <
MA[1] then MA.Color("Down") else MA.Color("Flat"));
SimpleMovingAvg("length" = 50) is greater than SimpleMovingAvg("length" = 50) from -1 bars ago
So, I tried to hand-write the code below and, unfortunately, it did not work either. I would very much appreciate someone's help! Thank you in advance!!!
input length = 50;
input price = close;
input AverageType = SimpleMovingAvg;
def MA = SimpleMovingAvg;
plot MA > MA[1];
##############################################
# Calculate and Plot Moving Average With Colors
# by Martin Begley
###############################################
input length = 50;
input price = close;
input AverageType = {Default Simple, Exponential, Weighted, Wilders, Hull};
def average;
switch (AverageType) {
case Simple:
average = Average(price, length);
case Exponential:
average = ExpAverage(price, length);
case Weighted:
average = wma(price, length);
case Wilders:
average = WildersAverage(price, length);
case Hull:
average = HullMovingAvg(price, length);
}
plot MA = average;
MA.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
MA.SetLineWeight(2);
MA.DefineColor("Up", Color.DARK_GREEN);
MA.DefineColor("Down", Color.RED);
MA.DefineColor("Flat", Color.GRAY);
MA.AssignValueColor(if MA[0] > MA[1] then MA.Color("Up") else if MA[0] <
MA[1] then MA.Color("Down") else MA.Color("Flat"));