Compare close of previous candle to open of current?

Learnbot

Active member
VIP
Hello guys/gals,

Quick question, I have a strategy that plots the entry point (uparrow in the script below), I want to compare the close of the uparrow candle to the open of the candle right after the signal, how do I script that? I sorta put this together but obviously, it is wrong lol

Code:
plot bbb = uparrow(open)>= uparrow(close);

Screen-Shot-2020-12-30-at-2-54-21-PM.png


As you can see in the image above the green arrow (uparrow) is a signal generated by my strategy and I want compare open of bare #2 in the image to bar#1's close.

Thank you for your time guys/gals
 

Learnbot

Active member
VIP
Here it is:

Code:
#Power_X_V3

#START OF RSI/Stochastic/MACD Confluence Strategy for ThinkOrSwim
#FVO_RSM_TREND_ADR_TICK_UPPER
#
#CHANGELOG
# 2020.11.30 V1.4 @cos251 - Added input "plotADR"
#                            - plots dynamic ATR/ADR targets- default plots 3 targets - can be turned off by setting "plotADR" to no
#                         - Added input "showExtraTargets"
#                            -  - plots dynamic ATR/ADR targets- for targets 4, 5, and 6
#                         - Added input "showADRZones"
#                            - Dynamic shading of ATR/ADR targets - can be turned off in settings using "showADRZones"
#                         - Added dynamic calculation of both ATR and ADR. User can select between ATR and ADR in settings
#                         - Added input "showADRLabels"
#                            - Added Dynamic Target labels for UpTrend or DownTrend; they will be green or red depending on Up or Down trend
#                         - Added input "showTodayOnly"
#                            - Added option to display shaded ADR/ATR zones for today only "showTodayOnly"
#                            - if set to no - ADR/ATR plots will be plotted for all available data on chart
#                         - Added ability to plot ATR or ADR on DAY chart - MUST TURN OFF "showTodayOnly"
#                         - Added Labels that can be used for "debug" - MUST change "debug" setting to yes
#                         - Added Trend information labels that can be turned on/off
#                           
#
# 2020.11.30 V1.3 @cos251 - Stripped down TICK Version; No ADR since time based aggregation period do not work on TICK #                           Charts
#
# 2020.11.30 V1.2 @cos251 - Add ADR plots and shading per request; will tweak these settings to improve overall
#                           options
# 2020.11.12 V1.1 @cos251 - Changed from strategy to standard study. Added Green Arrow UP
#                           and Red Arrow down when trend starts.  Added option to change to high
#                           timeframe but this WILL repaint; if used, should be used with other
#                           indicators to confirm an entry/exit.
#
# 2020.10.27 V1.0 @cos251 - Added RSI, StochasticSlow and MACD to same indicator
#                         - also calculates MACD;
#                         - Will shade the lower plot area of the following conditions are met
#                           Shade GREEN = RSI > 50 and SlowK > 50 and (macd)Value > (macd)Avg
#                           Shade RED = RSI < 50 and SlowK < 50 and (macd)Value < (macd)Avg
#
#                   
#REQUIREMENTS - RSI Set to 7, EXPONENTIAL
#               Stoch Slow 5(not14) and 3 WILDERS
#               MACD 12,26,9 WEIGHTED


declare upper;
################################################################
##########                 Variables                   #########
################################################################

input paintBars = yes;
input showRSMShade = no;
input tradetype = { "long", "short", default "both" };
input rangeType = { default "ADR", "ATR" };
input plotADR = yes;
input showADRZones = no;
input showTodayOnly = yes;
input showTrendLabels = no;
input showADRLabels = no;
input showExtraTargets = no;
input showIndicatorLabels = no;
input debug = no; # change to "NO" after testing



################################################################
##########              ATR/ADR Calc                   #########
################################################################
input ATRlength = 14;
input ATRaverageType = AverageType.WILDERS;
def Range;
if rangeType == rangeType.ATR {
    Range = MovingAverage(ATRaverageType, TrueRange(high, close, low), ATRlength);
} else {
    Range = Average(high - low, 7);
}

################################################################
##########         Booleans Set for Plot Use           #########
################################################################
def afterStart = GetTime() > RegularTradingStart(GetYYYYMMDD());
def beforeEnd = GetTime() < RegularTradingEnd(GetYYYYMMDD());
def today = if GetLastDay() == GetDay() then 1 else Double.NaN;
def dailyO = if today and afterStart and beforeEnd then DailyOpen() else Double.NaN;
plot openPrice = if dailyO then DailyOpen() else Double.NaN;
AddLabel(if debug then yes else no,"Day = :"+today);
AddLabel(if debug then yes else no,"Day = :"+GetDay());


################################################################
##########                 RSI                         #########
################################################################
input lengthRSI = 7;
input price = close;
input averageTypeRSI = AverageType.EXPONENTIAL;
def NetChgAvg = MovingAverage(averageTypeRSI, close - close[1], lengthRSI);
def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(close - close[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);


################################################################
##########                 Stochastic Slow             #########
################################################################
input over_boughtSt = 80;
input over_soldSt = 20;
input KPeriod = 14;
input DPeriod = 3;
input averageTypeStoch = AverageType.WILDERS;
def SlowK = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high, low, close, 3, averageTypeStoch).FullK;
def SlowD = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high, low, close, 3, averageTypeStoch).FullD;



################################################################
##########                  MACD                       #########
################################################################
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.WEIGHTED;
def Value = MovingAverage(averageTypeMACD, close, fastLength) - MovingAverage(averageTypeMACD, close, slowLength);
def Avg = MovingAverage(averageTypeMACD, Value, MACDLength);
def Diff = Value - Avg;



################################################################
##########         Assign Price Color                  #########
################################################################
#AssignPriceColor(if paintBars and RSI >= 50 and SlowK >= 50 and Value > Avg then Color.GREEN else if paintBars and RSI < 50 and SlowK < 50 and Value < Avg then Color.RED else if paintBars then Color.DARK_GRAY else Color.CURRENT);

#################################################################
#####   Up/Down Trend Check/SCAN Variables              #########
#################################################################
plot UpTrend = if RSI >= 50 and SlowK >= 50 and Value > Avg then 1 else 0;
plot DownTrend = if RSI < 50 and SlowK < 50 and Value < Avg then 1 else 0;
UpTrend.Hide();
DownTrend.Hide();
plot upArrow = if UpTrend == 1 and UpTrend[1] == 0 and (tradetype == tradetype.long or tradetype == tradetype.both) then low else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
upArrow.SetDefaultColor(Color.GREEN);
upArrow.SetLineWeight(4);
plot downArrow = if DownTrend == 1 and DownTrend[1] == 0 and (tradetype == tradetype.short or tradetype == tradetype.both) then high else Double.NaN;
downArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
downArrow.SetDefaultColor(Color.RED);
downArrow.SetLineWeight(4);

