0% found this document useful (0 votes)
4 views

f2r2HsHT

The document is a TradingView Pine Script code for an indicator called 'PROFIT FLOW' that utilizes MACD and price action to identify bullish and bearish divergences. It includes various conditions to determine price minima and maxima, as well as smoothing techniques for the oscillator. The indicator plots points on the chart to visualize bullish and bearish divergences based on the calculated values.

Uploaded by

jatinghrera2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

f2r2HsHT

The document is a TradingView Pine Script code for an indicator called 'PROFIT FLOW' that utilizes MACD and price action to identify bullish and bearish divergences. It includes various conditions to determine price minima and maxima, as well as smoothing techniques for the oscillator. The indicator plots points on the chart to visualize bullish and bearish divergences based on the calculated values.

Uploaded by

jatinghrera2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

//@version=5

indicator(title = "PROFIT FLOW", shorttitle = "PPROFIT FLOW")


source = close
long_term_div = input(true, title="Use long term Divergences?")
div_lookback_period = input.int(55, minval=1, title="Lookback Period")
fastLength = input.int(12, minval=1), slowLength = input.int(26, minval=1)
signalLength = input.int(9, minval=1)
smoother = input.int(2, minval=1)
fastMA = ta.ema(source, fastLength)
slowMA = ta.ema(source, slowLength)
macd = fastMA - slowMA
macd2 = (macd / slowMA) * 100
d = ta.sma(macd2, smoother) // smoothing PPO

bullishPrice = low

// Breaking down complex condition into smaller parts for priceMins


priceMinCondition1 = bullishPrice > bullishPrice[1] and bullishPrice[1] <
bullishPrice[2]
priceMinCondition2 = low[1] == low[2] and low[1] < low and low[1] < low[3]
priceMinCondition3 = low[1] == low[2] and low[1] == low[3] and low[1] < low and
low[1] < low[4]
priceMinCondition4 = low[1] == low[2] and low[1] == low[3] and low[1] == low[4] and
low[1] < low and low[1] < low[5]
priceMins = priceMinCondition1 or priceMinCondition2 or priceMinCondition3 or
priceMinCondition4

oscMins = d > d[1] and d[1] < d[2] // this line identifies bottoms in the PPO

BottomPointsInPPO = oscMins

bearishPrice = high

// Breaking down complex condition into smaller parts for priceMax


priceMaxCondition1 = bearishPrice < bearishPrice[1] and bearishPrice[1] >
bearishPrice[2]
priceMaxCondition2 = high[1] == high[2] and high[1] > high and high[1] > high[3]
priceMaxCondition3 = high[1] == high[2] and high[1] == high[3] and high[1] > high
and high[1] > high[4]
priceMaxCondition4 = high[1] == high[2] and high[1] == high[3] and high[1] ==
high[4] and high[1] > high and high[1] > high[5]
priceMax = priceMaxCondition1 or priceMaxCondition2 or priceMaxCondition3 or
priceMaxCondition4

oscMax = d < d[1] and d[1] > d[2] // this line identifies tops in the PPO

TopPointsInPPO = oscMax

currenttrough4 = ta.valuewhen(oscMins, d[1], 0) // identifies the value of PPO at


the most recent BOTTOM in the PPO
lasttrough4 = ta.valuewhen(oscMins, d[1], 1) // NOT USED identifies the value of
PPO at the second most recent BOTTOM in the PPO
currenttrough5 = ta.valuewhen(oscMax, d[1], 0) // identifies the value of PPO at
the most recent TOP in the PPO
lasttrough5 = ta.valuewhen(oscMax, d[1], 1) // NOT USED identifies the value of PPO
at the second most recent TOP in the PPO

currenttrough6 = ta.valuewhen(priceMins, low[1], 0) // this line identifies the low


(price) at the most recent bottom in the Price
lasttrough6 = ta.valuewhen(priceMins, low[1], 1) // NOT USED this line identifies
the low (price) at the second most recent bottom in the Price
currenttrough7 = ta.valuewhen(priceMax, high[1], 0) // this line identifies the
high (price) at the most recent top in the Price
lasttrough7 = ta.valuewhen(priceMax, high[1], 1) // NOT USED this line identifies
the high (price) at the second most recent top in the Price

