PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © btc_charlie / @TheParagonGrp
//@version=5
strategy('*', overlay=true,explicit_plot_zorder=true)
// Variables
var ok = 0
var countBuy = 0
var countSell = 0
src = input(close, title='OHLC Type')
i_fastEMA = input(12, title='Fast EMA')
i_slowEMA = input(25, title='Slow EMA')
i_defEMA = input(25, title='Consolidated EMA')
// Allow the option to show single or double EMA
i_bothEMAs = input(title='Show Both EMAs', defval=true)
// Define EMAs
v_fastEMA = ta.ema(src, i_fastEMA)
v_slowEMA = ta.ema(src, i_slowEMA)
v_biasEMA = ta.ema(src, i_defEMA)
// Color the EMAs
emaColor = v_fastEMA > v_slowEMA ? color.rgb(76, 175, 79, 100) : v_fastEMA < v_slowEMA ? color.rgb(255, 82, 82, 100) : #FF530D
// Plot EMAs
plot(i_bothEMAs ? na : v_biasEMA, color=emaColor, linewidth=3, title='Consolidated EMA')
plot(i_bothEMAs ? v_fastEMA : na, title='12EMA', color=emaColor)
plot(i_bothEMAs ? v_slowEMA : na, title='25EMA', color=emaColor)
// Colour the bars
buy = v_fastEMA > v_slowEMA
sell = v_fastEMA < v_slowEMA
if buy
countBuy += 1
countBuy
if buy
countSell := 0
countSell
if sell
countSell += 1
countSell
if sell
countBuy := 0
countBuy
buysignal = countBuy < 2 and countBuy > 0 and countSell < 1 and buy and not buy[1]
sellsignal = countSell > 0 and countSell < 2 and countBuy < 1 and sell and not sell[1]
barcolor(buysignal ? color.green : na)
barcolor(sellsignal ? color.red : na)
// Plot Bull/Bear
//plotshape(buysignal, title='Bull', text='Bull', style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.black, 0), size=size.tiny)
//plotshape(sellsignal, title='Bear', text='Bear', style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.black, 0), size=size.tiny)
bull = countBuy > 1
bear = countSell > 1
barcolor(bull ? color.yellow : na)
barcolor(bear ? color.blue : na)
/////////////////
start = input(0)
increment = input(0.01)
maximum = input(1, "Max Value")
out = ta.sar(start, increment, maximum)
plot(out, "ParabolicSAR", style=plot.style_cross, color=#f809ec)
//Inputs
lengthMA = input(25, 'Length DR', inline='Inp', group='Input')
color green = input(#00e677f6, inline='Col', group='Color')
color red = input(#ff5252, inline='Col', group='Color')
color gray =input(#787b86, inline='Col', group='Color')
// Function
dyn_rea(out, len) =>
var smma = 0.0
h = ta.ema(out, len)
smma := na(smma[1]) ? h : (smma[1] * (len - 1) + out) / len
smma
// Calculation
hi=dyn_rea(high, lengthMA)
lo=dyn_rea(low, lengthMA)
mi=(hi-lo)/2+lo
// Plots
//a=plot(hi,"", hlc3>hi?green:hlc3<lo?red:gray)
//b=plot(lo,"", hlc3>hi?green:hlc3<lo?red:gray)
c=plot(mi,"", hlc3>hi?green:hlc3<lo?red:gray)
//fill(a,b,hlc3>hi?color.new(green,60):hlc3<lo?color.new(red,60):color.gray)
////////////////
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MirNader_
//@version=5
//Input & Swing Detection
// Define the input "swingLength" for the number of candles to look back for Swing detection
int swingLength = input.int(20, 'Lookback Period' , minval = 5 , tooltip = "Determines the length of bullish and bearish swings in the market")
// Set the line color for bullish trend
color swingcolorBullish = input.color(color.green, 'Bullish Line' , inline = '01' , tooltip = "This line represents the trend direction. Green color indicates a bullish trend and red color indicates a bearish trend")
// Set the line color for bearish trend
color swingcolorBearish = input.color(color.red , 'Bearish Line' , inline = '01' , tooltip = "This line represents the trend direction. Green color indicates a bullish trend and red color indicates a bearish trend")
//End of Input & Swing Detection
//------------------------------\\
//Swing Detection Function
// The "detectSwing" function will calculate the swing highs and lows for the given number of candles
detectSwing(swingPeriod) =>
// Initialize the "currentSwingState" variable, which will be used to determine the swing state (0 for swing high, 1 for swing low)
var currentSwingState = 0
// Calculate the highest high and lowest low for the given number of candles
highestSwing = ta.highest(swingPeriod)
lowestSwing = ta.lowest(swingPeriod)
// Determine the swing state based on the current candle high and low compared to the highest high and lowest low
currentSwingState := high[swingPeriod] > highestSwing ? 0 : low[swingPeriod] < lowestSwing ? 1 : currentSwingState[1]
// If the current candle is a swing high and the previous candle was not a swing high, set "currentSwingTop" to the current candle high
currentSwingTop = currentSwingState == 0 and currentSwingState[1] != 0 ? high[swingPeriod] : 0
// If the current candle is a swing low and the previous candle was not a swing low, set "currentSwingBottom" to the current candle low
currentSwingBottom = currentSwingState == 1 and currentSwingState[1] != 1 ? low[swingPeriod] : 0
// Return the calculated swing high and swing low values
[currentSwingTop, currentSwingBottom]
//End of Swing Detection
//------------------------------\\
//Parameters
// Initialize the "trendDirection" variable, which will keep track of the trend state (0 for downtrend, 1 for uptrend)
var trendDirection = 0
// Initialize variables for storing pivot high values
var swingTopValue = 0., var swingTopTimestamp = 0
// Initialize variables for storing pivot low values
var swingBottomValue = 0., var swingBottomTimestamp = 0
// Initialize variables for keeping track of the trailing maximum
var trailingSwingHigh = high, var trailingSwingLow = low
var trailingSwingHighTimestamp = 0, var trailingSwingLowTimestamp = 0
// Initialize variables for keeping track of pivot crosses
var topCrossCheck = true, var bottomCrossCheck = true
// Call the "detectSwing" function to calculate the swing highs and lows
[currentSwingTop, currentSwingBottom] = detectSwing(swingLength)
//Line Extend
var line extendingTopLine = na // Initialize a line object for extending the recent top
var line extendingBottomLine = na // Initialize a line object for extending the recent bottom
//End of Parameters
//------------------------------\\
//Pivot High Function
//The calculation of pivot high is an important step in detecting bullish structures in the market
if currentSwingTop
// If a new top is found, set "topCrossCheck" to true
topCrossCheck := true
// Delete the previous extendingTopLine line
line.delete(extendingTopLine[1])
// Create a new extendingTopLine line from the recent top to the last bar
extendingTopLine := line.new(bar_index-swingLength, currentSwingTop, bar_index, currentSwingTop, color = swingcolorBullish)
// Store the pivot high values
swingTopValue := currentSwingTop
swingTopTimestamp := bar_index - swingLength
// Update the trailing maximum values
trailingSwingHigh := currentSwingTop
trailingSwingHighTimestamp := bar_index - swingLength
//Update the trailing maximum values
trailingSwingHigh := math.max(high, trailingSwingHigh)
trailingSwingHighTimestamp := trailingSwingHigh == high ? bar_index : trailingSwingHighTimestamp
//Set the top extension line properties
if barstate.islast
line.set_xy1(extendingTopLine, trailingSwingHighTimestamp, trailingSwingHigh)
line.set_xy2(extendingTopLine, bar_index + 20, trailingSwingHigh)
//End of Pivot High Function
//------------------------------\\
//Pivot Low Function
//the Pivot low is used to detect the presence of a bearish structure in the price movement and update the trend accordingly.
if currentSwingBottom
// If a new low is found, set "bottomCrossCheck" to true
bottomCrossCheck := true
//Extend recent bottom to last bar
line.delete(extendingBottomLine[1])
extendingBottomLine := line.new(bar_index - swingLength, currentSwingBottom, bar_index, currentSwingBottom, color = swingcolorBearish)
//Store the pivot low values
swingBottomValue := currentSwingBottom
swingBottomTimestamp := bar_index - swingLength
//Update the trailing minimum values
trailingSwingLow := currentSwingBottom
trailingSwingLowTimestamp := bar_index - swingLength
//Update the trailing minimum values
trailingSwingLow := math.min(low, trailingSwingLow)
trailingSwingLowTimestamp := trailingSwingLow == low ? bar_index : trailingSwingLowTimestamp
//Set the bottom extension line properties
if barstate.islast
line.set_xy1(extendingBottomLine, trailingSwingLowTimestamp, trailingSwingLow)
line.set_xy2(extendingBottomLine, bar_index + 20, trailingSwingLow)
// End of Pivot Low Function
//------------------------------\\
// You can use 'trendDirection' for your strategy to identify the uptrend or downtrend
// This section of code checks if the close price crosses over the trailing maximum value (top_y).
// If it does, the top_cross boolean is set to false and the trend is set to 1, indicating a bullish trend.
//Detect bullish Structure
if ta.crossover(close, swingTopValue) and topCrossCheck
topCrossCheck := false
trendDirection := 1
// This section of code checks if the close price crosses under the trailing minimum value (btm_y).
// If it does, the btm_cross boolean is set to false and the trend is set to -1, indicating a bearish trend.
// Detect bearish Structure
if ta.crossunder(close, swingBottomValue) and bottomCrossCheck
bottomCrossCheck := false
trendDirection := -1
// End
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mutantdog
//@version=5
// v1.1
//
string S01 = 'open'
string S02 = 'high'
string S03 = 'low'
string S04 = 'close'
string S11 = 'hl2'
string S12 = 'hlc3'
string S13 = 'ohlc4'
string S14 = 'hlcc4'
string S51 = 'oc2'
string S52 = 'hlc2-o2'
string S53 = 'hl-oc2'
string S54 = 'cc-ohlc4'
string S91 = '*AUX 1'
string S92 = '*AUX 2'
string S93 = '*TRIGGER'
string M00 = 'none'
string M01 = 'SMA'
string M02 = 'EMA'
string M03 = 'WMA'
string M04 = 'RMA'
string M11 = 'VWMA'
string M12 = 'VWEMA'
string M13 = 'HMA'
string M41 = 'Median'
string M42 = 'Mid Range'
// INPUTS
auxSource_1 = input.source (close, 'Aux 1 ', inline='01')
auxSource_2 = input.source (close, 'Aux 2 ', inline='01')
triggerSource = input.string ('close', 'Source', [S01, S02, S03, S04, S11, S12, S13, S14, S51, S52, S53, S54, S91, S92], inline='11', group='Trigger')
triggerFilter = input.string ('EMA', 'Filter ', [M00, M01, M02, M03, M04, M11, M12, M13, M41, M42], inline='12', group='Trigger')
triggerLength = input.int (12, 'Length', minval=1, inline='12', group='Trigger')
centreSource = input.string ('hl2', 'Source', [S01, S02, S03, S04, S11, S12, S13, S14, S51, S52, S53, S54, S91, S92, S93], inline='21', group='Centre')
centreFilter = input.string ('EMA', 'Filter ', [M00, M01, M02, M03, M04, M11, M12, M13, M41, M42], inline='22', group='Centre')
centreLength = input.int (25, 'Length', minval=1, inline='22', group='Centre')
tslActive = input.bool (true, 'Trailing ', inline='41', group='Dynamics')
tslPercent = input.float (0, '%', step=0.1, inline='41', group='Dynamics')
atrActive = input.bool (true, 'ATR', inline='42', group='Dynamics')
atrLength = input.int (8, 'Length', minval=1, inline='42', group='Dynamics')
atrMult = input.float (1, 'Mult', step=0.1, inline='42', group='Dynamics')
iqrActive = input.bool (true, 'IQR', inline='43', group='Dynamics')
iqrLength = input.int (12, 'Length', minval=1, inline='43', group='Dynamics')
iqrMult = input.float (0, 'Mult', step=0.1, inline='43', group='Dynamics')
filterSum = input.bool (false, 'Filter Sum', inline='47', group='Dynamics')
loMult = input.float (1, 'Side Mult: Lo', minval=0, step=0.05, inline='49', group='Dynamics')
hiMult = input.float (1, 'Hi ', minval=0, step=0.05, inline='49', group='Dynamics')
showLostop = input.bool (true, 'LoStop', inline='71', group='Visual')
showHistop = input.bool (true, 'HiStop', inline='71', group='Visual')
showCentre = input.bool (false, 'Centre', inline='71', group='Visual')
showTrigger = input.bool (false, 'Trigger', inline='71', group='Visual')
showBands = input.bool (false, 'Bands', inline='71', group='Visual')
bullCol = input.color (#5a6e30, '', inline='88', group='Visual')
bearCol = input.color (#a11030, '', inline='88', group='Visual')
centreCol = input.color (#58aeb1, '', inline='88', group='Visual')
triggerCol = input.color (#ccc26d, '', inline='88', group='Visual')
bandCol = input.color (#6d6969, '', inline='88', group='Visual')
stopsOpac = input.int (100, 'Opacity: Stops', minval=0, maxval=100, step=5, inline='89', group='Visual')
otherOpac = input.int (40, 'Other', minval=0, maxval=100, step=5, inline='89', group='Visual')
// FUNCTIONS
source_switch (src, aux1, aux2) =>
source = switch src
'open' => open
'high' => high
'low' => low
'close' => close
'hl2' => hl2
'hlc3' => hlc3
'ohlc4' => ohlc4
'hlcc4' => hlcc4
'oc2' => (open + close) / 2
'hlc2-o2' => (high + low + close - open) / 2
'hl-oc2' => high + low - (open + close) / 2
'cc-ohlc4' => 2 * close - ohlc4
'*AUX 1' => aux1
'*AUX 2' => aux2
//
filter_switch (src, len, mode) =>
filter = switch mode
'none' => src
'SMA' => ta.sma (src, len)
'EMA' => ta.ema (src, len)
'WMA' => ta.wma (src, len)
'RMA' => ta.rma (src, len)
'VWMA' => ta.vwma (src, len)
'Median' => ta.median (src, len)
'Mid Range' => ta.lowest (src, len) + ta.range (src, len) / 2
'VWEMA' => ta.ema (src * volume, len) / ta.ema (volume, len)
'HMA' => len >= 2 ? ta.hma (src, len) : src
//
iqr_array (len) =>
float[] hiArray = array.new_float (0)
float[] loArray = array.new_float (0)
float[] cmArray = array.new_float (0)
for i = 0 to len - 1
array.push (hiArray, high[i])
array.push (loArray, low[i])
array.push (cmArray, hlcc4[i])
hlArray = array.concat (hiArray, loArray)
hlcmArray = array.concat (hlArray, cmArray)
q1 = array.percentile_linear_interpolation (hlcmArray, 25)
q3 = array.percentile_linear_interpolation (hlcmArray, 75)
iqr = (q3 - q1) / 2
//
trail_blaze (srct, srcc, lofac, hifac) =>
lostop = 0.0
histop = 0.0
trend = 0
trend := srct > histop[1] ? 1 : srct < lostop[1] ? -1 : nz (trend[1], 1)
lostop00 = trend == 1 and trend[1] == -1
histop00 = trend == -1 and trend[1] == 1
lostop := lostop00 ? srcc - lofac : srct[1] > lostop[1] ? math.max (srcc - lofac, lostop[1]) : srcc - lofac
histop := histop00 ? srcc + hifac : srct[1] < histop[1] ? math.min (srcc + hifac, histop[1]) : srcc + hifac
[lostop, histop, trend]
//
// PROCESS
triggerSwitch = source_switch (triggerSource, auxSource_1, auxSource_2)
trigger = filter_switch (triggerSwitch, triggerLength, triggerFilter)
centreSwitch = centreSource == '*TRIGGER' ? trigger : source_switch (centreSource, auxSource_1, auxSource_2)
centre = filter_switch (centreSwitch, centreLength, centreFilter)
tslFactor = tslActive ? centre * tslPercent / 100 : 0
atrFactor = atrActive ? atrMult * ta.atr (atrLength) : 0
iqrFactor = iqrActive ? iqrMult * iqr_array (iqrLength) : 0
sumFactor = filterSum ? ta.swma (nz (tslFactor) + nz (atrFactor) + nz (iqrFactor)) : nz (atrFactor) + nz (iqrFactor) + nz (tslFactor)
loFactor = math.max (sumFactor, 0) * loMult
hiFactor = math.max (sumFactor, 0) * hiMult
[lostop, histop, trend] = trail_blaze (trigger, centre, loFactor, hiFactor)
// VISUALS AND ALERTS
lostopColour = color.new (bullCol, 100 - stopsOpac)
histopColour = color.new (bearCol, 100 - stopsOpac)
centreColour = color.new (centreCol, 100 - otherOpac)
triggerColour = color.new (triggerCol, 100 - otherOpac)
bandColour = color.new (bandCol, 100 - otherOpac)
plotCentre = plot (showCentre ? centre : na, 'Centre', centreColour, 2)
plotTrigger = plot (showTrigger ? trigger : na, 'Trigger', triggerColour, 2)
plotLoband = plot (showBands ? centre - loFactor : na, 'Lo Band', bandColour, 2)
plotHiband = plot (showBands ? centre + hiFactor : na, 'Hi Band', bandColour, 2)
plotLostop = plot (showLostop ? trend == 1 ? lostop : na : na, 'Lo Stop', lostopColour, 2, plot.style_linebr)
plotHistop = plot (showHistop ? trend == 1 ? na : histop : na, 'Hi Stop', histopColour, 2, plot.style_linebr)
isNewTrend = trend != trend[1]
isNewUp = trend == 1 and trend[1] == -1
isNewDown = trend == -1 and trend[1] == 1
plotshape (isNewUp ? lostop : na, 'Long Start', shape.circle, location.absolute, lostopColour, size=size.tiny)
plotshape (isNewDown ? histop : na, 'Short Start', shape.circle, location.absolute, histopColour, size=size.tiny)
alertcondition (isNewTrend, '00: Trail Blaze - Direction Change', 'Trail Blaze has changed direction!')
alertcondition (isNewDown, '01: Trail Blaze - Sell', 'SELL SIGNAL: Trail Blaze Down!')
alertcondition (isNewUp, '02: Trail Blaze - Buy', 'BUY SIGNAL: Trail Blaze Up!')
Yer İmleri