Support and Resistance Levels TP/SLSupport and resistance levels are critical concepts in trading, often used to set Take Profit (TP) and Stop Loss (SL) levels. Here's a guide to effectively determine these levels:
1. Identifying Support and Resistance Levels
- Support Level: A price level where demand is strong enough to prevent the price from falling further. Think of it as a floor.
- Resistance Level: A price level where selling pressure is strong enough to prevent the price from rising further. Think of it as a ceiling.
Methods to Identify Levels:
- Horizontal Lines: Use historical price data to find levels where prices frequently reversed.
- **Trendlines**: Draw diagonal lines connecting higher lows (support) or lower highs (resistance).
- Fibonacci Retracement: Calculate levels based on key Fibonacci ratios (e.g., 23.6%, 38.2%, 61.8%).
- Moving Averages: Identify dynamic support and resistance based on moving average levels.
- Volume Profile: Spot areas of high trading activity, which often act as support or resistance.
---
2. Setting Take Profit (TP) Levels
- Conservative Approach: Place the TP level slightly below a resistance level to ensure execution.
- Aggressive Approach: Target higher levels, considering momentum and trend strength.
Example:
- Resistance at $50.
- Set TP at $49.80 to account for slippage or premature reversals.
3. Setting Stop Loss (SL) Levels
- Below Support: For long trades, set the SL slightly below the identified support level.
- Above Resistance: For short trades, set the SL slightly above the resistance.
Example:
- Support at $45.
- Set SL at $44.80 to allow for minor price fluctuations.
4. Risk-Reward Ratio
- Aim for at least a 1:2 risk-reward ratio (e.g., risk $1 to gain $2).
- Calculate TP and SL levels accordingly to maintain this balance.
5. Adjusting for Market Conditions
- Volatile Markets: Widen TP and SL levels to account for larger price swings.
- Stable Markets: Use tighter levels for precise risk management.
6. Automating TP/SL
- Use trading platforms to automate TP/SL placements, ensuring discipline and emotional control.
Would you like help applying this to a specific scenario or chart?
Индикаторы и стратегии
Support and Resistance Levels TP/SLSupport and resistance levels are critical concepts in trading, often used to set Take Profit (TP) and Stop Loss (SL) levels. Here's a guide to effectively determine these levels:
1. Identifying Support and Resistance Levels
- Support Level: A price level where demand is strong enough to prevent the price from falling further. Think of it as a floor.
- Resistance Level: A price level where selling pressure is strong enough to prevent the price from rising further. Think of it as a ceiling.
Methods to Identify Levels:
- Horizontal Lines: Use historical price data to find levels where prices frequently reversed.
- **Trendlines**: Draw diagonal lines connecting higher lows (support) or lower highs (resistance).
- Fibonacci Retracement: Calculate levels based on key Fibonacci ratios (e.g., 23.6%, 38.2%, 61.8%).
- Moving Averages: Identify dynamic support and resistance based on moving average levels.
- Volume Profile: Spot areas of high trading activity, which often act as support or resistance.
---
2. Setting Take Profit (TP) Levels
- Conservative Approach: Place the TP level slightly below a resistance level to ensure execution.
- Aggressive Approach: Target higher levels, considering momentum and trend strength.
Example:
- Resistance at $50.
- Set TP at $49.80 to account for slippage or premature reversals.
3. Setting Stop Loss (SL) Levels
- Below Support: For long trades, set the SL slightly below the identified support level.
- Above Resistance: For short trades, set the SL slightly above the resistance.
Example:
- Support at $45.
- Set SL at $44.80 to allow for minor price fluctuations.
4. Risk-Reward Ratio
- Aim for at least a 1:2 risk-reward ratio (e.g., risk $1 to gain $2).
- Calculate TP and SL levels accordingly to maintain this balance.
5. Adjusting for Market Conditions
- Volatile Markets: Widen TP and SL levels to account for larger price swings.
- Stable Markets: Use tighter levels for precise risk management.
6. Automating TP/SL
- Use trading platforms to automate TP/SL placements, ensuring discipline and emotional control.
Would you like help applying this to a specific scenario or chart?
HPDR Bands IndicatorThe HPDR Bands indicator is a customizable tool designed to help traders visualize dynamic price action zones. By combining historical price ranges with adaptive bands, this script provides clear insights into potential support, resistance, and midline levels. The indicator is well-suited for all trading styles, including trend-following and range-bound strategies.
Features:
Dynamic Price Bands: Calculates price zones based on historical highs and lows, blending long-term and short-term price data for responsive adaptation to current market conditions.
Probability Enhancements: Includes a probability plot derived from the relative position of the closing price within the range, adjusted for volatility to highlight potential price movement scenarios.
Fibonacci-Like Levels: Highlights key levels (100%, 95%, 88%, 78%, 61%, 50%, and 38%) for intuitive visualization of price zones, aiding in identifying high-probability trading opportunities.
Midline Visualization: Displays a midline that serves as a reference for price mean reversion or breakout analysis.
How to Use:
Trending Markets: Use the adaptive upper and lower bands to gauge potential breakout or retracement zones.
Range-Bound Markets: Identify support and resistance levels within the defined price range.
Volatility Analysis: Observe the probability plot and its sensitivity to volatility for informed decision-making.
Important Notes:
This script is not intended as investment advice. It is a tool to assist with market analysis and should be used alongside proper risk management and other trading tools.
The script is provided as-is and without warranty. Users are encouraged to backtest and validate its suitability for their specific trading needs.
Happy Trading!
If you find this script helpful, consider sharing your feedback or suggestions for improvement. Collaboration strengthens the TradingView community, and your input is always appreciated!
luusang//@version=5
indicator('Swing', shorttitle='GoodLuck', overlay=true, max_lines_count=500)
//-----Input-------
customTF = input.timeframe(defval="",title = "Show Other TimeFrame")
GroupGann = "Gann"
showGann = input.bool(false, 'Show Gann/Color/Width', group = GroupGann, inline = "Gann1")
colorGann = input.color(color.aqua, '', group = GroupGann,inline = "Gann1")
widthGann = input.int(defval=1,title = "",minval=1,step=1, group = GroupGann,inline = "Gann1")
GroupSGann = "Swing of Gann"
showSGann = input.bool(true, 'Show Swing/Color/Width', group = GroupSGann,inline = "Swing1")
colorSGann = input.color(color.blue, '', group = GroupSGann,inline = "Swing1")
widthSGann = input.int(defval=1,title = "",minval=1,step=1, group = GroupSGann,inline = "Swing1")
showChoCh = input.bool(false, 'Show ChoCh/Color/Width', group = GroupSGann,inline = "Choch")
colorChoch = input.color(color.red, '', group = GroupSGann,inline = "Choch")
widthChoch = input.int(defval=1,title = "",minval=1,step=1, group = GroupSGann,inline = "Choch")
show2ChoCh = input.bool(false, 'Show 2Choch/Color/Width', group = GroupSGann,inline = "2Choch")
color2Choch = input.color(color.purple, '', group = GroupSGann,inline = "2Choch")
width2Choch = input.int(defval=1,title = "",minval=1,step=1, group = GroupSGann,inline = "2Choch")
showtargetOTL = input.bool(true, 'Show Target OTL/Color/Width',group = GroupSGann, inline = "target")
colortargetOTL = input.color(color.purple, '', group = GroupSGann, inline = "target")
widthtargetOTL = input.int(defval=1,title = "",minval=1,step=1, group = GroupSGann,inline = "target")
showLabel = input.bool(false, 'Show Label TimeFrame',group = GroupSGann)
//showLinePrice = input.bool(true, 'Show LinePrice/Color/Width', group = GroupSGann,inline = "LinePrice")
//colorLinePrice = input.color(color.blue, '', group = GroupSGann,inline = "LinePrice")
//widthLinePrice = input.int(defval=1,title = "",minval=1,step=1, group = GroupSGann,inline = "LinePrice")
///tùy chọn line//
lineGann = input.string(title="",options= ,defval='(╌)', group = GroupGann, inline = "Gann1")
lineStyleGann = lineGann == "(┈)" ? line.style_dotted : lineGann == "(╌)" ? line.style_dashed : line.style_solid
lineSGann = input.string(title="",options= ,defval="(─)", group = GroupSGann, inline = "Swing1")
lineStyleSGann = lineSGann == "(┈)" ? line.style_dotted : lineSGann == "(╌)" ? line.style_dashed : line.style_solid
line2Choch = input.string(title="",options= ,defval="(╌)", group = GroupSGann, inline = "2Choch")
lineStyle2Choch = line2Choch == "(┈)" ? line.style_dotted : line2Choch == "(╌)" ? line.style_dashed : line.style_dashed
lineChoch = input.string(title="",options= ,defval="(─)", group = GroupSGann, inline = "Choch")
lineStyleChoch = lineChoch == "(┈)" ? line.style_dotted : lineChoch == "(╌)" ? line.style_dashed : lineChoch == "(←)" ? line.style_arrow_left : lineChoch == "(→)" ? line.style_arrow_right : lineChoch == "(↔)" ? line.style_arrow_both : line.style_solid
linetargetOTL = input.string(title="",options= ,defval="(→)", group = GroupSGann, inline = "target")
lineStyletargetOTL = linetargetOTL == "(┈)" ? line.style_dotted : linetargetOTL == "(╌)" ? line.style_dashed : linetargetOTL == "(←)" ? line.style_arrow_left : linetargetOTL == "(→)" ? line.style_arrow_right : linetargetOTL == "(↔)" ? line.style_arrow_both : line.style_arrow_both
//in out side bar//
OSB_up_down ="Ousidebar up down"
//////////////////////////Global//////////////////////////
var arrayLineTemp = array.new_line()
// Funtion
f_resInMinutes() =>
_resInMinutes = timeframe.multiplier * (
timeframe.isseconds ? 1. / 60. :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 1440. :
timeframe.isweekly ? 10080. :
timeframe.ismonthly ? 43800. : na)
// Converts a resolution expressed in minutes into a string usable by "security()"
f_resFromMinutes(_minutes) =>
_minutes < 1 ? str.tostring(math.round(_minutes*60)) + "S" :
_minutes < 60 ? str.tostring(math.round(_minutes)) + "m" :
_minutes < 1440 ? str.tostring(math.round(_minutes/60)) + "H" :
_minutes < 10080 ? str.tostring(math.round(math.min(_minutes / 1440, 7))) + "D" :
_minutes < 43800 ? str.tostring(math.round(math.min(_minutes / 10080, 4))) + "W" :
str.tostring(math.round(math.min(_minutes / 43800, 12))) + "M"
f_tfRes(_res,_exp) =>
request.security(syminfo.tickerid,_res,_exp,lookahead=barmerge.lookahead_on)
var arrayLineChoCh = array.new_line()
var label labelTF = label.new(time, close, text = "",color = color.new(showSGann ? colorSGann : colorGann,95), textcolor = showSGann ? colorSGann : colorGann,xloc = xloc.bar_time, textalign = text.align_left)
var line lineChoChOTLTarget = line.new(x1= time , y1=close,x2=time, y2= close,color = showSGann ? colortargetOTL : colorGann,xloc = xloc.bar_time,style = lineStyletargetOTL,width = widthtargetOTL)
var line lineBosOTLTarget = line.new(x1= time , y1=close,x2=time, y2= close,color = showSGann ? colortargetOTL : colorGann,xloc = xloc.bar_time,style = lineStyletargetOTL, width = widthtargetOTL)
//var line line_Price = line.new(x1= time , y1=close,x2=time, y2= close,color = showSGann ? colorLinePrice : colorGann,xloc = xloc.bar_time,style = lineStyleLinePrice, width = widthLinePrice)
styleGann = showSGann ? line.style_dashed : line.style_solid
var arrayXGann = array.new_int(5,time)
var arrayYGann = array.new_float(5,close)
var arrayLineGann = array.new_line()
int drawLineGann = 0
_high = high
_low = low
_close = close
_open = open
if(customTF != timeframe.period)
_high := f_tfRes(customTF,high)
_low := f_tfRes(customTF,low)
_close := f_tfRes(customTF,close)
_open := f_tfRes(customTF,open)
highPrev = _high
lowPrev = _low
// drawLineGann => 2:Tiếp tục 1:Đảo chiều; // Outsidebar 2:Tiếp tục 3:Tiếp tục và Đảo chiều 4 : Đảo chiều 2 lần
drawLineGann := 0
if(_high > highPrev and _low > lowPrev )
if(array.get(arrayYGann,0) > array.get(arrayYGann,1))
if(_high <= high)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _high )
drawLineGann := 2
else
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_high )
drawLineGann := 1
else if(_high < highPrev and _low < lowPrev )
if(array.get(arrayYGann,0) > array.get(arrayYGann,1))
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_low )
drawLineGann := 1
else
if(_low >= low)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _low )
drawLineGann := 2
else if(_high >= highPrev and _low < lowPrev or _high > highPrev and _low <= lowPrev )
if(array.get(arrayYGann,0) > array.get(arrayYGann,1))
if(_high >= array.get(arrayYGann,0) and array.get(arrayYGann,1) < _low )
if(_high <= high)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _high )
drawLineGann := 2
else if(_high >= array.get(arrayYGann,0) and array.get(arrayYGann,1) > _low )
if(_close < _open)
if(_high <= high)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _high )
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_low )
drawLineGann := 3
else
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_low )
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_high )
drawLineGann := 4
else if(array.get(arrayYGann,0) < array.get(arrayYGann,1))
if(_low <= array.get(arrayYGann,0) and _high < array.get(arrayYGann,1))
if(_low >= low)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _low )
drawLineGann := 2
else if(_low <= array.get(arrayYGann,0) and _high > array.get(arrayYGann,1))
if(_close > _open)
if(_low >= low)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _low )
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_high )
drawLineGann := 3
else
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_high )
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_low )
drawLineGann := 4
else if((_high <= highPrev and _low >= lowPrev ))
highPrev := highPrev
lowPrev := lowPrev
if(f_resInMinutes() < f_tfRes(customTF,f_resInMinutes()) and drawLineGann == 0)
if(array.get(arrayYGann,0) > array.get(arrayYGann,1))
if(array.get(arrayYGann,0) <= high)
array.set(arrayXGann, 0, time)
drawLineGann := 2
else
if(array.get(arrayYGann,0) >= low)
array.set(arrayXGann, 0, time)
drawLineGann := 2
if(showGann and f_resInMinutes() <= f_tfRes(customTF,f_resInMinutes()))
if(drawLineGann == 2)
if(array.size(arrayLineGann) >0)
line.set_xy2(array.get(arrayLineGann,0),array.get(arrayXGann,0),array.get(arrayYGann,0))
else
array.unshift(arrayLineGann,line.new(array.get(arrayXGann,1),array.get(arrayYGann,1),array.get(arrayXGann,0),array.get(arrayYGann,0), color = colorGann,xloc = xloc.bar_time, style = lineStyleGann,width = widthGann))
else if(drawLineGann == 1)
array.unshift(arrayLineGann,line.new(array.get(arrayXGann,1),array.get(arrayYGann,1),array.get(arrayXGann,0),array.get(arrayYGann,0), color = colorGann,xloc = xloc.bar_time, style = lineStyleGann,width = widthGann))
else if(drawLineGann == 3)
if(array.size(arrayLineGann) >0)
line.set_xy2(array.get(arrayLineGann,0),array.get(arrayXGann,1),array.get(arrayYGann,1))
else
array.unshift(arrayLineGann,line.new(array.get(arrayXGann,2),array.get(arrayYGann,2),array.get(arrayXGann,1),array.get(arrayYGann,1), color = colorGann,xloc = xloc.bar_time, style = lineStyleGann,width = widthGann))
array.unshift(arrayLineGann,line.new(array.get(arrayXGann,1),array.get(arrayYGann,1),array.get(arrayXGann,0),array.get(arrayYGann,0), color = colorGann,xloc = xloc.bar_time, style = lineStyleGann,width = widthGann))
else if(drawLineGann == 4)
array.unshift(arrayLineGann,line.new(array.get(arrayXGann,2),array.get(arrayYGann,2),array.get(arrayXGann,1),array.get(arrayYGann,1), color = colorGann,xloc = xloc.bar_time, style = lineStyleGann,width = widthGann))
array.unshift(arrayLineGann,line.new(array.get(arrayXGann,1),array.get(arrayYGann,1),array.get(arrayXGann,0),array.get(arrayYGann,0), color = colorGann,xloc = xloc.bar_time, style = lineStyleGann,width = widthGann))
//////////////////////////Swing Gann//////////////////////////
var arrayXSGann = array.new_int(5,time)
var arrayYSGann = array.new_float(5,close)
var arrayLineSGann = array.new_line()
int drawLineSGann = 0
int drawLineSGann1 = 0
bool runCheckChoChSGann = false
runCheckChoChSGann := runCheckChoChSGann
if(showSGann)
if(math.max(array.get(arrayYSGann,0),array.get(arrayYSGann,1)) < math.min(array.get(arrayYGann,0),array.get(arrayYGann,1)) or math.min(array.get(arrayYSGann,0),array.get(arrayYSGann,1)) > math.max(array.get(arrayYGann,0),array.get(arrayYGann,1)))
//Khởi tạo bắt đầu
drawLineSGann1 := 5
array.set(arrayXSGann, 0, array.get(arrayXGann,1))
array.set(arrayYSGann, 0, array.get(arrayYGann,1))
array.unshift(arrayXSGann,array.get(arrayXGann,0))
array.unshift(arrayYSGann,array.get(arrayYGann,0))
// drawLineSGann kiểm tra điểm 1 => 13:Tiếp tục có sóng hồi // 12|19(reDraw):Tiếp tục không có sóng hồi // 14:Đảo chiều
if(array.get(arrayXGann,0) == array.get(arrayXGann,1))
if(array.get(arrayXSGann,0) >= array.get(arrayXGann,2) and array.get(arrayYSGann,0) != array.get(arrayYGann,1) and ((array.get(arrayYGann,1) > array.get(arrayYGann,2) and array.get(arrayYSGann,0) > array.get(arrayYSGann,1)) or (array.get(arrayYGann,1) < array.get(arrayYGann,2) and array.get(arrayYSGann,0) < array.get(arrayYSGann,1))))
drawLineSGann1 := 12
array.set(arrayXSGann, 0, array.get(arrayXGann,1))
array.set(arrayYSGann, 0, array.get(arrayYGann,1))
else if(array.get(arrayXSGann,0) <= array.get(arrayXGann,2))
if((array.get(arrayYSGann,0) > array.get(arrayYSGann,1) and array.get(arrayYGann,1) < array.get(arrayYSGann,1)) or (array.get(arrayYSGann,0) < array.get(arrayYSGann,1) and array.get(arrayYGann,1) > array.get(arrayYSGann,1)))
drawLineSGann1 := 14
runCheckChoChSGann := true
array.unshift(arrayXSGann,array.get(arrayXGann,1))
array.unshift(arrayYSGann,array.get(arrayYGann,1))
else if((array.get(arrayYSGann,0) > array.get(arrayYSGann,1) and array.get(arrayYGann,1) > array.get(arrayYSGann,0)) or (array.get(arrayYSGann,0) < array.get(arrayYSGann,1) and array.get(arrayYGann,1) < array.get(arrayYSGann,0)))
drawLineSGann1 := 13
_max = math.min(array.get(arrayYSGann,0),array.get(arrayYSGann,1))
_min = math.max(array.get(arrayYSGann,0),array.get(arrayYSGann,1))
_max_idx = 0
_min_idx = 0
for i = 2 to array.size(arrayXGann)
if(array.get(arrayXSGann,0) >= array.get(arrayXGann,i))
break
if(_min > array.get(arrayYGann,i))
_min := array.get(arrayYGann,i)
_min_idx := array.get(arrayXGann,i)
if(_max < array.get(arrayYGann,i))
_max := array.get(arrayYGann,i)
_max_idx := array.get(arrayXGann,i)
if(array.get(arrayYSGann,0) > array.get(arrayYSGann,1))
array.unshift(arrayXSGann,_min_idx)
array.unshift(arrayYSGann,_min)
else if(array.get(arrayYSGann,0) < array.get(arrayYSGann,1))
array.unshift(arrayXSGann,_max_idx)
array.unshift(arrayYSGann,_max)
array.unshift(arrayXSGann,array.get(arrayXGann,1))
array.unshift(arrayYSGann,array.get(arrayYGann,1))
if(f_resInMinutes() < f_tfRes(customTF,f_resInMinutes()))
if(array.get(arrayYSGann,0) == array.get(arrayYGann,1) and array.get(arrayXSGann,0) != array.get(arrayXGann,1))
array.set(arrayXSGann, 0, array.get(arrayXGann,1))
drawLineSGann1 := 19
if(f_resInMinutes() <= f_tfRes(customTF,f_resInMinutes()))
if(drawLineSGann1 == 12 or drawLineSGann1 == 19)
if(array.size(arrayLineSGann) >0)
line.set_xy2(array.get(arrayLineSGann,0),array.get(arrayXSGann,0),array.get(arrayYSGann,0))
else
array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGann,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc = xloc.bar_time,width = widthSGann, style = lineStyleSGann))
else if(drawLineSGann1 == 14)
array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGann,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc = xloc.bar_time,width = widthSGann,style = lineStyleSGann))
else if(drawLineSGann1 == 13)
array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,2),array.get(arrayYSGann,2),array.get(arrayXSGann,1),array.get(arrayYSGann,1), color = colorSGann,xloc = xloc.bar_time,width = widthSGann,style = lineStyleSGann))
array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGann,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc = xloc.bar_time,width = widthSGann,style = lineStyleSGann))
else if(drawLineSGann1 == 15)
if(array.size(arrayLineSGann) >0)
line.set_xy2(array.get(arrayLineSGann,0),array.get(arrayXSGann,1),array.get(arrayYSGann,1))
else
array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,2),array.get(arrayYSGann,2),array.get(arrayXSGann,1),array.get(arrayYSGann,1), color = colorSGann,xloc = xloc.bar_time,width = widthSGann,style = lineStyleSGann))
array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGann,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc = xloc.bar_time,width = widthSGann,style = lineStyleSGann))
if(runCheckChoChSGann)
runCheckChoChSGann := false
// ChoCh Trường hợp chữ N ngược, chữ N
if((array.get(arrayYSGann,3) > array.get(arrayYSGann,2) and array.get(arrayYSGann,3) < array.get(arrayYSGann,1) and array.get(arrayYSGann,0) < array.get(arrayYSGann,2)) or (array.get(arrayYSGann,3) < array.get(arrayYSGann,2) and array.get(arrayYSGann,3) > array.get(arrayYSGann,1) and array.get(arrayYSGann,0) > array.get(arrayYSGann,2)))
alert(syminfo.ticker + " : " + timeframe.period + " => Swing of Gann ChoCh" + (array.get(arrayYSGann,0) > array.get(arrayYSGann,1) ? "+ ⇑" : "- ⇓"))
if(showChoCh)
array.unshift(arrayLineChoCh,line.new(x1= array.get(arrayXSGann,2) , y1=array.get(arrayYSGann,2),x2=array.get(arrayXSGann,0), y2=array.get(arrayYSGann,2),color = colorChoch,xloc = xloc.bar_time,style = lineStyleChoch,width = widthChoch))
// ChoCh 2 Đầu Trường hợp chữ N ngược, chữ N
if(show2ChoCh and ((array.get(arrayYSGann,1) > array.get(arrayYSGann,3) and array.get(arrayYSGann,3) > array.get(arrayYSGann,4) and array.get(arrayYSGann,4) > array.get(arrayYSGann,2) and array.get(arrayYSGann,2) > array.get(arrayYSGann,0)) or (array.get(arrayYSGann,0) > array.get(arrayYSGann,2) and array.get(arrayYSGann,2) > array.get(arrayYSGann,4) and array.get(arrayYSGann,4) > array.get(arrayYSGann,3) and array.get(arrayYSGann,3) > array.get(arrayYSGann,1))))
line.set_width(array.get(arrayLineSGann,1),width2Choch)
line.set_style(array.get(arrayLineSGann,1), lineStyle2Choch)
line.set_color(array.get(arrayLineSGann,1),color2Choch)
// drawLineSGann kiểm tra điểm 0 => 3:Tiếp tục có sóng hồi // 2|9(reDraw):Tiếp tục không có sóng hồi // 4:Đảo chiều
if(array.get(arrayXSGann,0) >= array.get(arrayXGann,1) and array.get(arrayYSGann,0) != array.get(arrayYGann,0) and ((array.get(arrayYGann,0) > array.get(arrayYGann,1) and array.get(arrayYSGann,0) > array.get(arrayYSGann,1)) or (array.get(arrayYGann,0) < array.get(arrayYGann,1) and array.get(arrayYSGann,0) < array.get(arrayYSGann,1))))
drawLineSGann := 2
array.set(arrayXSGann, 0, array.get(arrayXGann,0))
array.set(arrayYSGann, 0, array.get(arrayYGann,0))
else if(array.get(arrayXSGann,0) <= array.get(arrayXGann,1))
if((array.get(arrayYSGann,0) > array.get(arrayYSGann,1) and array.get(arrayYGann,0) < array.get(arrayYSGann,1)) or (array.get(arrayYSGann,0) < array.get(arrayYSGann,1) and array.get(arrayYGann,0) > array.get(arrayYSGann,1)))
drawLineSGann := 4
runCheckChoChSGann := true
array.unshift(arrayXSGann,array.get(arrayXGann,0))
array.unshift(arrayYSGann,array.get(arrayYGann,0))
else if((array.get(arrayYSGann,0) > array.get(arrayYSGann,1) and array.get(arrayYGann,0) > array.get(arrayYSGann,0)) or (array.get(arrayYSGann,0) < array.get(arrayYSGann,1) and array.get(arrayYGann,0) < array.get(arrayYSGann,0)))
drawLineSGann := 3
_max = math.min(array.get(arrayYSGann,0),array.get(arrayYSGann,1))
_min = math.max(array.get(arrayYSGann,0),array.get(arrayYSGann,1))
_max_idx = 0
_min_idx = 0
for i = 1 to array.size(arrayXGann)
if(array.get(arrayXSGann,0) >= array.get(arrayXGann,i))
break
if(_min > array.get(arrayYGann,i))
_min := array.get(arrayYGann,i)
_min_idx := array.get(arrayXGann,i)
if(_max < array.get(arrayYGann,i))
_max := array.get(arrayYGann,i)
_max_idx := array.get(arrayXGann,i)
if(array.get(arrayYSGann,0) > array.get(arrayYSGann,1))
array.unshift(arrayXSGann,_min_idx)
array.unshift(arrayYSGann,_min)
else if(array.get(arrayYSGann,0) < array.get(arrayYSGann,1))
array.unshift(arrayXSGann,_max_idx)
array.unshift(arrayYSGann,_max)
array.unshift(arrayXSGann,array.get(arrayXGann,0))
array.unshift(arrayYSGann,array.get(arrayYGann,0))
if(f_resInMinutes() < f_tfRes(customTF,f_resInMinutes()))
if(array.get(arrayYSGann,0) == array.get(arrayYGann,0) and array.get(arrayXSGann,0) != array.get(arrayXGann,0))
array.set(arrayXSGann, 0, array.get(arrayXGann,0))
drawLineSGann := 9
if(f_resInMinutes() <= f_tfRes(customTF,f_resInMinutes()))
if(drawLineSGann == 2 or drawLineSGann == 9)
if(array.size(arrayLineSGann) >0)
line.set_xy2(array.get(arrayLineSGann,0),array.get(arrayXSGann,0),array.get(arrayYSGann,0))
else
array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGann,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc = xloc.bar_time,width = widthSGann,style = lineStyleSGann))
else if(drawLineSGann == 4)
array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGann,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc = xloc.bar_time,width = widthSGann,style = lineStyleSGann))
else if(drawLineSGann == 3)
array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,2),array.get(arrayYSGann,2),array.get(arrayXSGann,1),array.get(arrayYSGann,1), color = colorSGann,xloc = xloc.bar_time,width = widthSGann,style = lineStyleSGann))
array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGann,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc = xloc.bar_time,width = widthSGann,style = lineStyleSGann))
else if(drawLineSGann == 5)
if(array.size(arrayLineSGann) >0)
line.set_xy2(array.get(arrayLineSGann,0),array.get(arrayXSGann,1),array.get(arrayYSGann,1))
else
array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,2),array.get(arrayYSGann,2),array.get(arrayXSGann,1),array.get(arrayYSGann,1), color = colorSGann,xloc = xloc.bar_time,width = widthSGann,style = lineStyleSGann))
array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGann,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc = xloc.bar_time,width = widthSGann,style = lineStyleSGann))
if(runCheckChoChSGann)
runCheckChoChSGann := false
// ChoCh Trường hợp chữ N ngược, chữ N
if((array.get(arrayYSGann,3) > array.get(arrayYSGann,2) and array.get(arrayYSGann,3) < array.get(arrayYSGann,1) and array.get(arrayYSGann,0) < array.get(arrayYSGann,2)) or (array.get(arrayYSGann,3) < array.get(arrayYSGann,2) and array.get(arrayYSGann,3) > array.get(arrayYSGann,1) and array.get(arrayYSGann,0) > array.get(arrayYSGann,2)))
alert(syminfo.ticker + " : " + timeframe.period + " => Swing of Gann ChoCh" + (array.get(arrayYSGann,0) > array.get(arrayYSGann,1) ? "+ ⇑" : "- ⇓"))
if(showChoCh)
array.unshift(arrayLineChoCh,line.new(x1= array.get(arrayXSGann,2) , y1=array.get(arrayYSGann,2),x2=array.get(arrayXSGann,0), y2=array.get(arrayYSGann,2),color = colorChoch,xloc = xloc.bar_time,style = lineStyleChoch,width = widthChoch))
// ChoCh 2 Đầu Trường hợp chữ N ngược, chữ N
if(show2ChoCh and ((array.get(arrayYSGann,1) > array.get(arrayYSGann,3) and array.get(arrayYSGann,3) > array.get(arrayYSGann,4) and array.get(arrayYSGann,4) > array.get(arrayYSGann,2) and array.get(arrayYSGann,2) > array.get(arrayYSGann,0)) or (array.get(arrayYSGann,0) > array.get(arrayYSGann,2) and array.get(arrayYSGann,2) > array.get(arrayYSGann,4) and array.get(arrayYSGann,4) > array.get(arrayYSGann,3) and array.get(arrayYSGann,3) > array.get(arrayYSGann,1))))
line.set_width(array.get(arrayLineSGann,1),width2Choch)
line.set_style(array.get(arrayLineSGann,1),lineStyle2Choch)
line.set_color(array.get(arrayLineSGann,1),color2Choch)
///////////////////////Other//////////////////////////////////
if(f_resInMinutes() <= f_tfRes(customTF,f_resInMinutes()))
if(showSGann)
if(showtargetOTL)
if(drawLineSGann1 == 14)
line.set_xy1(lineChoChOTLTarget,array.get(arrayXSGann,3),array.get(arrayYSGann,3))
line.set_xy2(lineChoChOTLTarget,array.get(arrayXSGann,3),array.get(arrayYSGann,3)*2 - array.get(arrayYSGann,2))
else if(drawLineSGann1 == 13)
line.set_xy1(lineBosOTLTarget,array.get(arrayXSGann,3),array.get(arrayYSGann,3))
line.set_xy2(lineBosOTLTarget,array.get(arrayXSGann,3),array.get(arrayYSGann,3)*2 - array.get(arrayYSGann,2))
if(drawLineSGann == 4)
line.set_xy1(lineChoChOTLTarget,array.get(arrayXSGann,2),array.get(arrayYSGann,2))
line.set_xy2(lineChoChOTLTarget,array.get(arrayXSGann,2),array.get(arrayYSGann,2)*2 - array.get(arrayYSGann,1))
else if(drawLineSGann == 3)
line.set_xy1(lineBosOTLTarget,array.get(arrayXSGann,2),array.get(arrayYSGann,2))
line.set_xy2(lineBosOTLTarget,array.get(arrayXSGann,2),array.get(arrayYSGann,2)*2 - array.get(arrayYSGann,1))
if(showLabel and (barstate.islast or barstate.islastconfirmedhistory))
texLabel = f_resInMinutes() == f_tfRes(customTF,f_resInMinutes()) ? f_resFromMinutes(f_resInMinutes()) : f_resFromMinutes(f_tfRes(customTF,f_resInMinutes()))
label.set_xy(labelTF,array.get(arrayXSGann,0),array.get(arrayYSGann,0))
label.set_text(labelTF,texLabel)
label.set_style(labelTF,array.get(arrayYSGann,0) < array.get(arrayYSGann,1) ? label.style_label_upper_right : label.style_label_lower_right)
else if(showGann)
if(showLabel and (barstate.islast or barstate.islastconfirmedhistory))
texLabel = f_resInMinutes() == f_tfRes(customTF,f_resInMinutes()) ? f_resFromMinutes(f_resInMinutes()) : f_resFromMinutes(f_tfRes(customTF,f_resInMinutes()))
label.set_xy(labelTF,array.get(arrayXGann,0),array.get(arrayYGann,0))
label.set_text(labelTF,texLabel)
label.set_style(labelTF,array.get(arrayYGann,0) < array.get(arrayYGann,1) ? label.style_label_upper_right : label.style_label_lower_right)
///ema///
EMA = "EMA Setting"
len = input.int(21, minval=1, title="EMA Length")
len1= input.int(34, minval=1, title="EMA Length")
len2 = input.int(89, minval=1, title="EMA Length")
len3 = input.int(200, minval=1, title="EMA Length")
src = close
ema = ta.ema(src, len)
ema1 = ta.ema(close,len1) //34
ema2 = ta.ema(close,len2) //89
ema3 = ta.ema (close,len3)//200
up = ema > ema
down = ema < ema
mycolor = up ? #00a7bc : down ? #b91002 : color.blue
plot(ema, title="EMA", color=mycolor, linewidth=1)
//plot(ema1, title="EMA", color=mycolor, linewidth=1,editable = false)
//plot(ema2, title="EMA", color=mycolor, linewidth=1,editable = false)
//plot(ema3, title="EMA", color=mycolor, linewidth=1,editable = false)
table_color_up = color.new(#00a7bc,70)
table_color_down = color.new(#b91002,70)
//vẽ bảng ema + rsi//
t = table.new(position = position.bottom_right, columns = 5, rows = 9, bgcolor = #fde9c9)
table.cell(t, 0, 0, "Time",text_size = size.small)
table.cell(t, 1, 0, "EMA",text_size = size.small)
table.cell(t, 0, 1, "5m",text_size = size.small)
table.cell(t, 0, 2, "15m",text_size = size.small)
table.cell(t, 0, 3, "4h",text_size = size.small)
table.cell(t, 0, 4, "1d",text_size = size.small)
// tính toán giá EMA của các khung thời gian khác nhau
ema5 = request.security(syminfo.tickerid, "5", ta.ema(src, len))
ema15 = request.security(syminfo.tickerid, "15", ta.ema(src, len))
ema4h = request.security(syminfo.tickerid, "240", ta.ema(src, len))
ema1d = request.security(syminfo.tickerid, "D", ta.ema(src, len))
//tô màu cho bảng chứa EMA
ema5_color = ema5 < close ? table_color_up : table_color_down
ema15_color = ema15 < close ? table_color_up :table_color_down
ema4h_color = ema4h < close ? table_color_up : table_color_down
ema1d_color = ema1d < close ? table_color_up : table_color_down
//tính toán ema 123_5
//ema5_1 = request.security(syminfo.tickerid, "5", ta.ema(close, len1))
//ema5_2 = request.security(syminfo.tickerid, "5", ta.ema(close, len2))
//ema5_3 = request.security(syminfo.tickerid, "5", ta.ema(close, len3))
//trend_ema5_color = (ema5_1 > ema5_2 and ema5_2 > ema5_3) ? color.green : (ema5_1 > ema5_2 and ema5_2 < ema5_3)? color.new(color.green,70) : (ema5_1 < ema5_2 and ema5_2 < ema5_3) ? color.red : (ema5_1 < ema5_2 and ema5_2 > ema5_3) ? color.new(color.red,70) : color.orange
//tính toán ema 123_15
ema15_1 = request.security(syminfo.tickerid, "15", ta.ema(close, len1))
ema15_2 = request.security(syminfo.tickerid, "15", ta.ema(close, len2))
ema15_3 = request.security(syminfo.tickerid, "15", ta.ema(close, len3))
trend_ema15_color = (ema15_1 > ema15_2 and ema15_2 > ema15_3) ? color.green : (ema15_1 > ema15_2 and ema15_2 < ema15_3)? color.new(color.green,70) : (ema15_1 < ema15_2 and ema15_2 < ema15_3) ? color.red : (ema15_1 < ema15_2 and ema15_2 > ema15_3) ? color.new(color.red,70) : color.orange
//tính toán ema 123_4h
ema4h_1 = request.security(syminfo.tickerid, "240", ta.ema(close, len1))
ema4h_2 = request.security(syminfo.tickerid, "240", ta.ema(close, len2))
ema4h_3 = request.security(syminfo.tickerid, "240", ta.ema(close, len3))
trend_ema4h_color = (ema4h_1 > ema4h_2 and ema4h_2 > ema4h_3) ? color.green : (ema4h_1 > ema4h_2 and ema4h_2 < ema4h_3)? color.new(color.green,70) : (ema4h_1 < ema4h_2 and ema4h_2 < ema4h_3) ? color.red : (ema4h_1 < ema4h_2 and ema4h_2 > ema4h_3) ? color.new(color.red,70) : color.orange
// tính toán RSI của các khung thời gian khác nhau
rsi5 = request.security(syminfo.tickerid, "5", ta.rsi(src, 14))
rsi15 = request.security(syminfo.tickerid, "15", ta.rsi(src, 14))
rsi4h = request.security(syminfo.tickerid, "240", ta.rsi(src, 14))
rsi1d = request.security(syminfo.tickerid, "D", ta.rsi(src, 14))
//tô màu cho bảng chứa RSI
rsi5_color = rsi5 > 70 ? table_color_down : rsi5 < 30 ? table_color_up : color.orange
rsi15_color = rsi15 > 70 ? table_color_down : rsi15 < 30 ? table_color_up : color.orange
rsi4h_color = rsi4h > 70 ? table_color_down : rsi4h < 30 ? table_color_up : color.orange
rsi1d_color = rsi1d > 70 ? table_color_down : rsi1d < 30 ? table_color_up : color.orange
//tính toán % thay đổi 1d, 7d, 30d
// Lấy giá trị giá đóng cửa của các ngày trước đó
yesterday_close = request.security(syminfo.tickerid, "D", close )
last_week_close = request.security(syminfo.tickerid, "W", close )
last_month_close = request.security(syminfo.tickerid, "M", close )
// Tính toán phần trăm thay đổi giá so với các ngày trước đó
day_change = math.round((close / yesterday_close - 1) * 100,1)
week_change = math.round((close / last_week_close - 1) * 100,1)
month_change = math.round((close / last_month_close - 1) * 100,1)
//tô màu cho bảng chứa % thay đổi
day_change_color = day_change < 0 ? table_color_down : table_color_up
weak_change_color = week_change < 0 ? table_color_down : table_color_up
month_change_color = month_change < 0 ? table_color_down : table_color_up
// tính toán btc.d usdt.d dxy
btc_d = request.security("CRYPTOCAP:BTC.D", timeframe.period, close)
usdt_d = request.security("CRYPTOCAP:USDT.D", timeframe.period, close)
dxy = request.security("TVC:DXY", timeframe.period, close)
yesterday_btc_d = request.security("CRYPTOCAP:BTC.D", timeframe.period, close )
yesterday_usdt_d = request.security("CRYPTOCAP:USDT.D", timeframe.period, close )
yesterday_dxy = request.security("TVC:DXY", timeframe.period, close )
btc_d_color = btc_d < yesterday_btc_d ? table_color_down : table_color_up //too mau
usdt_d_color = usdt_d < yesterday_usdt_d ? table_color_down : table_color_up
dxy_color = dxy < yesterday_dxy ? table_color_down : table_color_up
// điền giá EMA vào bảng
table.cell(t, 1, 1, str.tostring(math.round(ema5, 3)), bgcolor = ema5_color,text_size = size.small)
table.cell(t, 1, 2, str.tostring(math.round(ema15, 3)), bgcolor = ema15_color,text_size = size.small)
table.cell(t, 1, 3, str.tostring(math.round(ema4h, 3)), bgcolor = ema4h_color,text_size = size.small)
table.cell(t, 1, 4, str.tostring(math.round(ema1d, 3)), bgcolor = ema1d_color,text_size = size.small)
// điền rsi vào bảng
show_info_2 = input.bool(title = "Show % RSI",defval = true,group = "Table Setting")
if show_info_2
table.cell(t, 2, 0, "RSI",text_size = size.small)
table.cell(t, 2, 1, str.tostring(math.round(rsi5,0)), bgcolor = rsi5_color,text_size = size.small)
table.cell(t, 2, 2, str.tostring(math.round(rsi15,0)), bgcolor = rsi15_color,text_size = size.small)
table.cell(t, 2, 3, str.tostring(math.round(rsi4h,0)), bgcolor = rsi4h_color,text_size = size.small)
table.cell(t, 2, 4, str.tostring(math.round(rsi1d,0)), bgcolor = rsi1d_color,text_size = size.small)
// điển % change vào bảng
show_info_1 = input.bool(title = "Show % Change 1d, 7d, 30d",defval = true,group = "Table Setting")
if show_info_1
table.cell(t,0,5,"%",text_size = size.small)
table.cell(t,1,5,"1d",text_size = size.small)
table.cell(t,2,5,"7d",text_size = size.small)
table.cell(t,3,5,"30d",text_size = size.small)
table.cell(t, 1, 6, str.tostring(day_change, "#.##") + "%",bgcolor= day_change_color,text_size = size.small)
table.cell(t, 2, 6, str.tostring(week_change, "#.##") + "%",bgcolor = weak_change_color,text_size = size.small)
table.cell(t, 3, 6, str.tostring(month_change,"#.##") + "%", bgcolor = month_change_color,text_size = size.small)
//điện btc.d usdt.d dxy vào bảng
Table_Info = "Table Setting"
show_info = input.bool(title = "Show BTC.D, USSDT, DXY",defval = true,group = "Table Setting")
if show_info
table.cell(t,0,7,"#",text_size = size.small)
table.cell(t,1,7,"BTC.D",text_size = size.small)
table.cell(t,2,7,"USDT.D",text_size = size.small)
table.cell(t,3,7,"DXY",text_size = size.small)
table.cell(t, 1, 8, str.tostring(btc_d, "#.##") + "%",bgcolor= btc_d_color,text_size = size.small)
table.cell(t, 2, 8, str.tostring(usdt_d, "#.##") + "%",bgcolor = usdt_d_color,text_size = size.small)
table.cell(t, 3, 8, str.tostring(dxy,"#.##") + "%", bgcolor = dxy_color,text_size = size.small)
//điền trend ema vào bảng
show_info_3 = input.bool(title = "Show Trend",defval = true,group = "Table Setting")
if show_info_3
table.cell(t,3,0,"Trend",text_size = size.small)
//table.cell(t,3,1,"",bgcolor = trend_ema5_color)
table.cell(t,3,2,"",bgcolor = trend_ema15_color)
table.cell(t,3,3,"",bgcolor = trend_ema4h_color)
//đánh dấu volume với các osb + nến bulish bearish
//indicator("Color Ultra Volume Background", shorttitle = "UV",overlay=true, max_boxes_count=500, max_labels_count=500, max_lines_count=500, max_bars_back=1000)
UltraVol = "Ultra volume background"
colorultravol = input.color(color.new(color.purple,50),"Color UltraVol",group = UltraVol)
//Công thức//
lengthVolumeMA = input.int(20,minval=1,title="Length of MA applied on Volume",group = UltraVol)
ratioUltraVolume = input.float(2.2,minval=1,title="Ultra High Volume Ratio", group = UltraVol)
float volumeMA = 0
volumeMA := nz(volumeMA ) + (volume-nz(volumeMA )) / lengthVolumeMA
ultraHighVolumeMin = volumeMA * ratioUltraVolume
volUltraHigh = volume >= ultraHighVolumeMin? true : false
// Màu volume
color_cande_up_down = input.color(color.new(color.purple,100),"Color UltraVol",group = OSB_up_down)
Candle_body = input.float(0.5, 'Height of Engulfing candle body (%)', group = OSB_up_down)
//scan nến osb-eng - mera mera//
osb_up = high > high and low < low and close > close
osb_down = high > high and low < low and close < close
eng_up = open >= close and close > high and (close - open) >= Candle_body*(high - low)
eng_down = open <= close and close < low and (open - close) >= Candle_body*(high - low)
mm_up = osb_up and close > close and close > close
mm_down = osb_down and close < close and close < close
cande_up = close > close
cande_down = close < close
//tô màu nến//
colorOSB_up = input.color(#0ba4f9,'colorOSB_up',inline = "Up Outside Bar",group = OSB_up_down)
colorOSB_down = input.color(#fd1700,'colorOSB_dowwn',inline = "Down Outside Bar",group = OSB_up_down)
barcolor(osb_up ? colorOSB_up : na, title="Up Outside Bar")
barcolor(osb_down ? colorOSB_down : na, title="Down Outside Bar")
coloreng_up = input.color(#00a7bc,'coloreng_up',inline = "Bullish Bar",group = OSB_up_down)
coloreng_down = input.color(#b91002,'coloreng_dowwn',inline = "Bearlish Bar",group = OSB_up_down)
barcolor(eng_up ? coloreng_up : na, title="Bullish Bar")
barcolor(eng_down ? coloreng_down : na, title="Bearlish Bar")
//đánh dấu vol - mera mera
plotshape(volUltraHigh and cande_up,"Candle_UltraVol_up_shape",style = shape.circle,location = location.belowbar,color = coloreng_up,size = size.tiny)
plotshape(volUltraHigh and cande_down,"Candle_UltraVol_down_shape",style = shape.circle,location = location.abovebar,color = coloreng_down,size = size.tiny)
plotshape(volUltraHigh and osb_up,"Up Outside Bar+ Vol",style = shape.circle,location = location.belowbar,color = color_cande_up_down,size = size.tiny)
plotshape(volUltraHigh and osb_down,"Down Outside Bar+ Vol",style = shape.circle,location = location.abovebar,color = color_cande_up_down,size = size.tiny)
plotshape(volUltraHigh and eng_up,"Bullish Bar + Vol",style = shape.circle,location = location.belowbar,color = color_cande_up_down,size = size.tiny)
plotshape(volUltraHigh and eng_down,"Bearlish + Vol Bar",style = shape.circle,location = location.abovebar,color = color_cande_up_down,size = size.tiny)
plotshape(mm_up ? high : na, style=shape.circle, location=location.belowbar, color=#0ba4f9,title = "Mera UP",size = size.tiny)
plotshape(mm_down ? low : na, style=shape.circle, location=location.abovebar, color=#fd1700, title = "Mera Down", size = size.tiny)
//cảnh báo khi xuất hiện nến/
close_osb_up = close
close_osb_down = close
close_eng_up = close
close_eng_down = close
close_mm_up = close
close_mm_down = close
time_h4 = request.security(syminfo.tickerid, "240",close)
time_D1 = request.security(syminfo.tickerid, "D",close)
if (osb_up and barstate.isconfirmed)
if (close_osb_up > ema)
alert("OSB_UP: Above Ema: " + str.tostring(close_osb_up))
if volUltraHigh
alert("OSB_UP + Volume: Above Ema: " + str.tostring(close_osb_up))
else if (close_osb_up < ema)
alert("OSB_UP: Below Ema: " + str.tostring(close_osb_up))
if volUltraHigh
alert("OSB_UP + Volume: Below Ema: " + str.tostring(close_osb_up))
if (osb_down and barstate.isconfirmed)
if (close_osb_down > ema)
alert("OSB_DOWN: Above Ema: " + str.tostring(close_osb_down))
if volUltraHigh
alert("OSB_DOWN + Volume: Above Ema: " + str.tostring(close_osb_down))
else if (close_osb_down < ema)
alert("OSB_DOWN: Below Ema: " + str.tostring(close_osb_down))
if volUltraHigh
alert("OSB_DOWN + Volume: Below Ema: " + str.tostring(close_osb_down))
if (eng_up and barstate.isconfirmed)
if (close_eng_up > ema)
alert("Bar_UP: Above Ema: " + str.tostring(close_eng_up))
if volUltraHigh
alert("Bar_UP + Volume: Above Ema: " + str.tostring(close_eng_up))
else if (close_eng_up < ema)
alert("Bar_UP: Below Ema: " + str.tostring(close_eng_up))
if volUltraHigh
alert("Bar_UP + Volume: Below Ema: " + str.tostring(close_eng_up))
if (eng_down and barstate.isconfirmed)
if (close_eng_down > ema)
alert("Bar_DOWN: Above Ema: " + str.tostring(close_eng_down))
if volUltraHigh
alert("Bar_DOWN + Volume: Above Ema: " + str.tostring(close_eng_down))
else if (close_eng_down < ema)
alert("Bar_DOWN: Below Ema: " + str.tostring(close_eng_down))
if volUltraHigh
alert("Bar_DOWN + Volume: Below Ema: " + str.tostring(close_eng_down))
if (mm_up and barstate.isconfirmed)
if (close_mm_up > ema)
alert("Mera_UP: Above Ema: " + str.tostring(close_mm_up))
if volUltraHigh
alert("Mera_UP + Volume: Above Ema: " + str.tostring(close_mm_up))
else if (close_mm_up < ema)
alert("Mera_UP: Below Ema: " + str.tostring(close_mm_up))
if volUltraHigh
alert("Mera_UP + Volume: Below Ema: " + str.tostring(close_mm_up))
if (mm_down and barstate.isconfirmed)
if (close_mm_down > ema)
alert("Mera_DOWN: Above Ema: " + str.tostring(close_mm_down))
if volUltraHigh
alert("Mera_DOWN + Volume: Above Ema: " + str.tostring(close_mm_down))
else if (close_mm_down < ema)
alert("Mera_DOWN: Below Ema: " + str.tostring(close_mm_down))
if volUltraHigh
alert("Mera_DOWN + Volume: Below Ema: " + str.tostring(close_mm_down))
//indicator("Initial Balance", shorttitle="Initial Balance", overlay=true, max_bars_back=5000)
ib_session = input.session("2300-0000", title="Initial Balance", group="Calculation period")
show_extra_levels = input.bool(false, "Show extra levels (IBH x2 & IBL x2)", group="Information")
show_intermediate_levels = input.bool(false, "Show intermediate levels (50%)", group="Information")
show_ib_calculation_area = input.bool(false, "Initial balance calculation period coloration", group="Information")
show_labels = input.bool(false, "Show labels", group="Information")
fill_ib_areas = input.bool(false, "Colour IB areas", group="Information")
only_current_levels = input.bool(true, "Only display the current IB Levels", group="Information")
only_current_zone = input.bool(false, "Only display the current IB calculation area", group="Information")
label_size = input.string("Small", title="Label Size", options= , group="Drawings")
lvl_width = input.int(1, "Daily price level width", group="Drawings")
high_col = input.color(color.black, "Initial balance high levels color", group="Drawings")
low_col = input.color(color.black, "Initial balance low levels color", group="Drawings")
middle_col = input.color(#ffa726, "50% initial balance color", group="Drawings")
extend_level = input.string("Right", title="Extend current levels", options= , group="Drawings")
main_levels_style = input.string("Solid" , "Main levels line style", options= , group="Drawings")
ext_levels_style = input.string("Dashed" , "Extended levels line style", options= , group="Drawings")
int_levels_style = input.string("Dotted" , "Intermediate levels line style", options= , group="Drawings")
fill_ib_color= input.color(#b8851faa, "IB area background color", group="Drawings")
ext = extend_level == "Right" ? extend.right : extend_level == "Left" ? extend.left : extend_level == "Both" ? extend.both : extend.none
var delta_history = array.new_float(20)
inSession(sess) => na(time(timeframe.period, sess)) == false
get_line_style(s) =>
s == "Solid" ? line.style_solid : s == "Dotted" ? line.style_dotted : line.style_dashed
get_levels(n) =>
h = high
l = low
for i=1 to n
if low < l
l := low
if high > h
h := high
var line ibh = na
var line ibl = na
var line ibm = na
var line ib_plus = na
var line ib_minus = na
var line ib_plus2 = na
var line ib_minus2 = na
var line ibm_plus = na
var line ibm_minus = na
var label labelh = na
var label labell = na
var label labelm = na
var label label_plus = na
var label label_minus = na
var label label_plus2 = na
var label label_minus2 = na
var label labelm_plus = na
var label labelm_minus = na
var box ib_area = na
labelSize = (label_size == "Huge") ? size.huge :
(label_size == "Large") ? size.large :
(label_size == "Small") ? size.small :
(label_size == "Tiny") ? size.tiny :
(label_size == "Auto") ? size.auto : size.normal
var offset = 0
ins = inSession(ib_session)
bgcolor(show_ib_calculation_area and ins ? #673ab730 : na, title="IB calculation zone")
var float ib_delta = na
if ins
offset += 1
if ins and not ins
= get_levels(offset)
ib_delta := h - l
if array.size(delta_history) >= 20
array.shift(delta_history)
array.push(delta_history, ib_delta)
line.set_extend(ibh, extend.none)
line.set_extend(ibl, extend.none)
if show_intermediate_levels
line.set_extend(ibm, extend.none)
if show_extra_levels
line.set_extend(ib_plus, extend.none)
line.set_extend(ib_minus, extend.none)
line.set_extend(ib_plus2, extend.none)
line.set_extend(ib_minus2, extend.none)
if show_intermediate_levels
line.set_extend(ibm_plus, extend.none)
line.set_extend(ibm_minus, extend.none)
if show_labels
if only_current_levels
label.delete(labelh)
label.delete(labell)
label.delete(labelm)
label.delete(label_plus)
label.delete(label_minus)
label.delete(label_plus2)
label.delete(label_minus2)
label.delete(labelm_plus)
label.delete(labelm_minus)
labelh := label.new(bar_index , h, text="IBH 100%: "+str.tostring(h), style=label.style_none, textcolor=high_col, size=labelSize)
labell := label.new(bar_index , l, text="IBL 0%: "+str.tostring(l), style=label.style_none, textcolor=low_col, size=labelSize)
if show_intermediate_levels
labelm := label.new(bar_index , m, text="IBM 50%: "+str.tostring(m)+" IBΔ: "+str.tostring(h - l), style=label.style_none, textcolor=middle_col, size=labelSize)
if show_extra_levels
label_plus := label.new(bar_index , h + ib_delta, text="IBH x2 - "+str.tostring(h + ib_delta), style=label.style_none, textcolor=high_col, size=labelSize)
label_minus := label.new(bar_index , l - ib_delta, text="IBL x2: "+str.tostring(l - ib_delta), style=label.style_none, textcolor=low_col, size=labelSize)
label_plus2 := label.new(bar_index , h + (ib_delta*2), text="IBH x3 - "+str.tostring(h + (ib_delta*2)), style=label.style_none, textcolor=high_col, size=labelSize)
label_minus2 := label.new(bar_index , l - (ib_delta*2), text="IBL x3: "+str.tostring(l - (ib_delta*2)), style=label.style_none, textcolor=low_col, size=labelSize)
if fill_ib_areas
if only_current_zone
box.delete(ib_area)
ib_area := box.new(bar_index , h, bar_index, l, bgcolor=fill_ib_color, border_color=#00000000)//, extend=ext)
if only_current_levels
line.delete(ibh)
line.delete(ibl)
line.delete(ibm)
line.delete(ib_plus)
line.delete(ib_minus)
line.delete(ib_plus2)
line.delete(ib_minus2)
line.delete(ibm_plus)
line.delete(ibm_minus)
ibh := line.new(bar_index , h, bar_index, h, color=high_col, extend=ext, width=lvl_width, style=get_line_style(main_levels_style))
ibl := line.new(bar_index , l, bar_index, l, color=low_col, extend=ext, width=lvl_width, style=get_line_style(main_levels_style))
if show_intermediate_levels
ibm := line.new(bar_index , m, bar_index, m, color=middle_col, style=get_line_style(int_levels_style), extend=ext, width=lvl_width)
if show_extra_levels
ib_plus := line.new(bar_index , h + ib_delta, bar_index, h + ib_delta, color=high_col, style=get_line_style(ext_levels_style), extend=ext, width=lvl_width)
ib_minus := line.new(bar_index , l - ib_delta, bar_index, l - ib_delta, color=low_col, style=get_line_style(ext_levels_style), extend=ext, width=lvl_width)
ib_plus2 := line.new(bar_index , h + (ib_delta*2), bar_index, h + (ib_delta *2), color=high_col, style=get_line_style(ext_levels_style), extend=ext, width=lvl_width)
ib_minus2 := line.new(bar_index , l - (ib_delta*2), bar_index, l - (ib_delta*2), color=low_col, style=get_line_style(ext_levels_style), extend=ext, width=lvl_width)
if show_intermediate_levels
ibm_plus := line.new(bar_index , h + (ib_delta/2), bar_index, h + (ib_delta/2), color=middle_col, style=get_line_style(int_levels_style), extend=ext, width=lvl_width)
ibm_minus := line.new(bar_index , l - (ib_delta/2), bar_index, l - (ib_delta/2), color=middle_col, style=get_line_style(int_levels_style), extend=ext, width=lvl_width)
offset := 0
if (not ins) and (not ins )
line.set_x2(ibh, bar_index)
line.set_x2(ibl, bar_index)
if show_intermediate_levels
line.set_x2(ibm, bar_index)
if show_extra_levels
line.set_x2(ib_plus, bar_index)
line.set_x2(ib_minus, bar_index)
line.set_x2(ib_plus2, bar_index)
line.set_x2(ib_minus2, bar_index)
if show_intermediate_levels
line.set_x2(ibm_plus, bar_index)
line.set_x2(ibm_minus, bar_index)
var table ib_analytics = table.new(position.bottom_left, 2, 6)
ib_sentiment() =>
h = array.max(delta_history)
l = array.min(delta_history)
a = array.avg(delta_history)
h_comp = ib_delta > h ? ib_delta - h : (ib_delta - h) * -1
l_comp = ib_delta > l ? ib_delta - l : (ib_delta - l) * -1
a_comp = ib_delta > a ? ib_delta - a : (ib_delta - a) * -1
(h_comp < l_comp and h_comp < a_comp) ? "Huge" : (l_comp < h_comp and l_comp < a_comp) ? "Small" : "Medium"
//@version=5
//indicator('Key Levels', overlay=true)
group = 'KEYLVL_SETTINGS'
displaystyle = input.string('Standard', ' Display Style', group = group, inline='onest', options= )
linestyle = input.string('Solid', ' Line Style ', group = group, inline='twost', options= )
fontstyle = input.string('Monospace', ' Font Type ', group = group, inline='trest', options= )
labelpos = input.string('Middle', ' Label Pos ', group = group, inline=' ', options= )
bar_offset = input.int (30, ' Offset ', group = group, inline='onest', minval=0, maxval=450, step = 5)
threshold = input.float (0.1, ' Threshold %', group = group, inline='twost', minval=0, step=0.05, tooltip='Threshold - the distance between the levels after which the labels merge.')
index = input.int (0, ' Index ', group = group, inline='trest', minval=0, step=1, tooltip='Index - Default 0 allows you to see current and past price levels. Changing to 1 will shift the current levels to the previous levels, and the previous levels to the previous levels, etc.')
color_cD = input.color (#2a89c9, ' cD', group = group, inline='cols1')
color_cW = input.color (#b7d123, ' cW', group = group, inline='cols1')
color_cM = input.color (#8056b8, ' cM', group = group, inline='cols1')
color_cQ = input.color (#c23eb0, ' cQ', group = group, inline='cols1')
color_cY = input.color (#d62e28, ' cY', group = group, inline='cols1')
color_pD = input.color (#2a89c9, ' pD', group = group, inline='cols2')
color_pW = input.color (#b7d123, ' pW', group = group, inline='cols2')
color_pM = input.color (#8056b8, ' pM', group = group, inline='cols2')
color_pQ = input.color (#c23eb0, ' pQ', group = group, inline='cols2')
color_pY = input.color (#d62e28, ' pY', group = group, inline='cols2', tooltip="Prefix 'C' = Current/today. Prefix 'P' = Previous/yesterday. Prefix 'D' = Day. Prefix 'W' = Week. Prefix 'M' = Mounth. Prefix 'Q' = Quarterly. Prefix 'Y' = Year.'" )
i_tG = input.bool (true, ' Global Color Text', group = group, inline='colsg')
color_tG = input.color (color.black, ' ', group = group, inline='colsg')
i_lG = input.bool (true, ' Global Color Line', group = group, inline='colsg')
color_lG = input.color (color.black, ' ', group = group, inline='colsg')
fontstyles = switch fontstyle
"Default" => font.family_default
"Monospace" => font.family_monospace
linestyles = switch linestyle
"Solid" => line.style_solid
"Dashed" => line.style_dashed
"Dotted" => line.style_dotted
displaystyles = switch displaystyle
"Standard" => extend.none
"Right" => extend.right
"Both" => extend.both
"Left" => extend.left
getprice(TimeFrame, Index)=> // Get Open, High, Low, Close, Time data
i = Index
tf = TimeFrame
= request.security(syminfo.tickerid, tf, [open , high , low , close , time ], lookahead=barmerge.lookahead_on)
= getprice('D', 0+index) // Get Current Day Open, High, Low, Close, Time
= getprice('W', 0+index) // Get Current Weekly Open, High, Low, Close, Time
= getprice('M', 0+index) // Get Current Mounth Open, High, Low, Close, Time
= getprice('3M', 0+index) // Get Current Quarter Open, High, Low, Close, Time
= getprice('12M', 0+index) // Get Current Year Open, High, Low, Close, Time
= getprice('D', 1+index) // Get Previous Day Open, High, Low, Close, Time
= getprice('W', 1+index) // Get Previous Weekly Open, High, Low, Close, Time
= getprice('M', 1+index) // Get Previous Mounth Open, High, Low, Close, Time
= getprice('3M', 1+index) // Get Previous Quarter Open, High, Low, Close, Time
= getprice('12M', 1+index) // Get Previous Year Open, High, Low, Close, Time
extend(bars) => // Extends the current time by the product of the time difference between elements and the number of bars.
timenow + (time - time ) * bars
getlevel(time, level, txtcolor, linecolor, txtlabel)=> // Get draws a line and a label on the chart
if barstate.islast // The following code doesn't need to be processed on every candle
xindex = displaystyle == 'Standard' ? time : bar_index+bar_offset
xloc = displaystyle == 'Standard' ? xloc.bar_time : xloc.bar_index
xid = displaystyle == 'Standard' ? extend(bar_offset) : bar_index+bar_offset+1
lblpos = labelpos == 'Middle' ? label.style_label_center : label.style_none
lines = line.new (x1=xindex, x2=xid, y1=level, y2=level, xloc=xloc, style=linestyles, extend=displaystyles, color=linecolor)
labels = label.new(x=xid, y=level, text=txtlabel, style=lblpos, xloc=xloc, text_font_family=fontstyles, textcolor=txtcolor, color = #ffffff00)
line.delete(lines ) // remove the previous line when new bar appears
label.delete(labels ) // remove the previous label when new bar appears
// Get Inputs, Lines, Labels
i_cDO = input(false, 'DO ', group = group, inline='D'), = getlevel(cDtime, i_cDO ? cDopen : na, i_tG ? color_tG : color_cD, i_lG ? color_lG : color_cD, 'DO' )
i_cDH = input(false, 'DH ', group = group, inline='D'), = getlevel(cDtime, i_cDH ? cDhigh : na, i_tG ? color_tG : color_cD, i_lG ? color_lG : color_cD, 'DH' )
i_cDL = input(false, 'DL ', group = group, inline='D'), = getlevel(cDtime, i_cDL ? cDlow : na, i_tG ? color_tG : color_cD, i_lG ? color_lG : color_cD, 'DL' )
i_pDO = input(false, 'pDO', group = group, inline='D'), = getlevel(pDtime, i_pDO ? pDopen : na, i_tG ? color_tG : color_pD, i_lG ? color_lG : color_pD, 'pDO' )
i_pDH = input(true, 'pDH', group = group, inline='D'), = getlevel(pDtime, i_pDH ? pDhigh : na, i_tG ? color_tG : color_pD, i_lG ? color_lG : color_pD, 'pDH' )
i_pDL = input(true, 'pDL', group = group, inline='D'), = getlevel(pDtime, i_pDL ? pDlow : na, i_tG ? color_tG : color_pD, i_lG ? color_lG : color_pD, 'pDL' )
i_cWO = input(false, 'WO ', group = group, inline='W'), = getlevel(cWtime, i_cWO ? cWopen : na, i_tG ? color_tG : color_cW, i_lG ? color_lG : color_cW, 'WO' )
i_cWH = input(false, 'WH ', group = group, inline='W'), = getlevel(cWtime, i_cWH ? cWhigh : na, i_tG ? color_tG : color_cW, i_lG ? color_lG : color_cW, 'WH' )
i_cWL = input(false, 'WL ', group = group, inline='W'), = getlevel(cWtime, i_cWL ? cWlow : na, i_tG ? color_tG : color_cW, i_lG ? color_lG : color_cW, 'WL' )
i_pWO = input(false, 'pWO', group = group, inline='W'), = getlevel(pWtime, i_pWO ? pWopen : na, i_tG ? color_tG : color_pW, i_lG ? color_lG : color_pW, 'pWO' )
i_pWH = input(false, 'pWH', group = group, inline='W'), = getlevel(pWtime, i_pWH ? pWhigh : na, i_tG ? color_tG : color_pW, i_lG ? color_lG : color_pW, 'pWH' )
i_pWL = input(false, 'pWL', group = group, inline='W'), = getlevel(pWtime, i_pWL ? pWlow : na, i_tG ? color_tG : color_pW, i_lG ? color_lG : color_pW, 'pWL' )
i_cMO = input(false, 'MO ', group = group, inline='M'), = getlevel(cMtime, i_cMO ? cMopen : na, i_tG ? color_tG : color_cM, i_lG ? color_lG : color_cM, 'MO' )
i_cMH = input(false, 'MH ', group = group, inline='M'), = getlevel(cMtime, i_cMH ? cMhigh : na, i_tG ? color_tG : color_cM, i_lG ? color_lG : color_cM, 'MH' )
i_cML = input(false, 'ML ', group = group, inline='M'), = getlevel(cMtime, i_cML ? cMlow : na, i_tG ? color_tG : color_cM, i_lG ? color_lG : color_cM, 'ML' )
i_pMO = input(false, 'pMO', group = group, inline='M'), = getlevel(pMtime, i_pMO ? pMopen : na, i_tG ? color_tG : color_pM, i_lG ? color_lG : color_pM, 'pMO' )
i_pMH = input(false, 'pMH', group = group, inline='M'), = getlevel(pMtime, i_pMH ? pMhigh : na, i_tG ? color_tG : color_pM, i_lG ? color_lG : color_pM, 'pMH' )
i_pML = input(false, 'pML', group = group, inline='M'), = getlevel(pMtime, i_pML ? pMlow : na, i_tG ? color_tG : color_pM, i_lG ? color_lG : color_pM, 'pML' )
i_cQO = input(false, 'QO ', group = group, inline='Q'), = getlevel(cQtime, i_cQO ? cQopen : na, i_tG ? color_tG : color_cQ, i_lG ? color_lG : color_cQ, 'QO' )
i_cQH = input(false, 'QH ', group = group, inline='Q'), = getlevel(cQtime, i_cQH ? cQhigh : na, i_tG ? color_tG : color_cQ, i_lG ? color_lG : color_cQ, 'QH' )
i_cQL = input(false, 'QL ', group = group, inline='Q'), = getlevel(cQtime, i_cQL ? cQlow : na, i_tG ? color_tG : color_cQ, i_lG ? color_lG : color_cQ, 'QL' )
i_pQO = input(false, 'pQO', group = group, inline='Q'), = getlevel(pQtime, i_pQO ? pQopen : na, i_tG ? color_tG : color_pQ, i_lG ? color_lG : color_pQ, 'pQO' )
i_pQH = input(false, 'pQH', group = group, inline='Q'), = getlevel(pQtime, i_pQH ? pQhigh : na, i_tG ? color_tG : color_pQ, i_lG ? color_lG : color_pQ, 'pQH' )
i_pQL = input(false, 'pQL', group = group, inline='Q'), = getlevel(pQtime, i_pQL ? pQlow : na, i_tG ? color_tG : color_pQ, i_lG ? color_lG : color_pQ, 'pQL' )
i_cYO = input(false, 'YO ', group = group, inline='Y'), = getlevel(cYtime, i_cYO ? cYopen : na, i_tG ? color_tG : color_cY, i_lG ? color_lG : color_cY, 'YO' )
i_cYH = input(false, 'YH ', group = group, inline='Y'), = getlevel(cYtime, i_cYH ? cYhigh : na, i_tG ? color_tG : color_cY, i_lG ? color_lG : color_cY, 'YH' )
i_cYL = input(false, 'YL ', group = group, inline='Y'), = getlevel(cYtime, i_cYL ? cYlow : na, i_tG ? color_tG : color_cY, i_lG ? color_lG : color_cY, 'YL' )
i_pYO = input(false, 'pYO', group = group, inline='Y'), = getlevel(pYtime, i_pYO ? pYopen : na, i_tG ? color_tG : color_pY, i_lG ? color_lG : color_pY, 'pYO' )
i_pYH = input(false, 'pYH', group = group, inline='Y'), = getlevel(pYtime, i_pYH ? pYhigh : na, i_tG ? color_tG : color_pY, i_lG ? color_lG : color_pY, 'pYH' )
i_pYL = input(false, 'pYL', group = group, inline='Y'), = getlevel(pYtime, i_pYL ? pYlow : na, i_tG ? color_tG : color_pY, i_lG ? color_lG : color_pY, 'pYL' )
// Сollecting labels into an array for normalization
labels = array.from(cDOlabel,cDHlabel,cDLlabel,pDOlabel,pDHlabel,pDLlabel,cWOlabel,cWHlabel,cWLlabel,pWOlabel,pWHlabel,pWLlabel,cMOlabel,cMHlabel,cMLlabel,pMOlabel,pMHlabel,pMLlabel,cQOlabel,cQHlabel,cQLlabel,pQOlabel,pQHlabel,pQLlabel,cYOlabel,cYHlabel,cYLlabel,pYOlabel,pYHlabel,pYLlabel)
// This loop merge items in arrays "labels" into a single label if their difference is less than a certain threshold, and updates the label text.
for i = 0 to array.size(labels) - 2 // Loop through all the labels
txt = label.get_text(array.get(labels, i)) // Get the text of the current label
price_i = label.get_y(array.get(labels, i)) // Get the y coordinate of the current label
label_i = array.get(labels, i) // Store the current label
for j = i + 1 to array.size(labels) - 1 // Loop through the remaining labels
price_j = label.get_y(array.get(labels, j)) // Get the y coordinate of the current label
if math.abs(price_i - price_j) < (threshold/100) * price_i // Compare the prices
txt := txt + ' / ' + label.get_text(array.get(labels, j)) // Add the text of the second label
label.delete(array.get(labels, j)) // Delete the second label
label.set_text(label_i, txt) // Set the text of the current label
repeat(str, num) => // Returns a string that is created by repeating the input str num times
res = ""
len = str.length(str)
if num > 0 and len * num <= 4096
for r = 1 to num
res := res + str
res
// Loop to change the position of the Label
if labelpos == 'Middle'
for z = 0 to array.size(labels) - 1
label_z = array.get(labels, z) // Get the label at position z
texts = label.get_text(label_z) // Get the text of the label
spaces = fontstyle=='Default' ? repeat(' ', math.ceil(str.length(texts))*2) : repeat(' ', math.ceil(str.length(texts))) // Calculate the number of spaces needed
label.set_text(label_z, displaystyle=='Right'? texts + spaces + ' ' : spaces+' ' + texts) // Set the label text with the calculated spaces
//
//@version=5
//indicator("Congestion Zone", overlay=true)
Congestion_Zone = "Congestio_Zone"
Show_CZ = input.bool(true, title="On/off Congestion Zone", group="Congestion_Zone")
minbar = input(title="Minimum Bars in Zone", defval=5, group="Congestion_Zone", inline="Box",tooltip = "Số lượng nến tối thiểu để có 1 vùng CZ")
border_width = input.int(title="CZ boder width", defval=1, inline="Box1", group="Congestion_Zone", step=1,tooltip = "Viền CZ")
max_boxes = input.int(title="Max CZ", defval=50, group="Congestion_Zone", minval=1,tooltip = "Số vùng box tối đa muốn hiển thị để tránh rối mắt")
boxcolor_basic = input.color(title="CZ Color Basic", defval=color.new(color.orange, 80), group="Congestion_Zone",tooltip = "Nến thoát khỏi box không có xu hướng rõ ràng")
boxcolor_up = input.color(title="CZ Color Up", defval=color.new(color.green, 80), group="Congestion_Zone",tooltip = "Nến thoát khỏi box có giá đóng cửa > vùng CZ")
boxcolor_down = input.color(title="CZ Color Dowwn", defval=color.new(color.red, 80), group="Congestion_Zone",tooltip = "Nến thoát khỏi box có đóng cửa < vùng CZ")
var boxopen = array.new_float()
var boxclose = array.new_float()
var boxes = array.new_box()
congestion_condition = close >= low and close <= high and open >= low and open <= high
if congestion_condition and Show_CZ
array.push(boxopen, open > close ? open : close)
array.push(boxclose, open > close ? close : open)
else if array.size(boxopen) < minbar
array.clear(boxopen)
array.clear(boxclose)
if not congestion_condition and array.size(boxopen) >= minbar and Show_CZ
box_max = array.max(boxopen)
box_min = array.min(boxclose)
box_color = close >= box_max ? boxcolor_up : close <= box_min ? boxcolor_down : boxcolor_basic
if box_color == boxcolor_basic
alert("CZ basic")
else if box_color == boxcolor_up
alert("CZ UP")
else if box_color == boxcolor_down
alert("CZ DOWN")
// Determine box color based on last candle
new_box = box.new(bar_index - array.size(boxopen), box_max, bar_index - 1, box_min, bgcolor=box_color, border_width=border_width,border_color = box_color)
array.push(boxes, new_box)
array.clear(boxopen)
array.clear(boxclose)
//Remove old boxes if limit is reached
while array.size(boxes) > max_boxes
box.delete(array.shift(boxes))
Шорт или ЛонгЕсли до конца не уверены лонговать или шортить индикатор подскажет. (не финансовый совет)
Jc Position Size CalculatorPosition Size Calculator
設定說明:
1:需要自行輸入該商品一個整數點值多少美元(圖中範例為MNQ 一個整數點$2)
2:手數變化跳動單位(期貨手數沒有小數點所以設為1,算法為除後無條件捨去)
3.1:文字是否顯示固定風險模式
3.2:固定風險值設定
4.1:文字是否顯示固定手數模式
4.2:固定手數值設定
30 EMA Breakout Strategy with Stop Loss and Target30 EMA Breakout Strategy with Stop Loss and Target this Strategy Give you 1:3 Reward on you risk and Hit Ratio of this Strategy is 71 %
CI, RSI & EMA StrategyTo be used with simple lines and triangles to confirm enter and exit strategy. Currently testing this script for when market is more choppy due to low volume eg. during weekends. Choppiness Index can give you an overall view on whether the market is hard or easy to trade. Script is originally written by LLM.
Combined ADX, RSI, and Stochastic Indicator
이 지표는 ADX (Average Directional Index), RSI (Relative Strength Index), 및 Stochastic Oscillator를 결합한 기술적 분석 도구입니다. 각 구성 요소는 시장 추세와 모멘텀을 분석하기 위해 사용됩니다.
ADX는 영역으로 표시하고 -DI만 표시해서 하락에 대한 추세와 힘을 표시했고 거기에 RSI가 40~50사이를 기어다닐때 스토캐스틱 선이 끝에 있으면 무조건 반전된다는 것을 보면서 추세를 보려고 만든 것
MTF EMA Cloud // Multi Time Frame Expodential Moving AveragesTo work properly, You should select the option from the dropdown menu >>> PIN TO SCALE > PIN TO RIGHT SCALE.
You can adjust the length of the EMAs and the timeframe to fit Your strategy.
Good Luck, Friends !
Trend Followermix of trader_xo and btc_charlie EMAs.
charlie_slowEMA_period = 50
charlie_fastEMA_period = 10
xo_slowEMA_period = 21
xo_fastEMA_period = 12
uses above EMAs to publish the trend. feel free to copy and update
13 EMA Cross - Next Day High/Low//@version=6
indicator("13 EMA Cross - Next Day High/Low", overlay=true)
// Inputs for EMAs
length1 = input.int(13, title="Short EMA (13 EMA)")
length2 = input.int(34, title="Long EMA (34 EMA)")
// Input for support line properties
supportColor = input.color(#A52A2A, title="Support Line Color") // Brown color
lineWidth = input.int(2, title="Line Width")
// Calculate EMAs
ema13 = ta.ema(close, length1)
ema34 = ta.ema(close, length2)
// Detect Crosses
crossAbove = ta.crossover(ema13, ema34)
crossBelow = ta.crossunder(ema13, ema34)
// Track when a crossover happens
var float nextDayHigh = na
var float nextDayLow = na
var int crossoverBarIndex = na
if crossAbove or crossBelow
crossoverBarIndex := bar_index
nextDayHigh := na
nextDayLow := na
// Capture next day candle's high and low after crossover
if bar_index == crossoverBarIndex + 1
nextDayHigh := high
nextDayLow := low
// Draw horizontal lines at the next day's high and low
if not na(nextDayHigh) and not na(nextDayLow)
line.new(x1=crossoverBarIndex + 1, y1=nextDayHigh, x2=bar_index, y2=nextDayHigh, color=supportColor, width=lineWidth)
line.new(x1=crossoverBarIndex + 1, y1=nextDayLow, x2=bar_index, y2=nextDayLow, color=supportColor, width=lineWidth)
three Supertrend EMA Strategy by Prasanna +DhanuThe indicator described in your Pine Script is a Supertrend EMA Strategy that combines the Supertrend and EMA (Exponential Moving Average) to create a trend-following strategy. Here’s a detailed breakdown of how this indicator works:
1. EMA (Exponential Moving Average):
The EMA is a moving average that places more weight on recent prices, making it more responsive to price changes compared to a simple moving average (SMA). In this strategy, the EMA is used to determine the overall trend direction.
Input Parameter:
ema_length: This is the period for the EMA, set to 50 periods by default. A shorter EMA will respond more quickly to price movements, while a longer EMA is smoother and less sensitive to short-term fluctuations.
How it's used:
If the price is above the EMA, it indicates an uptrend.
If the price is below the EMA, it indicates a downtrend.
2. Supertrend Indicator:
The Supertrend indicator is a trend-following tool based on the Average True Range (ATR), which is a volatility measure. It helps to identify the direction of the trend by setting a dynamic support or resistance level.
Input Parameters:
supertrend_atr_period: The period used for calculating the ATR, set to 10 periods by default.
supertrend_multiplier1: Multiplier for the first Supertrend, set to 3.0.
supertrend_multiplier2: Multiplier for the second Supertrend, set to 2.0.
supertrend_multiplier3: Multiplier for the third Supertrend, set to 1.0.
Each Supertrend line has a different multiplier, which affects its sensitivity to price changes. The ATR period defines how many periods of price data are used to calculate the ATR.
How the Supertrend works:
If the Supertrend value is below the price, the trend is considered bullish (uptrend).
If the Supertrend value is above the price, the trend is considered bearish (downtrend).
The Supertrend will switch between up and down based on price movement and ATR, providing a dynamic trend-following signal.
3. Three Supertrend Lines:
In this strategy, three Supertrend lines are calculated with different multipliers and the same ATR period (10 periods). Each line is more or less sensitive to price changes, and they are plotted on the chart in different colors based on whether the trend is bullish (green) or bearish (red).
Supertrend 1: The most sensitive Supertrend with a multiplier of 3.0.
Supertrend 2: A moderately sensitive Supertrend with a multiplier of 2.0.
Supertrend 3: The least sensitive Supertrend with a multiplier of 1.0.
Each Supertrend line signals a bullish trend when its value is below the price and a bearish trend when its value is above the price.
4. Strategy Rules:
This strategy uses the three Supertrend lines combined with the EMA to generate trade signals.
Entry Conditions:
A long entry is triggered when all three Supertrend lines are in an uptrend (i.e., all three Supertrend lines are below the price), and the price is above the EMA. This suggests a strong bullish market condition.
A short entry is triggered when all three Supertrend lines are in a downtrend (i.e., all three Supertrend lines are above the price), and the price is below the EMA. This suggests a strong bearish market condition.
Exit Conditions:
A long exit occurs when the third Supertrend (the least sensitive one) switches to a downtrend (i.e., the price falls below it).
A short exit occurs when the third Supertrend switches to an uptrend (i.e., the price rises above it).
5. Visualization:
The strategy also plots the following on the chart:
The EMA is plotted as a blue line, which helps identify the overall trend.
The three Supertrend lines are plotted with different colors:
Supertrend 1: Green (for uptrend) and Red (for downtrend).
Supertrend 2: Green (for uptrend) and Red (for downtrend).
Supertrend 3: Green (for uptrend) and Red (for downtrend).
Summary of the Strategy:
The strategy combines three Supertrend indicators (with different multipliers) and an EMA to capture both short-term and long-term trends.
Long positions are entered when all three Supertrend lines are bullish and the price is above the EMA.
Short positions are entered when all three Supertrend lines are bearish and the price is below the EMA.
Exits occur when the third Supertrend line (the least sensitive) signals a change in trend direction.
This combination of indicators allows for a robust trend-following strategy that adapts to both short-term volatility and long-term trend direction. The Supertrend lines provide quick reaction to price changes, while the EMA offers a smoother, more stable trend direction for confirmation.
The indicator described in your Pine Script is a Supertrend EMA Strategy that combines the Supertrend and EMA (Exponential Moving Average) to create a trend-following strategy. Here’s a detailed breakdown of how this indicator works:
1. EMA (Exponential Moving Average):
The EMA is a moving average that places more weight on recent prices, making it more responsive to price changes compared to a simple moving average (SMA). In this strategy, the EMA is used to determine the overall trend direction.
Input Parameter:
ema_length: This is the period for the EMA, set to 50 periods by default. A shorter EMA will respond more quickly to price movements, while a longer EMA is smoother and less sensitive to short-term fluctuations.
How it's used:
If the price is above the EMA, it indicates an uptrend.
If the price is below the EMA, it indicates a downtrend.
2. Supertrend Indicator:
The Supertrend indicator is a trend-following tool based on the Average True Range (ATR), which is a volatility measure. It helps to identify the direction of the trend by setting a dynamic support or resistance level.
Input Parameters:
supertrend_atr_period: The period used for calculating the ATR, set to 10 periods by default.
supertrend_multiplier1: Multiplier for the first Supertrend, set to 3.0.
supertrend_multiplier2: Multiplier for the second Supertrend, set to 2.0.
supertrend_multiplier3: Multiplier for the third Supertrend, set to 1.0.
Each Supertrend line has a different multiplier, which affects its sensitivity to price changes. The ATR period defines how many periods of price data are used to calculate the ATR.
How the Supertrend works:
If the Supertrend value is below the price, the trend is considered bullish (uptrend).
If the Supertrend value is above the price, the trend is considered bearish (downtrend).
The Supertrend will switch between up and down based on price movement and ATR, providing a dynamic trend-following signal.
3. Three Supertrend Lines:
In this strategy, three Supertrend lines are calculated with different multipliers and the same ATR period (10 periods). Each line is more or less sensitive to price changes, and they are plotted on the chart in different colors based on whether the trend is bullish (green) or bearish (red).
Supertrend 1: The most sensitive Supertrend with a multiplier of 3.0.
Supertrend 2: A moderately sensitive Supertrend with a multiplier of 2.0.
Supertrend 3: The least sensitive Supertrend with a multiplier of 1.0.
Each Supertrend line signals a bullish trend when its value is below the price and a bearish trend when its value is above the price.
4. Strategy Rules:
This strategy uses the three Supertrend lines combined with the EMA to generate trade signals.
Entry Conditions:
A long entry is triggered when all three Supertrend lines are in an uptrend (i.e., all three Supertrend lines are below the price), and the price is above the EMA. This suggests a strong bullish market condition.
A short entry is triggered when all three Supertrend lines are in a downtrend (i.e., all three Supertrend lines are above the price), and the price is below the EMA. This suggests a strong bearish market condition.
Exit Conditions:
A long exit occurs when the third Supertrend (the least sensitive one) switches to a downtrend (i.e., the price falls below it).
A short exit occurs when the third Supertrend switches to an uptrend (i.e., the price rises above it).
5. Visualization:
The strategy also plots the following on the chart:
The EMA is plotted as a blue line, which helps identify the overall trend.
The three Supertrend lines are plotted with different colors:
Supertrend 1: Green (for uptrend) and Red (for downtrend).
Supertrend 2: Green (for uptrend) and Red (for downtrend).
Supertrend 3: Green (for uptrend) and Red (for downtrend).
Summary of the Strategy:
The strategy combines three Supertrend indicators (with different multipliers) and an EMA to capture both short-term and long-term trends.
Long positions are entered when all three Supertrend lines are bullish and the price is above the EMA.
Short positions are entered when all three Supertrend lines are bearish and the price is below the EMA.
Exits occur when the third Supertrend line (the least sensitive) signals a change in trend direction.
This combination of indicators allows for a robust trend-following strategy that adapts to both short-term volatility and long-term trend direction. The Supertrend lines provide quick reaction to price changes, while the EMA offers a smoother, more stable trend direction for confirmation.
The indicator described in your Pine Script is a Supertrend EMA Strategy that combines the Supertrend and EMA (Exponential Moving Average) to create a trend-following strategy. Here’s a detailed breakdown of how this indicator works:
1. EMA (Exponential Moving Average):
The EMA is a moving average that places more weight on recent prices, making it more responsive to price changes compared to a simple moving average (SMA). In this strategy, the EMA is used to determine the overall trend direction.
Input Parameter:
ema_length: This is the period for the EMA, set to 50 periods by default. A shorter EMA will respond more quickly to price movements, while a longer EMA is smoother and less sensitive to short-term fluctuations.
How it's used:
If the price is above the EMA, it indicates an uptrend.
If the price is below the EMA, it indicates a downtrend.
2. Supertrend Indicator:
The Supertrend indicator is a trend-following tool based on the Average True Range (ATR), which is a volatility measure. It helps to identify the direction of the trend by setting a dynamic support or resistance level.
Input Parameters:
supertrend_atr_period: The period used for calculating the ATR, set to 10 periods by default.
supertrend_multiplier1: Multiplier for the first Supertrend, set to 3.0.
supertrend_multiplier2: Multiplier for the second Supertrend, set to 2.0.
supertrend_multiplier3: Multiplier for the third Supertrend, set to 1.0.
Each Supertrend line has a different multiplier, which affects its sensitivity to price changes. The ATR period defines how many periods of price data are used to calculate the ATR.
How the Supertrend works:
If the Supertrend value is below the price, the trend is considered bullish (uptrend).
If the Supertrend value is above the price, the trend is considered bearish (downtrend).
The Supertrend will switch between up and down based on price movement and ATR, providing a dynamic trend-following signal.
3. Three Supertrend Lines:
In this strategy, three Supertrend lines are calculated with different multipliers and the same ATR period (10 periods). Each line is more or less sensitive to price changes, and they are plotted on the chart in different colors based on whether the trend is bullish (green) or bearish (red).
Supertrend 1: The most sensitive Supertrend with a multiplier of 3.0.
Supertrend 2: A moderately sensitive Supertrend with a multiplier of 2.0.
Supertrend 3: The least sensitive Supertrend with a multiplier of 1.0.
Each Supertrend line signals a bullish trend when its value is below the price and a bearish trend when its value is above the price.
4. Strategy Rules:
This strategy uses the three Supertrend lines combined with the EMA to generate trade signals.
Entry Conditions:
A long entry is triggered when all three Supertrend lines are in an uptrend (i.e., all three Supertrend lines are below the price), and the price is above the EMA. This suggests a strong bullish market condition.
A short entry is triggered when all three Supertrend lines are in a downtrend (i.e., all three Supertrend lines are above the price), and the price is below the EMA. This suggests a strong bearish market condition.
Exit Conditions:
A long exit occurs when the third Supertrend (the least sensitive one) switches to a downtrend (i.e., the price falls below it).
A short exit occurs when the third Supertrend switches to an uptrend (i.e., the price rises above it).
5. Visualization:
The strategy also plots the following on the chart:
The EMA is plotted as a blue line, which helps identify the overall trend.
The three Supertrend lines are plotted with different colors:
Supertrend 1: Green (for uptrend) and Red (for downtrend).
Supertrend 2: Green (for uptrend) and Red (for downtrend).
Supertrend 3: Green (for uptrend) and Red (for downtrend).
Summary of the Strategy:
The strategy combines three Supertrend indicators (with different multipliers) and an EMA to capture both short-term and long-term trends.
Long positions are entered when all three Supertrend lines are bullish and the price is above the EMA.
Short positions are entered when all three Supertrend lines are bearish and the price is below the EMA.
Exits occur when the third Supertrend line (the least sensitive) signals a change in trend direction.
This combination of indicators allows for a robust trend-following strategy that adapts to both short-term volatility and long-term trend direction. The Supertrend lines provide quick reaction to price changes, while the EMA offers a smoother, more stable trend direction for confirmation.
cme big boyKết luận chiến lược:
1. Hỗ trợ:
o Vùng 2620 (OGF5): Tận dụng cơ hội mua khi thị trường kỳ vọng phục hồi ngắn hạn.
2. Kháng cự:
o Vùng 2640 (OGG5): Xem xét bán khống khi có dấu hiệu suy yếu.
o Vùng 2650 (OGF5 & OGG5): Đây là mức giá quan trọng, cần theo dõi sát để thực hiện chiến lược Buy nếu giá vượt kháng cự.
13 EMA Cross - Daily Supportwhen 13 ema cross 34 ema mark next day candle high and low. when high breaks wait for retest when retest happens after breakout go for 1:2 ratio
Multi-EMA Indicatorit is a multi-EMA indicator showing 20, 50, 100, 200 EMAs and can be used for potential market reversal, breakout trading and etc. the lines color can be changed as well
Multi-EMA Indicatorit is a multi-EMA indicator showing 20, 50, 100, 200 EMAs and can be used for potential market reversal, breakout trading and etc. the lines color can be changed as well
20 EMA Indicatorit is a 20 ema indicator where it is shown by a red line (the colour can be changed) and it moves, it is not stable. it can be used to indicate potential market reversal