def bnumUp;
def bnumDown;
def closeUpTrendStart;
def closeDownTrendStart;
def UpTrendBarCount;
def DownTrendBarCount;
if UpTrend and (!UpTrend[1] or DownTrend[1]) {
    bnumUp = BarNumber();
    bnumDown = 0;
    closeUpTrendStart = close;
    closeDownTrendStart = 0;
    UpTrendBarCount = 1;
    DownTrendBarCount = 0;
} else if UpTrend {
    bnumUp = bnumUp[1];
    bnumDown = 0;
    closeUpTrendStart = closeUpTrendStart[1];
    closeDownTrendStart = 0;
    UpTrendBarCount = UpTrendBarCount[1] + 1;
    DownTrendBarCount = 0;
} else if DownTrend and (!DownTrend[1] or UpTrend[1]) {
    bnumUp = 0;
    bnumDown = BarNumber();
    closeDownTrendStart = close;
    closeUpTrendStart = 0;
    UpTrendBarCount = 0;
    DownTrendBarCount = 1;
} else if DownTrend {
    bnumDown = bnumDown[1];
    closeDownTrendStart = closeDownTrendStart[1];
    DownTrendBarCount = DownTrendBarCount[1] + 1;
    bnumUp = 0;
    closeUpTrendStart = 0;
    UpTrendBarCount = 0;
} else {
    bnumUp = 0;
    bnumDown = 0;
    closeUpTrendStart = 0;
    closeDownTrendStart = 0;
    UpTrendBarCount = 0;
    DownTrendBarCount = 0;
}
def c;
if BarNumber() == bnumUp or BarNumber() == bnumDown {
    c = Range;
} else if UpTrend or DownTrend {
    c = c[1];
} else {
    c = 0;
}
AddLabel(if debug then yes else no, "Current Bar:" + BarNumber());
AddLabel(if debug then yes else no, "C:" + c);
AddLabel( if debug then yes else no, "PlotADR: "+plotADR);
AddLabel( if debug then yes else no, "TodayOnly: "+showTodayOnly);

#################################################################
############        ADR/ATR Targets Shading              #########
#################################################################
# - UpTrend Targets and StopLoss
plot UpTrendStopLoss = if UpTrend and plotADR and !showTodayOnly then closeUpTrendStart - (c * 1) else if UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeUpTrendStart - c else Double.NaN;
plot oneADRPlus = if UpTrend and plotADR and !showTodayOnly then closeUpTrendStart + (c * 1) else if UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeUpTrendStart + c else Double.NaN;
plot twoADRPlus = if UpTrend and plotADR and !showTodayOnly then closeUpTrendStart + (c * 2) else if UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeUpTrendStart + (c * 2) else Double.NaN;
plot threeADRPlus = if UpTrend and plotADR and !showTodayOnly then closeUpTrendStart + (c * 3) else if UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeUpTrendStart + (c * 3) else Double.NaN;
plot fourADRPlus = if UpTrend and plotADR and !showTodayOnly and showExtraTargets then closeUpTrendStart + (c * 4) else if UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd and showExtraTargets then closeUpTrendStart + (c * 4) else Double.NaN;
plot fiveADRPlus = if UpTrend and plotADR and !showTodayOnly and showExtraTargets then closeUpTrendStart + (c * 5) else if UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd and showExtraTargets then closeUpTrendStart + (c * 5) else Double.NaN;
plot sixADRPlus = if UpTrend and plotADR and !showTodayOnly and showExtraTargets then closeUpTrendStart + (c * 6) else if UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd and showExtraTargets then closeUpTrendStart + (c * 6) else Double.NaN;
# - DownTrend Targets and StopLoss
plot DownTrendStopLoss = if DownTrend and plotADR and !showTodayOnly then closeDownTrendStart + c else if DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeDownTrendStart + c else Double.NaN;
plot oneADRMinus = if DownTrend and plotADR and !showTodayOnly then closeDownTrendStart - c else if DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeDownTrendStart - c else Double.NaN;
plot twoADRMinus = if DownTrend and plotADR and !showTodayOnly then closeDownTrendStart - (c * 2) else if DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeDownTrendStart - (c * 2) else Double.NaN;
plot threeADRMinus = if DownTrend and plotADR and !showTodayOnly then closeDownTrendStart - (c * 3) else if DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeDownTrendStart - (c * 3) else Double.NaN;
plot fourADRMinus = if DownTrend and plotADR and !showTodayOnly and showExtraTargets then closeDownTrendStart - (c * 4) else if DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd  and showExtraTargets then closeDownTrendStart - (c * 4) else Double.NaN;
plot fiveADRMinus = if DownTrend and plotADR and !showTodayOnly and showExtraTargets then closeDownTrendStart - (c * 5) else if DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd  and showExtraTargets then closeDownTrendStart - (c * 5) else Double.NaN;
plot sixADRMinus = if DownTrend and plotADR and !showTodayOnly and showExtraTargets then closeDownTrendStart - (c * 6) else if DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd  and showExtraTargets then closeDownTrendStart - (c * 6) else Double.NaN;

UpTrendStopLoss.SetDefaultColor(Color.LIGHT_RED);
oneADRPlus.SetDefaultColor(Color.LIGHT_GREEN);
twoADRPlus.SetDefaultColor(Color.LIGHT_GREEN);
threeADRPlus.SetDefaultColor(Color.LIGHT_GREEN);
fourADRPlus.SetDefaultColor(Color.LIGHT_GREEN);
fiveADRPlus.SetDefaultColor(Color.LIGHT_GREEN);
sixADRPlus.SetDefaultColor(Color.LIGHT_GREEN);

DownTrendStopLoss.SetDefaultColor(Color.LIGHT_GREEN);
oneADRMinus.SetDefaultColor(Color.LIGHT_RED);
twoADRMinus.SetDefaultColor(Color.LIGHT_RED);
threeADRMinus.SetDefaultColor(Color.LIGHT_RED);
fourADRMinus.SetDefaultColor(Color.LIGHT_RED);
fiveADRMinus.SetDefaultColor(Color.LIGHT_RED);
sixADRMinus.SetDefaultColor(Color.LIGHT_RED);


#################################################################
############          ADR/ATR Zone Shading              #########
#################################################################
def u = if UpTrend then closeUpTrendStart else Double.NaN;
def d = if DownTrend then closeDownTrendStart else Double.NaN;
def bnumUpCheck = if bnumUp != 0 then 1 else Double.NaN;
def bnumDownCheck = if bnumDown != 0 then 1 else Double.NaN;
# - Shade UpTrend ADR/ATR zones
AddCloud(if showADRZones and UpTrend and bnumUpCheck and showExtraTargets then sixADRPlus else if showADRZones and UpTrend and bnumUpCheck then threeADRPlus else Double.NaN, if showADRZones and UpTrend and bnumUpCheck then u else Double.NaN , CreateColor(69, 224, 255));
AddCloud(if showADRZones and UpTrend then u else Double.NaN, if showADRZones and UpTrend then UpTrendStopLoss else Double.NaN , CreateColor(255, 12, 151));
# - Shade Downtrend ADR/ATR zones
AddCloud(if showADRZones and DownTrend and bnumDownCheck then d else Double.NaN,  if showADRZones and DownTrend and bnumDownCheck and showExtraTargets then sixADRMinus else if showADRZones and DownTrend and bnumDownCheck then threeADRMinus else Double.NaN , CreateColor(255, 12, 151));
AddCloud(if showADRZones and DownTrend then DownTrendStopLoss else Double.NaN, if showADRZones and DownTrend then d else Double.NaN, CreateColor(69, 224, 255));