delayedlow = priceMins and ta.barssince(oscMins) < 3 ? low[1] : na


delayedhigh = priceMax and ta.barssince(oscMax) < 3 ? high[1] : na

// only take tops/bottoms in price when tops/bottoms are less than 5 bars away
filter = ta.barssince(priceMins) < 5 ? ta.lowest(currenttrough6, 4) : na
filter2 = ta.barssince(priceMax) < 5 ? ta.highest(currenttrough7, 4) : na

// delayed bottom/top when oscillator bottom/top is earlier than price bottom/top


y11 = ta.valuewhen(oscMins, delayedlow, 0)
y12 = ta.valuewhen(oscMax, delayedhigh, 0)

// only take tops/bottoms in price when tops/bottoms are less than 5 bars away,
since 2nd most recent top/bottom in osc
y2 = ta.valuewhen(oscMax, filter2, 1) // identifies the highest high in the tops of
price with 5 bar lookback period SINCE the SECOND most recent top in PPO
y6 = ta.valuewhen(oscMins, filter, 1) // identifies the lowest low in the bottoms
of price with 5 bar lookback period SINCE the SECOND most recent bottom in PPO

long_term_bull_filt = ta.valuewhen(priceMins, ta.lowest(div_lookback_period), 1)


long_term_bear_filt = ta.valuewhen(priceMax, ta.highest(div_lookback_period), 1)

y3 = ta.valuewhen(oscMax, currenttrough5, 0) // identifies the value of PPO in the


most recent top of PPO
y4 = ta.valuewhen(oscMax, currenttrough5, 1) // identifies the value of PPO in the
second most recent top of PPO

y7 = ta.valuewhen(oscMins, currenttrough4, 0) // identifies the value of PPO in the


most recent bottom of PPO
y8 = ta.valuewhen(oscMins, currenttrough4, 1) // identifies the value of PPO in the
SECOND most recent bottom of PPO

y9 = ta.valuewhen(oscMins, currenttrough6, 0)
y10 = ta.valuewhen(oscMax, currenttrough7, 0)

bulldiv = BottomPointsInPPO ? d[1] : na // plots dots at bottoms in the PPO


beardiv = TopPointsInPPO ? d[1] : na // plots dots at tops in the PPO

i = currenttrough5 < ta.highest(d, div_lookback_period) // long term bearish


oscillator divergence
i2 = y10 > long_term_bear_filt // long term bearish top divergence
i3 = delayedhigh > long_term_bear_filt // long term bearish delayedhigh divergence

i4 = currenttrough4 > ta.lowest(d, div_lookback_period) // long term bullish osc


divergence
i5 = y9 < long_term_bull_filt // long term bullish bottom div
i6 = delayedlow < long_term_bull_filt // long term bullish delayedbottom div

plot(d, color=color.white)
plot(bulldiv, title="Tops", color=color.aqua, style=plot.style_circles,
linewidth=4, offset=-1)
plot(beardiv, title="Bottoms", color=color.red, style=plot.style_circles,
linewidth=4, offset=-1)
plot(y10 > y2 and oscMax and y3 < y4 ? d : na, title="Bearish Divergence2",
color=color.orange, style=plot.style_circles, linewidth=4)
plot(y9 < y8 ? d : na, title="Bullish Divergence2", color=color.purple,
style=plot.style_circles, linewidth=4)
plot(delayedlow < y8 ? d : na, title="Bullish Divergence2", color=color.purple,
style=plot.style_circles, linewidth=4)
plot(delayedhigh > y2 and y3 < y4 ? d : na, title="Bearish Divergence2",
color=color.orange, style=plot.style_circles, linewidth=4)

plot(long_term_div and oscMax and i and i2 ? d : na, title="Bearish Divergence2",


color=color.orange, style=plot.style_circles, linewidth=4)
plot(long_term_div and oscMins and i4 and i5 ? d : na, title="Bullish Divergence2",
color=color.purple, style=plot.style_circles, linewidth=4)
plot(long_term_div and i and i3 ? d : na, title="Bearish Divergence2",
color=color.orange, style=plot.style_circles, linewidth=4)
plot(long_term_div and i4 and i6 ? d : na, title="Bullish Divergence2",
color=color.purple, style=plot.style_circles, linewidth=4)

You might also like