// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.
0
at https://mozilla.org/MPL/2.0/
// © sehrishqasim067
//@version = 5
strategy("Trend Meter - breakeven", overlay=true,max_lines_count =
500,max_labels_count = 500,max_bars_back = 500,max_boxes_count = 500)
sl_inp = input.float(0.5, title='Stop Loss %', minval= 0.0, step=0.1, group="TP/SL
Settings")
sl_inp := sl_inp / 100
tp_inp = input.float(1.0, title='Take Profit %', minval = 0.0, step=0.1,
group="TP/SL Settings")
tp_inp := tp_inp / 100
tp1 = input.float(0.5, 'TP 1 That activate the Breakeven', group = "TP/SL
Settings" )/100
be = input.float(0.1, 'Breakeven level', group = "TP/SL Settings")/100
rr_active = input.bool(true, "RR %")
/////////////-------------------------- Trend Meter
-----------------------------------/////////////////////////
//indicator(title='Trend Meter')
// s1 = input.bool(true, "Trend Mete Settings")
// Inputs / Menus
PosNegPressure = input.bool(false, 'Pos / Neg Pressure', tooltip='Positive Pressure
= RSI14 and Wave Trend Over Sold with WT Delta Pointing Up
Negative Pressure = RSI14 and Wave Trend Over Bought with WT Delta Pointing Down',
group='Signals')
TMSetups = input.bool(true, 'Trend Meter Signal', tooltip='All 3 Trend Meters Now
Align', group='Signals')
TMSetupsANDWT = input.bool(false, 'Wave Trend Cross Aligns with Trend Meter
Signal', group='Signals')
TrendBar1 = input.string(title='Trend Meter 1', defval='MACD Crossover - Fast - 8,
21, 5', options=['MACD Crossover - 12, 26, 9', 'MACD Crossover - Fast - 8, 21, 5',
'Mom Dad Cross (Top Dog Trading)', 'RSI Signal Line Cross - RSI 13, Sig 21', 'RSI
13: > or < 50', 'RSI 5: > or < 50', 'Trend Candles', 'N/A'], group='Trend Meters')
// "MA Crossover", "DAD Direction (Top Dog Trading)",
TrendBar2 = input.string(title='Trend Meter 2', defval='RSI 13: > or < 50',
options=['MACD Crossover - 12, 26, 9', 'MACD Crossover - Fast - 8, 21, 5', 'Mom Dad
Cross (Top Dog Trading)', 'RSI Signal Line Cross - RSI 13, Sig 21', 'RSI 13: > or <
50', 'RSI 5: > or < 50', 'Trend Candles', 'N/A'], group='Trend Meters') // "MA
Crossover", "DAD Direction (Top Dog Trading)",
TrendBar3 = input.string(title='Trend Meter 3', defval='RSI 5: > or < 50',
options=['MACD Crossover - 12, 26, 9', 'MACD Crossover - Fast - 8, 21, 5', 'Mom Dad
Cross (Top Dog Trading)', 'RSI Signal Line Cross - RSI 13, Sig 21', 'RSI 13: > or <
50', 'RSI 5: > or < 50', 'Trend Candles', 'N/A'], group='Trend Meters') // "MA
Crossover", "DAD Direction (Top Dog Trading)",
////////////////Signals - Wave
Trend//////////////////////////////////////////////////////////////////////////////
///////////////////
// Wave Trend - RSI
RSIMC = ta.rsi(close, 14)
// Wave Trend
ap = hlc3 // input(hlc3, "Wave Trend - Source")
n1 = 9 //input(9, "Wave Trend - WT Channel Length")
n2 = 12 // input(12, "Wave Trend - WT Average Length")
esa = ta.ema(ap, n1)
de = ta.ema(math.abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * de)
tci = ta.ema(ci, n2)
wt1 = tci
wt2 = ta.sma(wt1, 3)
YellowWave = wt1 - wt2
// Wave Trend - Overbought & Oversold lines
obLevel2 = 60 // input( 60, "Wave Trend - WT Very Overbought")
obLevel = 50 // input( 50, "Wave Trend - WT Overbought")
osLevel = -50 // input(-50, "Wave Trend - WT Oversold")
osLevel2 = -60 // input(-60, "Wave Trend - WT Very Oversold")
// Wave Trend - Conditions
WTCross = ta.cross(wt1, wt2)
WTCrossUp = wt2 - wt1 <= 0
WTCrossDown = wt2 - wt1 >= 0
WTOverSold = wt2 <= osLevel2
WTOverBought = wt2 >= obLevel2
// MA Inputs
ShowTrendBar1 = input.bool(true, 'Trend Bar 1', group='Trend Bar 1', inline='Trend
Bar 1')
ShowTrendBar2 = input.bool(true, 'Trend Bar 2', group='Trend Bar 2', inline='Trend
Bar 2')
TrendBar4 = input.string(title='', defval='MA Crossover', options=['MA Crossover',
'MA Direction - Fast MA - TB1', 'MA Direction - Slow MA - TB1'], group='Trend Bar
1', inline='Trend Bar 1') // "MACD Crossover - 12, 26 9", "MACD Crossover - Fast
- 8, 21, 5", "DAD Direction (Top Dog Trading)",
TrendBar5 = input.string(title='', defval='MA Crossover', options=['MA Crossover',
'MA Direction - Fast MA - TB2', 'MA Direction - Slow MA - TB2'], group='Trend Bar
2', inline='Trend Bar 2') // "MACD Crossover - 12, 26 9", "MACD Crossover - Fast
- 8, 21, 5", "DAD Direction (Top Dog Trading)",
MA1_Length = input.int(5, title='Fast MA', minval=1, group='Trend Bar 1',
inline='TB1 Fast')
MA1_Type = input.string(title='', defval='EMA', options=['EMA', 'SMA'],
group='Trend Bar 1', inline='TB1 Fast')
MA2_Length = input.int(11, title='Slow MA', minval=1, group='Trend Bar 1',
inline='TB1 Slow')
MA2_Type = input.string(title='', defval='EMA', options=['EMA', 'SMA'],
group='Trend Bar 1', inline='TB1 Slow')
MA3_Length = input.int(13, title='Fast MA', minval=1, group='Trend Bar 2',
inline='TB2 Fast')
MA3_Type = input.string(title='', defval='EMA', options=['EMA', 'SMA'],
group='Trend Bar 2', inline='TB2 Fast')
MA4_Length = input.int(36, title='Slow MA', minval=1, group='Trend Bar 2',
inline='TB2 Slow')
MA4_Type = input.string(title='', defval='SMA', options=['EMA', 'SMA'],
group='Trend Bar 2', inline='TB2 Slow')
// MA Calculations
Close = close //security(syminfo.tickerid, timeframe.period, close,
barmerge.lookahead_off)
MA1 = if MA1_Type == 'SMA'
ta.sma(Close, MA1_Length)
else
ta.ema(Close, MA1_Length)
MA2 = if MA2_Type == 'SMA'
ta.sma(Close, MA2_Length)
else
ta.ema(Close, MA2_Length)
MA3 = if MA3_Type == 'SMA'
ta.sma(Close, MA3_Length)
else
ta.ema(Close, MA3_Length)
MA4 = if MA4_Type == 'SMA'
ta.sma(Close, MA4_Length)
else
ta.ema(Close, MA4_Length)
// MA Crossover Condition
MACrossover1 = MA1 > MA2 ? 1 : 0
MACrossover2 = MA3 > MA4 ? 1 : 0
// MA Direction Condition
MA1Direction = MA1 > MA1[1] ? 1 : 0
MA2Direction = MA2 > MA2[1] ? 1 : 0
MA3Direction = MA3 > MA3[1] ? 1 : 0
MA4Direction = MA4 > MA4[1] ? 1 : 0
// MA Direction Change Condition
MA1PositiveDirectionChange = MA1Direction and not MA1Direction[1] ? 1 : 0
MA2PositiveDirectionChange = MA2Direction and not MA2Direction[1] ? 1 : 0
MA3PositiveDirectionChange = MA3Direction and not MA3Direction[1] ? 1 : 0
MA4PositiveDirectionChange = MA4Direction and not MA4Direction[1] ? 1 : 0
MA1NegativeDirectionChange = not MA1Direction and MA1Direction[1] ? 1 : 0
MA2NegativeDirectionChange = not MA2Direction and MA2Direction[1] ? 1 : 0
MA3NegativeDirectionChange = not MA3Direction and MA3Direction[1] ? 1 : 0
MA4NegativeDirectionChange = not MA4Direction and MA4Direction[1] ? 1 : 0
// MACD and MOM & DAD - Top Dog Trading
// Standard MACD Calculations
MACDfastMA = 12
MACDslowMA = 26
MACDsignalSmooth = 9
MACDLine = ta.ema(close, MACDfastMA) - ta.ema(close, MACDslowMA)
SignalLine = ta.ema(MACDLine, MACDsignalSmooth)
MACDHistogram = MACDLine - SignalLine
// MACD- Background Color Change Condition
MACDHistogramCross = MACDHistogram > 0 ? 1 : 0
MACDLineOverZero = MACDLine > 0 ? 1 : 0
MACDLineOverZeroandHistogramCross = MACDHistogramCross and MACDLineOverZero ? 1 : 0
MACDLineUnderZeroandHistogramCross = not MACDHistogramCross and not
MACDLineOverZero ? 1 : 0
// Fast MACD Calculations
FastMACDfastMA = 8
FastMACDslowMA = 21
FastMACDsignalSmooth = 5
FastMACDLine = ta.ema(close, FastMACDfastMA) - ta.ema(close, FastMACDslowMA)
FastSignalLine = ta.ema(FastMACDLine, FastMACDsignalSmooth)
FastMACDHistogram = FastMACDLine - FastSignalLine
// Fast MACD- Background Color Change Condition
FastMACDHistogramCross = FastMACDHistogram > 0 ? 1 : 0
FastMACDLineOverZero = FastMACDLine > 0 ? 1 : 0
FastMACDLineOverZeroandHistogramCross = FastMACDHistogramCross and
FastMACDLineOverZero ? 1 : 0
FastMACDLineUnderZeroandHistogramCross = not FastMACDHistogramCross and not
FastMACDLineOverZero ? 1 : 0
// Top Dog Trading - Mom Dad Calculations
TopDog_Fast_MA = 5
TopDog_Slow_MA = 20
TopDog_Sig = 30
TopDogMom = ta.ema(close, TopDog_Fast_MA) - ta.ema(close, TopDog_Slow_MA)
TopDogDad = ta.ema(TopDogMom, TopDog_Sig)
// Top Dog Dad - Background Color Change Condition
TopDogDadDirection = TopDogDad > TopDogDad[1] ? 1 : 0
TopDogMomOverDad = TopDogMom > TopDogDad ? 1 : 0
TopDogMomOverZero = TopDogMom > 0 ? 1 : 0
TopDogDadDirectandMomOverZero = TopDogDadDirection and TopDogMomOverZero ? 1 : 0
TopDogDadDirectandMomUnderZero = not TopDogDadDirection and not TopDogMomOverZero ?
1 : 0
////// Trend Barmeter Calculations //////
// UCS_Trend / Trend Candles Trend Barmeter Calculations
//UCS_Trend by ucsgears copy Trend Candles
//Interpretation of TTM Trend bars. It is really close to the actual.
haclose = ohlc4
haopen = 0.0
haopen := na(haopen[1]) ? (open + close) / 2 : (haopen[1] + haclose[1]) / 2
//hahigh = max(high, max(haopen, haclose))
//halow = min(low, min(haopen, haclose))
ccolor = haclose - haopen > 0 ? 1 : 0
inside6 = haopen <= math.max(haopen[6], haclose[6]) and haopen >=
math.min(haopen[6], haclose[6]) and haclose <= math.max(haopen[6], haclose[6]) and
haclose >= math.min(haopen[6], haclose[6]) ? 1 : 0
inside5 = haopen <= math.max(haopen[5], haclose[5]) and haopen >=
math.min(haopen[5], haclose[5]) and haclose <= math.max(haopen[5], haclose[5]) and
haclose >= math.min(haopen[5], haclose[5]) ? 1 : 0
inside4 = haopen <= math.max(haopen[4], haclose[4]) and haopen >=
math.min(haopen[4], haclose[4]) and haclose <= math.max(haopen[4], haclose[4]) and
haclose >= math.min(haopen[4], haclose[4]) ? 1 : 0
inside3 = haopen <= math.max(haopen[3], haclose[3]) and haopen >=
math.min(haopen[3], haclose[3]) and haclose <= math.max(haopen[3], haclose[3]) and
haclose >= math.min(haopen[3], haclose[3]) ? 1 : 0
inside2 = haopen <= math.max(haopen[2], haclose[2]) and haopen >=
math.min(haopen[2], haclose[2]) and haclose <= math.max(haopen[2], haclose[2]) and
haclose >= math.min(haopen[2], haclose[2]) ? 1 : 0
inside1 = haopen <= math.max(haopen[1], haclose[1]) and haopen >=
math.min(haopen[1], haclose[1]) and haclose <= math.max(haopen[1], haclose[1]) and
haclose >= math.min(haopen[1], haclose[1]) ? 1 : 0
colorvalue = inside6 ? ccolor[6] : inside5 ? ccolor[5] : inside4 ? ccolor[4] :
inside3 ? ccolor[3] : inside2 ? ccolor[2] : inside1 ? ccolor[1] : ccolor
TrendBarTrend_Candle_Color = colorvalue ? #288a75 : color.red
TrendBarTrend_Candle = colorvalue ? 1 : 0
// RSI 5 Trend Barmeter Calculations
RSI5 = ta.rsi(close, 5)
RSI5Above50 = RSI5 > 50 ? 1 : 0
RSI5Color = RSI5Above50 ? #288a75 : color.red
TrendBarRSI5Color = RSI5Above50 ? #288a75 : color.red
// RSI 5 Trend Barmeter Calculations
RSI13 = ta.rsi(close, 13)
// Linear Regression Calculation For RSI Signal Line
SignalLineLength1 = 21
x = bar_index
y = RSI13
x_ = ta.sma(x, SignalLineLength1)
y_ = ta.sma(y, SignalLineLength1)
mx = ta.stdev(x, SignalLineLength1)
my = ta.stdev(y, SignalLineLength1)
c = ta.correlation(x, y, SignalLineLength1)
slope = c * (my / mx)
inter = y_ - slope * x_
LinReg1 = x * slope + inter
RSISigDirection = LinReg1 > LinReg1[1] ? 1 : 0
RSISigCross = RSI13 > LinReg1 ? 1 : 0
RSI13Above50 = RSI13 > 50 ? 1 : 0
// Trend Barmeter Color Calculation
RSI13Color = RSI13Above50 ? #288a75 : color.red
TrendBarRSI13Color = RSI13Above50 ? #288a75 : color.red
TrendBarRSISigCrossColor = RSISigCross ? #288a75 : color.red
TrendBarMACDColor = MACDHistogramCross ? #288a75 : color.red
TrendBarFastMACDColor = FastMACDHistogramCross ? #288a75 : color.red
TrendBarMACrossColor = MACrossover1 ? #288a75 : color.red
TrendBarMomOverDadColor = TopDogMomOverDad ? #288a75 : color.red
TrendBarDadDirectionColor = TopDogDadDirection ? #288a75 : color.red
TrendBar1Result = TrendBar1 == 'MA Crossover' ? MACrossover1 : TrendBar1 == 'MACD
Crossover - 12, 26, 9' ? MACDHistogramCross : TrendBar1 == 'MACD Crossover - Fast -
8, 21, 5' ? FastMACDHistogramCross : TrendBar1 == 'Mom Dad Cross (Top Dog Trading)'
? TopDogMomOverDad : TrendBar1 == 'DAD Direction (Top Dog Trading)' ?
TopDogDadDirection : TrendBar1 == 'RSI Signal Line Cross - RSI 13, Sig 21' ?
RSISigCross : TrendBar1 == 'RSI 5: > or < 50' ? RSI5Above50 : TrendBar1 == 'RSI 13:
> or < 50' ? RSI13Above50 : TrendBar1 == 'Trend Candles' ? TrendBarTrend_Candle :
na
TrendBar2Result = TrendBar2 == 'MA Crossover' ? MACrossover1 : TrendBar2 == 'MACD
Crossover - 12, 26, 9' ? MACDHistogramCross : TrendBar2 == 'MACD Crossover - Fast -
8, 21, 5' ? FastMACDHistogramCross : TrendBar2 == 'Mom Dad Cross (Top Dog Trading)'
? TopDogMomOverDad : TrendBar2 == 'DAD Direction (Top Dog Trading)' ?
TopDogDadDirection : TrendBar2 == 'RSI Signal Line Cross - RSI 13, Sig 21' ?
RSISigCross : TrendBar2 == 'RSI 5: > or < 50' ? RSI5Above50 : TrendBar2 == 'RSI 13:
> or < 50' ? RSI13Above50 : TrendBar2 == 'Trend Candles' ? TrendBarTrend_Candle :
na
TrendBar3Result = TrendBar3 == 'MA Crossover' ? MACrossover1 : TrendBar3 == 'MACD
Crossover - 12, 26, 9' ? MACDHistogramCross : TrendBar3 == 'MACD Crossover - Fast -
8, 21, 5' ? FastMACDHistogramCross : TrendBar3 == 'Mom Dad Cross (Top Dog Trading)'
? TopDogMomOverDad : TrendBar3 == 'DAD Direction (Top Dog Trading)' ?
TopDogDadDirection : TrendBar3 == 'RSI Signal Line Cross - RSI 13, Sig 21' ?
RSISigCross : TrendBar3 == 'RSI 5: > or < 50' ? RSI5Above50 : TrendBar3 == 'RSI 13:
> or < 50' ? RSI13Above50 : TrendBar3 == 'Trend Candles' ? TrendBarTrend_Candle :
na
TrendBars2Positive = TrendBar1Result and TrendBar2Result or TrendBar1Result and
TrendBar3Result or TrendBar2Result and TrendBar3Result ? 1 : 0
TrendBars2Negative = not TrendBar1Result and not TrendBar2Result or not
TrendBar1Result and not TrendBar3Result or not TrendBar2Result and not
TrendBar3Result ? 1 : 0
TrendBars3Positive = TrendBar1Result and TrendBar2Result and TrendBar3Result ? 1 :
0
TrendBars3Negative = not TrendBar1Result and not TrendBar2Result and not
TrendBar3Result ? 1 : 0
PositiveWaveTrendCross = WTCross and WTCrossUp
NegativeWaveTrendCross = WTCross and WTCrossDown
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////
BackgroundColorChangePositive = TrendBars3Positive and not TrendBars3Positive[1]
BackgroundColorChangeNegative = TrendBars3Negative and not TrendBars3Negative[1]
// Signals Color Calculations
MSBar2Color = BackgroundColorChangePositive ? #288a75 :
BackgroundColorChangeNegative ? color.red : na
// Trend Barmeter Color Assignments
TrendBar1Color = TrendBar1 == 'N/A' ? na : TrendBar1 == 'MACD Crossover - 12, 26,
9' ? TrendBarMACDColor : TrendBar1 == 'MACD Crossover - Fast - 8, 21, 5' ?
TrendBarFastMACDColor : TrendBar1 == 'Mom Dad Cross (Top Dog Trading)' ?
TrendBarMomOverDadColor : TrendBar1 == 'DAD Direction (Top Dog Trading)' ?
TrendBarDadDirectionColor : TrendBar1 == 'RSI Signal Line Cross - RSI 13, Sig 21' ?
TrendBarRSISigCrossColor : TrendBar1 == 'RSI 5: > or < 50' ? TrendBarRSI5Color :
TrendBar1 == 'RSI 13: > or < 50' ? TrendBarRSI13Color : TrendBar1 == 'Trend
Candles' ? TrendBarTrend_Candle_Color : TrendBar1 == 'MA Crossover' ?
TrendBarMACrossColor : na
TrendBar2Color = TrendBar2 == 'N/A' ? na : TrendBar2 == 'MACD Crossover - 12, 26,
9' ? TrendBarMACDColor : TrendBar2 == 'MACD Crossover - Fast - 8, 21, 5' ?
TrendBarFastMACDColor : TrendBar2 == 'Mom Dad Cross (Top Dog Trading)' ?
TrendBarMomOverDadColor : TrendBar2 == 'DAD Direction (Top Dog Trading)' ?
TrendBarDadDirectionColor : TrendBar2 == 'RSI Signal Line Cross - RSI 13, Sig 21' ?
TrendBarRSISigCrossColor : TrendBar2 == 'RSI 5: > or < 50' ? TrendBarRSI5Color :
TrendBar2 == 'RSI 13: > or < 50' ? TrendBarRSI13Color : TrendBar2 == 'Trend
Candles' ? TrendBarTrend_Candle_Color : TrendBar2 == 'MA Crossover' ?
TrendBarMACrossColor : na
TrendBar3Color = TrendBar3 == 'N/A' ? na : TrendBar3 == 'MACD Crossover - 12, 26,
9' ? TrendBarMACDColor : TrendBar3 == 'MACD Crossover - Fast - 8, 21, 5' ?
TrendBarFastMACDColor : TrendBar3 == 'Mom Dad Cross (Top Dog Trading)' ?
TrendBarMomOverDadColor : TrendBar3 == 'DAD Direction (Top Dog Trading)' ?
TrendBarDadDirectionColor : TrendBar3 == 'RSI Signal Line Cross - RSI 13, Sig 21' ?
TrendBarRSISigCrossColor : TrendBar3 == 'RSI 5: > or < 50' ? TrendBarRSI5Color :
TrendBar3 == 'RSI 13: > or < 50' ? TrendBarRSI13Color : TrendBar3 == 'Trend
Candles' ? TrendBarTrend_Candle_Color : TrendBar3 == 'MA Crossover' ?
TrendBarMACrossColor : na
CrossoverType2 = TrendBar4 == 'DAD Direction (Top Dog Trading)' ?
TopDogDadDirection : TrendBar4 == 'MACD Crossover' ? MACDHistogramCross : TrendBar4
== 'MA Direction - Fast MA - TB1' ? MA1Direction : TrendBar4 == 'MA Direction -
Slow MA - TB1' ? MA2Direction : MACrossover1
color_1 = color.new(color.green, 15)
color_2 = color.new(color.red, 20)
TrendBar4Color1 = TrendBar4 == 'N/A' ? na : CrossoverType2 ? color_1 : color_2
CrossoverType3 = TrendBar5 == 'DAD Direction (Top Dog Trading)' ?
TopDogDadDirection : TrendBar5 == 'MACD Crossover' ? MACDHistogramCross : TrendBar5
== 'MA Direction - Fast MA - TB2' ? MA3Direction : TrendBar5 == 'MA Direction -
Slow MA - TB2' ? MA4Direction : MACrossover2
color_3 = color.new(color.green, 15)
color_4 = color.new(color.red, 20)
TrendBar5Color1 = TrendBar5 == 'N/A' ? na : CrossoverType3 ? color_3 : color_4
WTVOB = wt1 > 60
WTVOS = wt1 < -60
// Weekness / Pos/Neg Pressure
YellowWavePointingUp = YellowWave > YellowWave[1]
RSI14 = ta.rsi(close, 14)
RSI14OB = RSI14 > 70 ? 1 : 0
RSI14OS = RSI14 < 30 ? 1 : 0
RSI14OBOS = RSI14OB or RSI14OS ? 1 : 0
OBIndicatorsYellowPointingDown = (RSI14OB or RSI14OB[1]) and WTVOB and not
YellowWavePointingUp
OSIndicatorsYellowPointingUp = (RSI14OS or RSI14OS[1]) and WTVOS and
YellowWavePointingUp
// plot(PosNegPressure and OSIndicatorsYellowPointingUp ? 138.5 : na, 'Wave Trend -
Positive Pressure', color=color.new(#288a75, 25), style=plot.style_circles,
linewidth=1)
// plot(PosNegPressure and OBIndicatorsYellowPointingDown ? 138.5 : na, 'Wave Trend
- Negative Pressure', color=color.new(#DC143C, 32), style=plot.style_circles,
linewidth=1)
// alertcondition(OBIndicatorsYellowPointingDown or OSIndicatorsYellowPointingUp,
title=' - Pos / Neg Pressure', message='Pos / Neg Pressure - Trend Meter')
// plot(TMSetups ? 134.5 : na, title='All 3 Trend Meters Now Align',
style=plot.style_circles, color=MSBar2Color, linewidth=3, transp=20)
// plot(TMSetupsANDWT and (PositiveWaveTrendCross and TrendBars3Positive or
NegativeWaveTrendCross and TrendBars3Negative) ? 134.5 : na, title='Wave Trend X &
All 3 Trend Meters Now Align', style=plot.style_cross, color=MSBar2Color,
linewidth=4, transp=20)
// Trend Barmeter Plots
// plot(128.5, title='Trend Meter 1', style=plot.style_circles,
color=TrendBar1Color, linewidth=2, transp=18)
// plot(122.5, title='Trend Meter 2', style=plot.style_circles,
color=TrendBar2Color, linewidth=2, transp=18)
// plot(116.5, title='Trend Meter 3', style=plot.style_circles,
color=TrendBar3Color, linewidth=2, transp=18)
// plot(ShowTrendBar1 and ShowTrendBar2 ? 110 : na, title='Trend Bar 1 - Thin
Line', style=plot.style_line, color=TrendBar4Color1, linewidth=4, transp=20)
// plot(ShowTrendBar1 and not ShowTrendBar2 ? 110 : na, title='Trend Bar 1 - Thick
Line', style=plot.style_line, color=TrendBar4Color1, linewidth=9, transp=20)
// plot(ShowTrendBar2 and ShowTrendBar1 ? 104.5 : na, title='Trend Bar 2 - Thin
Line', style=plot.style_line, color=TrendBar5Color1, linewidth=6, transp=20)
// plot(ShowTrendBar2 and not ShowTrendBar1 ? 110 : na, title='Trend Bar 2 - Thick
Line', style=plot.style_line, color=TrendBar5Color1, linewidth=9, transp=20)
// Background Highlights
TrendBar3BarsSame = TrendBars3Positive ? color.green : TrendBars3Negative ?
color.red : na
// TMa = hline(113.7, color=color.new(color.white, 100))
// TMb = hline(131.3, color=color.new(color.white, 100))
// fill(TMa, TMb, color=TrendBar3BarsSame, title='Trend Meter Background Highlight
- 3 Trend Meter Conditions Met', transp=91)
////////////////----------------------------- EMA Trend
----------------------------------////////////////
// indicator('EMA Trend', overlay=true)
Curly_Fries = input(50, title='Fast',group="EMA Trend Settings")
Popeyes = input(200, title='Medium',group="EMA Trend Settings")
Chicken_Sandwich = input(200, 'Slow',group="EMA Trend Settings")
ema_150 = ta.ema(close, Curly_Fries)
ema_200 = ta.ema(close, Popeyes)
ema_250 = ta.ema(close, Chicken_Sandwich)
a = plot(ema_150, transp=100)
b = plot(ema_200, transp=100)
c_1 = plot(ema_250, transp=100)
up = ema_150 > ema_250
down = ema_150 < ema_250
mycolor = up ? color.green : down ? color.red : na
fill(a, c_1, color=mycolor, transp=40)
//////////////-------------------------------- ADX
-----------------------------------//////////////////////
//indicator("Average Directional Index", shorttitle="ADX", format=format.price,
precision=2, timeframe="", timeframe_gaps=true)
adxlen = input(14, title="ADX Smoothing",group="ADX Settings")
dilen = input(14, title="DI Length",group="ADX Settings")
adx_level = input(20, title = "ADX level",group="ADX Settings")
dirmov(len) =>
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
// plot(sig, color=color.red, title="ADX")
///////////////---------------------------- Conditions
--------------------------------------//////////////////
longCondition = up and close > ema_150 and close > ema_250 and
BackgroundColorChangePositive and CrossoverType2 and sig > adx_level
shortCondition = down and close < ema_150 and close < ema_250 and
BackgroundColorChangeNegative and not CrossoverType2 and sig > adx_level
var long_sl = 0.0
var long_tp = 0.0
var long_be = 0.0
var short_sl = 0.0
var short_tp = 0.0
var short_be = 0.0
var long_sl_up5=0.0
var long_tp_up5=0.0
var long_be_up5=0.0
var short_sl_up5=0.0
var short_tp_up5=0.0
var short_be_up5=0.0
var sell_tp=line.new(na,na,na,na)
var sell_be=line.new(na,na,na,na)
var sell_sl=line.new(na,na,na,na)
var sell_entry=line.new(na,na,na,na)
var sell_topbox=box.new(na,na,na,na)
var sell_bottombox=box.new(na,na,na,na)
var buy_tp=line.new(na,na,na,na)
var buy_be=line.new(na,na,na,na)
var buy_sl=line.new(na,na,na,na)
var buy_entry=line.new(na,na,na,na)
var buy_topbox=box.new(na,na,na,na)
var buy_bottombox=box.new(na,na,na,na)
// Submit entry (or reverse) orders
if longCondition and strategy.position_size <= 0
//i=input("")
//label.new(bar_index,low,
text="Buy" ,color=color.green,textcolor=color.white,style=label.style_label_up)
strategy.entry(id='long', direction=strategy.long,alert_message= "Long Entry
Alert")
long_sl_up5 := close * (1 - sl_inp)
long_tp_up5 := rr_active ? close + math.abs(close-long_sl_up5)*2 : close * (1 +
tp_inp)
long_be_up5 := close + math.abs(close-long_sl_up5)*1
//long_sl := low[1]
//long_tp := close + (close - long_sl) * tpLength
buy_sl :=
line.new(bar_index,long_sl_up5,bar_index+10,long_sl_up5,color=color.red)
buy_tp :=
line.new(bar_index,long_tp_up5,bar_index+10,long_tp_up5,color=color.green)
buy_be :=
line.new(bar_index,long_be_up5,bar_index+10,long_be_up5,color=color.yellow)
buy_entry := line.new(bar_index, close ,bar_index+10,close,color=color.purple)
buy_topbox :=
box.new(bar_index,long_tp_up5,bar_index+10,close,bgcolor=color.new(color.green,90),
border_color=color.new(color.green,100))
buy_bottombox :=
box.new(bar_index,close,bar_index+10,long_sl_up5,bgcolor=color.new(color.red,90),bo
rder_color=color.new(color.green,100))
if shortCondition and strategy.position_size >= 0
//label.new(bar_index,high,"Sell",color=color.red,textcolor=color.white)
strategy.entry(id='short', direction=strategy.short,alert_message= "Short Entry
Alert")
short_sl_up5 := close * (1 + sl_inp)
short_tp_up5 := rr_active ? close - math.abs(close-short_sl_up5)*2 : close * (1
- tp_inp)
short_be_up5 := close - math.abs(close-short_sl_up5)
//short_sl := math.max(high[1],high)
//short_tp := close - (short_sl - close) * tpLength
sell_sl :=
line.new(bar_index,short_sl_up5,bar_index+20,short_sl_up5,color=color.red)
sell_tp:=
line.new(bar_index,short_tp_up5,bar_index+20,short_tp_up5,color=color.green)
sell_be:=
line.new(bar_index,short_be_up5,bar_index+20,short_be_up5,color=color.yellow)
sell_entry := line.new(bar_index, close ,bar_index+20,close,color=color.purple)
sell_bottombox :=
box.new(bar_index,short_sl_up5,bar_index+20,close,bgcolor=color.new(color.red,90),b
order_color=color.new(color.green,100))
sell_topbox :=
box.new(bar_index,close,bar_index+20,short_tp_up5,bgcolor=color.new(color.green,90)
,border_color=color.new(color.green,100))
if strategy.position_size < 0
if low < strategy.position_avg_price - (strategy.position_avg_price*tp1)
short_sl_up5 := strategy.position_avg_price -
(strategy.position_avg_price*be)
short_be_up5 := strategy.position_avg_price -
(strategy.position_avg_price*tp1)
box.set_top(sell_bottombox, strategy.position_avg_price)
line.set_x2(sell_tp,bar_index+1)
line.set_x2(sell_be,bar_index+1)
line.set_x2(sell_sl,bar_index+1)
line.set_y2(sell_be, short_be_up5)
line.set_y1(sell_be, short_be_up5)
line.set_y2(sell_sl, short_sl_up5)
line.set_y1(sell_sl, short_sl_up5)
line.set_x2(sell_entry,bar_index+1)
box.set_right(sell_bottombox,bar_index+1)
box.set_right(sell_topbox,bar_index+1)
strategy.exit("Short TP/SL","short" ,
stop=short_sl_up5,limit=short_tp_up5,alert_message= "Short TP/SL Alert")
//box.set_right()
if strategy.position_size > 0
if high > strategy.position_avg_price + (strategy.position_avg_price*tp1)
long_be_up5 := strategy.position_avg_price +
(strategy.position_avg_price*tp1)
long_sl_up5 := strategy.position_avg_price +
(strategy.position_avg_price*be)
box.set_bottom(buy_bottombox, strategy.position_avg_price)
line.set_x2(buy_tp,bar_index+1)
line.set_x2(buy_be,bar_index+1)
line.set_x2(buy_sl,bar_index+1)
line.set_y2(buy_sl,long_sl_up5)
line.set_y1(buy_sl,long_sl_up5)
line.set_y2(buy_be,long_be_up5)
line.set_y1(buy_be,long_be_up5)
line.set_x2(buy_entry,bar_index+1)
box.set_right(buy_bottombox,bar_index+1)
box.set_right(buy_topbox,bar_index+1)
strategy.exit("Long TP/SL","long" ,
stop=long_sl_up5,limit=long_tp_up5,alert_message= "Long TP/SL Alert")