#################################################################
####    RSM shade areas based on criteria; adjust as needed  ####
#################################################################
AddCloud(if showRSMShade and RSI >= 50 and SlowK >= 50 and Value > Avg then Double.POSITIVE_INFINITY else Double.NaN, if RSI >= 50 and SlowK >= 50 and Value > Avg then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_GREEN);
AddCloud(if showRSMShade and RSI < 50 and SlowK < 50 and Value < Avg then Double.POSITIVE_INFINITY else Double.NaN, if RSI < 50 and SlowK < 50 and Value < Avg then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_RED);


#################################################################
############   Labels disable/blockout as needed        #########
#################################################################
# - Trend Labels
AddLabel(if showTrendLabels and (bnumDown != 0 or bnumUp != 0) then yes else no,if bnumUp > 0 then "Trend Started on BAR:" + bnumUp else "Trend Started on BAR: "+ bnumDown, if bnumUp > 0 then Color.GREEN else Color.RED);
AddLabel(if showTrendLabels and (bnumDown != 0 or bnumUp != 0) then yes else no, if bnumUp > 0 then "UpTrend Started at $" + closeUpTrendStart else "DownTrend Started at $:" + closeDownTrendStart, if bnumUp > 0 then Color.GREEN else Color.RED);
AddLabel(if showTrendLabels then yes else no, if bnumUp > 0 then "Tot Bars UpTrend: " + UpTrendBarCount else "Tot BARS in DownTrend " + DownTrendBarCount, if bnumUp > 0 then Color.GREEN else Color.RED);
AddLabel(if showTrendLabels then yes else no, if UpTrend == 1 then "::RSM-Signal:LONG" else if DownTrend == 1 then "::RSM-Signal:SHORT" else "::RSM-Signal:IDLE", if UpTrend == 1 then Color.GREEN else if DownTrend == 1 then Color.RED else Color.GRAY);
# - ADR/ATR Labels Targets
AddLabel(if showADRLabels then yes else no, "Open:" + dailyO, Color.ORANGE);
AddLabel(if showADRLabels and (UpTrend or DownTrend) then yes else no, if UpTrend then  "Target #1: " + oneADRPlus else if DownTrend then "Target #1: " + oneADRMinus  else "I" , if UpTrend then Color.GREEN else if DownTrend then Color.RED else Color.GRAY);
AddLabel(if showADRLabels and (UpTrend or DownTrend) then yes else no, if UpTrend then  "Target #2: " + twoADRPlus else if DownTrend then "Target #2: " + twoADRMinus  else "I" , if UpTrend then Color.GREEN else if DownTrend then Color.RED else Color.GRAY);
AddLabel(if showADRLabels and (UpTrend or DownTrend) then yes else no, if UpTrend then  "Target #3: " + threeADRPlus else if DownTrend then "Target #3: " + threeADRMinus else "I" , if UpTrend then Color.GREEN else if DownTrend then Color.RED else Color.GRAY);
# - Indicator Label
AddLabel(if showIndicatorLabels then yes else no, "RSI:" + RSI + " | sK:" + SlowK + " | Macd:" + Value, Color.ORANGE);




def longSignal = UpTrend == 1;
def barNumberLong = CompoundValue(1, if LongSignal == 1 then barNumberLong[1] + 1 else 0, 0);
plot barsUp = if barNumberLong > 0 then barNumberLong else Double.NaN;
barsUp.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
barsUp.SetDefaultColor(Color.GREEN);
# Dn
def shortSignal = DownTrend == 1;
def barNumberShort = CompoundValue(1, if shortSignal == 1 then barNumberShort[1] + 1 else 0, 0);
plot barsDn = if barNumberShort > 0 then barNumberShort else Double.NaN;
barsDn.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
barsDn.SetDefaultColor(Color.RED);
 

XeoNoX

Well-known member
VIP
You stated "want to compare just the candle that has generated a signal to the one after it." and "plot bbb = uparrow(open)>= uparrow(close);" which my interpretation is you are seeing if the uparrows candle's close is equal to the next ones open. Strange scan because where one bar closes is normally just about always equal to the next bars open unless there is a HALT or market close.

What are you trying to do?
 

BrianPaul

New member
Hi,

I'm trying to find/create an indictor, specifically a label to appear on the chart that will tell me if the stock is in and UP trend or DOWN trend based on the following criteria...(imagine it looks something similar to the below)...

1. Define UP Trend - If the close of the most recent candle is above its previous candle high
2. Define DOWN Trend - If the close of the most recent candle is below its previous candles low

Then when the current candle closes, the trend label would change if needed.

Seems like a standard way to understand trends, but cant find much online that defines trends the same way.

Also, i would like to have more than one time frame to add as a label, like below.

Can anyone help? :)

Thanks!

MbBegua.jpg
 

XeoNoX

Well-known member
VIP
@BrianPaul here at your req:

Code:
declare lower;
def up = close > high[1];
def down = close < low[1];

AddLabel(yes, if up >= 1 then "UP " else if down >=1 then "DOWN" else "NA " , if up >= 1 then Color.DARK_GREEN  else if down >=1 then Color.red else color.gray);
 

BrianPaul

New member
@XeoNoX Awesome! You guys are amazing here. Remind me of a website called MR. Excel if you've ever heard of it. Its like Geniuses in these forums. How would i be able to make it similar the the one here where the colors indicate the up or down signal and there are multiple time frames indicated?? Here is the original code on the referenced example, which i suppose could be used as a base code...i just have no idea how the change the definition of the up or down signal, as this one below is based on moving averages, etc...

Code:
input MAtype = AverageType.EXPONENTIAL;
input ShortAverage = 5;
input LongAverage = 21;

