Price and Volume Breakout Buy Strategy For ThinkOrSwim

QUIKTDR1

Active member
VIP
Author states:
The "Price and Volume Breakout Buy Strategy" is a trading strategy designed to identify buying opportunities by detecting concurrent price and volume breakouts over a specified range of candlesticks.

This strategy is optimized for assets demonstrating high volatility and significant momentum spikes.

HOW IT WORKS

The strategy first takes the specific number of candlesticks as the examination window for both price and volume.

These values are used as benchmarks to identify breakout conditions.

A trade is initiated when both the closing price and the trading volume surpass the maximum values observed within the predetermined window.

Price must be above a designated moving average, serving as the trend indicator, ensuring that all trades align with the prevailing market trend.

APPLICATION

This strategy is particularly effective for highly volatile assets such as Bitcoin and Ethereum, capitalizing on the cues from sudden price and volume breakouts indicative of significant market movement, often driven by market smart money traders.

However, for broader markets like the S&P 500, this strategy may be less effective due to less pronounced volume and price shifts compared to the cryptocurrency markets.

Ppo5DnP.png


Please covert from Tradingview
https://www.tradingview.com/script/jc2hs2qK-Price-and-Volume-Breakout-Buy-Strategy-TradeDots/
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Please covert from Tradingview
https://www.tradingview.com/script/jc2hs2qK-Price-and-Volume-Breakout-Buy-Strategy-TradeDots/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tradedots
//@version=5
strategy("Price and Volume Breakout Buy Strategy [TradeDots]", overlay=true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 70, commission_type = strategy.commission.percent, commission_value = 0.01)
input_price_breakout_period = input.int(60, "Price Breakout Period")
input_volume_breakout_period = input.int(60, "Volume Breakout Period")
input_trendline_legnth = input.int(200, "Trendline Length")
input_order_direction = input.string("Long", options = ["Long", "Short", "Long and Short"], title = "Order Direction")
price_highest = ta.highest(input_price_breakout_period)
price_lowest = ta.lowest(input_price_breakout_period)
volume_highest = ta.highest(volume, input_volume_breakout_period)
// Long Orders
if close > price_highest[1] and volume > volume_highest[1] and close > ta.sma(close, input_trendline_legnth) and strategy.opentrades == 0 and input_order_direction != "Short"
strategy.entry("Long", strategy.long)
line.new(bar_index[input_price_breakout_period], price_highest[1], bar_index, price_highest[1], color = #9cff87, width = 2)
label.new(bar_index,low, "🟢 Breakout Buy", style = label.style_label_up, color = #9cff87)
// Close when price is below moving average for 5 consecutive days
if close < ta.sma(close, input_trendline_legnth) and close[1] < ta.sma(close, input_trendline_legnth) and close[2] < ta.sma(close, input_trendline_legnth) and close[3] < ta.sma(close, input_trendline_legnth) and close[4] < ta.sma(close, input_trendline_legnth) and strategy.opentrades.size(strategy.opentrades - 1) > 0
strategy.close("Long")
label.new(bar_index, high, "🔴 Close Position", style = label.style_label_down, color = #f9396a, textcolor = color.white)
// Short Orders
if close < price_lowest[1] and volume > volume_highest[1] and close < ta.sma(close, input_trendline_legnth) and strategy.opentrades == 0 and input_order_direction != "Long"
strategy.entry("Short", strategy.short)
line.new(bar_index[input_price_breakout_period], price_lowest[1], bar_index, price_lowest[1], color = #f9396a, width = 2)
label.new(bar_index,high , "🔴 Breakout Sell", style = label.style_label_down, color = #f9396a, textcolor = color.white)
// Close when price is above moving average for 5 consecutive days
if close > ta.sma(close, input_trendline_legnth) and close[1] > ta.sma(close, input_trendline_legnth) and close[2] > ta.sma(close, input_trendline_legnth) and close[3] > ta.sma(close, input_trendline_legnth) and close[4] > ta.sma(close, input_trendline_legnth) and strategy.opentrades.size(strategy.opentrades - 1) < 0
strategy.close("Short")
label.new(bar_index, low, "🟢 Close Position", style = label.style_label_up, color = #9cff87)
plot(ta.sma(close, input_trendline_legnth), color = color.white, linewidth = 2)
plotcandle(open, high, low, close, title='Candles', color = (close > ta.sma(close, input_trendline_legnth) ? #9cff87 : #f9396a), wickcolor=(close > ta.sma(close, input_trendline_legnth) ? #9cff87 : #f9396a), force_overlay = true)
check the below:
CSS:
#// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
#// © tradedots
#strategy("Price and Volume Breakout Buy Strategy [TradeDots]", overlay=true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 70, commission_type = strategy.commission.percent, commission_value = 0.01)
# Converted by Sam4Cok@Samer800    - 06/2024

input labelOptions = {default "Summary", "Detailed", "Don't Show"};
input source = close;
input movAvgType = AverageType.SIMPLE;
input price_breakout_period = 60; #, "Price Breakout Period")
input volume_breakout_period = 60; #, "Volume Breakout Period")
input trendline_legnth = 200; #, "Trendline Length")
input order_direction = {default "Long", "Short", "Long and Short"}; #, title = "Order Direction")
input exitTradeCondition = {Default "Auto Conditions", "Manual Conditions", "Both Conditions"}; # "TPSL Condition"
input entryExitLineDisplay = {Default "Enter Long/Short", "Exit Long/Short", "Both Entry/Exit", "Don't Show Lines"};
input lotSize = 15;
input takeProfitPercentage = 1.25; #, title="Take Profit (%)")
input stopLossPercentage = 0.5; #, title="Stop Loss (%)")


def na = Double.NaN;
def src = source;
def tpPer = takeProfitPercentage / 100;
def slPer = stopLossPercentage / 100;
def allSig = entryExitLineDisplay==entryExitLineDisplay."Both Entry/Exit";
def enter = entryExitLineDisplay==entryExitLineDisplay."Enter Long/Short" or allSig;
def exit = entryExitLineDisplay==entryExitLineDisplay."Exit Long/Short" or allSig;
def short = order_direction == order_direction."Short" or order_direction == order_direction."Long and Short";
def long = order_direction == order_direction."Long" or order_direction == order_direction."Long and Short";
def full = labelOptions == labelOptions."Detailed";
def summ = labelOptions == labelOptions."Summary" or full;
def Aut = exitTradeCondition == exitTradeCondition."Auto Conditions" or exitTradeCondition == exitTradeCondition."Both Conditions";
def man = exitTradeCondition == exitTradeCondition."Manual Conditions" or exitTradeCondition == exitTradeCondition."Both Conditions";

def price_highest = Highest(high, price_breakout_period);
def price_lowest = Lowest(low, price_breakout_period);
def volume_highest = Highest(volume, volume_breakout_period);
#def parSar = ParabolicSAR();
#def supTrd = supertrend();
#plot ExtAvg = MovingAverage(movAvgType, src, 20);
#def parDir = if supTrd < close then 1 else if supTrd > close then 0 else parDir[1];
def volume_filter = volume > volume_highest[1];

plot movAvg = MovingAverage(movAvgType, src, trendline_legnth);

def inTrades;
def entryLong;
def closeLong;
def entryShort;
def closeShort;

def trade = if isNaN(inTrades[1]) then 0 else inTrades[1];
def longCond = src > price_highest[1] and volume_filter and src > movAvg and trade==0 and long;
def shortCond = src < price_lowest[1] and volume_filter and src < movAvg and trade==0 and short;
def LcloseCond =(src < movAvg and src[1] < movAvg and src[2] < movAvg and src[3] < movAvg and src[4] < movAvg) and inTrades[1] > 0;
def ScloseCond =(src > movAvg and src[1] > movAvg and src[2] > movAvg and src[3] > movAvg and src[4] > movAvg) and inTrades[1] < 0;

def tpLvlLong  = close * (1 + tpPer);
def slLvlLong  = close * (1 - slPer);
def tpLvlShort = close * (1 - tpPer);
def slLvlShort = close * (1 + slPer);
def manExitLong = ((entryLong[1] >= tpLvlLong) or (entryLong[1] < slLvlLong)) and trade > 0;
def manExitShort = ((entryShort[1] <= tpLvlShort) or (entryShort[1] > slLvlShort)) and trade < 0;
def exitLong;
def exitShort;

Switch (exitTradeCondition) {
Case "Manual Conditions" :
    exitLong = manExitLong;
    exitShort = manExitShort;
Case "Both Conditions" :
    exitLong = manExitLong or LcloseCond;
    exitShort = manExitShort or ScloseCond;
Default :
    exitLong = LcloseCond;
    exitShort = ScloseCond;
}
def price = open[-1];
if longCond {
    inTrades = 1;
    entryLong = price;
    entryShort = entryShort[1];
    closeLong = 0;
    closeShort = 0;
} else if exitLong {
    inTrades = 0;
    entryLong = entryLong[1];
    entryShort = entryShort[1];
    closeLong = price - entryLong;
    closeShort = 0;
} else if shortCond {
    inTrades = -1;
    entryLong = entryLong[1];
    entryShort = price;
    closeLong = 0;
    closeShort = 0;
} else if exitShort {
    inTrades = 0;
    entryLong = entryLong[1];
    entryShort = entryShort[1];
    closeLong = 0;
    closeShort = entryShort - price;
} else {
    inTrades  = trade;
    entryLong = if isNaN(entryLong[1]) then 0 else entryLong[1];
    entryShort= if isNaN(entryShort[1]) then 0 else entryShort[1];
    closeLong = 0;
    closeShort= 0;
}
#-- lines
def n = price_breakout_period / 2;
def longLine = if entryLong!=entryLong[-n] then if exitLong then na else entryLong[-n] else
               if close > longLine[1] then na else longLine[1];
def shortLine = if entryShort!=entryShort[-n] then if exitShort then na else entryShort[-n] else
                if close < shortLine[1] then na else shortLine[1];
plot lineLong = if enter and longLine then longLine else na;
plot lineShort = if enter and shortLine then shortLine else na;
lineLong.SetDefaultColor(Color.GREEN);
lineShort.SetDefaultColor(Color.RED);
lineLong.SetPaintingStrategy(PaintingStrategy.DASHES);
lineShort.SetPaintingStrategy(PaintingStrategy.DASHES);
#def tot1 = inTrades;
def longSig  = inTrades == 1 and inTrades[1] != 1;
def shortSig = inTrades ==-1 and inTrades[1] !=-1;
def exitL = inTrades == 0 and inTrades[1] == 1;
def exitS = inTrades == 0 and inTrades[1] ==-1;
def totLong  = TotalSum(if exitL then 1 else 0);
def totShort = TotalSum(if exitS then 1 else 0);
def tottrd =  totLong + totShort;
def tradeL = Sign(closeLong);
def tradeS = Sign(closeShort);
def WinL = TotalSum(if tradeL > 0 then 1 else 0);
def WinS = TotalSum(if tradeS > 0 then 1 else 0);
def totWin = (WinL + WinS);
def winRt = Round(totWin / totTrd *100, 1);
def winRtL = Round(WinL / totLong *100, 1);
def winRtS = Round(WinS / totShort *100, 1);
def amtL = TotalSum(if exitLong then closeLong else 0) * lotSize;
def amtS = TotalSum(if exitShort then closeShort else 0) * lotSize;
def pl = RoundDown(amtL + amtS, 2);
def plL = RoundDown(amtL, 2);
def plS = RoundDown(amtS, 2);

AddChartBubble(shortCond, high, "S", Color.RED);
AddChartBubble(longCond, low, "L", Color.GREEN, no);

AddVerticalLine(exit and exitLong, "Exit L", Color.CYAN);
AddVerticalLine(exit and exitShort,"Exit S", Color.MAGENTA);

AddLabel(summ, "WinRate(" + winRt + "%," + totWin + "/" + tottrd + ")", if winRt >= 50 then Color.GREEN else Color.RED);

AddLabel(full and long, "Long(" + winRtL + "%," + WinL + "/" + totLong + ")", if winRtL >= 50 then Color.GREEN else Color.RED);
AddLabel(full and short, "Short(" + winRtS + "%," + WinS +"/" + totShort + ")", if winRtS >= 50 then Color.GREEN else Color.RED);

AddLabel(full and long, "AmtLong($" + plL + ")", if amtL > 0 then Color.GREEN else Color.RED);
AddLabel(full and short, "AmtShort($" + plS + ")", if amtS > 0 then Color.GREEN else Color.RED);

AddLabel(summ, "P/L($" + pl + ")", if pl > 0 then Color.GREEN else if pl < 0 then Color.RED else Color.GRAY);


#-- end o Code
 
check the below:
CSS:
#// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
#// © tradedots
#strategy("Price and Volume Breakout Buy Strategy [TradeDots]", overlay=true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 70, commission_type = strategy.commission.percent, commission_value = 0.01)
# Converted by Sam4Cok@Samer800    - 06/2024

input labelOptions = {default "Summary", "Detailed", "Don't Show"};
input source = close;
input movAvgType = AverageType.SIMPLE;
input price_breakout_period = 60; #, "Price Breakout Period")
input volume_breakout_period = 60; #, "Volume Breakout Period")
input trendline_legnth = 200; #, "Trendline Length")
input order_direction = {default "Long", "Short", "Long and Short"}; #, title = "Order Direction")
input exitTradeCondition = {Default "Auto Conditions", "Manual Conditions", "Both Conditions"}; # "TPSL Condition"
input entryExitLineDisplay = {Default "Enter Long/Short", "Exit Long/Short", "Both Entry/Exit", "Don't Show Lines"};
input lotSize = 15;
input takeProfitPercentage = 1.25; #, title="Take Profit (%)")
input stopLossPercentage = 0.5; #, title="Stop Loss (%)")


def na = Double.NaN;
def src = source;
def tpPer = takeProfitPercentage / 100;
def slPer = stopLossPercentage / 100;
def allSig = entryExitLineDisplay==entryExitLineDisplay."Both Entry/Exit";
def enter = entryExitLineDisplay==entryExitLineDisplay."Enter Long/Short" or allSig;
def exit = entryExitLineDisplay==entryExitLineDisplay."Exit Long/Short" or allSig;
def short = order_direction == order_direction."Short" or order_direction == order_direction."Long and Short";
def long = order_direction == order_direction."Long" or order_direction == order_direction."Long and Short";
def full = labelOptions == labelOptions."Detailed";
def summ = labelOptions == labelOptions."Summary" or full;
def Aut = exitTradeCondition == exitTradeCondition."Auto Conditions" or exitTradeCondition == exitTradeCondition."Both Conditions";
def man = exitTradeCondition == exitTradeCondition."Manual Conditions" or exitTradeCondition == exitTradeCondition."Both Conditions";

def price_highest = Highest(high, price_breakout_period);
def price_lowest = Lowest(low, price_breakout_period);
def volume_highest = Highest(volume, volume_breakout_period);
#def parSar = ParabolicSAR();
#def supTrd = supertrend();
#plot ExtAvg = MovingAverage(movAvgType, src, 20);
#def parDir = if supTrd < close then 1 else if supTrd > close then 0 else parDir[1];
def volume_filter = volume > volume_highest[1];

plot movAvg = MovingAverage(movAvgType, src, trendline_legnth);

def inTrades;
def entryLong;
def closeLong;
def entryShort;
def closeShort;

def trade = if isNaN(inTrades[1]) then 0 else inTrades[1];
def longCond = src > price_highest[1] and volume_filter and src > movAvg and trade==0 and long;
def shortCond = src < price_lowest[1] and volume_filter and src < movAvg and trade==0 and short;
def LcloseCond =(src < movAvg and src[1] < movAvg and src[2] < movAvg and src[3] < movAvg and src[4] < movAvg) and inTrades[1] > 0;
def ScloseCond =(src > movAvg and src[1] > movAvg and src[2] > movAvg and src[3] > movAvg and src[4] > movAvg) and inTrades[1] < 0;

def tpLvlLong  = close * (1 + tpPer);
def slLvlLong  = close * (1 - slPer);
def tpLvlShort = close * (1 - tpPer);
def slLvlShort = close * (1 + slPer);
def manExitLong = ((entryLong[1] >= tpLvlLong) or (entryLong[1] < slLvlLong)) and trade > 0;
def manExitShort = ((entryShort[1] <= tpLvlShort) or (entryShort[1] > slLvlShort)) and trade < 0;
def exitLong;
def exitShort;

Switch (exitTradeCondition) {
Case "Manual Conditions" :
    exitLong = manExitLong;
    exitShort = manExitShort;
Case "Both Conditions" :
    exitLong = manExitLong or LcloseCond;
    exitShort = manExitShort or ScloseCond;
Default :
    exitLong = LcloseCond;
    exitShort = ScloseCond;
}
def price = open[-1];
if longCond {
    inTrades = 1;
    entryLong = price;
    entryShort = entryShort[1];
    closeLong = 0;
    closeShort = 0;
} else if exitLong {
    inTrades = 0;
    entryLong = entryLong[1];
    entryShort = entryShort[1];
    closeLong = price - entryLong;
    closeShort = 0;
} else if shortCond {
    inTrades = -1;
    entryLong = entryLong[1];
    entryShort = price;
    closeLong = 0;
    closeShort = 0;
} else if exitShort {
    inTrades = 0;
    entryLong = entryLong[1];
    entryShort = entryShort[1];
    closeLong = 0;
    closeShort = entryShort - price;
} else {
    inTrades  = trade;
    entryLong = if isNaN(entryLong[1]) then 0 else entryLong[1];
    entryShort= if isNaN(entryShort[1]) then 0 else entryShort[1];
    closeLong = 0;
    closeShort= 0;
}
#-- lines
def n = price_breakout_period / 2;
def longLine = if entryLong!=entryLong[-n] then if exitLong then na else entryLong[-n] else
               if close > longLine[1] then na else longLine[1];
def shortLine = if entryShort!=entryShort[-n] then if exitShort then na else entryShort[-n] else
                if close < shortLine[1] then na else shortLine[1];
plot lineLong = if enter and longLine then longLine else na;
plot lineShort = if enter and shortLine then shortLine else na;
lineLong.SetDefaultColor(Color.GREEN);
lineShort.SetDefaultColor(Color.RED);
lineLong.SetPaintingStrategy(PaintingStrategy.DASHES);
lineShort.SetPaintingStrategy(PaintingStrategy.DASHES);
#def tot1 = inTrades;
def longSig  = inTrades == 1 and inTrades[1] != 1;
def shortSig = inTrades ==-1 and inTrades[1] !=-1;
def exitL = inTrades == 0 and inTrades[1] == 1;
def exitS = inTrades == 0 and inTrades[1] ==-1;
def totLong  = TotalSum(if exitL then 1 else 0);
def totShort = TotalSum(if exitS then 1 else 0);
def tottrd =  totLong + totShort;
def tradeL = Sign(closeLong);
def tradeS = Sign(closeShort);
def WinL = TotalSum(if tradeL > 0 then 1 else 0);
def WinS = TotalSum(if tradeS > 0 then 1 else 0);
def totWin = (WinL + WinS);
def winRt = Round(totWin / totTrd *100, 1);
def winRtL = Round(WinL / totLong *100, 1);
def winRtS = Round(WinS / totShort *100, 1);
def amtL = TotalSum(if exitLong then closeLong else 0) * lotSize;
def amtS = TotalSum(if exitShort then closeShort else 0) * lotSize;
def pl = RoundDown(amtL + amtS, 2);
def plL = RoundDown(amtL, 2);
def plS = RoundDown(amtS, 2);

AddChartBubble(shortCond, high, "S", Color.RED);
AddChartBubble(longCond, low, "L", Color.GREEN, no);

AddVerticalLine(exit and exitLong, "Exit L", Color.CYAN);
AddVerticalLine(exit and exitShort,"Exit S", Color.MAGENTA);

AddLabel(summ, "WinRate(" + winRt + "%," + totWin + "/" + tottrd + ")", if winRt >= 50 then Color.GREEN else Color.RED);

AddLabel(full and long, "Long(" + winRtL + "%," + WinL + "/" + totLong + ")", if winRtL >= 50 then Color.GREEN else Color.RED);
AddLabel(full and short, "Short(" + winRtS + "%," + WinS +"/" + totShort + ")", if winRtS >= 50 then Color.GREEN else Color.RED);

AddLabel(full and long, "AmtLong($" + plL + ")", if amtL > 0 then Color.GREEN else Color.RED);
AddLabel(full and short, "AmtShort($" + plS + ")", if amtS > 0 then Color.GREEN else Color.RED);

AddLabel(summ, "P/L($" + pl + ")", if pl > 0 then Color.GREEN else if pl < 0 then Color.RED else Color.GRAY);


#-- end o Code
TY 4 your consideration and conversion
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
473 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top