답변완료
수식 부탁드립니다
지표식 부탁드립니다.
//@version=5
indicator("Target Trend ", overlay = true, max_lines_count = 40)
// INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
length = input.int(10, "Trend Length")
target = input.int(0, "Set Targets")
// }
// VARIABLES ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
var bool trend = na
float trend_value = na
// Colors
color up_color = #06b690
color dn_color = color.rgb(182, 112, 6)
// ATR for calculating stop loss and target levels
series float atr_value = ta.sma(ta.atr(200), 200) * 0.8
// Moving averages for trend detection
series float sma_high = ta.sma(high, length) + atr_value
series float sma_low = ta.sma(low, length) - atr_value
color plot_color = color.new(chart.fg_color, 80)
// UDT for managing lines and labels
type TrendTargets
line[] lines
label[] labels
// Initialize UDT
var TrendTargets targets_up = TrendTargets.new(array.new_line(), array.new_label())
var TrendTargets targets_down = TrendTargets.new(array.new_line(), array.new_label())
// }
// CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
// Determine trend based on crossovers
if ta.crossover(close, sma_high) and barstate.isconfirmed
trend := true
if ta.crossunder(close, sma_low) and barstate.isconfirmed
trend := false
trend_value := switch
trend => sma_low
not trend => sma_high
trend_color = trend ? up_color : not trend ? dn_color : na
// Signal detection for trend changes
bool signal_up = ta.change(trend) and not trend[1]
bool signal_down = ta.change(trend) and trend[1]
// Method to draw trend targets and manage lines/labels
method draw_targets(TrendTargets targets, bool signal1, bool signal2, bool direction)=>
float base = direction ? sma_low : sma_high
float atr_multiplier = atr_value * (direction ? 1 : -1)
// Reset counters for up and down targets
var int count_up = 0
var int count_down = 0
if trend
count_down := 0
count_up += 1
if not trend
count_down += 1
count_up := 0
int count = direction ? count_up : count_down
if signal1
float target_len1 = atr_multiplier * (5+target)
float target_len2 = atr_multiplier * (10+target*2)
float target_len3 = atr_multiplier * (15+target*3)
// Clear existing lines and labels
for line_i in targets.lines
int i = targets.lines.indexof(line_i)
label.delete(targets.labels.get(i))
line.delete(line_i)
array.clear(targets.lines)
array.clear(targets.labels)
// Draw new lines for trend targets
line stop_loss_line = line.new(bar_index, base, bar_index + 20, base)
line entry_line = line.new(bar_index, close, bar_index + 20, close)
line target1_line = line.new(bar_index, close + target_len1, bar_index + 20, close + target_len1)
line target2_line = line.new(bar_index, close + target_len2, bar_index + 20, close + target_len2)
line target3_line = line.new(bar_index, close + target_len3, bar_index + 20, close + target_len3)
// Fill between stop loss and entry line
linefill.new(stop_loss_line, entry_line, color.new(dn_color, 95))
linefill.new(entry_line, target3_line, color.new(up_color, 95))
// Draw new labels for trend targets
label stop_loss_label = label.new(bar_index + 20, base, str.tostring(math.round(base, 2)))
label entry_label = label.new(bar_index + 20, close, str.tostring(math.round(close, 2)))
label target1_label = label.new(bar_index + 20, close + target_len1, "1 - " + str.tostring(math.round(close + target_len1, 2)))
label target2_label = label.new(bar_index + 20, close + target_len2, "2 - " + str.tostring(math.round(close + target_len2, 2)))
label target3_label = label.new(bar_index + 20, close + target_len3, "3 - " + str.tostring(math.round(close + target_len3, 2)))
// Push lines and labels to the UDT
targets.lines.push(stop_loss_line)
targets.lines.push(entry_line)
targets.lines.push(target1_line)
targets.lines.push(target2_line)
targets.lines.push(target3_line)
targets.labels.push(stop_loss_label)
targets.labels.push(entry_label)
targets.labels.push(target1_label)
targets.labels.push(target2_label)
targets.labels.push(target3_label)
// 업데이트 styles for labels and lines
for lbl in targets.labels
int idx = targets.labels.indexof(lbl)
line line_ref = targets.lines.get(idx)
lbl.set_style(label.style_label_left)
lbl.set_color(chart.fg_color)
lbl.set_textcolor(chart.bg_color)
line_ref.set_color(chart.fg_color)
if signal2
// Clear existing lines and labels
for line_i in targets.lines
int i = targets.lines.indexof(line_i)
label.delete(targets.labels.get(i))
line.delete(line_i)
array.clear(targets.lines)
array.clear(targets.labels)
for line_i in targets.lines
int idx = targets.lines.indexof(line_i)
label lbl_ref = targets.labels.get(idx)
label first_label = targets.labels.first()
line entry_line = targets.lines.get(1)
label entry_label = targets.labels.get(1)
// Targets
if high >= line.get_y2(line_i) and low <= line.get_y2(line_i) and count > 1
lbl_ref.set_style(label.style_label_left)
lbl_ref.set_color(chart.fg_color)
lbl_ref.set_text(" ✔ ")
lbl_ref.set_textcolor(#16ac09)
line_i.set_style(line.style_dashed)
line_i.set_color(plot_color)
// Stop Loss
if high >= line.get_y2(targets.lines.first()) and low <= line.get_y2(targets.lines.first()) and count > 1
first_label.set_text(" ✖ ")
if direction ? trend : not trend
first_label.set_textcolor(#db1e1e)
line_i.set_x2(bar_index + 20)
targets.lines.first().set_color(#db1e1e)
label.set_x(targets.labels.get(idx), bar_index + 20)
entry_line.set_style(line.style_solid)
entry_line.set_color(up_color)
entry_label.set_text("◉ " + str.tostring(math.round(line.get_y2(entry_line), 2)))
entry_label.set_textcolor(#1d80dd)
// }
// PLOT―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
// Call the draw_targets method for both upward and downward trends
targets_down.draw_targets(signal_down, signal_up, false)
targets_up.draw_targets(signal_up, signal_down, true)
// Plot candlesticks with trend color
plotcandle(open, high, low, close,
title = 'Title',
color = trend_color,
wickcolor = trend_color,
bordercolor = trend_color)
// Plot trailing stops
p1 = plot(trend ? trend_value : na, style = plot.style_linebr, color = plot_color)
p2 = plot(not trend ? trend_value : na, style = plot.style_linebr, color = plot_color)
p0 = plot(hl2, display = display.none, editable = false)
fill(p1, p0, trend_value, hl2, color.new(chart.fg_color, 90), na)
fill(p2, p0, trend_value, hl2, color.new(chart.fg_color, 90), na)
// Plot signals on the chart
float sigUp = signal_up ? low - atr_value*2 : na
float sigDn = signal_down ? high + atr_value*2 : na
plotshape(sigUp, "", shape.triangleup, location.absolute, up_color, size = size.tiny)
plotshape(sigUp, "", shape.triangleup, location.absolute, color.new(up_color, 80), size = size.small)
plotshape(sigDn, "", shape.triangledown, location.absolute, dn_color, size = size.tiny)
plotshape(sigDn, "", shape.triangledown, location.absolute, color.new(dn_color, 80), size = size.small)
// }
2025-05-30
248
글번호 191280
지표
답변완료
수식 검증 및 문의
안녕하세요, 아래 문의사항 확인 부탁드립니다
1. 아래 로직대로 코드가 짜였는지 검증 부탁드립니다.
- 장 오픈 후 5분~30분(변수로 테스트) 봉의 High and Low를 파악 (8시~익일 7시 운영 거래소)
- 첫 봉이 양봉이었으면 매수만 가능. 종가가 High를 돌파하면 매수 진입
- 첫 봉이 음봉이었으면 매도만 가능, 종가가 Low를 돌파하면 매도 진입
- 스탑로스는 14일 ATR * XX%
- 당일청산 (익일 7시 전)
2. 14일 ATR을 사용하고 싶은데 코드는 봉수 기준이라 14일만 따로 적용할 수 있는 방법이 있을까요?
3. SetStopEndofDay는 한국시간 익일에 장 마감하는 미국장에도 적용이 올바르게 된건가요?
감사합니다
[코드]
Input: NMin(5); // Step 1 until 30
Vars: FirstNHigh(0), FirstNLow(0), FirstNOpen(0), FirstNClose(0);
Vars: ATR14(0), StopLoss(0);
// N분 단위 첫 봉의 종료시간 계산
Vars: FirstEndTime(0);
FirstEndTime = 80000 + NMin * 100;
// 1. 첫 5분봉 High/Low/Open/Close 파악 (5분봉 기준)
If Date <> Date[1] Then
{
FirstNHigh = TimeHigh(80000, FirstEndTime);
FirstNLow = TimeLow(80000, FirstEndTime);
FirstNOpen = TimeOpen(80000, FirstEndTime);
FirstNClose = TimeClose(80000, FirstEndTime);
}
// 2. ATR(14) 계산 및 스탑로스 설정
Input: ATRFactor(10); // Step 10 until 100
ATR14 = ATR(14);
StopLoss = ATR14 * ATRFactor / 100;
// 3. 매수 조건: 첫 5분봉 양봉 & High 돌파
If FirstNClose > FirstNOpen and Close > FirstNHigh Then
{
If MarketPosition == 0 Then
Buy("ORBLong",AtMarket,DEf,1);
}
// 4. 매도 조건: 첫 5분봉 음봉 & Low 돌파
If FirstNClose < FirstNOpen and Close < FirstNLow Then
{
If MarketPosition == 0 Then
Sell("ORBShort",AtMarket,DEf,1);
}
// 5. 스탑로스 (ATR 10% 이탈 시)
If MarketPosition == 1 Then ExitLong("A1",AtStop,EntryPrice - StopLoss);
If MarketPosition == -1 Then ExitShort("B1",AtStop,EntryPrice + StopLoss);
// 6. 당일 청산
If MarketPosition <> 0 Then SetStopEndofday(065500);
2025-05-30
166
글번호 191279
시스템
답변완료
지표부탁드립니다.
<첫번째>
동그라미한 라인의 중간선들 굵기를 1~2포인트 굵게 부탁드립니다.
input : 간격(2.5);
var : cnt(0);
Array : HTL1[100](0),LTL1[100](0);
Array : HTL2[100](0),LTL2[100](0);
Array : HTL3[100](0),LTL3[100](0);
Array : HTL4[100](0),LTL4[100](0);
if Index == 1 or Bdate != Bdate[1] Then
{
var1 = Floor(DayOpen/간격)*간격;
For cnt = 0 to 99
{
TL_Delete(HTL1[cnt]);
TL_Delete(LTL1[cnt]);
TL_Delete(HTL2[cnt]);
TL_Delete(LTL2[cnt]);
TL_Delete(HTL3[cnt]);
TL_Delete(LTL3[cnt]);
TL_Delete(HTL4[cnt]);
TL_Delete(LTL4[cnt]);
value1 = var1+간격*cnt;
value2 = value1+(간격/4)*1;
value3 = value1+(간격/4)*2;
value4 = value1+(간격/4)*3;
HTL1[cnt] = TL_New(sDate,sTime,value1,NextBarSdate,NextBarStime,Value1);
HTL2[cnt] = TL_New(sDate,sTime,value2,NextBarSdate,NextBarStime,Value2);
HTL3[cnt] = TL_New(sDate,sTime,value3,NextBarSdate,NextBarStime,Value3);
HTL4[cnt] = TL_New(sDate,sTime,value4,NextBarSdate,NextBarStime,Value4);
TL_SetExtLeft(HTL1[cnt],true);
TL_SetExtLeft(HTL2[cnt],true);
TL_SetExtLeft(HTL3[cnt],true);
TL_SetExtLeft(HTL4[cnt],true);
TL_SetExtRight(HTL1[cnt],true);
TL_SetExtRight(HTL2[cnt],true);
TL_SetExtRight(HTL3[cnt],true);
TL_SetExtRight(HTL4[cnt],true);
TL_SetSize(HTL1[cnt],5);
TL_SetSize(HTL2[cnt],0);
TL_SetSize(HTL3[cnt],0.5);
TL_SetSize(HTL4[cnt],0);
TL_SetStyle(HTL1[cnt],0.5);
TL_SetStyle(HTL2[cnt],3);
TL_SetStyle(HTL3[cnt],0.5);
TL_SetStyle(HTL4[cnt],3);
if cnt >= 1 Then
{
value5 = var1-간격*cnt;
value6 = value5+(간격/4)*1;
value7 = value5+(간격/4)*2;
value8 = value5+(간격/4)*3;
LTL1[cnt] = TL_New(sDate,sTime,value5,NextBarSdate,NextBarStime,Value5);
LTL2[cnt] = TL_New(sDate,sTime,value6,NextBarSdate,NextBarStime,Value6);
LTL3[cnt] = TL_New(sDate,sTime,value7,NextBarSdate,NextBarStime,Value7);
LTL4[cnt] = TL_New(sDate,sTime,value8,NextBarSdate,NextBarStime,Value8);
TL_SetExtLeft(LTL1[cnt],true);
TL_SetExtLeft(LTL2[cnt],true);
TL_SetExtLeft(LTL3[cnt],true);
TL_SetExtLeft(LTL4[cnt],true);
TL_SetExtRight(LTL1[cnt],true);
TL_SetExtRight(LTL2[cnt],true);
TL_SetExtRight(LTL3[cnt],true);
TL_SetExtRight(LTL4[cnt],true);
TL_SetSize(LTL1[cnt],5);
TL_SetSize(LTL2[cnt],0);
TL_SetSize(LTL3[cnt],0.5);
TL_SetSize(LTL4[cnt],0);
TL_SetStyle(LTL1[cnt],0.5);
TL_SetStyle(LTL2[cnt],3);
TL_SetStyle(LTL3[cnt],0.5);
TL_SetStyle(LTL4[cnt],3);
}
}
}
<두번째 키움에서 쓰던 수식선입니다. 5가지선 부탁드립니다.>
<중심선>
N2=(predayhigh()+dayopen())/2;
중심값=(predayclose()+predayhigh()+predaylow())/3;
G2=2*중심값-predaylow();
H2=중심값+predayhigh()-predaylow();
M2=(G2+H2)/2;
하양중심=(N2+M2)/2;
J2=((중심값*2-predayhigh())+(중심값+predaylow()-predayhigh()))/2;
L2=(predaylow()+dayopen())/2;
K2=(J2+L2)/2;
신중심=(하양중심+k2)/2;
<고점중심>
N2=(predayhigh()+dayopen())/2;
중심값=(predayclose()+predayhigh()+predaylow())/3;
G2=2*중심값-predaylow();
H2=중심값+predayhigh()-predaylow();
M2=(G2+H2)/2;
하양중심=(N2+M2)/2;
<저점중심>
중심값=(predayclose()+predayhigh()+predaylow())/3;
J2=((중심값*2-predayhigh())+(중심값+predaylow()-predayhigh()))/2;
L2=(predaylow()+dayopen())/2;
K2=(J2+L2)/2;
<상중심>
N2=(predayhigh()+dayopen())/2;
중심값=(predayclose()+predayhigh()+predaylow())/3;
G2=2*중심값-predaylow();
H2=중심값+predayhigh()-predaylow();
M2=(G2+H2)/2;
하양중심=(N2+M2)/2;
J2=((중심값*2-predayhigh())+(중심값+predaylow()-predayhigh()))/2;
L2=(predaylow()+dayopen())/2;
K2=(J2+L2)/2;
신중심=(하양중심+k2)/2;
상중심=신중심+1.25;
<하중심>
N2=(predayhigh()+dayopen())/2;
중심값=(predayclose()+predayhigh()+predaylow())/3;
G2=2*중심값-predaylow();
H2=중심값+predayhigh()-predaylow();
M2=(G2+H2)/2;
하양중심=(N2+M2)/2;
J2=((중심값*2-predayhigh())+(중심값+predaylow()-predayhigh()))/2;
L2=(predaylow()+dayopen())/2;
K2=(J2+L2)/2;
신중심=(하양중심+k2)/2;
하중심=신중심-1.25;
2025-06-17
225
글번호 191278
지표
답변완료
수식 부탁드립니다
지표식 부탁드립니다.
//@version=5
indicator("JFKPS",
shorttitle="JFKPS",
overlay = false,
timeframe="",
timeframe_gaps = true)
import loxx/loxxjuriktools/1 as jf
greencolor = #2DD204
redcolor = #D2042D
pstLength = input.int(9, "Period", group = "Basic Settings")
pstX = input.int(5, "Synthetic Multiplier", group = "Basic Settings")
pstSmooth = input.int(3, "Stochasitc Smoothing Period", group = "Basic Settings")
smoothPeriod = input.int(10, "Jurik Smoothing Period", group = "Basic Settings")
jphs = input.float(0., "Jurik Phase", group = "Basic Settings")
colorbars = input.bool(true, "Color bars?", group = "UI Options")
showSigs = input.bool(true, "Show signals?", group = "UI Options")
lookBackPeriod = pstLength * pstX
alpha = 2.0 / (1.0 + pstSmooth)
TripleK = 0., TripleDF = 0., TripleDS = 0., TripleDSs = 0., TripleDFs = 0.
fmin = ta.lowest(low, lookBackPeriod)
fmax = ta.highest(high, lookBackPeriod) - fmin
if (fmax > 0)
TripleK := 100.0 * (close - fmin) / fmax
else
TripleK := 0.0
TripleDF := nz(TripleDF[pstX]) + alpha * (TripleK - nz(TripleDF[pstX]))
TripleDS := (nz(TripleDS[pstX]) * 2.0 + TripleDF) / 3.0
TripleDSs := ta.sma(TripleDS, 3)
pssBuffer = jf.jurik_filt(TripleDSs, smoothPeriod, jphs)
TripleDFs := ta.sma(TripleDF, 3)
pstBuffer = jf.jurik_filt(TripleDFs, smoothPeriod, jphs)
trend = 0
trend := nz(trend[1])
if (pstBuffer > pssBuffer)
trend := 1
if (pstBuffer < pssBuffer)
trend := -1
colorout = trend == 1 ? greencolor : trend == -1 ? redcolor : color.gray
plot(pssBuffer, color = color.white, linewidth = 1)
plot(pstBuffer, color = colorout, linewidth = 3)
barcolor(colorbars ? colorout : na)
goLong = ta.crossover(pstBuffer, pssBuffer)
goShort = ta.crossunder(pstBuffer, pssBuffer)
plotshape(showSigs and goLong, title = "Long", color = color.yellow, textcolor = color.yellow, text = "UP", style = shape.triangleup, location = location.bottom, size = size.tiny)
plotshape(showSigs and goShort, title = "Short", color = color.fuchsia, textcolor = color.fuchsia, text = "DW", style = shape.triangledown, location = location.top, size = size.tiny)
alertcondition(goLong, title = "Long", message = "Jurik-Filtered Kase Permission Stochastic [Loxx]: Long₩nSymbol: {{ticker}}₩nPrice: {{close}}")
alertcondition(goShort, title = "Short", message = "Jurik-Filtered Kase Permission Stochastic [Loxx]: Short₩nSymbol: {{ticker}}₩nPrice: {{close}}")
2025-05-29
284
글번호 191275
지표
답변완료
문의 드립니다.
안녕하세요
항상 감사드립니다.
아래의 서식에서 추가 사항 부탁드립니다.
*손절 조건 추가
1. 손절: 10pt 하락시 손절
2. 당일 손절 발생시 더 이상의 진입 금지
**조건 추가사항은 최적화를 할 수 있도록 input에 넣어주시기 바랍니다.
# KOSPI 선물 5분봉
input: 당일진입횟수(3);
Input: chkP(5), reChkP(10), stopChk(25);
var: HH(0), LL(0), BS(0), SS(0);
var: dayChk(0);
var : TotalCount(0),PreDay(0),DayEntry(0);
TotalCount = TotalTrades;
if Bdate != Bdate[1] Then
PreDay = TotalCount[1];
DayEntry = (TotalCount-PreDay)+IFF(MarketPosition != 0,1,0);
if BarIndex == 0 then ClearDebug();
if dayindex == chkP then
{
HH = Highest(Max(C,O), chkP+1);
LL = Lowest(Min(C,O), chkP+1);
#if date == 20240612 then messageLog("--HH %.2f, LL: %.2f", HH, LL);
}
#if High >= HH and MarketPosition == 0 and ExitDate(1) < Date and time > 93000 then messageLog("HH %.2f, High: %.2f", HH, High);
if DayIndex >= chkP
# and Time < 95000
and sDate == NextBarSdate
and EntryDate(0) < Date
and EntryDate(1) < Date
and DayEntry < 당일진입횟수
Then {
Buy("B1", AtStop, HH);
Sell("S1", AtStop, LL);
}
//if dayChk == 0 and High >= HH and MarketPosition == 0 and ExitDate(1) < Date and time > 93000 then {
// messageLog("HH %.2f, High: %.2f", HH, High);
// dayChk = 1;
//}
if ExitDate(1) == Date
and Time < 150000
// and LatestEntryName(1) != "B2"
// and LatestEntryName(1) != "S2"
// and LatestEntryName(0) != "B2"
// and LatestEntryName(0) != "S2"
Then
{
if DayIndex < reChkP Then
{
HH = Highest(Max(C,O), DayIndex+1);
LL = Lowest(Min(C,O), DayIndex+1);
}
Else
{
HH = Highest(Max(C,O), reChkP);
LL = Lowest(Min(C,O), reChkP);
}
if DayEntry < 당일진입횟수 Then
{
Buy("B2", AtStop, HH);
Sell("S2", AtStop, LL);
}
}
if (MarketPosition == 1) Then {
if DayIndex < stopChk Then {
BS = Lowest(Min(C,O), DayIndex+1);
}
Else {
BS = Lowest(Min(C,O), stopChk);
}
ExitLong("EL", AtStop, BS);
}
if (MarketPosition == -1) Then {
if DayIndex < stopChk Then {
SS = Highest(Max(C,O), DayIndex+1);
}
Else {
SS = Highest(Max(C,O), stopChk);
}
#messageLog(" SS %.2f", SS);
ExitShort("ES", AtStop, SS);
}
var : month(0),nday(0),week(0),X(False);
month = int(date/100)-int(date/10000)*100;
nday = date - int(date/100)*100;
Week = DayOfWeek(date);
#만기일
if (month%3 == 0 and nday >= 8 and nday <= 14 and week == 4) then
{
X = true;
SetStopEndofday(151500);
}
Else#만기일아닐때
{
X = False;
SetStopEndofday(152000);
}
2025-05-29
241
글번호 191263
지표