답변완료
전환추세 동시
Input : 전환(0.8);
Var:j(0),jj(0),HH(0),LL(0),hiBar(0),loBar(0),최종꼭지점(""),처리구분("");
Array:고[10,4](0),저[10,4](0);
var :box(0), TL(0), TL1(0),T(0),Tx(0),Tx2(0);
Plot1(c);
HH = H;
LL = L;
If Index == 0 Then
{
고[1,1] = HH;
고[1,2] = 0;
고[1,3] = sDate;
고[1,4] = sTime;
저[1,1] = LL;
저[1,2] = 0;
저[1,3] = sDate;
저[1,4] = sTime;
}
If Index > 0 Then
{
hiBar = hiBar + 1;
loBar = loBar + 1;
}
If HH[hiBar] < HH Then hiBar = 0;
If LL[loBar] > LL Then loBar = 0;
Condition1 = 저[1,1]+전환 <= HH and hiBar == 0;
Condition2 = 고[1,1]-전환 >= LL and loBar == 0;
처리구분 = "";
If Condition1 and Condition2 Then
{
If 최종꼭지점 == "저점" Then
{
If 저[1,1] > LL Then 처리구분 = "저점처리";
Else 처리구분 = "고점처리";
}
Else If 최종꼭지점 == "고점" Then
{
If 고[1,1] < HH Then 처리구분 = "고점처리";
Else 처리구분 = "저점처리";
}
}
Else If Condition1 Then 처리구분 = "고점처리";
Else If Condition2 Then 처리구분 = "저점처리";
If 처리구분 == "고점처리" Then
{
t = 1;
If 최종꼭지점 == "저점" Then
{
For j = 10 DownTo 2
{
For jj = 1 To 4
{
고[j,jj] = 고[j-1,jj];
}
}
고[1,1] = HH[hiBar];
고[1,2] = Index - hiBar;
고[1,3] = sDate[hiBar];
고[1,4] = sTime[hiBar];
hiBar = -1;
loBar = -1;
TX = Text_New(고[1,3],고[1,4],고[1,1],NumToStr(고[1,1]-저[1,1],2));
Text_SetSize(tx,25);
Text_SetColor(tx,Red);
Text_SetStyle(tx,1,1);
Text_SetBold(tx,1);
TL = TL_New(저[1,3],저[1,4],저[1,1],고[1,3],고[1,4],고[1,1]);
TL_SetSize(TL,1);
TL_SetColor(TL,RED);
Condition8 = False;
}
If 고[1,1] < HH[hiBar] Then
{
고[1,1] = HH[hiBar];
고[1,2] = Index - hiBar;
고[1,3] = sDate[hiBar];
고[1,4] = sTime[hiBar];
hiBar = -1;
loBar = -1;
if Condition8 == False and 저[1,1] <= 고[1,1]-0.8 Then
{
Condition8 = true;
TL1= TL_New(sDate,sTime,0,sDate,sTime,999);
TL_SetColor(TL1,Blue);
}
TL_SetEnd(TL,고[1,3],고[1,4],고[1,1]);
Text_SetString(TX,NumToStr(고[1,1]-저[1,1],2));
Text_SetLocation(TX,고[1,3],고[1,4],고[1,1]);
}
최종꼭지점 = "고점";
}
If 처리구분 == "저점처리" Then
{
t = -1;
If 최종꼭지점 == "고점" Then
{
For j = 10 DownTo 2
{
For jj = 1 To 4
{
저[j,jj] = 저[j-1,jj];
}
}
저[1,1] = LL[loBar];
저[1,2] = Index - loBar;
저[1,3] = sDate[loBar];
저[1,4] = sTime[loBar];
hiBar = -1;
loBar = -1;
TX = Text_New(저[1,3],저[1,4],저[1,1],NumToStr(고[1,1]-저[1,1],2));
Text_SetSize(tx,25);
Text_SetColor(tx,Blue);
Text_SetStyle(tx,1,0);
Text_SetBold(tx,1);
TL = TL_New(고[1,3],고[1,4],고[1,1],저[1,3],저[1,4],저[1,1]);
TL_SetSize(TL,1);
TL_SetColor(TL,Green);
Condition4 = False;
}
If 저[1,1] > LL[loBar] Then
{
저[1,1] = LL[loBar];
저[1,2] = Index - loBar;
저[1,3] = sDate[loBar];
저[1,4] = sTime[loBar];
hiBar = -1;
loBar = -1;
if Condition4 == False and 저[1,1] <= 고[1,1]-0.8 Then
{
Condition4 = true;
TL1= TL_New(sDate,sTime,0,sDate,sTime,999);
TL_SetColor(TL1,Red);
}
TL_SetEnd(TL,저[1,3],저[1,4],저[1,1]);
Text_SetString(TX,NumToStr(고[1,1]-저[1,1],2));
Text_SetLocation(TX,저[1,3],저[1,4],저[1,1]);
}
최종꼭지점 = "저점";
}
지난번에 알려주신 수식을, 여기에 응용해봤는데 잘 안맞네요.
전환조건 0.8과 추세 크기 0.8일 때 세로선 표시를, 같은 크기로 설정하면, (30틱 차트)
해당 첫봉에 세로선 표시가 안되고, 다음 해당봉에 표시가 됩니다. 수정 부탁드립니다.
2024-11-05
582
글번호 184997
지표
답변완료
수고하십니다
항상 수고에 감사드리며
변환 부탁드립니다
//@version=5
indicator("Z-Score Heikin Ashi Transformed", "[Ʌ] - 𝘡 𝘏-𝘈", false)
type bar
float o = open
float h = high
float l = low
float c = close
type alerts
bool s = na
bool b = na
bool u = na
bool d = na
bool p = na
bool n = na
bool x = na
bool y = na
type prompt
string s = ''
bool c = false
method notify(prompt p) =>
if p.c
alert(p.s, alert.freq_once_per_bar_close)
method any(alerts a) =>
string s = switch
a.s => 'OB Signal'
a.b => 'OS Signal'
a.u => 'Bullish Trend'
a.d => 'Bearish Trend'
a.p => 'Heikin-Ashi Uptrend '
a.n => 'Heikin-Ashi Downtrend'
a.x => 'MACD Bullish Cross'
a.y => 'MACD Bearish Cross'
=> na
prompt.new(s, not na(s))
method src(bar b, simple string src) =>
float x = switch src
'oc2' => math.avg(b.o, b.c )
'hl2' => math.avg(b.h, b.l )
'hlc3' => math.avg(b.h, b.l, b.c )
'ohlc4' => math.avg(b.o, b.h, b.l, b.c)
'hlcc4' => math.avg(b.h, b.l, b.c, b.c)
x
method ha(bar b, simple bool p = true) =>
var bar x = bar.new( )
x.c := b .src('ohlc4')
x := bar.new(
na(x.o[1]) ?
b.src('oc2') : nz(x.src('oc2')[1]),
math.max(b.h, math.max(x.o, x.c)) ,
math.min(b.l, math.min(x.o, x.c)) ,
x.c )
p ? x : b
f_z(float src, simple int len) =>
(src - ta.sma(src, len)) / ta.stdev(src, len)
method z(bar b, simple int len) =>
bar x = bar.new(
f_z(b.o, len),
f_z(b.h, len),
f_z(b.l, len),
f_z(b.c, len))
x
const string gz = "Z-Score", const string ge = "EMAs"
len = input.int (21 , "Z Period" , group = gz)
revs = input.bool (true , "Reversions" , inline = '0', group = gz)
revt = input.int (2 , "Threshold" , [1, 2, 3], inline = '0', group = gz)
hol = input.bool (true , "Hollow Candles", group = gz)
ma1 = input.bool (true , "EMA |" , inline = '1', group = ge)
len1 = input.int (20 , "Length" , inline = '1', group = ge)
ma2 = input.bool (false , "EMA |" , inline = '2', group = ge)
len2 = input.int (50 , "Length" , inline = '2', group = ge)
col1 = input.color(#FFD6E8, "" , inline = '3', group = ge)
col2 = input.color(#9a9adf, "" , inline = '3', group = ge)
bar score = bar.new().ha().z(len)
var color colup = chart.fg_color
const color coldn = #6fa8dc
color haColor = switch
score.c > score.o => colup
score.c < score.o => coldn
plotcandle(score.o, score.h, score.l, score.c, "𝘚𝘤𝘰𝘳𝘦",
hol ? score.c < score.o ? haColor : na : haColor, haColor, bordercolor = haColor)
m = hline(0 , "Mid Line", chart.fg_color, hline.style_solid)
min = hline(-4 , display = display.none )
ll = hline(-3 , display = display.none )
hl = hline(-2 , display = display.none )
max = hline(+4 , display = display.none )
hh = hline(+3 , display = display.none )
lh = hline(+2 , display = display.none )
e1 = plot (ma1 ? ta.ema(score.c, len1) : na, "𝘌𝘔𝘈 1" , col1 )
e2 = plot (ma2 ? ta.ema(score.c, len2) : na, "𝘌𝘔𝘈 2" , col2 )
fill(lh, hh , color = #9a9adf2a)
fill(hh, max, color = #9a9adf4d)
fill(ll, hl , color = #ffd6e83b)
fill(ll, min, color = #ffd6e85e)
alerts a = alerts.new(
ta.crossunder(score.c, score.o) and (score.h > revt),
ta.crossover (score.c, score.o) and (score.l < -revt),
ta.crossover (score.c, 0) ,
ta.crossunder(score.c, 0) ,
ta.crossunder(score.c, score.o) and not (score.h > revt),
ta.crossover (score.c, score.o) and not (score.l < -revt),
ta.crossover (score.c, ta.ema(score.c, len1)) ,
ta.crossunder(score.c, ta.ema(score.c, len1)) )
plotshape(revs ? a.s ? score.h + 0.75 : na : na, "OB", shape.triangledown, location.absolute, col1, size = size.tiny)
plotshape(revs ? a.b ? score.l - 0.75 : na : na, "OS", shape.triangleup , location.absolute, col2, size = size.tiny)
alertcondition(a.s, "Overbought" , 'OB Signal' )
alertcondition(a.b, "Oversold " , 'OS Signal' )
alertcondition(a.u, "Midline Crossover " , 'Bullish Trend' )
alertcondition(a.d, "Midline Crossunder" , 'Bearish Trend' )
alertcondition(a.p, "Positive Heikin-Ashi", 'Heikin-Ashi Uptrend ')
alertcondition(a.n, "Negative Heikin-Ashi", 'Heikin-Ashi Downtrend')
alertcondition(a.x, "EMA Bull Cross" , 'EMA Bullish Cross' )
alertcondition(a.y, "EMA Bear Cross" , 'EMA Bearish Cross' )
a.any().notify()
//Source Construction For Indicator₩Strategy Exports
plot(score.o , "open" , editable = false, display = display.none)
plot(score.h , "high" , editable = false, display = display.none)
plot(score.l , "low" , editable = false, display = display.none)
plot(score.c , "close", editable = false, display = display.none)
plot(score.src('hl2' ), "hl2" , editable = false, display = display.none)
plot(score.src('hlc3' ), "hlc3" , editable = false, display = display.none)
plot(score.src('ohlc4'), "ohlc4", editable = false, display = display.none)
plot(score.src('hlcc4'), "hlcc4", editable = false, display = display.none)
2024-11-05
843
글번호 184975
지표