def MA_month_close;
def MA_month_shortAvg;
def MA_month_longAvg;
def MA_month_higher;
def MA_month_lower;
def MA_month_same;
def MA_month_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.MONTH {
    MA_month_close = close(period="Month");
    MA_month_shortAvg = MovingAverage(MAtype, MA_month_close, ShortAverage);
    MA_month_longAvg = MovingAverage(MAtype,MA_month_close, LongAverage);
    MA_month_nowcrossing = if Crosses(MA_month_shortAvg, MA_month_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_month_same = if MA_month_nowcrossing == 1 then 1 else Double.NaN;
    if MA_month_same == 1 {
        MA_month_higher = Double.NaN;
        MA_month_lower = Double.NaN;
    } else {
        MA_month_higher = if MA_month_shortAvg >= MA_month_longAvg then 1 else Double.NaN;
        MA_month_lower = if MA_month_shortAvg < MA_month_longAvg then 1 else Double.NaN;
    }
} else {
    MA_month_close = 0;
    MA_month_shortAvg = 0;
    MA_month_longAvg = 0;
    MA_month_higher = Double.NaN;
    MA_month_lower = Double.NaN;
    MA_month_same = Double.NaN;
    MA_month_nowcrossing = 0;
}
AddLabel(MA_month_higher, "M", Color.DARK_GREEN);
AddLabel(MA_month_lower, "M", Color.DARK_RED);
AddLabel(MA_month_same, "M", Color.WHITE);

def MA_week_close;
def MA_week_shortAvg;
def MA_week_longAvg;
def MA_week_higher;
def MA_week_lower;
def MA_week_same;
def MA_week_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.WEEK {
    MA_week_close = close(period="Week");
    MA_week_shortAvg = MovingAverage(MAtype, MA_week_close, ShortAverage);
    MA_week_longAvg = MovingAverage(MAtype,MA_week_close, LongAverage);
    MA_week_nowcrossing = if Crosses(MA_week_shortAvg, MA_week_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_week_same = if MA_week_nowcrossing == 1 then 1 else Double.NaN;
    if MA_week_same == 1 {
        MA_week_higher = Double.NaN;
        MA_week_lower = Double.NaN;
    } else {
        MA_week_higher = if MA_week_shortAvg >= MA_week_longAvg then 1 else Double.NaN;
        MA_week_lower = if MA_week_shortAvg < MA_week_longAvg then 1 else Double.NaN;
    }
} else {
    MA_week_close = 0;
    MA_week_shortAvg = 0;
    MA_week_longAvg = 0;
    MA_week_higher = Double.NaN;
    MA_week_lower = Double.NaN;
    MA_week_same = Double.NaN;
    MA_week_nowcrossing = 0;
}
AddLabel(MA_week_higher, "W", Color.DARK_GREEN);
AddLabel(MA_week_lower, "W", Color.DARK_RED);
AddLabel(MA_week_same, "W", Color.WHITE);

def MA_4day_close;
def MA_4day_shortAvg;
def MA_4day_longAvg;
def MA_4day_higher;
def MA_4day_lower;
def MA_4day_same;
def MA_4day_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_DAYS {
    MA_4day_close = close(period="4 days");
    MA_4day_shortAvg = MovingAverage(MAtype, MA_4day_close, ShortAverage);
    MA_4day_longAvg = MovingAverage(MAtype,MA_4day_close, LongAverage);
    MA_4day_nowcrossing = if Crosses(MA_4day_shortAvg, MA_4day_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_4day_same = if MA_4day_nowcrossing == 1 then 1 else Double.NaN;
    if MA_4day_same == 1 {
        MA_4day_higher = Double.NaN;
        MA_4day_lower = Double.NaN;
    } else {
        MA_4day_higher = if MA_4day_shortAvg >= MA_4day_longAvg then 1 else Double.NaN;
        MA_4day_lower = if MA_4day_shortAvg < MA_4day_longAvg then 1 else Double.NaN;
    }
} else {
    MA_4day_close = 0;
    MA_4day_shortAvg = 0;
    MA_4day_longAvg = 0;
    MA_4day_higher = Double.NaN;
    MA_4day_lower = Double.NaN;
    MA_4day_same = Double.NaN;
    MA_4day_nowcrossing = 0;
}
AddLabel(MA_4day_higher, "4D", Color.DARK_GREEN);
AddLabel(MA_4day_lower, "4D", Color.DARK_RED);
AddLabel(MA_4day_same, "4D", Color.WHITE);

def MA_3day_close;
def MA_3day_shortAvg;
def MA_3day_longAvg;
def MA_3day_higher;
def MA_3day_lower;
def MA_3day_same;
def MA_3day_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.THREE_DAYS {
    MA_3day_close = close(period="3 days");
    MA_3day_shortAvg = MovingAverage(MAtype, MA_3day_close, ShortAverage);
    MA_3day_longAvg = MovingAverage(MAtype,MA_3day_close, LongAverage);
    MA_3day_nowcrossing = if Crosses(MA_3day_shortAvg, MA_3day_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_3day_same = if MA_3day_nowcrossing == 1 then 1 else Double.NaN;
    if MA_3day_same == 1 {
        MA_3day_higher = Double.NaN;
        MA_3day_lower = Double.NaN;
    } else {
        MA_3day_higher = if MA_3day_shortAvg >= MA_3day_longAvg then 1 else Double.NaN;
        MA_3day_lower = if MA_3day_shortAvg < MA_3day_longAvg then 1 else Double.NaN;
    }
} else {
    MA_3day_close = 0;
    MA_3day_shortAvg = 0;
    MA_3day_longAvg = 0;
    MA_3day_higher = Double.NaN;
    MA_3day_lower = Double.NaN;
    MA_3day_same = Double.NaN;
    MA_3day_nowcrossing = 0;
}
AddLabel(MA_3day_higher, "3D", Color.DARK_GREEN);
AddLabel(MA_3day_lower, "3D", Color.DARK_RED);
AddLabel(MA_3day_same, "3D", Color.WHITE);

def MA_2day_close;
def MA_2day_shortAvg;
def MA_2day_longAvg;
def MA_2day_higher;
def MA_2day_lower;
def MA_2day_same;
def MA_2day_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.TWO_DAYS {
    MA_2day_close = close(period="2 days");
    MA_2day_shortAvg = MovingAverage(MAtype, MA_2day_close, ShortAverage);
    MA_2day_longAvg = MovingAverage(MAtype,MA_2day_close, LongAverage);
    MA_2day_nowcrossing = if Crosses(MA_2day_shortAvg, MA_2day_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_2day_same = if MA_2day_nowcrossing == 1 then 1 else Double.NaN;
    if MA_2day_same == 1 {
        MA_2day_higher = Double.NaN;
        MA_2day_lower = Double.NaN;
    } else {
        MA_2day_higher = if MA_2day_shortAvg >= MA_2day_longAvg then 1 else Double.NaN;
        MA_2day_lower = if MA_2day_shortAvg < MA_2day_longAvg then 1 else Double.NaN;
    }
} else {
    MA_2day_close = 0;
    MA_2day_shortAvg = 0;
    MA_2day_longAvg = 0;
    MA_2day_higher = Double.NaN;
    MA_2day_lower = Double.NaN;
    MA_2day_same = Double.NaN;
    MA_2day_nowcrossing = 0;
}
AddLabel(MA_2day_higher, "2D", Color.DARK_GREEN);
AddLabel(MA_2day_lower, "2D", Color.DARK_RED);
AddLabel(MA_2day_same, "2D", Color.WHITE);

def MA_1day_close;
def MA_1day_shortAvg;
def MA_1day_longAvg;
def MA_1day_higher;
def MA_1day_lower;
def MA_1day_same;
def MA_1day_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.DAY {
    MA_1day_close = close(period="Day");
    MA_1day_shortAvg = MovingAverage(MAtype, MA_1day_close, ShortAverage);
    MA_1day_longAvg = MovingAverage(MAtype,MA_1day_close, LongAverage);
    MA_1day_nowcrossing = if Crosses(MA_1day_shortAvg, MA_1day_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_1day_same = if MA_1day_nowcrossing == 1 then 1 else Double.NaN;
    if MA_1day_same == 1 {
        MA_1day_higher = Double.NaN;
        MA_1day_lower = Double.NaN;
    } else {
        MA_1day_higher = if MA_1day_shortAvg >= MA_1day_longAvg then 1 else Double.NaN;
        MA_1day_lower = if MA_1day_shortAvg < MA_1day_longAvg then 1 else Double.NaN;
    }
} else {
    MA_1day_close = 0;
    MA_1day_shortAvg = 0;
    MA_1day_longAvg = 0;
    MA_1day_higher = Double.NaN;
    MA_1day_lower = Double.NaN;
    MA_1day_same = Double.NaN;
    MA_1day_nowcrossing = 0;
}
AddLabel(MA_1day_higher, "1D", Color.DARK_GREEN);
AddLabel(MA_1day_lower, "1D", Color.DARK_RED);
AddLabel(MA_1day_same, "1D", Color.WHITE);

def MA_4hour_close;
def MA_4hour_shortAvg;
def MA_4hour_longAvg;
def MA_4hour_higher;
def MA_4hour_lower;
def MA_4hour_same;
def MA_4hour_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS {
    MA_4hour_close = close(period="4 hours");
    MA_4hour_shortAvg = MovingAverage(MAtype, MA_4hour_close, ShortAverage);
    MA_4hour_longAvg = MovingAverage(MAtype,MA_4hour_close, LongAverage);
    MA_4hour_nowcrossing = if Crosses(MA_4hour_shortAvg, MA_4hour_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_4hour_same = if MA_4hour_nowcrossing == 1 then 1 else Double.NaN;
    if MA_4hour_same == 1 {
        MA_4hour_higher = Double.NaN;
        MA_4hour_lower = Double.NaN;
    } else {
        MA_4hour_higher = if MA_4hour_shortAvg >= MA_4hour_longAvg then 1 else Double.NaN;
        MA_4hour_lower = if MA_4hour_shortAvg < MA_4hour_longAvg then 1 else Double.NaN;
    }
} else {
    MA_4hour_close = 0;
    MA_4hour_shortAvg = 0;
    MA_4hour_longAvg = 0;
    MA_4hour_higher = Double.NaN;
    MA_4hour_lower = Double.NaN;
    MA_4hour_same = Double.NaN;
    MA_4hour_nowcrossing = 0;
}
AddLabel(MA_4hour_higher, "4h", Color.DARK_GREEN);
AddLabel(MA_4hour_lower, "4h", Color.DARK_RED);
AddLabel(MA_4hour_same, "4h", Color.WHITE);

def MA_2hour_close;
def MA_2hour_shortAvg;
def MA_2hour_longAvg;
def MA_2hour_higher;
def MA_2hour_lower;
def MA_2hour_same;
def MA_2hour_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.TWO_HOURS {
    MA_2hour_close = close(period="2 hours");
    MA_2hour_shortAvg = MovingAverage(MAtype, MA_2hour_close, ShortAverage);
    MA_2hour_longAvg = MovingAverage(MAtype,MA_2hour_close, LongAverage);
    MA_2hour_nowcrossing = if Crosses(MA_2hour_shortAvg, MA_2hour_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_2hour_same = if MA_2hour_nowcrossing == 1 then 1 else Double.NaN;
    if MA_2hour_same == 1 {
        MA_2hour_higher = Double.NaN;
        MA_2hour_lower = Double.NaN;
    } else {
        MA_2hour_higher = if MA_2hour_shortAvg >= MA_2hour_longAvg then 1 else Double.NaN;
        MA_2hour_lower = if MA_2hour_shortAvg < MA_2hour_longAvg then 1 else Double.NaN;
    }
} else {
    MA_2hour_close = 0;
    MA_2hour_shortAvg = 0;
    MA_2hour_longAvg = 0;
    MA_2hour_higher = Double.NaN;
    MA_2hour_lower = Double.NaN;
    MA_2hour_same = Double.NaN;
    MA_2hour_nowcrossing = 0;
}
AddLabel(MA_2hour_higher, "2h", Color.DARK_GREEN);
AddLabel(MA_2hour_lower, "2h", Color.DARK_RED);
AddLabel(MA_2hour_same, "2h", Color.WHITE);

def MA_1hour_close;
def MA_1hour_shortAvg;
def MA_1hour_longAvg;
def MA_1hour_higher;
def MA_1hour_lower;
def MA_1hour_same;
def MA_1hour_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.HOUR {
    MA_1hour_close = close(period="1 hour");
    MA_1hour_shortAvg = MovingAverage(MAtype, MA_1hour_close, ShortAverage);
    MA_1hour_longAvg = MovingAverage(MAtype,MA_1hour_close, LongAverage);
    MA_1hour_nowcrossing = if Crosses(MA_1hour_shortAvg, MA_1hour_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_1hour_same = if MA_1hour_nowcrossing == 1 then 1 else Double.NaN;
    if MA_1hour_same == 1 {
        MA_1hour_higher = Double.NaN;
        MA_1hour_lower = Double.NaN;
    } else {
        MA_1hour_higher = if MA_1hour_shortAvg >= MA_1hour_longAvg then 1 else Double.NaN;
        MA_1hour_lower = if MA_1hour_shortAvg < MA_1hour_longAvg then 1 else Double.NaN;
    }
} else {
    MA_1hour_close = 0;
    MA_1hour_shortAvg = 0;
    MA_1hour_longAvg = 0;
    MA_1hour_higher = Double.NaN;
    MA_1hour_lower = Double.NaN;
    MA_1hour_same = Double.NaN;
    MA_1hour_nowcrossing = 0;
}
AddLabel(MA_1hour_higher, "1h", Color.DARK_GREEN);
AddLabel(MA_1hour_lower, "1h", Color.DARK_RED);
AddLabel(MA_1hour_same, "1h", Color.WHITE);

def MA_30min_close;
def MA_30min_shortAvg;
def MA_30min_longAvg;
def MA_30min_higher;
def MA_30min_lower;
def MA_30min_same;
def MA_30min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN {
    MA_30min_close = close(period="30 min");
    MA_30min_shortAvg = MovingAverage(MAtype, MA_30min_close, ShortAverage);
    MA_30min_longAvg = MovingAverage(MAtype,MA_30min_close, LongAverage);
    MA_30min_nowcrossing = if Crosses(MA_30min_shortAvg, MA_30min_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_30min_same = if MA_30min_nowcrossing == 1 then 1 else Double.NaN;
    if MA_30min_same == 1 {
        MA_30min_higher = Double.NaN;
        MA_30min_lower = Double.NaN;
    } else {
        MA_30min_higher = if MA_30min_shortAvg >= MA_30min_longAvg then 1 else Double.NaN;
        MA_30min_lower = if MA_30min_shortAvg < MA_30min_longAvg then 1 else Double.NaN;
    }
} else {
    MA_30min_close = 0;
    MA_30min_shortAvg = 0;
    MA_30min_longAvg = 0;
    MA_30min_higher = Double.NaN;
    MA_30min_lower = Double.NaN;
    MA_30min_same = Double.NaN;
    MA_30min_nowcrossing = 0;
}
AddLabel(MA_30min_higher, "30m", Color.DARK_GREEN);
AddLabel(MA_30min_lower, "30m", Color.DARK_RED);
AddLabel(MA_30min_same, "30m", Color.WHITE);

def MA_15min_close;
def MA_15min_shortAvg;
def MA_15min_longAvg;
def MA_15min_higher;
def MA_15min_lower;
def MA_15min_same;
def MA_15min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN {
    MA_15min_close = close(period="15 min");
    MA_15min_shortAvg = MovingAverage(MAtype, MA_15min_close, ShortAverage);
    MA_15min_longAvg = MovingAverage(MAtype,MA_15min_close, LongAverage);
    MA_15min_nowcrossing = if Crosses(MA_15min_shortAvg, MA_15min_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_15min_same = if MA_15min_nowcrossing == 1 then 1 else Double.NaN;
    if MA_15min_same == 1 {
        MA_15min_higher = Double.NaN;
        MA_15min_lower = Double.NaN;
    } else {
        MA_15min_higher = if MA_15min_shortAvg >= MA_15min_longAvg then 1 else Double.NaN;
        MA_15min_lower = if MA_15min_shortAvg < MA_15min_longAvg then 1 else Double.NaN;
    }
} else {
    MA_15min_close = 0;
    MA_15min_shortAvg = 0;
    MA_15min_longAvg = 0;
    MA_15min_higher = Double.NaN;
    MA_15min_lower = Double.NaN;
    MA_15min_same = Double.NaN;
    MA_15min_nowcrossing = 0;
}
AddLabel(MA_15min_higher, "15m", Color.DARK_GREEN);
AddLabel(MA_15min_lower, "15m", Color.DARK_RED);
AddLabel(MA_15min_same, "15m", Color.WHITE);

def MA_10min_close;
def MA_10min_shortAvg;
def MA_10min_longAvg;
def MA_10min_higher;
def MA_10min_lower;
def MA_10min_same;
def MA_10min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.TEN_MIN {
    MA_10min_close = close(period="10 min");
    MA_10min_shortAvg = MovingAverage(MAtype, MA_10min_close, ShortAverage);
    MA_10min_longAvg = MovingAverage(MAtype,MA_10min_close, LongAverage);
    MA_10min_nowcrossing = if Crosses(MA_10min_shortAvg, MA_10min_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_10min_same = if MA_10min_nowcrossing == 1 then 1 else Double.NaN;
    if MA_10min_same == 1 {
        MA_10min_higher = Double.NaN;
        MA_10min_lower = Double.NaN;
    } else {
        MA_10min_higher = if MA_10min_shortAvg >= MA_10min_longAvg then 1 else Double.NaN;
        MA_10min_lower = if MA_10min_shortAvg < MA_10min_longAvg then 1 else Double.NaN;
    }
} else {
    MA_10min_close = 0;
    MA_10min_shortAvg = 0;
    MA_10min_longAvg = 0;
    MA_10min_higher = Double.NaN;
    MA_10min_lower = Double.NaN;
    MA_10min_same = Double.NaN;
    MA_10min_nowcrossing = 0;
}
AddLabel(MA_10min_higher, "10m", Color.DARK_GREEN);
AddLabel(MA_10min_lower, "10m", Color.DARK_RED);
AddLabel(MA_10min_same, "10m", Color.WHITE);

def MA_shortAvgmin_close;
def MA_shortAvgmin_shortAvg;
def MA_shortAvgmin_longAvg;
def MA_shortAvgmin_higher;
def MA_shortAvgmin_lower;
def MA_shortAvgmin_same;
def MA_shortAvgmin_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN {
    MA_shortAvgmin_close = close(period="5 min");
    MA_shortAvgmin_shortAvg = MovingAverage(MAtype, MA_shortAvgmin_close, ShortAverage);
    MA_shortAvgmin_longAvg = MovingAverage(MAtype,MA_shortAvgmin_close, LongAverage);
    MA_shortAvgmin_nowcrossing = if Crosses(MA_shortAvgmin_shortAvg, MA_shortAvgmin_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_shortAvgmin_same = if MA_shortAvgmin_nowcrossing == 1 then 1 else Double.NaN;
    if MA_shortAvgmin_same == 1 {
        MA_shortAvgmin_higher = Double.NaN;
        MA_shortAvgmin_lower = Double.NaN;
    } else {
        MA_shortAvgmin_higher = if MA_shortAvgmin_shortAvg >= MA_shortAvgmin_longAvg then 1 else Double.NaN;
        MA_shortAvgmin_lower = if MA_shortAvgmin_shortAvg < MA_shortAvgmin_longAvg then 1 else Double.NaN;
    }
} else {
    MA_shortAvgmin_close = 0;
    MA_shortAvgmin_shortAvg = 0;
    MA_shortAvgmin_longAvg = 0;
    MA_shortAvgmin_higher = Double.NaN;
    MA_shortAvgmin_lower = Double.NaN;
    MA_shortAvgmin_same = Double.NaN;
    MA_shortAvgmin_nowcrossing = 0;
}
AddLabel(MA_shortAvgmin_higher, "5m", Color.DARK_GREEN);
AddLabel(MA_shortAvgmin_lower, "5m", Color.DARK_RED);
AddLabel(MA_shortAvgmin_same, "5m", Color.WHITE);

def MA_4min_close;
def MA_4min_shortAvg;
def MA_4min_longAvg;
def MA_4min_higher;
def MA_4min_lower;
def MA_4min_same;
def MA_4min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_MIN {
    MA_4min_close = close(period="4 min");
    MA_4min_shortAvg = MovingAverage(MAtype, MA_4min_close, ShortAverage);
    MA_4min_longAvg = MovingAverage(MAtype,MA_4min_close, LongAverage);
    MA_4min_nowcrossing = if Crosses(MA_4min_shortAvg, MA_4min_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_4min_same = if MA_4min_nowcrossing == 1 then 1 else Double.NaN;
    if MA_4min_same == 1 {
        MA_4min_higher = Double.NaN;
        MA_4min_lower = Double.NaN;
    } else {
        MA_4min_higher = if MA_4min_shortAvg >= MA_4min_longAvg then 1 else Double.NaN;
        MA_4min_lower = if MA_4min_shortAvg < MA_4min_longAvg then 1 else Double.NaN;
    }
} else {
    MA_4min_close = 0;
    MA_4min_shortAvg = 0;
    MA_4min_longAvg = 0;
    MA_4min_higher = Double.NaN;
    MA_4min_lower = Double.NaN;
    MA_4min_same = Double.NaN;
    MA_4min_nowcrossing = 0;
}
AddLabel(MA_4min_higher, "4m", Color.DARK_GREEN);
AddLabel(MA_4min_lower, "4m", Color.DARK_RED);
AddLabel(MA_4min_same, "4m", Color.WHITE);

def MA_3min_close;
def MA_3min_shortAvg;
def MA_3min_longAvg;
def MA_3min_higher;
def MA_3min_lower;
def MA_3min_same;
def MA_3min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.THREE_MIN {
    MA_3min_close = close(period="3 min");
    MA_3min_shortAvg = MovingAverage(MAtype, MA_3min_close, ShortAverage);
    MA_3min_longAvg = MovingAverage(MAtype,MA_3min_close, LongAverage);
    MA_3min_nowcrossing = if Crosses(MA_3min_shortAvg, MA_3min_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_3min_same = if MA_3min_nowcrossing == 1 then 1 else Double.NaN;
    if MA_3min_same == 1 {
        MA_3min_higher = Double.NaN;
        MA_3min_lower = Double.NaN;
    } else {
        MA_3min_higher = if MA_3min_shortAvg >= MA_3min_longAvg then 1 else Double.NaN;
        MA_3min_lower = if MA_3min_shortAvg < MA_3min_longAvg then 1 else Double.NaN;
    }
} else {
    MA_3min_close = 0;
    MA_3min_shortAvg = 0;
    MA_3min_longAvg = 0;
    MA_3min_higher = Double.NaN;
    MA_3min_lower = Double.NaN;
    MA_3min_same = Double.NaN;
    MA_3min_nowcrossing = 0;
}
AddLabel(MA_3min_higher, "3m", Color.DARK_GREEN);
AddLabel(MA_3min_lower, "3m", Color.DARK_RED);
AddLabel(MA_3min_same, "3m", Color.WHITE);

def MA_2min_close;
def MA_2min_shortAvg;
def MA_2min_longAvg;
def MA_2min_higher;
def MA_2min_lower;
def MA_2min_same;
def MA_2min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.TWO_MIN {
    MA_2min_close = close(period="2 min");
    MA_2min_shortAvg = MovingAverage(MAtype, MA_2min_close, ShortAverage);
    MA_2min_longAvg = MovingAverage(MAtype,MA_2min_close, LongAverage);
    MA_2min_nowcrossing = if Crosses(MA_2min_shortAvg, MA_2min_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_2min_same = if MA_2min_nowcrossing == 1 then 1 else Double.NaN;
    if MA_2min_same == 1 {
        MA_2min_higher = Double.NaN;
        MA_2min_lower = Double.NaN;
    } else {
        MA_2min_higher = if MA_2min_shortAvg >= MA_2min_longAvg then 1 else Double.NaN;
        MA_2min_lower = if MA_2min_shortAvg < MA_2min_longAvg then 1 else Double.NaN;
    }
} else {
    MA_2min_close = 0;
    MA_2min_shortAvg = 0;
    MA_2min_longAvg = 0;
    MA_2min_higher = Double.NaN;
    MA_2min_lower = Double.NaN;
    MA_2min_same = Double.NaN;
    MA_2min_nowcrossing = 0;
}
AddLabel(MA_2min_higher, "2m", Color.DARK_GREEN);
AddLabel(MA_2min_lower, "2m", Color.DARK_RED);
AddLabel(MA_2min_same, "2m", Color.WHITE);


def MA_1min_close;
def MA_1min_shortAvg;
def MA_1min_longAvg;
def MA_1min_higher;
def MA_1min_lower;
def MA_1min_same;
def MA_1min_nowcrossing;
if GetAggregationPeriod() == AggregationPeriod.MIN {
    MA_1min_close = close(period="1 min");
    MA_1min_shortAvg = MovingAverage(MAtype, MA_1min_close, ShortAverage);
    MA_1min_longAvg = MovingAverage(MAtype,MA_1min_close, LongAverage);
    MA_1min_nowcrossing = if Crosses(MA_1min_shortAvg, MA_1min_longAvg, CrossingDirection.ANY) then 1 else 0;
    MA_1min_same = if MA_1min_nowcrossing == 1 then 1 else Double.NaN;
    if MA_1min_same == 1 {
        MA_1min_higher = Double.NaN;
        MA_1min_lower = Double.NaN;
    } else {
        MA_1min_higher = if MA_1min_shortAvg >= MA_1min_longAvg then 1 else Double.NaN;
        MA_1min_lower = if MA_1min_shortAvg < MA_1min_longAvg then 1 else Double.NaN;
    }
} else {
    MA_1min_close = 0;
    MA_1min_shortAvg = 0;
    MA_1min_longAvg = 0;
    MA_1min_higher = Double.NaN;
    MA_1min_lower = Double.NaN;
    MA_1min_same = Double.NaN;
    MA_1min_nowcrossing = 0;
}
AddLabel(MA_1min_higher, "1m", Color.DARK_GREEN);
AddLabel(MA_1min_lower, "1m", Color.DARK_RED);
AddLabel(MA_1min_same, "1m", Color.WHITE);
 

XeoNoX

Well-known member
VIP
Grab all the nowcrossings and plug them in as follows till you have all them inputted:

MA_1min_nowcrossing MA_2min_nowcrossing MA_3min_nowcrossing and so on as listed in your script and plug them in like below.

Code:
AddLabel(yes, if   MA_1min_nowcrossing  and MA_2min_nowcrossing  and MA_3min_nowcrossing = 1 then "UP " else if   MA_1min_nowcrossing  and MA_2min_nowcrossing  and MA_3min_nowcrossing >=1 then "DOWN" else "NA " , if MA_1min_nowcrossing  and MA_2min_nowcrossing  and MA_3min_nowcrossing >= 1 then Color.DARK_GREEN  else color.red);

To be honest with you if you want them all crossing a certain way its more practical to just scan for the symbol(s) using the scanner and an alert and just add all the time frames you want unless you really plan on waiting there for it to all turn green. that can all be done with the built in ToS scanner.
 

BrianPaul

New member
@XeoNoX I'll play around with it and see if I can get it to work. More want to use these as a checklist item before entering into trades, i.e. daily up trend, look for pull backs to get long, etc. I'm finally deciding the spend this year journaling my trades and want to find any correlations I can with winning trades.

This is my first post in this forum and just looking to make some new friends here as it seems like a great group.

For what its worth, to introduce myself, I'm currently a VSA and Supply/Demand trader and studying Wyckoff, Tom Williams (VSA), and Tom Leksey LRA "Locked-In-Range" analysis. But i imagine there is a introduction forum in here somewhere. :)

If you know anyone in the group here you recommend i talk to, please let me know. I'm still a new trader (1 year) and just looking for as much truth as i can find about what really drives the market and how to be consistent.

Thanks again for the help on this.
 

adii800

Member
@BrianPaul

Hey man, finished it up this morning.

This is a picture of the indicator:

Simple_Candle_Trend.png


I've created the indicator to display the 15 specified time frames (from the first image, which was in the original post), if you want to customize them, its pretty ez to do so by playing around with the code.

Indicator code:
Ruby:
#Created by @adii800
#Idea by @BrianPaul

def C1 = close(period = AggregationPeriod.TWO_MIN);
def H1 = high(period = AggregationPeriod.TWO_MIN);
def L1 = low(period = AggregationPeriod.TWO_MIN);
def UpTrend1 = C1 > H1[1];
def DownTrend1 = C1 < L1[1];

def C2 = close(period = AggregationPeriod.THREE_MIN);
def H2 = high(period = AggregationPeriod.THREE_MIN);
def L2 = low(period = AggregationPeriod.THREE_MIN);
def UpTrend2 = C2 > H2[1];
def DownTrend2 = C2 < L2[1];

def C3 = close(period = AggregationPeriod.FOUR_MIN);
def H3 = high(period = AggregationPeriod.FOUR_MIN);
def L3 = low(period = AggregationPeriod.FOUR_MIN);
def UpTrend3 = C3 > H3[1];
def DownTrend3 = C3 < L3[1];

def C4 = close(period = AggregationPeriod.FIVE_MIN);
def H4 = high(period = AggregationPeriod.FIVE_MIN);
def L4 = low(period = AggregationPeriod.FIVE_MIN);
def UpTrend4 = C4 > H4[1];
def DownTrend4 = C4 < L4[1];

def C5 = close(period = AggregationPeriod.TEN_MIN);
def H5 = high(period = AggregationPeriod.TEN_MIN);
def L5 = low(period = AggregationPeriod.TEN_MIN);
def UpTrend5 = C5 > H5[1];
def DownTrend5 = C5 < L5[1];

def C6 = close(period = AggregationPeriod.FIFTEEN_MIN);
def H6 = high(period = AggregationPeriod.FIFTEEN_MIN);
def L6 = low(period = AggregationPeriod.FIFTEEN_MIN);
def UpTrend6 = C6 > H6[1];
def DownTrend6 = C6 < L6[1];

def C7 = close(period = AggregationPeriod.THIRTY_MIN);
def H7 = high(period = AggregationPeriod.THIRTY_MIN);
def L7 = low(period = AggregationPeriod.THIRTY_MIN);
def UpTrend7 = C7 > H7[1];
def DownTrend7 = C7 < L7[1];

def C8 = close(period = AggregationPeriod.HOUR);
def H8 = high(period = AggregationPeriod.HOUR);
def L8 = low(period = AggregationPeriod.HOUR);
def UpTrend8 = C8 > H8[1];
def DownTrend8 = C8 < L8[1];

def C9 = close(period = AggregationPeriod.TWO_HOURS);
def H9 = high(period = AggregationPeriod.TWO_HOURS);
def L9 = low(period = AggregationPeriod.TWO_HOURS);
def UpTrend9 = C9 > H9[1];
def DownTrend9 = C9 < L9[1];

def C10 = close(period = AggregationPeriod.FOUR_HOURS);
def H10 = high(period = AggregationPeriod.FOUR_HOURS);
def L10 = low(period = AggregationPeriod.FOUR_HOURS);
def UpTrend10 = C10 > H10[1];
def DownTrend10 = C10 < L10[1];

def C11 = close(period = AggregationPeriod.DAY);
def H11 = high(period = AggregationPeriod.DAY);
def L11 = low(period = AggregationPeriod.DAY);
def UpTrend11 = C11 > H11[1];
def DownTrend11 = C11 < L11[1];

def C12 = close(period = AggregationPeriod.TWO_DAYS);
def H12 = high(period = AggregationPeriod.TWO_DAYS);
def L12 = low(period = AggregationPeriod.TWO_DAYS);
def UpTrend12 = C12 > H12[1];
def DownTrend12 = C12 < L12[1];

def C13 = close(period = AggregationPeriod.THREE_DAYS);
def H13 = high(period = AggregationPeriod.THREE_DAYS);
def L13 = low(period = AggregationPeriod.THREE_DAYS);
def UpTrend13 = C13 > H13[1];
def DownTrend13 = C13 < L13[1];

def C14 = close(period = AggregationPeriod.FOUR_DAYS);
def H14 = high(period = AggregationPeriod.FOUR_DAYS);
def L14 = low(period = AggregationPeriod.FOUR_DAYS);
def UpTrend14 = C14 > H14[1];
def DownTrend14 = C14 < L14[1];

def C15 = close(period = AggregationPeriod.WEEK);
def H15 = high(period = AggregationPeriod.WEEK);
def L15 = low(period = AggregationPeriod.WEEK);
def UpTrend15 = C15 > H15[1];
def DownTrend15 = C15 < L15[1];


input Show_Labels = yes;

AddLabel(Show_Labels,"W", if UpTrend15 then Color.GREEN else if DownTrend15 then Color.RED else Color.GRAY);
AddLabel(Show_Labels,"4D", if UpTrend14 then Color.GREEN else if DownTrend14 then Color.RED else Color.GRAY);
AddLabel(Show_Labels,"3D", if UpTrend13 then Color.GREEN else if DownTrend13 then Color.RED else Color.GRAY);
AddLabel(Show_Labels,"2D", if UpTrend12 then Color.GREEN else if DownTrend12 then Color.RED else Color.GRAY);
AddLabel(Show_Labels,"1D", if UpTrend11 then Color.GREEN else if DownTrend11 then Color.RED else Color.GRAY);
AddLabel(Show_Labels,"4h", if UpTrend10 then Color.GREEN else if DownTrend10 then Color.RED else Color.GRAY);
AddLabel(Show_Labels,"2h", if UpTrend9 then Color.GREEN else if DownTrend9 then Color.RED else Color.GRAY);
AddLabel(Show_Labels,"1h", if UpTrend8 then Color.GREEN else if DownTrend8 then Color.RED else Color.GRAY);
AddLabel(Show_Labels,"30m", if UpTrend7 then Color.GREEN else if DownTrend7 then Color.RED else Color.GRAY);
AddLabel(Show_Labels,"15m", if UpTrend6 then Color.GREEN else if DownTrend6 then Color.RED else Color.GRAY);
AddLabel(Show_Labels,"10m", if UpTrend5 then Color.GREEN else if DownTrend5 then Color.RED else Color.GRAY);
AddLabel(Show_Labels,"5m", if UpTrend4 then Color.GREEN else if DownTrend4 then Color.RED else Color.GRAY);
AddLabel(Show_Labels,"4m", if UpTrend3 then Color.GREEN else if DownTrend3 then Color.RED else Color.GRAY);
AddLabel(Show_Labels,"3m", if UpTrend2 then Color.GREEN else if DownTrend2 then Color.RED else Color.GRAY);
AddLabel(Show_Labels,"2m", if UpTrend1 then Color.GREEN else if DownTrend1 then Color.RED else Color.GRAY);

Enjoy yall, and tell me if something is wrong :)

Edit: removed the 'tos.mx' link, sorry for being lazy haha
 
Last edited:

bmoney

New member
New to thinkscript and am looking for a way to make a basic indicator that measures the opening stock price - the prior days closing price. any help is appreciated. thank you!
 

Similar threads

Top