답변완료
수식작성 부탁드립니다.
안녕하세요. 운영자님
아래와 같은 트레이딩뷰 수식을 예스트레이더 수식으로 변환 부탁드립니다.
감사합니다.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © loxx
//@version=5
indicator("STD-Filtered, N-Pole Gaussian Filter [Loxx]",
shorttitle="STDFNPGF [Loxx]",
overlay = true)
import loxx/loxxexpandedsourcetypes/4
greencolor = #2DD204
redcolor = #D2042D
//factorial calc
fact(int n)=>
float a = 1
for i = 1 to n
a *= i
a
//alpha calc
_alpha(int period, int poles)=>
w = 2.0 * math.pi / period
float b = (1.0 - math.cos(w)) / (math.pow(1.414, 2.0 / poles) - 1.0)
float a = - b + math.sqrt(b * b + 2.0 * b)
a
//n-pole calc
_makeCoeffs(simple int period, simple int order)=>
coeffs = matrix.new<float>(order + 1, 3, 0.)
float a = _alpha(period, order)
for r = 0 to order
out = nz(fact(order) / (fact(order - r) * fact(r)), 1)
matrix.set(coeffs, r, 0, out)
matrix.set(coeffs, r, 1, math.pow(a, r))
matrix.set(coeffs, r, 2, math.pow(1.0 - a, r))
coeffs
//n-pole calc
_npolegf(float src, simple int period, simple int order)=>
var coeffs = _makeCoeffs(period, order)
float filt = src * matrix.get(coeffs, order, 1)
int sign = 1
for r = 1 to order
filt += sign * matrix.get(coeffs, r, 0) * matrix.get(coeffs, r, 2) * nz(filt[r])
sign *= -1
filt
//std filter
_filt(float src, int len, float filter)=>
float price = src
float filtdev = filter * ta.stdev(src, len)
price := math.abs(price - nz(price[1])) < filtdev ? nz(price[1]) : price
price
smthtype = input.string("Kaufman", "Heiken-Ashi Better Smoothing", options = ["AMA", "T3", "Kaufman"], group= "Source Settings")
srcoption = input.string("Close", "Source", group= "Source Settings",
options =
["Close", "Open", "High", "Low", "Median", "Typical", "Weighted", "Average", "Average Median Body", "Trend Biased", "Trend Biased (Extreme)",
"HA Close", "HA Open", "HA High", "HA Low", "HA Median", "HA Typical", "HA Weighted", "HA Average", "HA Average Median Body", "HA Trend Biased", "HA Trend Biased (Extreme)",
"HAB Close", "HAB Open", "HAB High", "HAB Low", "HAB Median", "HAB Typical", "HAB Weighted", "HAB Average", "HAB Average Median Body", "HAB Trend Biased", "HAB Trend Biased (Extreme)"])
period = input.int(25,'Period', group = "Basic Settings")
order = input.int(5,'Order', group = "Basic Settings", minval = 1)
filterop = input.string("Gaussian Filter", "Filter Options", options = ["Price", "Gaussian Filter", "Both", "None"], group= "Filter Settings")
filter = input.float(1, "Filter Devaitions", minval = 0, group= "Filter Settings")
filterperiod = input.int(10, "Filter Period", minval = 0, group= "Filter Settings")
colorbars = input.bool(true, "Color bars?", group = "UI Options")
showSigs = input.bool(true, "Show signals?", group= "UI Options")
kfl=input.float(0.666, title="* Kaufman's Adaptive MA (KAMA) Only - Fast End", group = "Moving Average Inputs")
ksl=input.float(0.0645, title="* Kaufman's Adaptive MA (KAMA) Only - Slow End", group = "Moving Average Inputs")
amafl = input.int(2, title="* Adaptive Moving Average (AMA) Only - Fast", group = "Moving Average Inputs")
amasl = input.int(30, title="* Adaptive Moving Average (AMA) Only - Slow", group = "Moving Average Inputs")
[haclose, haopen, hahigh, halow, hamedian, hatypical, haweighted, haaverage] = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, [close, open, high, low, hl2, hlc3, hlcc4, ohlc4])
float src = switch srcoption
"Close" => loxxexpandedsourcetypes.rclose()
"Open" => loxxexpandedsourcetypes.ropen()
"High" => loxxexpandedsourcetypes.rhigh()
"Low" => loxxexpandedsourcetypes.rlow()
"Median" => loxxexpandedsourcetypes.rmedian()
"Typical" => loxxexpandedsourcetypes.rtypical()
"Weighted" => loxxexpandedsourcetypes.rweighted()
"Average" => loxxexpandedsourcetypes.raverage()
"Average Median Body" => loxxexpandedsourcetypes.ravemedbody()
"Trend Biased" => loxxexpandedsourcetypes.rtrendb()
"Trend Biased (Extreme)" => loxxexpandedsourcetypes.rtrendbext()
"HA Close" => loxxexpandedsourcetypes.haclose(haclose)
"HA Open" => loxxexpandedsourcetypes.haopen(haopen)
"HA High" => loxxexpandedsourcetypes.hahigh(hahigh)
"HA Low" => loxxexpandedsourcetypes.halow(halow)
"HA Median" => loxxexpandedsourcetypes.hamedian(hamedian)
"HA Typical" => loxxexpandedsourcetypes.hatypical(hatypical)
"HA Weighted" => loxxexpandedsourcetypes.haweighted(haweighted)
"HA Average" => loxxexpandedsourcetypes.haaverage(haaverage)
"HA Average Median Body" => loxxexpandedsourcetypes.haavemedbody(haclose, haopen)
"HA Trend Biased" => loxxexpandedsourcetypes.hatrendb(haclose, haopen, hahigh, halow)
"HA Trend Biased (Extreme)" => loxxexpandedsourcetypes.hatrendbext(haclose, haopen, hahigh, halow)
"HAB Close" => loxxexpandedsourcetypes.habclose(smthtype, amafl, amasl, kfl, ksl)
"HAB Open" => loxxexpandedsourcetypes.habopen(smthtype, amafl, amasl, kfl, ksl)
"HAB High" => loxxexpandedsourcetypes.habhigh(smthtype, amafl, amasl, kfl, ksl)
"HAB Low" => loxxexpandedsourcetypes.hablow(smthtype, amafl, amasl, kfl, ksl)
"HAB Median" => loxxexpandedsourcetypes.habmedian(smthtype, amafl, amasl, kfl, ksl)
"HAB Typical" => loxxexpandedsourcetypes.habtypical(smthtype, amafl, amasl, kfl, ksl)
"HAB Weighted" => loxxexpandedsourcetypes.habweighted(smthtype, amafl, amasl, kfl, ksl)
"HAB Average" => loxxexpandedsourcetypes.habaverage(smthtype, amafl, amasl, kfl, ksl)
"HAB Average Median Body" => loxxexpandedsourcetypes.habavemedbody(smthtype, amafl, amasl, kfl, ksl)
"HAB Trend Biased" => loxxexpandedsourcetypes.habtrendb(smthtype, amafl, amasl, kfl, ksl)
"HAB Trend Biased (Extreme)" => loxxexpandedsourcetypes.habtrendbext(smthtype, amafl, amasl, kfl, ksl)
=> haclose
src := filterop == "Both" or filterop == "Price" and filter > 0 ? _filt(src, filterperiod, filter) : src
out = _npolegf(src, period, order)
out := filterop == "Both" or filterop == "Gaussian Filter" and filter > 0 ? _filt(out, filterperiod, filter) : out
sig = nz(out[1])
state = 0
if (out > sig)
state := 1
if (out < sig)
state := -1
pregoLong = out > sig and (nz(out[1]) < nz(sig[1]) or nz(out[1]) == nz(sig[1]))
pregoShort = out < sig and (nz(out[1]) > nz(sig[1]) or nz(out[1]) == nz(sig[1]))
contsw = 0
contsw := nz(contsw[1])
contsw := pregoLong ? 1 : pregoShort ? -1 : nz(contsw[1])
goLong = pregoLong and nz(contsw[1]) == -1
goShort = pregoShort and nz(contsw[1]) == 1
var color colorout = na
colorout := state == -1 ? redcolor : state == 1 ? greencolor : nz(colorout[1])
plot(out, "N-Pole GF", color = colorout, linewidth = 3)
barcolor(colorbars ? colorout : na)
plotshape(showSigs and goLong, title = "Long", color = color.yellow, textcolor = color.yellow, text = "L", style = shape.triangleup, location = location.belowbar, size = size.tiny)
plotshape(showSigs and goShort, title = "Short", color = color.fuchsia, textcolor = color.fuchsia, text = "S", style = shape.triangledown, location = location.abovebar, size = size.tiny)
alertcondition(goLong, title = "Long", message = "STD-Filtered, N-Pole Gaussian Filter [Loxx]: Long₩nSymbol: {{ticker}}₩nPrice: {{close}}")
alertcondition(goShort, title = "Short", message = "STD-Filtered, N-Pole Gaussian Filter [Loxx]: Short₩nSymbol: {{ticker}}₩nPrice: {{close}}")
2023-03-29
1893
글번호 167679
지표
답변완료
시스템식 부탁드립니다.
항상 도움 주셔서 감사합니다.
종목 : 해외선물
차트 : 5분봉
최초 매수, 매도 진입이후 10틱 간격으로 불타기나 물타기 할경우
실제 진입한 가격을 보면 같은 가격에 진입되는 경우가 많은것 같습니다.
요청사항1 :
저는 일정한 간격으로 불타기나 물타기를 하고 싶습니다.
최대한 정확한 진입가격을 위한 방법이 무엇인지 도움 부탁드립니다.
[일정한 간격으로 진입]
요청사항2 :
청산할때 일정계약수 이하에서는 개별청산,
일정계약수 이상에서는 평균진입가보다 10틱이상일 경우 일괄청산 하고 싶습니다.
[개별청산은 진입건보다 10틱이상 수익시 청산
[일괄청산은 남아있는 계약의 평균가격 대비 10틱 이상 수익이면 일괄청산]
# 매수의 경우
var : 이평(0) ;
이평 = ma(C,20) ;
if marketposition == 0 and C > 이평 then
buy("b",atlimit,C,1) ;
매수가격 = entryprice ;
# 불타기
# 방법1
if marketposition == 1 then
{
buy("b2",atlimit,매수가격+10*pricescale*2,1) ;
buy("b3",atlimit,매수가격+10*pricescale*3,1) ;
buy("b4",atlimit,매수가격+10*pricescale*4,1) ;
buy("b5",atlimit,매수가격+10*pricescale*5,1) ;
buy("b6",atlimit,매수가격+10*pricescale*6,1) ;
# 방법2
if marketposition == 1 then
{
if MaxEntries == 1 Then
buy("b2",atlimit,매수가격+10*pricescale*2,1) ;
if MaxEntries == 2 Then
buy("b3",atlimit,매수가격+10*pricescale*3,1) ;
if MaxEntries == 3 Then
buy("b4",atlimit,매수가격+10*pricescale*4,1) ;
if MaxEntries == 4 Then
buy("b5",atlimit,매수가격+10*pricescale*5,1) ;
if MaxEntries == 5 Then
buy("b6",atlimit,매수가격+10*pricescale*6,1) ;
}
#방법3
if MarketPosition == 1 Then
{
if highest(H,BarsSinceEntry) < 매수가격-10*pricescale*2 Then
Buy("b2",AtLimit,매수가격+10*pricescale*MaxEntries,amt);
if highest(H,BarsSinceEntry) < 매수가격-10*pricescale*3 Then
Buy("b3",AtLimit,매수가격+10*pricescale*MaxEntries,amt);
if highest(H,BarsSinceEntry) < 매수가격-10*pricescale*4 Then
Buy("b4",AtLimit,매수가격+10*pricescale*MaxEntries,amt);
if highest(H,BarsSinceEntry) < 매수가격-10*pricescale*5 Then
Buy("b5",AtLimit,매수가격+10*pricescale*MaxEntries,amt);
if highest(H,BarsSinceEntry) < 매수가격-10*pricescale*6 Then
Buy("b6",AtLimit,매수가격+10*pricescale*MaxEntries,amt);
}
# 위 셋중 어느방법이 더 정확하게 진입이 되나요?
# 위 방법외에 더 정확한 진입을 위한 수식이 있으면 수정 부탁드립니다.
# 물타기
# 방법1
if marketposition == 1 then
buy("bb2",atlimit,매수가격-10*pricescale*2,1) ;
buy("bb3",atlimit,매수가격-10*pricescale*3,1) ;
buy("bb4",atlimit,매수가격-10*pricescale*4,1) ;
buy("bb5",atlimit,매수가격-10*pricescale*5,1) ;
buy("bb6",atlimit,매수가격-10*pricescale*6,1) ;
# 방법2
if marketposition == 1 then
{
if MaxEntries == 1 Then
buy("b2",atlimit,매수가격-10*pricescale*2,1) ;
if MaxEntries == 2 Then
buy("b3",atlimit,매수가격-10*pricescale*3,1) ;
if MaxEntries == 3 Then
buy("b4",atlimit,매수가격-10*pricescale*4,1) ;
if MaxEntries == 4 Then
buy("b5",atlimit,매수가격-10*pricescale*5,1) ;
if MaxEntries == 5 Then
buy("b6",atlimit,매수가격-10*pricescale*6,1) ;
}
#방법3
if MarketPosition == 1 Then
{
if lowest(L,BarsSinceEntry) > 매수가격-10*pricescale*2 Then
Buy("b2",AtLimit,매수가격-10*pricescale*MaxEntries,amt);
if lowest(L,BarsSinceEntry) > 매수가격-10*pricescale*3 Then
Buy("b3",AtLimit,매수가격-10*pricescale*MaxEntries,amt);
if lowest(L,BarsSinceEntry) > 매수가격-10*pricescale*4 Then
Buy("b4",AtLimit,매수가격-10*pricescale*MaxEntries,amt);
if lowest(L,BarsSinceEntry) > 매수가격-10*pricescale*5 Then
Buy("b5",AtLimit,매수가격-10*pricescale*MaxEntries,amt);
if lowest(L,BarsSinceEntry) > 매수가격-10*pricescale*6 Then
Buy("b6",AtLimit,매수가격-10*pricescale*MaxEntries,amt);
}
# 개별청산
if MarketPosition == 1 and CurrentContracts < 3 Then
{
SetStopProfittarget(PriceScale*10,PointStop);
}
Else
SetStopProfittarget(0);
# 일괄청산
#방법1:
if MarketPosition == 1 and CurrentContracts >= 3 Then
{
exitlong("bx",atlimit,avgentryprice-PriceScale*10,PointStop);
}
#방법2:
if MarketPosition == 1 and CurrentContracts >= 3 Then
{
if openpositionprofit/0.025[틱사이즈] < 10*pricescap then
exitlong("bx",atlimit,c,PointStop);
}
# 둘중 어느것이 더 정확한 코딩인가요?
# 위 방법외에 더 정확한 청산을 위한 방법이 있으면 수정 부탁드립니다.
도움 부탁드립니다.
감사합니다.
2023-03-29
1153
글번호 167677
시스템