Vimal — Strategy by mmbrupesh

By version

Performance Metrics

Description

Very good ye bahut good hae //version=5strategy("Editable Range Breakout Strategy + Fibonacci Re-Entry", overlay=true, pyramiding=20, initial_capital=100000)//========================// Inputs//========================rangeSession = input.session("0530-0545", "Range Time")tz = input.string("Asia/Kolkata", "Timezone")baseQty = input.float(1, "Base Quantity", step=1)slPerc = input.float(50.0, "SL at Range %", step=0.1)target1Perc = input.float(250.0, "Target 1 Range %", step=0.1)target2Perc = input.float(450.0, "Target 2 Range %", step=0.1)showLevels = input.bool(true, "Show Range Levels")tradeLong = input.bool(true, "Enable Bullish Breakout Buy")tradeShort = input.bool(true, "Enable Bearish Breakout Sell")tradeMon = input.bool(true, "Trade Monday")tradeTue = input.bool(true, "Trade Tuesday")tradeWed = input.bool(true, "Trade Wednesday")tradeThu = input.bool(true, "Trade Thursday")tradeFri = input.bool(true, "Trade Friday")tradeSat = input.bool(false, "Trade Saturday")tradeSun = input.bool(false, "Trade Sunday")//========================// Session detection//========================inRangeSession = not na(time(timeframe.period, rangeSession, tz))rangeStart = inRangeSession and not inRangeSession[1]rangeEnd = not inRangeSession and inRangeSession[1]//========================// Variables//========================var float rangeHigh = navar float rangeLow = navar float rangeSize = navar bool rangeReady = falsevar bool longTp1Hit = falsevar bool shortTp1Hit = false//========================// Fibonacci Counter//========================var int lossCount = 0fibQty(x) => x == 0 ? 1 : x == 1 ? 2 : x == 2 ? 3 : x == 3 ? 5 : x == 4 ? 8 : x == 5 ? 13 : x == 6 ? 21 : x == 7 ? 34 : x == 8 ? 55 : x == 9 ? 89 : 144rawQty = baseQty * fibQty(lossCount)roundedQty = math.round(rawQty)currentQty = roundedQty % 2 != 0 ? roundedQty + 1 : roundedQty//========================// New Day Reset//========================newDay = dayofmonth != dayofmonth[1]if newDay rangeHigh := na rangeLow := na rangeSize := na rangeReady := false longTp1Hit := false shortTp1Hit := false//========================// Day filter//========================currentDay = dayofweek(time)allowedDay = (currentDay == dayofweek.monday and tradeMon) or (currentDay == dayofweek.tuesday and tradeTue) or (currentDay == dayofweek.wednesday and tradeWed) or (currentDay == dayofweek.thursday and tradeThu) or (currentDay == dayofweek.friday and tradeFri) or (currentDay == dayofweek.saturday and tradeSat) or (currentDay == dayofweek.sunday and tradeSun)//========================// Build Range//========================if rangeStart rangeHigh := high rangeLow := low rangeReady := falseif inRangeSession rangeHigh := math.max(nz(rangeHigh, high), high) rangeLow := math.min(nz(rangeLow, low), low)if rangeEnd rangeSize := rangeHigh - rangeLow rangeReady := rangeSize > 0//========================// Entry Conditions//========================canTrade = allowedDay and rangeReady and not inRangeSession and strategy.position_size == 0longCondition = tradeLong and canTrade and close > rangeHigh and close[1] = rangeLow//========================// Long Levels//========================longSLInitial = rangeLow + rangeSize * (slPerc / 100)longTP1 = rangeLow + rangeSize * (target1Perc / 100)longTP2 = rangeLow + rangeSize * (target2Perc / 100)//========================// Short Levels//========================shortSLInitial = rangeHigh - rangeSize * (slPerc / 100)shortTP1 = rangeHigh - rangeSize * (target1Perc / 100)shortTP2 = rangeHigh - rangeSize * (target2Perc / 100)//========================// Entries//========================if longCondition strategy.entry("Long", strategy.long, qty=currentQty) longTp1Hit := false shortTp1Hit := falseif shortCondition strategy.entry("Short", strategy.short, qty=currentQty) shortTp1Hit := false longTp1Hit := false//========================// TP1 Detection//========================if strategy.position_size > 0 and high >= longTP1 longTp1Hit := true lossCount := 0if strategy.position_size strategy.closedtrades[1]lastTradeLoss = tradeClosed and strategy.closedtrades.profit(strategy.closedtrades - 1) 0 strategy.exit( "L-TP1", from_entry="Long", stop=longSLInitial, limit=longTP1, qty_percent=50) strategy.exit( "L-TP2", from_entry="Long", stop=activeLongSL, limit=longTP2, qty_percent=100)if strategy.position_size 0 ? activeLongSL : na, "Long SL", color=color.orange, linewidth=2)plot(showLevels and strategy.position_size > 0 ? longTP1 : na, "Long TP1", color=color.blue, linewidth=2)plot(showLevels and strategy.position_size > 0 ? longTP2 : na, "Long TP2", color=color.purple, linewidth=2)plot(showLevels and strategy.position_size < 0 ? activeShortSL : na, "Short SL", color=color.orange, linewidth=2)plot(showLevels and strategy.position_size < 0 ? shortTP1 : na, "Short TP1", color=color.blue, linewidth=2)plot(showLevels and strategy.position_size < 0 ? shortTP2 : na, "Short TP2", color=color.purple, linewidth=2)plot(showLevels and strategy.position_size != 0 ? entryPrice : na, "Entry Price", color=color.white, linewidth=1)bgcolor(inRangeSession ? color.new(color.yellow, 85) : na)//========================// Signals//========================plotshape(longCondition, title="BUY", style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", textcolor=color.white)plotshape(shortCondition, title="SELL", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white)//========================// Qty Label//========================var label qtyLabel = naif barstate.islast label.delete(qtyLabel) qtyLabel := label.new( bar_index, high, "Next Qty: " + str.tostring(currentQty) + "\nLoss Count: " + str.tostring(lossCount), style=label.style_label_down, color=color.blue, textcolor=color.white)

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView