Mr_Wheeler
Active member
I was successful with standard moving average types supplied by TOS but I'm running into problems with a custom triangle study.
https://tos.mx/tEyrGZg - that's my completed custom MTF label study.
This is the line of code I'm having issues with.
specifically
&
Here's my full code.
https://tos.mx/tEyrGZg - that's my completed custom MTF label study.
This is the line of code I'm having issues with.
Code:
addlabel(one_minute_label, if price >= tmaline then "Golden Cross " + barssince( crossup_1m) + " bars ago" else if price <= tmaline then "Death Cross " + barssince(crossdn_1m) + " bars ago" else "", if price >= tmaline then Color.GREEN else if price <= tmaline then Color.WHITE else Color.GRAY);
specifically
Code:
barssince( crossup_1m)
&
Code:
barssince(crossdn_1m)
Here's my full code.
Code:
## Golden and Death Cross indicator
## Coded by Chemmy at usethinkscript.com
input src = close;
input price = close;
input length = 200;
input one_minute_label = yes;
input two_minute_label = yes;
input five_minute_label = yes;
input ten_minute_label = yes;
input fifteen_minute_label = yes;
input twenty_minute_label = yes;
input thirty_minute_label = no;
input one_hour_label = no;
input two_hour_label = no;
input four_hour_label = no;
input one_day_label = no;
############################################################ Triangle
# Calculate TMA
def tma = MovingAverage(AverageType.WEIGHTED, MovingAverage(AverageType.WEIGHTED, MovingAverage(AverageType.WEIGHTED, price, length / 2), length / 2), length);
# Plot TMA
plot tmaLine = tma;
tmaLine.AssignValueColor(if tma > tma[1] then Color.GREEN else if tma < tma[1] then Color.RED else Color.YELLOW);
tmaLine.SetLineWeight(2);
# Define alert conditions for green, red, and yellow plot line color changes
def isGreen = tmaLine > tmaLine[1];
def isRed = tmaLine < tmaLine[1];
def up = close > tma;
def down = close < tma;
def Hold_Up_Value = if up then 1 else if !down then Hold_Up_Value[1] else 0;
def Hold_Dn_Value = if down then 1 else if !up then Hold_Dn_Value[1] else 0;
plot Signal_Up = if up and Hold_Dn_Value[1] == 1 then low else Double.NaN;
Signal_Up.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
plot Signal_Dn = if down and Hold_Up_Value[1] == 1 then high else Double.NaN;
Signal_Dn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
# Define the barssince script
def bn = barnumber();
script barssince {
input Condition = 0;
def barssince = if Condition then 1 else barssince[1] + 1;
plot return = barssince;
}
def crossup_1m = price crosses above tmaline;
def crossdn_1m = price crosses below tmaline;
###################################################################################################
###################################################################################################
AddLabel(one_minute_label, "triangle", Color.LIME);
AddLabel(one_minute_label, "2 minute", Color.ORANGE);
addlabel(one_minute_label, if price >= tmaline then "Golden Cross " + barssince( crossup_1m) + " bars ago" else if price <= tmaline then "Death Cross " + barssince(crossdn_1m) + " bars ago" else "", if price >= tmaline then Color.GREEN else if price <= tmaline then Color.WHITE else Color.GRAY);