BTC 4H strategy
Forums › ProRealTime English forum › General trading discussions › BTC 4H strategy
- This topic has 7 replies, 2 voices, and was last updated 22 hours ago by JS.
Viewing 8 posts - 1 through 8 (of 8 total)
-
-
01/31/2025 at 1:28 PM #243264
Hi guys,
I want to share with you my first trading strategy for BTC 4H.
Sorry for putting the code in Pine Script but I cant test it in 4h timeframe in PRT.
I just wanted to share with you in case it is interesting for someone that can translate it to PRT code and test it with more data.
BTC 4H Strategy based in BB width and volume12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152//Juan Diaz Maldonado//@version=6strategy(title = "Bollinger Bands Width Strategy @ JDM", shorttitle = "BBW Strat @ JDM", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value = 100, initial_capital =1000, currency = currency.USD, slippage = 10, commission_type = strategy.commission.percent, commission_value = 0.1)// ------------------------- Paramethers -------------------------// Bollinger bands parametherslength = input.int(22, minval=1, title="Length")src = input.source(close, title="Source")mult = input.float(2, minval=0.001, maxval=50, title="StdDev")// Bollinger bands Width paramethersncandles = input.int(120, minval=1, title="n candles") // number of candles for normalized BB widthcompthreshold = input.int(20, minval=1, title="Compresion Threshold") // compression band under which we will open trades// ------------------------- Bollinger bands calculation -------------------------// Bollinger bandsbasis = ta.sma(src, length)dev = mult * ta.stdev(src, length)upper = basis + devlower = basis - dev// Bollinger bands widthbbWidth = (upper - lower) / basis// Normalize BB widhtbbWidthMax = ta.highest(bbWidth, ncandles) // maximum width of ncandlesbbWidthMin = ta.lowest(bbWidth, ncandles) // minimum width of ncandlesbbWidthNormalized = ((bbWidth - bbWidthMin) / (bbWidthMax - bbWidthMin)) * (100) // bollinger bands width normalized// ------------------------- Long entry and exits and Stop Loss if any -------------------------// Longs conditionlongCondition = src > basis and src < upper and volume > ta.sma(volume, 20) and bbWidthNormalized < compthresholdif (longCondition)strategy.entry("Long", strategy.long)// Exit longs conditionlongExitCondition = ta.crossunder(src, lower)if (longExitCondition)strategy.close("Long")// ------------------------- Gráficos -------------------------// Representación de la amplitud normalizada (oscila entre -20 y 120)plot(bbWidthNormalized, title="BB Width Normalized", color=color.new(color.orange, 0), linewidth=1)// Líneas de referencia fijas en 100 y 0 para %Bhline(100, title="Upper Band", color=color.new(color.black, 0), linestyle=hline.style_solid)hline(compthreshold, title="Threshold", color=color.new(color.blue, 0), linestyle=hline.style_solid)hline(0, title="Lower Band", color=color.new(color.black, 0), linestyle=hline.style_solid)Regards,
01/31/2025 at 2:10 PM #243270Hi,
Hereby the conversion to PRT…
BB Width and Volume12345678910111213141516171819202122232425262728293031323334353637383940414243DefParam CumulateOrders=FalseDefParam PreloadBars = 1000// Bollinger Bands settingslength = 22mult = 2.0ncandles = 120compthreshold = 20// Bollinger Bands calculationbasis = Average[length](close)deviation = mult * Std[length](close)upper = basis + deviationlower = basis - deviation// Bollinger Band WidthbbWidth = (upper - lower) / basis// Normalized BB WidthbbWidthMax = Highest[ncandles](bbWidth)bbWidthMin = Lowest[ncandles](bbWidth)bbWidthNormalized = ((bbWidth - bbWidthMin) / (bbWidthMax - bbWidthMin)) * 100// Long entry conditionslongCondition = close > basis AND close < upper AND volume > Average[20](volume) AND bbWidthNormalized < compthresholdIF longCondition THENBUY 1 CONTRACT AT MARKETENDIF// Long exit conditionslongExitCondition = close < lowerIF longExitCondition THENSELL AT MARKETENDIF// Plot BB Width NormalizedGraph bbWidthNormalizedGraph 100Graph 0Graph compthresholdGraphOnPrice UpperGraphOnPrice LowerGraphOnPrice Basis2 users thanked author for this post.
01/31/2025 at 2:22 PM #243272Thank you very much JS.
May you test it for a longer period? Maybe around 30k bars could be good.
01/31/2025 at 2:34 PM #24327301/31/2025 at 2:46 PM #243274I would say 30-50 pips spread can be a realistic one.
01/31/2025 at 2:56 PM #24327501/31/2025 at 3:34 PM #243284Thank you very much! Really helpful. What can we do in ProRealTime to compare with a benchmark? Like buy and hold the own BTC in this case.
01/31/2025 at 3:53 PM #243286 -
AuthorPosts
Viewing 8 posts - 1 through 8 (of 8 total)
Find exclusive trading pro-tools on
Similar topics: