354 lines
9.0 KiB
Plaintext
354 lines
9.0 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center XTrade SR15M Strategy
|
|
// ---------------------------------------------
|
|
// in this strategy i must use:
|
|
// - Price Action Candle Recognition;
|
|
// - Leledc Levels (IS) InSillico;
|
|
// - ATR Stop Loss garethyeo;
|
|
// - Cycle Channel Oscillator;
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////
|
|
|
|
//
|
|
//@version=5
|
|
indicator(title="SaherElm XTrade SR15M Strategy", shorttitle = "XST_SR15M", overlay = true)
|
|
|
|
//
|
|
// START Inputs ....
|
|
//
|
|
//
|
|
// Determines Show Signals or not ...
|
|
showSignals = input.bool(defval = true, title = "Show Signals", group = "Strategy")
|
|
showStopLosses = input.bool(defval = true, title = "Show Stop Losses", group = "Strategy")
|
|
showSupportResistance = input.bool(defval = false, title = "Show Support and Resistance", group = "Strategy")
|
|
|
|
//
|
|
// Show Signals based on their types ...
|
|
showLongSignals = input.bool(defval = true, title = "Show Long Signals", group = "Signals")
|
|
showShortSignals = input.bool(defval = true, title = "Show Short Signals", group = "Signals")
|
|
|
|
//
|
|
// Show Stop Losses based on their types ...
|
|
showLongStopLosses = input.bool(defval = true, title = "Show Long Stop Losses", group = "Stop Loss")
|
|
showShortStopLosses = input.bool(defval = true, title = "Show Short Stop Losses", group = "Stop Loss")
|
|
//
|
|
// END Inputs ....
|
|
//
|
|
|
|
//
|
|
// START Functions ....
|
|
//
|
|
//////////////////////////////
|
|
// START Price Action Candles
|
|
//////////////////////////////
|
|
//
|
|
// Retrieve Specific Candle Height (based on low and high) ...
|
|
getCandleRange() =>
|
|
high - low
|
|
|
|
//
|
|
// Retrieve Candle Ranges Thirs Section ...
|
|
getCandleThird() =>
|
|
getCandleRange() / 3
|
|
|
|
//
|
|
// Determines a Candle is Bullish or not ...
|
|
isBullishCandle() =>
|
|
close > low + (getCandleThird() * 2)
|
|
|
|
//
|
|
// Determines a Candle is Bearish or not ...
|
|
isNeutralCandle() =>
|
|
close < low + (getCandleThird() * 2) and close > low + getCandleThird()
|
|
|
|
//
|
|
// Determines a Candle is Neutral or not ...
|
|
isBearishCandle() =>
|
|
close < low + getCandleThird()
|
|
/////////////////////////////
|
|
// END Price Action Candles
|
|
/////////////////////////////
|
|
|
|
///////////////////////
|
|
// START Leledc Levels
|
|
///////////////////////
|
|
//
|
|
Lelec(bars, len) =>
|
|
//
|
|
result = 0
|
|
bindex = int(na)
|
|
bindex := nz(bindex[1], 0)
|
|
sindex = int(na)
|
|
sindex := nz(sindex[1], 0)
|
|
|
|
//
|
|
bindex := close > close[4] ? bindex + 1 : bindex
|
|
sindex := close < close[4] ? sindex + 1 : sindex
|
|
|
|
//
|
|
lowest = ta.lowest(low, len)
|
|
highest = ta.highest(high, len)
|
|
|
|
//
|
|
if bindex > bars and close < open and high >= highest
|
|
bindex := 0
|
|
result := -1
|
|
result
|
|
else
|
|
if sindex > bars and close > open and low <= lowest
|
|
sindex := 0
|
|
result := 1
|
|
result
|
|
///////////////////////
|
|
// END Leledc Levels
|
|
///////////////////////
|
|
//
|
|
// END Functions ....
|
|
//
|
|
|
|
//
|
|
// START Calculations ....
|
|
//
|
|
//
|
|
var shortColor = color.red
|
|
var longColor = color.lime
|
|
|
|
//////////////////////////////
|
|
// START Price Action Candles
|
|
//////////////////////////////
|
|
//
|
|
var bullishColor = color.lime
|
|
var bullishShape = shape.arrowup
|
|
var bullishTitle = "Bullish"
|
|
var bullishType = 1
|
|
|
|
//
|
|
var bearishColor = color.red
|
|
var bearishShape = shape.arrowdown
|
|
var bearishTitle = "Bearish"
|
|
var bearishType = -1
|
|
|
|
//
|
|
var neutralColor = color.gray
|
|
var neutralShape = shape.circle
|
|
var neutralTitle = "Neutral"
|
|
var neutralType = 0
|
|
|
|
//
|
|
candleType = isBullishCandle() ? bullishType : isNeutralCandle() ? neutralType : isBearishCandle() ? bearishType : neutralType
|
|
|
|
//
|
|
prevCandleType = not na(candleType[1]) ? candleType[1] : neutralType
|
|
|
|
//
|
|
candleNeighborhoodBaseType = prevCandleType + candleType
|
|
/////////////////////////////
|
|
// END Price Action Candles
|
|
/////////////////////////////
|
|
|
|
///////////////////////
|
|
// START Leledc Levels
|
|
///////////////////////
|
|
//
|
|
LLBars = 42
|
|
LLLength = 40
|
|
LLLevelSwitch = true
|
|
LLThicknesSwitch = 7
|
|
LLExhaustionSwitch = true
|
|
|
|
//
|
|
// Out C ...
|
|
Lelex = Lelec(LLBars, LLLength)
|
|
|
|
//
|
|
// Out Bar ...
|
|
LLHighLel = Lelex == -1 ? high : na
|
|
LLLowLel = Lelex == 1 ? low : na
|
|
|
|
//
|
|
// Out level ...
|
|
LLResistance = float(na)
|
|
LLSupport = float(na)
|
|
LLResistance := close < open and Lelex ? high : LLResistance[1]
|
|
LLSupport := close > open and Lelex ? low : LLSupport[1]
|
|
|
|
//
|
|
// Resistance Color ...
|
|
LLResistanceColor = shortColor
|
|
LLHighColor = ta.change(LLResistance) == 0 ? LLResistanceColor : na
|
|
|
|
//
|
|
// Support Color ...
|
|
LLSupportColor = longColor
|
|
LLLowColor = ta.change(LLSupport) == 0 ? LLSupportColor : na
|
|
|
|
//
|
|
// Has Signal ...
|
|
LLHasSignal = LLExhaustionSwitch
|
|
|
|
//
|
|
// Up Signals ...
|
|
LLUpSignal = LLHasSignal ? LLLowLel : na
|
|
|
|
//
|
|
// Down Signals ...
|
|
LLDownSignal = LLHasSignal ? LLHighLel : na
|
|
///////////////////////
|
|
// END Leledc Levels
|
|
///////////////////////
|
|
|
|
///////////////////////
|
|
// START ATR Stop Loss
|
|
///////////////////////
|
|
//
|
|
ATRSLSource = low
|
|
ATRSLLength = 14
|
|
ATRSLMultiplier = 1.6
|
|
|
|
//
|
|
ATRSLLongStopLoss = ATRSLSource - ta.atr(ATRSLLength) * ATRSLMultiplier
|
|
ATRSLShortStopLoss = ATRSLSource + ta.atr(ATRSLLength) * ATRSLMultiplier
|
|
///////////////////////
|
|
// END ATR Stop Loss
|
|
///////////////////////
|
|
|
|
///////////////////////
|
|
// START Cycle Channel
|
|
///////////////////////
|
|
//
|
|
CCHSclT = 10
|
|
CCHMclT = 30
|
|
CCHScm = 1.0
|
|
CCHMcm = 3.0
|
|
CCHSrc = close
|
|
CCHEbc = false
|
|
|
|
//
|
|
CCHScl = CCHSclT / 2
|
|
CCHMcl = CCHMclT / 2
|
|
|
|
//
|
|
CCHMaScl = ta.rma(CCHSrc, CCHScl)
|
|
CCHMaMcl = ta.rma(CCHSrc, CCHMcl)
|
|
|
|
//
|
|
CCHScmOff = CCHScm * ta.atr(CCHScl)
|
|
CCHMcmOff = CCHMcm * ta.atr(CCHMcl)
|
|
|
|
//
|
|
CCHScl2 = CCHScl / 2
|
|
CCHMcl2 = CCHMcl / 2
|
|
|
|
//
|
|
CCHSct = nz(CCHMaScl[CCHScl2], CCHSrc) + CCHScmOff
|
|
CCHScb = nz(CCHMaScl[CCHScl2], CCHSrc) - CCHScmOff
|
|
|
|
//
|
|
CCHMct = nz(CCHMaMcl[CCHMcl2], CCHSrc) + CCHMcmOff
|
|
CCHMcb = nz(CCHMaMcl[CCHMcl2], CCHSrc) - CCHMcmOff
|
|
|
|
//
|
|
CCHScmm = math.avg(CCHSct, CCHScb)
|
|
|
|
//
|
|
CCHOmed = (CCHScmm - CCHMcb) / (CCHMct - CCHMcb)
|
|
CCHOshort = (CCHSrc - CCHMcb) / (CCHMct - CCHMcb)
|
|
|
|
//
|
|
CCHBc = (CCHOshort > 0.5) ? (CCHOshort > 1.0 ? color.purple : (CCHOshort > CCHOmed ? color.lime : color.green)) : (CCHOshort < 0 ? color.purple : ( CCHOshort < CCHOmed ? color.red : color.orange))
|
|
///////////////////////
|
|
// END Cycle Channel
|
|
///////////////////////
|
|
|
|
///////////////////////
|
|
// START Strategy ...
|
|
///////////////////////
|
|
//
|
|
canShowStopLoss = showSignals and showStopLosses and (showLongSignals or showShortSignals) and (showLongStopLosses or showShortStopLosses)
|
|
canShowLongStopLoss = canShowStopLoss and showLongStopLosses and not na(ATRSLLongStopLoss)
|
|
canShowShortStopLoss = canShowStopLoss and showShortStopLosses and not na(ATRSLShortStopLoss)
|
|
|
|
//
|
|
// retrieve verification from CCH ...
|
|
//
|
|
// Red Line ...
|
|
fastLine = CCHOshort
|
|
// plot(fastLine, color = color.red)
|
|
|
|
//
|
|
// Green Line ...
|
|
slowLine = CCHOmed
|
|
// plot(slowLine, color = color.green)
|
|
|
|
//
|
|
// CCH Long Verification ...
|
|
isLongPositionVerifiedByCCH = fastLine < 0.5 and slowLine < 0.5 and fastLine < slowLine
|
|
|
|
//
|
|
// CCH Short Verification ...
|
|
isShortPositionVerifiedByCCH = fastLine > 0.5 and slowLine > 0.5 and fastLine > slowLine
|
|
|
|
//
|
|
hasSignal = LLHasSignal
|
|
|
|
//
|
|
hasLongSignal = hasSignal and not na(LLUpSignal) and isLongPositionVerifiedByCCH and isBullishCandle()
|
|
longSignal = hasLongSignal ? LLUpSignal : na
|
|
|
|
//
|
|
hasShortSignal = hasSignal and not na(LLDownSignal) and isShortPositionVerifiedByCCH and isBearishCandle()
|
|
shortSignal = hasShortSignal ? LLDownSignal : na
|
|
|
|
//
|
|
canShowSignal = showSignals and (showLongSignals or showShortSignals)
|
|
canShowLongSignal = canShowSignal and showLongSignals and hasLongSignal
|
|
canShowShortSignal = canShowSignal and showShortSignals and hasShortSignal
|
|
///////////////////////
|
|
// END Strategy ...
|
|
///////////////////////
|
|
//
|
|
// END Calculations ....
|
|
//
|
|
|
|
//
|
|
// START Plots ....
|
|
//
|
|
//
|
|
// Signals ...
|
|
plotshape(canShowLongSignal ? longSignal : na, title = "Long Signal", color = longColor, location = location.belowbar, style = shape.triangleup, size = size.normal)
|
|
plotshape(canShowShortSignal ? shortSignal : na, title = "Short Signal", color = shortColor, location = location.abovebar, style = shape.triangledown, size = size.normal)
|
|
|
|
//
|
|
// Stop Losses ...
|
|
plot(series = canShowLongStopLoss ? ATRSLLongStopLoss : na, color = color.fuchsia, linewidth = 1, style = plot.style_stepline, title = "Long Stop Loss")
|
|
plot(series = canShowShortStopLoss ? ATRSLShortStopLoss : na, color = color.aqua, linewidth = 1, style = plot.style_stepline, title = "Short Stop Loss")
|
|
|
|
//
|
|
// Support and Resistance level ...
|
|
plot(showSupportResistance and LLLevelSwitch ? LLSupport : na, title = "Support Level", style = plot.style_line, color = LLLowColor, linewidth = LLThicknesSwitch)
|
|
plot(showSupportResistance and LLLevelSwitch ? LLResistance : na, title = "Reistance Level", style = plot.style_line, color = LLHighColor, linewidth = LLThicknesSwitch)
|
|
//
|
|
// END Plots ....
|
|
//
|
|
|
|
//
|
|
// START Alerts ...
|
|
//
|
|
alertcondition(hasSignal, "XST_SR15M > Signal")
|
|
alertcondition(hasLongSignal, "XST_SR15M > Long Signal")
|
|
alertcondition(hasShortSignal, "XST_SR15M > Short Signal")
|
|
//
|
|
// END Alerts ...
|
|
//
|
|
|
|
//////////////////////////////////////////////////////
|
|
// TODOS:
|
|
// -------
|
|
// - []
|
|
//////////////////////////////////////////////////////
|