답변완료
수정 부탁 드립니다.
피보나치 되돌림선 전캔들 까지만 표시 되는데
우측 끝까지 추세선 연장 부탁 드립니다.
Input:length(5);
input : Per1(0),Per2(23.6),Per3(38.2),Per4(50.0),Per5(61.8),Per6(76.4),Per7(100);
Var:j(0),lastHiVal(0),lastLoVal(0),sBar(0),eBar(0),TL1(0),Text1(0),처리구분(""),T(0),mav(0),diff(0);
var: TL2(0),TL3(0),TL4(0),TL5(0),TL6(0),TL7(0),TL8(0);
var: TL12(0),TL13(0),TL14(0),TL15(0),TL16(0),TL17(0),TL18(0);
Array:고점[10,2](0),저점[10,2](0);
처리구분 = "";
If Highest(H,length) == H and lastHiVal <> H and Lowest(L,length) == L and lastLoVal <> L Then
{ If 저점[1,1] > L Then 처리구분 = "저점처리";
If 고점[1,1] < H Then 처리구분 = "고점처리";
}
Else If Highest(H,length) == H and lastHiVal <> H Then 처리구분 = "고점처리";
Else If Lowest(L,length) == L and lastLoVal <> L Then 처리구분 = "저점처리";
If 처리구분 == "고점처리" Then
{
T = 1;
lastHiVal = H;
If 고점[1,2] < 저점[1,2] Then
{
For j = 10 DownTo 2
{
고점[j,1] = 고점[j-1,1];
고점[j,2] = 고점[j-1,2];
}
}
If 고점[1,2] < 저점[1,2] or 고점[1,1] < H Then
{
고점[1,1] = H;
고점[1,2] = Index;
sBar = Index - 저점[1,2];
eBar = 0;
If TL_GetBeginDate(TL1) == sDate[sBar] and TL_GetBeginTime(TL1) == sTime[sBar] Then
{
TL_Delete(TL1);
TL_Delete(TL2);
TL_Delete(TL3);
TL_Delete(TL4);
TL_Delete(TL5);
TL_Delete(TL6);
TL_Delete(TL7);
TL_Delete(TL8);
Text_Delete(Text1);
}
TL1 = TL_New(sDate[sBar],sTime[sBar],저점[1,1],sDate[eBar],sTime[eBar],고점[1,1]);
TL_SetColor(TL1,YELLOW);
#TL_SetSize(TL1,1);
var1 = 고점[2,1];
var2 = 저점[1,1];
var3 = abs(var1-var2);
TL2 = TL_New(sdate[index-고점[1,2]],stime[index-고점[1,2]],var1-var3*(Per1/100),sdate[index-저점[1,2]],stime[index-저점[1,2]],var1-var3*(Per1/100));
TL3 = TL_New(sdate[index-고점[1,2]],stime[index-고점[1,2]],var1-var3*(Per2/100),sdate[index-저점[1,2]],stime[index-저점[1,2]],var1-var3*(Per2/100));
TL4 = TL_New(sdate[index-고점[1,2]],stime[index-고점[1,2]],var1-var3*(Per3/100),sdate[index-저점[1,2]],stime[index-저점[1,2]],var1-var3*(Per3/100));
TL5 = TL_New(sdate[index-고점[1,2]],stime[index-고점[1,2]],var1-var3*(Per4/100),sdate[index-저점[1,2]],stime[index-저점[1,2]],var1-var3*(Per4/100));
TL6 = TL_New(sdate[index-고점[1,2]],stime[index-고점[1,2]],var1-var3*(Per5/100),sdate[index-저점[1,2]],stime[index-저점[1,2]],var1-var3*(Per5/100));
TL7 = TL_New(sdate[index-고점[1,2]],stime[index-고점[1,2]],var1-var3*(Per6/100),sdate[index-저점[1,2]],stime[index-저점[1,2]],var1-var3*(Per6/100));
TL8 = TL_New(sdate[index-고점[1,2]],stime[index-고점[1,2]],var1-var3*(Per7/100),sdate[index-저점[1,2]],stime[index-저점[1,2]],var1-var3*(Per7/100));
TL_SetColor(TL2,BLUE);
TL_SetColor(TL3,BLUE);
TL_SetColor(TL4,BLUE);
TL_SetColor(TL5,BLUE);
TL_SetColor(TL6,BLUE);
TL_SetColor(TL7,BLUE);
TL_SetColor(TL8,BLUE);
Text1 = Text_New(sDate[eBar],sTime[eBar],고점[1,1]+PriceScale*3,NumToStr((고점[1,1]*10)%1000,0)+" +"+NumToStr(abs(고점[1,1]-저점[1,1])/PriceScale,0));
Text_SetStyle(Text1, 2, 1);
Text_SetColor(Text1,RED);
If 고점[3,1] < 고점[2,1] and 고점[2,1] > 고점[1,1] and 저점[2,1] < 저점[1,1] Then
{
sBar = Index - 저점[2,2];
eBar = Index - 저점[1,2];
}
}
}
If 처리구분 == "저점처리" Then
{
T = -1;
lastLoVal = L;
If 저점[1,2] < 고점[1,2] Then
{
For j = 10 DownTo 2
{
저점[j,1] = 저점[j-1,1];
저점[j,2] = 저점[j-1,2];
}
}
If 저점[1,2] < 고점[1,2] or 저점[1,1] > L Then
{
저점[1,1] = L;
저점[1,2] = Index;
sBar = Index - 고점[1,2];
eBar = 0;
If TL_GetBeginDate(TL1) == sDate[sBar] and TL_GetBeginTime(TL1) == sTime[sBar] Then
{
TL_Delete(TL1);
TL_Delete(TL2);
TL_Delete(TL3);
TL_Delete(TL4);
TL_Delete(TL5);
TL_Delete(TL6);
TL_Delete(TL7);
TL_Delete(TL8);
Text_Delete(Text1);
}
TL1 = TL_New(sDate[sBar],sTime[sBar],고점[1,1],sDate[eBar],sTime[eBar],저점[1,1]);
#TL_SetSize(TL1,1);
TL_SetColor(TL1,YELLOW);
var1 = 고점[1,1];
var2 = 저점[2,1];
var3 = abs(var1-var2);
TL2 = TL_New(sdate[index-저점[1,2]],stime[index-저점[1,2]],var1-var3*(Per1/100),sdate[index-고점[1,2]],stime[index-고점[1,2]],var1-var3*(Per1/100));
TL3 = TL_New(sdate[index-저점[1,2]],stime[index-저점[1,2]],var1-var3*(Per2/100),sdate[index-고점[1,2]],stime[index-고점[1,2]],var1-var3*(Per2/100));
TL4 = TL_New(sdate[index-저점[1,2]],stime[index-저점[1,2]],var1-var3*(Per3/100),sdate[index-고점[1,2]],stime[index-고점[1,2]],var1-var3*(Per3/100));
TL5 = TL_New(sdate[index-저점[1,2]],stime[index-저점[1,2]],var1-var3*(Per4/100),sdate[index-고점[1,2]],stime[index-고점[1,2]],var1-var3*(Per4/100));
TL6 = TL_New(sdate[index-저점[1,2]],stime[index-저점[1,2]],var1-var3*(Per5/100),sdate[index-고점[1,2]],stime[index-고점[1,2]],var1-var3*(Per5/100));
TL7 = TL_New(sdate[index-저점[1,2]],stime[index-저점[1,2]],var1-var3*(Per6/100),sdate[index-고점[1,2]],stime[index-고점[1,2]],var1-var3*(Per6/100));
TL8 = TL_New(sdate[index-저점[1,2]],stime[index-저점[1,2]],var1-var3*(Per7/100),sdate[index-고점[1,2]],stime[index-고점[1,2]],var1-var3*(Per7/100));
TL_SetColor(TL2,red);
TL_SetColor(TL3,red);
TL_SetColor(TL4,red);
TL_SetColor(TL5,red);
TL_SetColor(TL6,red);
TL_SetColor(TL7,red);
TL_SetColor(TL8,red);
Text1 = Text_New(sDate[eBar],sTime[eBar],저점[1,1]-PriceScale*3,NumToStr((저점[1,1]*10)%1000,0)+" -"+NumToStr(abs(저점[1,1]-고점[1,1])/PriceScale,0));
Text_SetStyle(Text1, 2, 0);
Text_SetColor(Text1,BLUE);
If 저점[2,1] < 저점[1,1] and 저점[2,1] < 저점[3,1] and 고점[2,1] > 고점[1,1] Then
{
sBar = Index - 고점[2,2];
eBar = Index - 고점[1,2];
}
}
}
mav = ma(C,20);
if T == 1 Then{
TL_Delete(TL12);
TL_Delete(TL13);
TL_Delete(TL14);
TL_Delete(TL15);
TL_Delete(TL16);
TL_Delete(TL17);
TL_Delete(TL18);
var11 = 고점[1,1];
var12 = 저점[1,1];
var13 = abs(var11-var12);
TL12 = TL_New(sdate[index-고점[1,2]],stime[index-고점[1,2]],var11-var13*(Per1/100),sdate,stime,var11-var13*(Per1/100));
TL13 = TL_New(sdate[index-고점[1,2]],stime[index-고점[1,2]],var11-var13*(Per2/100),sdate,stime,var11-var13*(Per2/100));
TL14 = TL_New(sdate[index-고점[1,2]],stime[index-고점[1,2]],var11-var13*(Per3/100),sdate,stime,var11-var13*(Per3/100));
TL15 = TL_New(sdate[index-고점[1,2]],stime[index-고점[1,2]],var11-var13*(Per4/100),sdate,stime,var11-var13*(Per4/100));
TL16 = TL_New(sdate[index-고점[1,2]],stime[index-고점[1,2]],var11-var13*(Per5/100),sdate,stime,var11-var13*(Per5/100));
TL17 = TL_New(sdate[index-고점[1,2]],stime[index-고점[1,2]],var11-var13*(Per6/100),sdate,stime,var11-var13*(Per6/100));
TL18 = TL_New(sdate[index-고점[1,2]],stime[index-고점[1,2]],var11-var13*(Per7/100),sdate,stime,var11-var13*(Per7/100));
TL_SetColor(TL12,red);
TL_SetColor(TL13,red);
TL_SetColor(TL14,red);
TL_SetColor(TL15,red);
TL_SetColor(TL16,red);
TL_SetColor(TL17,red);
TL_SetColor(TL18,red);
}
if T == -1 Then{
TL_Delete(TL12);
TL_Delete(TL13);
TL_Delete(TL14);
TL_Delete(TL15);
TL_Delete(TL16);
TL_Delete(TL17);
TL_Delete(TL18);
var11 = 고점[1,1];
var12 = 저점[1,1];
var13 = abs(var11-var12);
TL12 = TL_New(sdate[index-저점[1,2]],stime[index-저점[1,2]],var11-var13*(Per1/100),sdate,stime,var11-var13*(Per1/100));
TL13 = TL_New(sdate[index-저점[1,2]],stime[index-저점[1,2]],var11-var13*(Per2/100),sdate,stime,var11-var13*(Per2/100));
TL14 = TL_New(sdate[index-저점[1,2]],stime[index-저점[1,2]],var11-var13*(Per3/100),sdate,stime,var11-var13*(Per3/100));
TL15 = TL_New(sdate[index-저점[1,2]],stime[index-저점[1,2]],var11-var13*(Per4/100),sdate,stime,var11-var13*(Per4/100));
TL16 = TL_New(sdate[index-저점[1,2]],stime[index-저점[1,2]],var11-var13*(Per5/100),sdate,stime,var11-var13*(Per5/100));
TL17 = TL_New(sdate[index-저점[1,2]],stime[index-저점[1,2]],var11-var13*(Per6/100),sdate,stime,var11-var13*(Per6/100));
TL18 = TL_New(sdate[index-저점[1,2]],stime[index-저점[1,2]],var11-var13*(Per7/100),sdate,stime,var11-var13*(Per7/100));
TL_SetColor(TL12,red);
TL_SetColor(TL13,red);
TL_SetColor(TL14,red);
TL_SetColor(TL15,red);
TL_SetColor(TL16,red);
TL_SetColor(TL17,red);
TL_SetColor(TL18,red);
}
2021-04-27
794
글번호 148431
지표
답변완료
수식변경 부탁드립니다.
아래 트레이딩뷰 지표(SuperTrend MTF Headtmap) 수식변경 부탁드립니다.
1. 지표와 전략 두개로 작성 부탁드립니다. 함수로 작성하여 분리해주셔도 감사하겠습니다.
총 4개 주기를 각각 지정가능했으면 좋겠고, 긴 주기 2개가 상승추세일때 아래주기 두개가 하락>상승추세로 바뀔경우 매수, 반대의 경우 매도입니다.
2. 추세색상(형광, 빨강) 이외에 추세전환전 옅게 색칠되는 부분이 잘 보였으면 좋겠습니다.
//@version=4
study("Supertrend MTF Heatmap", shorttitle="Supertrend MTF Heatmap", overlay=false, precision=6)
Factor=input(3,title="[SUPERTREND] Factor", minval=1,maxval = 100, type=input.float)
Pd=input(7, title="[SUPERTREND] PD", minval=1,maxval = 100)
res1 = input("60", type=input.resolution, title="First Timeframe")
res2 = input("120", type=input.resolution, title="Second Timeframe")
res3 = input("240", type=input.resolution, title="Third Timeframe")
res4 = input("D", type=input.resolution, title="Fourth Timeframe")
res5 = input("W", type=input.resolution, title="Fifth Timeframe")
Supertrend(Factor, Pd) =>
Up=hl2-(Factor*atr(Pd))
Dn=hl2+(Factor*atr(Pd))
TrendUp = 0.0
TrendUp := close[1]>TrendUp[1] ? max(Up,TrendUp[1]) : Up
TrendDown = 0.0
TrendDown := close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
Trend = 0.0
Trend := close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)
Tsl = Trend==1? TrendUp: TrendDown
S_Buy = Trend == 1 ? 1 : 0
S_Sell = Trend != 1 ? 1 : 0
[Trend, Tsl]
[Trend,Tsl] = Supertrend(Factor, Pd)
// Security
ST1_Trend_MTF = security(syminfo.tickerid, res1, Trend[1], lookahead=barmerge.lookahead_on)
ST2_Trend_MTF = security(syminfo.tickerid, res2, Trend[1], lookahead=barmerge.lookahead_on)
ST3_Trend_MTF = security(syminfo.tickerid, res3, Trend[1], lookahead=barmerge.lookahead_on)
ST4_Trend_MTF = security(syminfo.tickerid, res4, Trend[1], lookahead=barmerge.lookahead_on)
ST5_Trend_MTF = security(syminfo.tickerid, res5, Trend[1], lookahead=barmerge.lookahead_on)
h0 = hline(1, color=color.new(color.black, 10), linewidth=2, linestyle=hline.style_solid)
h1 = hline(2, color=color.new(color.black, 10), linewidth=2, linestyle=hline.style_solid)
h2 = hline(3, color=color.new(color.black, 10), linewidth=2, linestyle=hline.style_solid)
h3 = hline(4, color=color.new(color.black, 10), linewidth=2, linestyle=hline.style_solid)
h4 = hline(5, color=color.new(color.black, 10), linewidth=2, linestyle=hline.style_solid)
h5 = hline(6, color=color.new(color.black, 10), linewidth=2, linestyle=hline.style_solid)
get_bars(Trend)=>
since_st_buy = barssince(Trend == 1)
since_st_sell = barssince(Trend == -1)
[since_st_buy, since_st_sell]
[since_st_1_buy, since_st_1_sell] = get_bars(ST1_Trend_MTF)
[since_st_2_buy, since_st_2_sell] = get_bars(ST2_Trend_MTF)
[since_st_3_buy, since_st_3_sell] = get_bars(ST3_Trend_MTF)
[since_st_4_buy, since_st_4_sell] = get_bars(ST4_Trend_MTF)
[since_st_5_buy, since_st_5_sell] = get_bars(ST5_Trend_MTF)
// selec the right heatmsap color
heatmap_color(cond1, cond2) =>
cond1 ? color.new(color.green, 20) : cond2 ? color.new(color.red, 20) : na
lapos_x = timenow + round(change(time)*3)
lapos_y = highest(5)// + (0.15 * highest(20))
// Displays the timeframe labels at the right
f_draw_label(x,y,_text,_textcolor, _size)=>
var label Label = na
label.delete(Label)
Label := label.new(x, y, _text, color=color.new(color.white, 20), textcolor=_textcolor, style=label.style_none, yloc=yloc.price, xloc=xloc.bar_time, size=_size)
// Display the labels in a more readable way
// If timeframe seleced is "Same as symbol" displays the timeframe.period string value
res_to_string(res)=>
str = iff(res == "1", "m1", iff(res == "5", "m5", iff(res == "15", "m15", iff(res == "30", "m30", iff(res == "60", "H1", iff(res == "120", "H2",
iff(res == "240", "H4", iff(res == "480", "H8", iff(res == "D", "Daily", iff(res == "W", "Weekly", iff(res == "360", "H3", timeframe.period)))))))))))
str
// draw the TF labels
f_draw_label(lapos_x, 1, res_to_string(res1), color.black, size.large)
f_draw_label(lapos_x, 2, res_to_string(res2), color.black, size.large)
f_draw_label(lapos_x, 3, res_to_string(res3), color.black, size.large)
f_draw_label(lapos_x, 4, res_to_string(res4), color.black, size.large)
f_draw_label(lapos_x, 5, res_to_string(res5), color.black, size.large)
// Draw the green/red heatmap raws
fill(h0 ,h1, color=heatmap_color(since_st_1_sell>since_st_1_buy, since_st_1_sell<since_st_1_buy))
fill(h1, h2, color=heatmap_color(since_st_2_sell>since_st_2_buy, since_st_2_sell<since_st_2_buy))
fill(h2, h3, color=heatmap_color(since_st_3_sell>since_st_3_buy, since_st_3_sell<since_st_3_buy))
fill(h3, h4, color=heatmap_color(since_st_4_sell>since_st_4_buy, since_st_4_sell<since_st_4_buy))
fill(h4, h5, color=heatmap_color(since_st_5_sell>since_st_5_buy, since_st_5_sell<since_st_5_buy))
2021-04-27
1526
글번호 148427
지표
답변완료
수식변경 부탁드립니다.
아래 TradingView 수식(Adaptive ATR-ADX Trend v2) 변경부탁드립니다.
1. 기존과 똑같이 ATR, ATR Multiplier(ADX Rising), ATR Multiplier(ADX Falling), Interval, ADX, BandPip, ADX Threshold 등 모든 변수들의 변경이 가능했으면 좋겠습니다.
2. Interval 옵션은 반드시 변경가능했으면 좋겠습니다.
3. Default옵션인 ADX Above Threshold uses ATR Falling Multiplier Even if Rising?도 항시 체크상태였으면 좋겠습니다.
4. 지표와 전략 두개로 작성 부탁드립니다. 함수로 작성하여 분리해주셔도 감사하겠습니다.
//@version=3
// Constructs the trailing ATR stop above or below the price, and switches
// directions when the source price breaks the ATR stop. Uses the Average
// Directional Index (ADX) to switch between ATR multipliers. The higher
// multiplier is used when the ADX is rising, and the lower ATR multiplier
// is used with the ADX is falling. This ADX criteria further widens the gap
// between the source price and the trailing ATR stop when the price is trending,
// and lessens the gap between the ATR and the price when then price is not
// trending.
//
// The ATR-ADX stop is effectively a double adapative stop that trails the price,
// by both adapting to the true range of the price, and the average directional
// change. When the stop is below the price (long trade) the value never decreases
// until the price intersects the stop, and it reverses to being above the price
// (short trade). When the stop is above the price it will never increase until
// it is intersected by the price. As the true range and ADX change, the stop
// will move more quickly or more slowly.
// http://www.fxtsp.com/1287-doubly-adaptive-profit-average-true-range-objectives/
study(title = "Adaptive ATR-ADX Trend Multi-Timeframe", shorttitle = "Adaptive ATR Multi", overlay = true)
//Mode
atrLen = input(title = "ATR", type = integer, defval = 14, minval = 1, maxval = 100)
m1 = input(title = "ATR Multiplier - ADX Rising", type = float, defval = 3.5, minval = 1, step = 0.1, maxval = 100)
m2 = input(title = "ATR Multiplier - ADX Falling", type = float, defval = 1.75, minval = 1, step = 0.1, maxval = 100)
dintval = input(title = "Inverval (i.e. 15, 60, 240, D, W)", defval = '60')
useIntval = input(false, title = "Use Chart Interval")
bandHalfWidth = input(1, title = "Band Pip/Tick Size Around Stop", minval = 0)
showBand = input(false, title = "Use Band Around Stop?")
adxLen = input(title = "ADX", type = integer, defval = 14, minval = 1, maxval = 100)
adxThresh = input(title = "ADX Threshold", type = integer, defval = 25, minval = 1)
aboveThresh = input(true, title = "ADX Above Threshold uses ATR Falling Multiplier Even if Rising?")
useHeikin = input(false, title = "Use Heikin-Ashi Bars (Source will be ohlc4)")
src = ohlc4
tk = syminfo.mintick
blockMult = tk < 0.1 and (tk != 0.01 or syminfo.pointvalue < 10 or syminfo.pointvalue * tk <= 1) and (tk != 0.001 or syminfo.pointvalue <= 1) and tk != 0.005 and tk != 0.0001 and tk != 0.0005 and tk != 0.03125 and tk != 0.015625 ? tk == 0.00005 or tk * 100 == 0.00005 ? 2 : 10 : 1
block = tk * blockMult
atrCalc() =>
// DI-Pos, DI-Neg, ADX
hR = change(high)
lR = -change(low)
dmPos = hR > lR ? max(hR, 0) : 0
dmNeg = lR > hR ? max(lR, 0) : 0
sTR = tr
sTR := nz(sTR[1]) - nz(sTR[1]) / adxLen + tr
sDMPos = tr
sDMPos := nz(sDMPos[1]) - nz(sDMPos[1]) / adxLen + dmPos
sDMNeg = tr
sDMNeg := nz(sDMNeg[1]) - nz(sDMNeg[1]) / adxLen + dmNeg
DIP = sDMPos / sTR * 100
DIN = sDMNeg / sTR * 100
DX = abs(DIP - DIN) / (DIP + DIN) * 100
adx = sma(DX, adxLen)
// Heikin-Ashi
xClose = ohlc4
xOpen = open
xOpen := (nz(xOpen[1]) + nz(xClose[1])) / 2
xHigh = max(high, max(xOpen, xClose))
xLow = min(low, min(xOpen, xClose))
// Trailing ATR
v1 = abs(xHigh - xClose[1])
v2 = abs(xLow - xClose[1])
v3 = xHigh - xLow
trueRange = max(v1, max(v2, v3))
atr = useHeikin ? rma(trueRange, atrLen) : atr(atrLen)
m = m1
m := rising(adx, 1) and (adx < adxThresh or not aboveThresh) ? m1 : falling(adx, 1) or (adx > adxThresh and aboveThresh) ? m2 : nz(m[1])
mUp = DIP >= DIN ? m : m2
mDn = DIN >= DIP ? m : m2
src_ = useHeikin ? (xOpen + xHigh + xLow + xClose) / 4 : src
c = useHeikin ? xClose : close
t = useHeikin ? (xHigh + xLow) / 2 : hl2
up = t - mUp * atr
dn = t + mDn * atr
TUp = close
TUp := max(src_[1], max(c[1], close[1])) > TUp[1] ? max(up, TUp[1]) : up
TDown = close
TDown := min(src_[1], min(c[1], close[1])) < TDown[1] ? min(dn, TDown[1]) : dn
trend = 1
trend := min(src_, min(c, close)) > TDown[1] ? 1 : max(src_, max(c, close)) < TUp[1]? -1 : nz(trend[1], 1)
// ceil positive trend to nearest pip/tick, floor negative trend to nearest pip/tick
stop = trend == 1 ? ceil(TUp / block) * block : floor(TDown / block) * block
trendChange = change(trend)
[adx, trend, stop, trendChange]
[adx, _trend, _stop, _trendChange] = atrCalc()
start = security(tickerid, dintval, time, lookahead = true)
newSession = iff(change(start), 1, 0)
sinceNew = barssince(newSession)
// Fixes intervals that are uneven, i.e. 120 on normal 6.5 hour NYSE day
// This will happen if a 2H interval closes at 4:00 EST but opened at 3:30
// EST. This is a new session candle. The 9:30 open the next day will also
// be a new session candle, which shouldn't happen. There should never be
// 2 consecutive candles that are new session candles, unless the indicator
// interval is less than or equal to the chart interval. If there are 3
// consecutive candles where each candle is a new session, then the chart
// interval is <= the declared indicator interval.
isChartIntval = sinceNew == 0 and sinceNew[1] == 0 and sinceNew[2] == 0
trend = useIntval or isChartIntval ? _trend : security(tickerid, dintval, _trend[1], lookahead = true)
stop = useIntval or isChartIntval ? _stop : security(tickerid, dintval, _stop[1], lookahead = true)
trendChange = useIntval or isChartIntval ? _trendChange : security(tickerid, dintval, _trendChange[1], lookahead = true)
// Plot
upC = #00FF00DD
dnC = #FF0000DD
upC2 = #00FF0037
dnC2 = #FF000037
trans = #00000000
lineColor = not(trendChange) or trendChange[1] ? trend > 0 ? upC : dnC : trans
fillColor = not(trendChange) or trendChange[1] ? trend > 0 ? upC2 : dnC2 : trans
// Can't figure out any other way to solve this issue for fixing a problem where
// the indicator interval is greater than the chart interval, and the indicator is
// not divisible by the chart interval without a remainder.
oddIntervalTest = (lineColor[1] == upC and lineColor[0] == dnC) or (lineColor[1] == dnC and lineColor[0] == upC)
stopColor = oddIntervalTest ? trans : lineColor
trendChangeReal = stopColor == trans
shapeColor = trendChangeReal ? trend > 0 ? #00FF00F8 : #FF0000F8 : trans
upperBand = stop + bandHalfWidth * block
lowerBand = stop - bandHalfWidth * block
stopPlot = plot(stop, color = stopColor, title = "ATR-ADX Trend")
upper = plot(showBand ? upperBand : na, color = oddIntervalTest ? trans : lineColor, style = circles)
lower = plot(showBand ? lowerBand : na, color = oddIntervalTest ? trans : lineColor, style = circles)
fill(upper, stopPlot, title = "ATR Band Fill - Upper", color = fillColor)
fill(lower, stopPlot, title = "ATR Band Fill - Lower", color = fillColor)
plotshape(trendChangeReal ? stop : na, style = shape.circle, size = size.tiny, location = location.absolute, color = shapeColor, title = "Trend Change")
// alerts
alertcondition(trendChangeReal and trend > 0, "Adaptive ATR-ADX Trend Change Up", "Adaptive ATR-ADX Trend Change Up")
alertcondition(trendChangeReal and trend < 0, "Adaptive ATR-ADX Trend Change Down", "Adaptive ATR-ADX Trend Change Down")
alertcondition(not trendChangeReal and ((crossunder(low, stop) and trend > 0) or (crossover(high, stop) and trend < 0)), "Adaptive ATR-ADX Trend Retest", "Adaptive ATR-ADX Trend Retest")
// end
2021-04-27
1698
글번호 148424
지표