diff --git a/strategies/Hammer_Candle_Strategy.pine b/Candle_Bear-Bull_v6.pine similarity index 55% rename from strategies/Hammer_Candle_Strategy.pine rename to Candle_Bear-Bull_v6.pine index 5d1133a..4d5ab89 100755 --- a/strategies/Hammer_Candle_Strategy.pine +++ b/Candle_Bear-Bull_v6.pine @@ -1,9 +1,9 @@ -//@version=5 -strategy("Hammer Candle Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100) +//@version=6 +strategy('Hammer Candle Strategy', overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100) // Inputs for customization -hammertBodyRatio = input.float(0.3, title="Max Body Size Ratio", minval=0.1, maxval=0.5, step=0.1) -hammerWickRatio = input.float(2.0, title="Min Wick to Body Ratio", minval=1.0, maxval=5.0, step=0.1) +hammertBodyRatio = input.float(0.3, title = 'Max Body Size Ratio', minval = 0.1, maxval = 0.5, step = 0.1) +hammerWickRatio = input.float(2.0, title = 'Min Wick to Body Ratio', minval = 1.0, maxval = 5.0, step = 0.1) // Function to determine if a candle is bullish or bearish is_candle_bullish(index) => @@ -14,7 +14,7 @@ is_candle_bearish(index) => // Hammer Candle Detection Function //isHammer() => -string dbg = "" +string dbg = '' bodySize = math.abs(close - open) totalRange = high - low @@ -23,18 +23,18 @@ upperWick = high - math.max(close, open) lowerWick = math.min(close, open) - low // Check if body is small (less than 30% of total candle range) -isSmallBody = bodySize <= (totalRange * hammertBodyRatio) +isSmallBody = bodySize <= totalRange * hammertBodyRatio //plotchar(isSmallBody, title="lw", char='-', location=location.abovebar, color=#40fbf5, size=size.small) // Lower/Upper wick should be at least 2x the body size and significantly long -bool isLongUpperWick = upperWick >= (totalRange * 0.5) and upperWick >= (bodySize * hammerWickRatio) -bool isLongLowerWick = lowerWick >= (totalRange * 0.5) and lowerWick >= (bodySize * hammerWickRatio) +bool isLongUpperWick = upperWick >= totalRange * 0.5 and upperWick >= bodySize * hammerWickRatio +bool isLongLowerWick = lowerWick >= totalRange * 0.5 and lowerWick >= bodySize * hammerWickRatio //plotchar(isLongUpperWick, title="LW", char='L', location=location.abovebar, color=color.fuchsia, size=size.small) //plotchar(isLongLowerWick, title="lw", char='l', location=location.belowbar, color=color.fuchsia, size=size.small) // Minimal lower/upper wick -bool isShortUpperWick = upperWick <= (bodySize * 0.5) or upperWick <= (totalRange * 0.2) -bool isShortLowerWick = lowerWick <= (bodySize * 0.5) or lowerWick <= (totalRange * 0.2) +bool isShortUpperWick = upperWick <= bodySize * 0.5 or upperWick <= totalRange * 0.2 +bool isShortLowerWick = lowerWick <= bodySize * 0.5 or lowerWick <= totalRange * 0.2 //plotchar(isShortUpperWick, title="Bullish Candle", char='S', location=location.abovebar, color=color.fuchsia, size=size.small) //plotchar(isShortLowerWick, title="Bullish Candle", char='s', location=location.belowbar, color=color.fuchsia, size=size.small) @@ -43,41 +43,32 @@ isBullishHammer = isSmallBody and isShortUpperWick and isLongLowerWick //and is_ // Bearish Hammer (Red/Black) isBearishHammer = isSmallBody and isLongUpperWick and isShortLowerWick // and is_candle_bullish(1) and is_candle_bullish(2) // and close < open -if (isBearishHammer) - dbg := "TEST: " + str.tostring(isShortUpperWick) + " | "+ str.tostring(upperWick) + " | "+ str.tostring(bodySize) + " | "+ str.tostring(totalRange) + " | " - +if isBearishHammer + dbg := 'TEST: ' + str.tostring(isShortUpperWick) + ' | ' + str.tostring(upperWick) + ' | ' + str.tostring(bodySize) + ' | ' + str.tostring(totalRange) + ' | ' + dbg + // [isBullishHammer, isBearishHammer, dbg] //[bullish, bearish, deb] = isHammer() bullish = isBullishHammer bearish = isBearishHammer // Plot a '*' when close is above open (bullish candle) -plotchar(bullish, title="Bullish Candle", char='*', location=location.belowbar, color=color.green, size=size.small) +plotchar(bullish, title = 'Bullish Candle', char = '*', location = location.belowbar, color = color.green, size = size.small) // Plot an '*' when close is below open (bearish candle) -plotchar(bearish, title="Bearish Candle", char='*', location=location.abovebar, color=color.red, size=size.small) +plotchar(bearish, title = 'Bearish Candle', char = '*', location = location.abovebar, color = color.red, size = size.small) bullish := isBullishHammer and is_candle_bullish(1) and is_candle_bullish(2) bearish := isBearishHammer and is_candle_bullish(1) and is_candle_bullish(2) // Plot hammer candle markers -plotshape(bullish, - title="Bullish Hammer", - location=location.belowbar, - style=shape.triangleup, - size=size.small, - color=color.green) +plotshape(bullish, title = 'Bullish Hammer', location = location.belowbar, style = shape.triangleup, size = size.small, color = color.green) -plotshape(bearish, - title="Bearish Hammer", - location=location.abovebar, - style=shape.triangledown, - size=size.small, - color=color.red) +plotshape(bearish, title = 'Bearish Hammer', location = location.abovebar, style = shape.triangledown, size = size.small, color = color.red) // Trading logic -if (bullish) - strategy.entry("Long", strategy.long) +if bullish + strategy.entry('Long', strategy.long) -if (bearish) - strategy.entry("Short", strategy.short) \ No newline at end of file +if bearish + strategy.entry('Short', strategy.short)