// This source code is subject to the terms of the Mozilla Public License 2.
0 at
// [Link]
// © moneymovesalgo
//@version=5
indicator('GG Shot - Decoded', overlay=true)
length = input(title='Period', defval=1)
mult = [Link](title='Multiplier', step=0.1, defval=13)
//ichimoku inputs
conversionPeriods = [Link](9, minval=1, title='Conversion Line Periods')
basePeriods = [Link](26, minval=1, title='Base Line Periods')
laggingSpan2Periods = [Link](52, minval=1, title='Lagging Span 2 Periods')
displacement = [Link](26, minval=1, title='Displacement')
//algo
atr = mult * [Link](length)
//kumo
donchian(len) =>
[Link]([Link](len), [Link](len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = [Link](conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
longStop = hl2 - atr
longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? [Link](longStop, longStopPrev) : longStop
shortStop = hl2 + atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? [Link](shortStop, shortStopPrev) :
shortStop
dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and close > shortStopPrev ? 1 : dir == 1 and close <
longStopPrev ? -1 : dir
longColor = [Link]
shortColor = [Link]
// Define long and short conditions
longCond = [Link](close[1], shortStopPrev)
shortCond = [Link](close[1], longStopPrev)
var float sectionLongs = 0
var float sectionShorts = 0
if longCond
sectionLongs := sectionLongs + 1
sectionShorts := 0
if shortCond
sectionLongs := 0
sectionShorts := sectionShorts + 1
pyrl = 1
longCondition = longCond and sectionLongs <= pyrl
shortCondition = shortCond and sectionShorts <= pyrl
// Initialize last open prices properly
var float last_open_longCondition = na
var float last_open_shortCondition = na
last_open_longCondition := longCondition ? open : nz(last_open_longCondition[1])
last_open_shortCondition := shortCondition ? open : nz(last_open_shortCondition[1])
// Check if your last position was a long or a short
var float last_longCondition = na
var float last_shortCondition = na
last_longCondition := longCondition ? time : nz(last_longCondition[1])
last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])
in_longCondition = last_longCondition > last_shortCondition
in_shortCondition = last_shortCondition > last_longCondition
// Take profit
isTPl = input(true, 'Take Profit Long')
isTPs = input(true, 'Take Profit Short')
tp = input(2, 'Take Profit %')
long_tp = isTPl and [Link](high, (1 + tp / 100) * last_open_longCondition)
and not longCondition and in_longCondition
short_tp = isTPs and [Link](low, (1 - tp / 100) * last_open_shortCondition)
and not shortCondition and in_shortCondition
// Stop Loss
isSLl = input(false, 'Stop Loss Long')
isSLs = input(false, 'Stop Loss Short')
sl = [Link](3, 'Stop Loss %')
long_sl = isSLl and [Link](low, (1 - sl / 100) * last_open_longCondition)
and not longCondition and in_longCondition
short_sl = isSLs and [Link](high, (1 + sl / 100) * last_open_shortCondition)
and not shortCondition and in_shortCondition
// Create a single close for all closing conditions
long_close = long_tp or long_sl ? 1 : 0
short_close = short_tp or short_sl ? 1 : 0
// Get the time of the last close
var float last_long_close = na
var float last_short_close = na
last_long_close := long_close ? time : nz(last_long_close[1])
last_short_close := short_close ? time : nz(last_short_close[1])
// Signals
plotchar(long_tp and last_longCondition > nz(last_long_close[1]), text='TP',
title='Take Profit Long', size=[Link], location=[Link],
color=[Link]([Link], 0))
plotchar(short_tp and last_shortCondition > nz(last_short_close[1]), text='TP',
title='Take Profit Short', size=[Link], location=[Link],
color=[Link]([Link], 0))
plotchar(long_sl and last_longCondition > nz(last_long_close[1]), char='⛔',
text='SL LONG', title='Stop Loss Long', size=[Link], location=[Link],
color=[Link]([Link], 0))
plotchar(short_sl and last_shortCondition > nz(last_short_close[1]), char='⛔',
text='SL SHORT', title='Stop Loss Short', size=[Link],
location=[Link], color=[Link]([Link], 0))
plotshape(dir == 1 and dir[1] == -1 ? longStop : na, title='LONG',
style=[Link], location=[Link], size=[Link], text='LONG',
textcolor=[Link]([Link], 0), color=[Link]([Link], 0))
plotshape(dir == -1 and dir[1] == 1 ? shortStop : na, title='SHORT',
style=[Link], location=[Link], size=[Link],
text='SHORT', textcolor=[Link]([Link], 0), color=[Link]([Link], 0))