답변완료
질문 있습니다.
안녕하세요!답변 덕분에 해결이 되었지만특정 시간대 진입 거래만 누적 손익 계산이 잘 안되서 도움 요청합니다. ㅠㅠ제가 원하는 것은예를 들어서 특정 시간대(예: 7시~21시)에 진입한 거래의 누적 손익만 별도로 계산하고 싶습니다.=== 현재 시도한 방법 ===Input : StartHour(7), EndHour(21);var : TradingPL(0), InTimeEntry(0), SignalHour(0);// 신호 발생 시 시간 기록if 매수신호 Then { SignalHour = CurrentHour; if SignalHour >= StartHour and SignalHour < EndHour Then InTimeEntry = 1; Else InTimeEntry = 0;}// 진입 (다음 봉)if 신호[1] == 1 Then { Buy();}// 청산 시 누적if TotalTrades > TotalTrades[1] Then { if InTimeEntry[1] == 1 Then { TradingPL = TradingPL[1] + (NetProfit - NetProfit[1]) / PriceScale; }}// 22시 누적수익 표시 (EndHour + 1)if CurrentHour == 22 and CurrentHour != CurrentHour[1] Then { Text_New(sDate, sTime, H + 2.0, NumToStr(TradingPL, 0) + "T");}// 영업일 변경if Bdate != Bdate[1] Then { TradingPL = 0;}=== 문제 상황 ===실제 거래 (7시~21시 진입):- 9시 진입 → 11시 청산 +25틱- 13시 진입 → 15시 청산 -18틱 - 17시 진입 → 19시 청산 +67틱- 20시 진입 → 22시 청산 -12틱합계: +62틱하지만 22시 표시 결과: 3틱 또는 부정확한 값!! (이것 때문에 미치겠습니다. ㅠㅠ)=== 질문 ===1. 변수 InTimeEntry가 청산 시점까지 제대로 유지되나요? (신호 → 진입 → 청산 과정에서 [1] 참조의 타이밍 문제?)2. TradingPL 누적 방식이 올바른가요? 매 봉마다 TradingPL = TradingPL[1]로 상태 유지가 필요한가요?3. 특정 시간대 진입 거래만 필터링하여 누적 손익을 계산하는 표준적인 방법이 있을까요?바쁘신데 감사합니다. ㅠㅠ
2025-10-23
131
글번호 227224
시스템
답변완료
검색식 요청 드립니다.
안녕하세요항상 빠른 답변 감사 드립니다.아래 식을 종목 검색식으로 요청 드립니다.그럼 좋은 하루 되세요// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/// © LuxAlgo//@version=5indicator("Range Detector [LuxAlgo]", "LuxAlgo - Range Detector", overlay = true, max_boxes_count = 500, max_lines_count = 500)//------------------------------------------------------------------------------//Settings//-----------------------------------------------------------------------------{length = input.int(20, 'Minimum Range Length', minval = 2)mult = input.float(1., 'Range Width', minval = 0, step = 0.1)atrLen = input.int(500, 'ATR Length', minval = 1)//StyleupCss = input(#089981, 'Broken Upward', group = 'Style')dnCss = input(#f23645, 'Broken Downward', group = 'Style')unbrokenCss = input(#2157f3, 'Unbroken', group = 'Style')//-----------------------------------------------------------------------------}//Detect and highlight ranges//-----------------------------------------------------------------------------{//Ranges drawingsvar box bx = navar line lvl = na//Extensionsvar float max = navar float min = navar os = 0color detect_css = nan = bar_indexatr = ta.atr(atrLen) * multma = ta.sma(close, length)count = 0for i = 0 to length-1 count += math.abs(close[i] - ma) > atr ? 1 : 0if count == 0 and count[1] != count //Test for overlap and change coordinates if n[length] <= bx.get_right() max := math.max(ma + atr, bx.get_top()) min := math.min(ma - atr, bx.get_bottom()) //Box new coordinates bx.set_top(max) bx.set_rightbottom(n, min) bx.set_bgcolor(color.new(unbrokenCss, 80)) //Line new coordinates avg = math.avg(max, min) lvl.set_y1(avg) lvl.set_xy2(n, avg) lvl.set_color(unbrokenCss) else max := ma + atr min := ma - atr //Set new box and level bx := box.new(n[length], ma + atr, n, ma - atr, na , bgcolor = color.new(unbrokenCss, 80)) lvl := line.new(n[length], ma, n, ma , color = unbrokenCss , style = line.style_dotted) detect_css := color.new(color.gray, 80) os := 0else if count == 0 bx.set_right(n) lvl.set_x2(n)//Set colorif close > bx.get_top() bx.set_bgcolor(color.new(upCss, 80)) lvl.set_color(upCss) os := 1else if close < bx.get_bottom() bx.set_bgcolor(color.new(dnCss, 80)) lvl.set_color(dnCss) os := -1//-----------------------------------------------------------------------------}//Plots//-----------------------------------------------------------------------------{//Range detection bgcolorbgcolor(detect_css)plot(max, 'Range Top' , max != max[1] ? na : os == 0 ? unbrokenCss : os == 1 ? upCss : dnCss)plot(min, 'Range Bottom' , min != min[1] ? na : os == 0 ? unbrokenCss : os == 1 ? upCss : dnCss)//-----------------------------------------------------------------------------}
2025-10-23
117
글번호 227223
종목검색
답변완료
종목검색식 부탁드립니다
Inputs:
N(14), // 14일 최고가 계산
FlatLookback(10), // 횡보 탐지 기간 (현재는 사용하지 않음)
FlatThreshold(1), // 횡보 변동폭 (%)
Lookback(10), // AVWAP 계산 기준 (10봉)
ShortLen(10), // 변화율 비교용 기간 (최근 10봉)
Tolerance(0.009); // -0.9% 기준 (0.9% 이상 하락 시 점 표시)
Vars:
i(0), j(0),
searchLen(0),
maxVol(-1),
anchorAgo(-1),
anchorBar(0),
sumsrc(0),
sumvol(0),
avwap(0),
src(0),
src_j(0),
cnt(0),
hh(0), LL(0),
avwapHigh(0),
avwapLow(9999999),
avgAVWAP(0),
changeRatio(0),
isDown(False);
// 현재 봉 가격 소스
src = (H + L + C) / 3;
// 검색 길이 결정
If CurrentBar > Lookback Then
Begin
searchLen = Lookback;
End
Else
Begin
searchLen = CurrentBar;
End;
// 최근 최대 거래량 봉 찾기
maxVol = -1;
anchorAgo = -1;
For i = 0 To searchLen - 1 Begin
If V[i] > maxVol Then Begin
maxVol = V[i];
anchorAgo = i;
End;
End;
anchorBar = CurrentBar - anchorAgo;
If anchorAgo < 0 Then anchorBar = -1;
// AVWAP 계산
If anchorAgo >= 0 Then Begin
sumsrc = 0;
sumvol = 0;
For j = anchorAgo Downto 0 Begin
src_j = (H[j] + L[j] + C[j]) / 3;
sumsrc = sumsrc + src_j * V[j];
sumvol = sumvol + V[j];
End;
If sumvol > 0 Then Begin
avwap = sumsrc / sumvol;
Plot3(avwap, "AVWAP");
// 최근 10봉 평균 대비 변화율 계산
If CurrentBar > ShortLen Then Begin
avgAVWAP = Average(Plot3, ShortLen); // 최근 10봉 평균
changeRatio = (avwap - avgAVWAP) / avgAVWAP;
// -0.9% 이상 하락 시 점 표시
isDown = changeRatio < -Tolerance;
If isDown Then Begin
Plot5(avwap, "AVWAP 하락점");
End
Else Begin
NoPlot(5);
End;
End;
End;
End;
질문:
위종목 검색식에서 현재값이 plot3 값을 5봉이내 1회 crossup 하는 종목을 검색하고 싶습니다.
단 plot5가 발동되는 시점의 crossup은 무시(제외)하고 싶어요
일목균형
2025-10-23
138
글번호 227214
종목검색