답변완료
진입봉의 저가/고가
안녕하세요
해당 코드로 진입 시 손절라인을 진입봉의 저가/고가 or 특정 봉 수 지난 후로 설정하고 있습니다
var : hh(0),ll(0);
input:X1(5); // 1~10, 직전 XX봉 횟수
ll = lowest(L,X1);
hh = highest(H,X1);
Condition1 = CrossUp(C,hh[1]) and MarketPosition == 0;
Condition2 = CrossDown(C,ll[1]) and MarketPosition == 0;
If Condition1 == True then Buy("B1",AtMarket,DEf,1);
If Condition2 == True then Sell("B2",AtMarket,DEf,1);
// 손절: 진입신호 봉의 저가 손절
input:FF(8); // 1~10, 진입 후 XX봉 경과
If MarketPosition == 1 and (EntryPrice < L[BarsSinceEntry[0]] or BarsSinceEntry > FF) Then ExitLong("C1");
If MarketPosition == -1 and (EntryPrice > H[BarsSinceEntry[0]] or BarsSinceEntry > FF) Then ExitShort("C2");
// 청산: 1% 단위로 일정 되돌림 비율
If OpenPositionProfit / EntryPrice >= 0.01 and OpenPositionProfit / EntryPrice < 0.02
Then SetStopTrailing(1,2,PercentStop);
If OpenPositionProfit / EntryPrice >= 0.02 and OpenPositionProfit / EntryPrice < 0.03
Then SetStopTrailing(1.8,3,PercentStop);
If OpenPositionProfit / EntryPrice >= 0.03 and OpenPositionProfit / EntryPrice < 0.04
Then SetStopTrailing(2.8,4,PercentStop);
If OpenPositionProfit / EntryPrice >= 0.04 and OpenPositionProfit / EntryPrice < 0.05
Then SetStopTrailing(4,5,PercentStop);
하지만 NG.1로 백테스트했을때 진입봉 저가/고가 조건이 전혀 발동이 안되네요
확인 부탁드리겠습니다
감사합니다
2025-05-25
218
글번호 191147
시스템
답변완료
부틱드립니다
수고하십니다
아래수식을 예스로 부탁드립니다
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Adarsh
//@version=4
// Moving Average 3.0 (3rd Generation) s cript may be freely distributed under the MIT license. Copyright (c) 2018-present, Alex Orekhov (everget)
study("IDEAL BB with MA (With Alerts) by Adarsh", overlay=true)
length1 = input(title="1st Length", type=input.integer, minval=1, defval=120)
length2 = input(title="2nd Length", type=input.integer, minval=1, defval=12)
maInput = input(title="MA Type", defval="EMA", options=["EMA", "SMA", "VWMA", "WMA"])
src = input(title="Source", type=input.source, defval=hl2)
getMA(src, length) =>
ma = 0.0
if maInput == "EMA"
ma := ema(src, length)
if maInput == "SMA"
ma := sma(src, length)
if maInput == "VWMA"
ma := vwma(src, length)
if maInput == "WMA"
ma := wma(src, length)
ma
getNMA(src, length1, length2) =>
lambda = length1 / length2
alpha = lambda * (length1 - 1) / (length1 - lambda)
ma1 = getMA(src, length1)
ma2 = getMA(ma1, length2)
nma = (1 + alpha) * ma1 - alpha * ma2
nma = getNMA(src, length1, length2)
//emaLength = input(90, minval=1, title="EMA Length")
//emaSource = input(close, title="EMA Source")
//ema = ema(emaSource, emaLength)
plot(nma, title="NMA Black Line", linewidth=2, style=plot.style_stepline, color=color.black, transp=0)
//plot(ema, title="EMA", linewidth=1, color=color.red, transp=0)
//VWAP BANDS
lenvwap = input(1, minval=1, title="VWAP Length")
src1a = input(close, title="VWAP Source")
offsetvwap = input(title="VWAP Offset", type=input.integer, defval=0, minval=-500, maxval=500)
srcvwap = hlc3
vvwap = vwap(srcvwap)
line1 = sma(src1a, lenvwap)
plot(vvwap, color=#e91e63, linewidth=2, style=plot.style_line, title="VWAP MIDDLE")
// Boll Bands
emaSource = close
emaPeriod = 20
devMultiple = 2
baseline = sma(emaSource, emaPeriod)
plot(baseline, title = "BB Red Line", color = color.red)
stdDeviation = devMultiple * (stdev(emaSource, emaPeriod))
upperBand = (baseline + stdDeviation)
lowerBand = (baseline - stdDeviation)
p1 = plot(upperBand, title = "BB Top", color = color.blue)
p2 = plot(lowerBand, title = "BB Bottom", color = #311b92)
fill(p1, p2, color = color.blue)
//HULL TREND WITH KAHLMAN
srchull = input(hl2, "Price Data")
lengthhull = input(24, "Lookback")
showcross = input(true, "Show cross over/under")
gain = input(10000, "Gain")
k = input(true, "Use Kahlman")
hma(_srchull, _lengthhull) =>
wma((2 * wma(_srchull, _lengthhull / 2)) - wma(_srchull, _lengthhull), round(sqrt(_lengthhull)))
hma3(_srchull, _lengthhull) =>
p = lengthhull/2
wma(wma(close,p/3)*3 - wma(close,p/2) - wma(close,p),p)
kahlman(x, g) =>
kf = 0.0
dk = x - nz(kf[1], x)
smooth = nz(kf[1],x)+dk*sqrt((g/10000)*2)
velo = 0.0
velo := nz(velo[1],0) + ((g/10000)*dk)
kf := smooth+velo
a = k ? kahlman(hma(srchull, lengthhull), gain) : hma(srchull, lengthhull)
b = k ? kahlman(hma3(srchull, lengthhull), gain) : hma3(srchull, lengthhull)
c = b > a ? color.lime : color.red
crossdn = a > b and a[1] < b[1]
crossup = b > a and b[1] < a[1]
p1hma = plot(a,color=c,linewidth=1,transp=75, title="Long Plot")
p2hma = plot(b,color=c,linewidth=1,transp=75, title="Short Plot")
fill(p1hma,p2hma,color=c,transp=55,title="Fill")
plotshape(showcross and crossdn ? a : na, location=location.abovebar, style=shape.labeldown, color=color.red, size=size.tiny, text="Sell", textcolor=color.white, transp=0, offset=-1)
plotshape(showcross and crossup ? a : na, location=location.belowbar, style=shape.labelup, color=color.green, size=size.tiny, text="Buy", textcolor=color.white, transp=0, offset=-1)
//ALERTS
alertcondition(crossup, title='Buy', message='Go Long')
alertcondition(crossdn, title='Sell', message='Go Short')
2025-05-25
353
글번호 191143
지표
답변완료
질문 부탁드립니다
주말 잘 보내셨길 바랍니다
text 관련 질문 하나 드려요
새로운 조건이 나왔을때는 0으로 표시하고
그 전은 1 (txtt1[1] 에는 1), 전전은 2 ... 이런식으로 text 표시를 하려고
아래 수식 for 문에
Text_SetString(txtt1[cnt],NumToStr(cnt,0));
넣었는데요 다 0 으로 나오게 되네요
어디서 작성이 잘못 된건지 한 번 봐주셨으면 합니다
감사합니다
var : cnt(0), sum1(0), sumi1(0),summ(0),tt(0),hh(0),ll(0),tl(0),tl1(0),n(0),ae(0);
var: sum2(0),sumi2(0),count(0),sumaa(0),sumai(0),avgaa(0);
var : t(0),StartBarIndex(0),dd(0),d1(0),d2(0),e1(0),e2(0);
Array : ii[50](0),aa[50](0),cc[50](0),ee[50](0),ttl[30](0),txtt[40](0),txtt1[40](0),
tttl1[40](0),tttl2[40](0),sd[45](0),st[45](0),ad[50](0),at[50](0);
if Bdate != Bdate[1] Then
{
DD = DD+1;
}
if (h>l*1.08) and (d1 == 0 or (d1 > 0 and dd >= d1+5)) Then
{
d1 = dd;
hh = h;
var1 = Index;
Var2 = var1[1];
Var3 = Var2[1];
sum1=0; sumi1=0; sum2=0; sumi2=0;
For cnt = 1 to (var1-Var2)
{
sum1=sum1+l[cnt];
sumi1=sumi1+1;
}
value1=sum1/sumi1;
For cnt = 49 DownTo 1
{
aa[cnt] = aa[cnt-1];
sd[cnt] =sd[cnt-1];
st[cnt] =st[cnt-1];
txtt[cnt] = txtt[cnt-1];
tttl1[cnt]=tttl1[cnt-1];
Text_SetString(txtt1[cnt],NumToStr(cnt,0));
}
aa[0] = value1;
sd[0] = sDate;
st[0] = sTime;
txtt1[0]=text_new(sd[0],st[0],aa[0],numToStr(0,0));
TL_SetExtRight( tttl1[6],False);
tttl1[0] = TL_New(sd[7],st[7],aa[7],sd[3],st[3],aa[3]);
TL_SetDrawMode( tttl1[0],0);
TL_Delete( tttl1[6]);
TL_SetExtRight( tttl1[0],true);
}
2025-05-26
220
글번호 191140
지표