답변완료
부탁합니다.
아래 지표로 시스템식을 부탁합니다.
기본사항
: 투자금액을 100% 로 잡았을때 30%를 3회까지 분할매수
( 예: 1천만원일때 1회 3백만원씩 신호나올때마다 3회까지 매수 )
매수
1. 밴드의 중심선이 상승일때 and
2. 저점이 밴드 하단밖에 있을때 양봉이면 매수
청산
1. 시가가 밴드안에서 시작해서 양봉으로 상단밴드밖에서 종가일때 or
2. 익절 1% ~ (변수로 부탁합니다) or
3. 종가기준 3% 손절 ( 변수로 부탁합니다.) or
4. 매수후 중심선이 하락으로 바뀌면 본절청산
input : HalfLength(60);
input : PriceType(5);#1: Close, 2:Open, 3:High, 4:Low, 5:Median, 6:Typical, 7:Weighted, 8:Average
input : AtrPeriod(60);
input : AtrMultiplier(4);
input : TMAangle(2);
input : crossUpInput(false);
input : crossDownInput(false);
input : comingBackInput(false);
input : onArrowDownInput(false);
input : onArrowUpInput(false);
input : colorDOWN(red);
input : colorUP(green);
input : colorBands(Gray);
input : cautionInput(true);
Array : TX1[100](0),TX2[100](0),TX3[100](0);
var : cnt(0),price(0),colorBuffer(Nan);
var : asum(0),ATR(0),i(0),j(0);
var : sum(0),sumw(0),k(0),tmac(0),tmau(0),tmad(0);
var : pastTmac(nan),pastTmau(nan),pastTmad(Nan);
var : tmau_temp(nan),tmac_temp(Nan),tmad_temp(nan);
var : point(0),reboundD(0),reboundU(0),caution(0),last(False);
For cnt = 0 to 99
{
Text_Delete(TX1[cnt]);
Text_Delete(TX2[cnt]);
Text_Delete(TX3[cnt]);
}
if PriceType == 1 Then
Price = close;
Else if PriceType == 2 Then
Price = open;
Else if PriceType == 3 Then
Price = high;
Else if PriceType == 4 Then
Price = low;
Else if PriceType == 5 Then
Price = (high + low) / 2;
Else if PriceType == 6 Then
Price = (high + low + close) / 3;
Else if PriceType == 7 Then
Price = (high + low + close + close) / 4;
Else
Price = (high + low + close + open)/ 4;
//MAIN
for i = HalfLength downto 0
{
//ATR
asum = 0.0;
for j = 0 to AtrPeriod - 1
{
asum = asum + max(high[i + j + 10], close[i + j + 11]) - min(low[i + j + 10], close[i + j + 11]);
}
atr = asum/AtrPeriod;
//BANDS
sum = (HalfLength + 1) * Price[i];
sumw = (HalfLength + 1);
k = HalfLength;
for j = 1 to HalfLength
{
sum = sum + k * Price[i + j];
sumw = sumw + k;
if (j <= i) Then
{
sum = sum + k * Price[i - j];
sumw = sumw + k;
}
k = k -1;
}
tmac = sum/sumw;
tmau = tmac+AtrMultiplier*atr;
tmad = tmac-AtrMultiplier*atr;
//CHANGE TREND COLOR
if pastTmac != 0.0 Then
{
if tmac > pastTmac Then
colorBuffer = colorUP;
if tmac < pastTmac then
colorBuffer = colorDOWN;
}
//SIGNALS
reboundD = 0.0;
reboundU = 0.0;
caution = 0.0;
if pastTmac != 0.0 Then
{
if (high[i + 1] > pastTmau and close[i + 1] > open[i + 1] and close[i] < open[i]) Then
{
reboundD = high[i] + AtrMultiplier * atr / 2;
if (tmac - pastTmac > TMAangle * point) Then
{
caution = reboundD + 10 * point;
}
}
if (low[i + 1] < pastTmad and close[i + 1] < open[i + 1] and close[i] > open[i]) Then
{
reboundU = low[i] - AtrMultiplier * atr / 2;
if (pastTmac - tmac > TMAangle * point) then
{
caution = reboundU - 10 * point;
}
}
}
//LAST REAL
if i == HalfLength Then
{
last = true;
tmau_temp = tmau;
tmac_temp = tmac;
tmad_temp = tmad;
}
//DRAW HANDICAPPED BANDS
if i < HalfLength Then
{
TX1[i] = Text_New(NextBarSdate[i],NextBarStime[i],Tmau,"-");
Text_SetColor(TX1[i],colorBands);
Text_SetStyle(TX1[i],2,2);
TX2[i] = Text_New(NextBarSdate[i],NextBarStime[i],Tmac,"-");
Text_SetColor(TX2[i],colorBuffer);
Text_SetStyle(TX2[i],2,2);
TX3[i] = Text_New(NextBarSdate[i],NextBarStime[i],Tmad,"-");
Text_SetColor(TX3[i],colorBands);
Text_SetStyle(TX3[i],2,2);
}
}
//DRAW REAL BANDS
plot1(iff(last , tmau_temp , tmau), "TMA Up", colorBands);
plot2(iff(last , tmac_temp , tmac), "TMA Mid", colorBuffer);
plot3(iff(last , tmad_temp , tmad), "TMA Down", colorBands);
FixPlotShift(1,-HalfLength);
FixPlotShift(2,-HalfLength);
FixPlotShift(3,-HalfLength);
답변완료
수식변환 수정 요청
보완사항이 있어서 다시 글을 올립니다. 전화까지 주셨는데 이렇게 다시 글을 쓰게 되었네요.ㅠ
지난 질문에서 전일고가 라인 돌파와 함께, 현재가가 전일 변동폭(50%+금일시가) 라인 돌파, 현재가가 볼린저(60,2) 상단 돌파 하는 검색식을 만들고자 합니다. 단 현재가가 전일 고가 캔들의 저가 라인 위에 있어야만 한다고 했었습니다.
전일고가 라인 돌파와 함께라는 전제를 보완(조건 추가)하고 싶습니다.
주가가 전일 고가 캔들의 저가 라인 위에 있으면서(전제 조건)
->(1) 전일 고가 라인 돌파와 함께 변동폭 라인 돌파 또는 볼린저(602.2) 돌파 또는
->(2) 전일 고가 라인 아래에 있을 때(저가라인과 고가라인 중간에 위치) 변동폭 돌파 또는 볼린저(60.2) 돌파 또는
->(3) 전일 고가 라인 위에 있을 때 변동폭 돌파 또는 볼린저(60.2) 돌파
로 수정 보완 부탁 드립니다.
(1), (3)은 같은 유형의 조건이지만 분리해주시면 고맙겠습니다. 테스트를 통해 조건을 조정 해보고 싶습니다. 주석 처리 꼭 부탁드립니다.
기타 거래대금 10억 이상, 거래량 20만주 이상, RSI(11) 50 이상 또는 돌파, 전일 종가 대비 시가 등락율(갭상승) 3% 이하, 위 모든 조건들이 당일 시가 대비 당일 종가 등락율 7% 범위 안에 만족 시 검색 되도록 하는 것은 동일 합니다.
부탁드립니다.
=================================================================================
> 예스스탁 님이 쓴 글입니다.
> 제목 : Re : 수식변환 요청
>
안녕하세요
예스스탁입니다.
var : DHlow(0),DHlow1(0);
if sDate != sDate[1] then
DHlow1 = DHlow[1];
if h == DayHigh Then
DHlow = l;
var1 = dayopen + (DayHigh(1)-DayLow(1))*0.5;
var2 = BollBandUp(60,2);
var3 = (highest(H,26)+lowest(L,26))/2;
var4 = RSI(11);
Condition1 = CrossUp(C,DayHigh(1));
Condition2 = DHlow > 0 and C > DHlow;
Condition3 = CrossUp(c,var1);
Condition4 = CrossUp(C,var2);
Condition5 = CrossUp(C,var3);
Condition6 = money >= 1000000000;
Condition7 = Volume >= 200000;
Condition8 = var4 >= 55 or CrossUp(var4,55);
Condition9 = DayOpen <= DayClose(1)*1.03;
Condition10 = c <= DayOpen*1.05 and C >= DayOpen*0.95;
if Condition1 == true and
Condition2 == true and
Condition3 == true and
Condition4 == true and
Condition5 == true and
Condition6 == true and
Condition7 == true and
Condition8 == true and
Condition9 == true and
Condition10 == true Then
Find(1);
즐거운 하루되세요
=================================================================================
> saeroi 님이 쓴 글입니다.
> 제목 : 수식변환 요청
> 현재가 전일 고가 발생 시의 저가(즉, 전일 고가 캔들의 저가)라인과 전일 고가라인 사이에서 전일고가 라인 돌파와 함께, 현재가가 전일 변동폭(50%+금일시가) 라인 돌파, 현재가가 볼린저(60,2) 상단 돌파 하는 검색식을 만들고자 합니다. 단 현재가가 전일 고가 캔들의 저가 라인 위에 있어야만 합니다.
전일고가 라인 돌파
가=highestSince(1, date!=date(1), H);
Valuewhen(1, date!=date(1), 가(1));
현재가가 전일고가캔들이 저가 라인 위 위치
가=highestSince(1, date!=date(1), H);
나=Valuewhen(1, 가==H, L); Valuewhen(1, date!=date(1), 나(1));
변동폭 라인 돌파
가=dayhigh(1)-daylow(1);
나=dayopen()+A*0.5;
볼린저 (60,2) 상단 돌파
현재가가 일목균형표 기준선 돌파(3분 기준)
거래대금 10억 이상(3분 기준)
거래량 20만주 이상(3분 기준)
RSI(11) 55 이상 또는 돌파
전일 종가 대비 시가 등락율(갭상승) 3% 이하 상승만 허용
위 모든 조건들이 당일 시가 대비 당일 종가 등락율 5% 범위 안에 만족 시 검색
3분봉 단타용으로 검색 활용하고자 하니 이를 감안하여 수식 만들어 주시면 고맙겠습니다.
답변완료
종목검색식 부탁드립니다
1. 아래지표를 참고하여,
(수식2) "과매수" 를,
일봉기준으로 "5일중 2일이상"을 "과매수"하는 종목의 종목검색식 부탁드려요.
("몇일중 몇일이상" 은 변수로 처리해주세요)
----아래-------
(수식1) 매수
i_wvf = ((high - lowest(C, 22)) / lowest(C, 22)) * 100;
i_sDev = 2.0 * stdev(i_wvf, 20);
i_midLine = avg(i_wvf, 20);
i_upperBand = i_midLine + i_sDev;
i_rangeHigh = (highest(i_wvf, 50)) * ph;
i_wvf;
(수식2) 과매수
i_wvf = ((high - lowest(C, 22)) / lowest(C, 22)) * 100;
i_sDev = 2.0 * stdev(i_wvf, 20);
i_midLine = avg(i_wvf, 20);
i_upperBand = i_midLine + i_sDev;
i_rangeHigh = (highest(i_wvf, 50)) * ph;
if(i_wvf >= i_upperBand or i_wvf >= i_rangeHigh, i_wvf, 0);
(수식3) 과매수이탈
i_wvf = ((H - lowest(C, 22)) / lowest(C, 22)) * 100;
i_sDev = 2.0 * stdev(i_wvf, 20);
i_midLine = avg(i_wvf, 20);
i_upperBand = i_midLine + i_sDev;
i_rangeHigh = (highest(i_wvf, 50)) * ph;
ob = (i_wvf >= i_upperBand) or (i_wvf >= i_rangeHigh);
if(ob,1,0); //os : OverBuy
// 과매수 4회이상 연속후 이탈)
if( ((ob(1)>0 and ob(2)>0 and ob(3)>0 and ob(4)>0) and ob == 0), i_wvf, 0);
-지표조건설정
PH : 0.55
답변완료
부탁드립니다 항상 감사합니다
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(3)
# 1) 가상의 OHLC 데이터 만들기
n = 120
base = 100 + np.cumsum(np.random.randn(n)*0.6)
high = base + np.abs(np.random.randn(n)*0.5)
low = base - np.abs(np.random.randn(n)*0.5)
close = base.copy()
# 2) 파라미터
length = 14 # 채널 길이
len2 = 6 # Exit 단기 길이
def rolling_max(x, w, i):
s = max(0, i-w+1)
return np.max(x[s:i+1])
def rolling_min(x, w, i):
s = max(0, i-w+1)
return np.min(x[s:i+1])
upper = np.zeros(n)
lower = np.zeros(n)
up = np.zeros(n)
down = np.zeros(n)
sup = np.zeros(n)
sdown = np.zeros(n)
for i in range(n):
upper[i] = rolling_max(high, length, i)
lower[i] = rolling_min(low , length, i)
up[i] = rolling_max(high, length, i)
down[i] = rolling_min(low , length, i)
sup[i] = rolling_max(high, len2 , i)
sdown[i] = rolling_min(low , len2 , i)
# 3) Trend Line(K1): 최근 고점/저점 갱신 시점 비교
trend_line = np.zeros(n)
k2 = np.zeros(n) # Exit Line(K2)
last_high_idx = 0
last_low_idx = 0
for i in range(1, n):
# 최근 고점/저점 갱신 판정
if high[i] >= up[i-1]:
last_high_idx = i
if low[i] <= down[i-1]:
last_low_idx = i
# i 시점의 추세
up_trend = last_high_idx >= last_low_idx
# K1 선택: 상승이면 up, 하락이면 down
trend_line[i] = up[i] if up_trend else down[i]
# K2 선택: 상승이면 sdown(저점선=손절), 하락이면 sup(고점선=손절)
k2[i] = sdown[i] if up_trend else sup[i]
trend_line[0] = up[0]
k2[0] = sdown[0]
# 4) 신호 계산 (buy/sell) + 청산
buy_sig = np.zeros(n, dtype=bool)
sell_sig = np.zeros(n, dtype=bool)
buy_exit = np.zeros(n, dtype=bool)
sell_exit = np.zeros(n, dtype=bool)
for i in range(1, n):
# 채널 돌파 신호
buy_sig[i] = (high[i] >= upper[i-1]) and (high[i-1] < upper[i-1])
sell_sig[i] = (low[i] <= lower[i-1]) and (low[i-1] > lower[i-1])
# 추세에 따른 Exit 판정
up_trend = trend_line[i] == up[i] # 간단 판별
if up_trend:
buy_exit[i] = (low[i] <= sdown[i-1]) and (low[i-1] > sdown[i-1])
else:
sell_exit[i] = (high[i] >= sup[i-1]) and (high[i-1] < sup[i-1])
# 5) 시각화 (규정: seaborn 미사용, 단일 플롯, 색상 지정 안 함)
plt.figure(figsize=(13,6))
plt.plot(close, label="Price")
plt.plot(upper, label="Upper")
plt.plot(lower, label="Lower")
plt.plot(trend_line, label="Trend Line (K1)")
plt.plot(k2, label="Exit Line (K2)")
# 텍스트 라벨: '수' / '도' / '청'
for i in range(n):
if buy_sig[i]:
plt.text(i, low[i], "수")
if sell_sig[i]:
plt.text(i, high[i], "도")
if buy_exit[i]:
plt.text(i, low[i], "청")
if sell_exit[i]:
plt.text(i, high[i], "청")
plt.title("Trend Line (K1) + Exit Line (K2) + ‘수/도/청’ 신호 예시")
plt.xlabel("Bar Index")
plt.ylabel("Price")
plt.legend()
plt.grid(True)
plt.show()
전환부탁드립니다 감사합니다
답변완료
부탁드립니다 항상 감사합니다
{==========================================
Disparity Index + RSI (YesLanguage version)
- DI = 100 * (src - SMA(src,L)) / SMA(src,L)
- scaledDI = 20 * DI + 50
- RSI = Wilder RMA
- RSI MA/BB 옵션: 0=None, 1=SMA, 2=SMA+BB, 3=EMA, 4=RMA, 5=WMA, 6=VWMA
- Regular Bullish/Bearish Divergence (라벨)
==========================================}
{----------- Inputs -----------}
input: DI_Length(14);
input: DI_Source(1); { 1=Close, 2=Open, 3=High, 4=Low, 5=Typical(H+L+C)/3 }
input: RSI_Length(14);
{ RSI Smoothing / BB }
input: MA_Type(1); { 0=None, 1=SMA, 2=SMA+BB, 3=EMA, 4=RMA, 5=WMA, 6=VWMA }
input: MA_Len(14);
input: BB_Mult(2.0);
{ Divergence }
input: CalcDivergence(false);
input: LB_Left(5);
input: LB_Right(5);
input: RangeLower(5);
input: RangeUpper(60);
{ Colors }
input: DiUpColor(RGB(14,187,35)); { ≈ #0ebb23 }
input: DiDnColor(Red);
input: LevelColor(Gray);
input: RsiColor(RGB(126,87,194)); { ≈ #7E57C2 }
input: BBColor(Green);
input: BullColor(Green);
input: BearColor(Red);
{----------- Vars -----------}
vars:
srcVal(0), smaDI(0), di(0), scaledDi(0),
chg(0), up(0), dn(0), upRMA(0), dnRMA(0), rsi(0),
rsiMA(0), rsiStDev(0), rsiBB_Up(0), rsiBB_Dn(0),
bullCond(false), bearCond(false),
rsiPivotLow(0), rsiPrevPivotLow(0), pxPivotLow(0), pxPrevPivotLow(0),
rsiPivotHigh(0), rsiPrevPivotHigh(0), pxPivotHigh(0), pxPrevPivotHigh(0),
pivBarsL(0), pivBarsH(0),
lblBull(0), lblBear(0);
{----------- Source 선택 -----------}
if DI_Source = 1 then
srcVal = Close
else if DI_Source = 2 then
srcVal = Open
else if DI_Source = 3 then
srcVal = High
else if DI_Source = 4 then
srcVal = Low
else
srcVal = (High + Low + Close) / 3;
{----------- Disparity Index -----------}
smaDI = Average(srcVal, DI_Length);
if smaDI <> 0 then
di = 100 * (srcVal - smaDI) / smaDI
else
di = 0;
scaledDi = 20 * di + 50;
{ 색상 }
vars: diColor(0);
if scaledDi >= 50 then diColor = DiUpColor else diColor = DiDnColor;
Plot1(scaledDi, "Scaled DI", diColor);
Plot2(50, "DI 50", LevelColor);
{----------- RSI (Wilder RMA) -----------}
chg = Close - Close[1];
up = MaxList(chg, 0);
dn = MaxList(-chg, 0);
if CurrentBar = 1 then begin
upRMA = up;
dnRMA = dn;
end else begin
upRMA = (upRMA[1] * (RSI_Length - 1) + up) / RSI_Length;
dnRMA = (dnRMA[1] * (RSI_Length - 1) + dn) / RSI_Length;
end;
if dnRMA = 0 then
rsi = 100
else if upRMA = 0 then
rsi = 0
else
rsi = 100 - (100 / (1 + upRMA / dnRMA));
Plot3(rsi, "RSI", RsiColor);
{ RSI 레벨 라인: 70/60/50/40/30 }
Plot4(70, "RSI 70", LevelColor);
Plot5(60, "RSI 60", LevelColor);
Plot6(50, "RSI 50", LevelColor);
Plot7(40, "RSI 40", LevelColor);
Plot8(30, "RSI 30", LevelColor);
{----------- RSI Smoothing / BB -----------}
{ MA_Type: 0=None, 1=SMA, 2=SMA+BB, 3=EMA, 4=RMA, 5=WMA, 6=VWMA }
if MA_Type = 1 or MA_Type = 2 then
rsiMA = Average(rsi, MA_Len)
else if MA_Type = 3 then
rsiMA = XAverage(rsi, MA_Len)
else if MA_Type = 4 then begin
if CurrentBar = 1 then rsiMA = rsi
else rsiMA = (rsiMA[1] * (MA_Len - 1) + rsi) / MA_Len;
end
else if MA_Type = 5 then
rsiMA = WAverage(rsi, MA_Len)
else if MA_Type = 6 then
rsiMA = Summation(rsi * Volume, MA_Len) / Summation(Volume, MA_Len)
else
rsiMA = 0;
if MA_Type >= 1 then
Plot9(rsiMA, "RSI_MA", Yellow);
if MA_Type = 2 then begin
rsiStDev = StdDev(rsi, MA_Len);
rsiBB_Up = rsiMA + rsiStDev * BB_Mult;
rsiBB_Dn = rsiMA - rsiStDev * BB_Mult;
Plot10(rsiBB_Up, "RSI_BB_Up", BBColor);
Plot11(rsiBB_Dn, "RSI_BB_Dn", BBColor);
end;
{----------- Regular Divergence -----------}
if CalcDivergence then begin
{ RSI Pivot Low }
if SwingLow(rsi, LB_Left, LB_Right, pivBarsL) then begin
rsiPivotLow = rsi[pivBarsL];
pxPivotLow = Low[LB_Right];
bullCond = (rsiPrevPivotLow <> 0) and (pxPrevPivotLow <> 0)
and (pxPivotLow < pxPrevPivotLow) { Price LL }
and (rsiPivotLow > rsiPrevPivotLow) { RSI HL }
and (pivBarsL >= RangeLower and pivBarsL <= RangeUpper);
if bullCond then begin
lblBull = Text_New(sDate[LB_Right], sTime[LB_Right], rsiPivotLow, " Bull ");
Text_SetStyle(lblBull, 2, 0);
Text_SetColor(lblBull, BullColor);
end;
rsiPrevPivotLow = rsiPivotLow;
pxPrevPivotLow = pxPivotLow;
end;
{ RSI Pivot High }
if SwingHigh(rsi, LB_Left, LB_Right, pivBarsH) then begin
rsiPivotHigh = rsi[pivBarsH];
pxPivotHigh = High[LB_Right];
bearCond = (rsiPrevPivotHigh <> 0) and (pxPrevPivotHigh <> 0)
and (pxPivotHigh > pxPrevPivotHigh) { Price HH }
and (rsiPivotHigh < rsiPrevPivotHigh) { RSI LH }
and (pivBarsH >= RangeLower and pivBarsH <= RangeUpper);
if bearCond then begin
lblBear = Text_New(sDate[LB_Right], sTime[LB_Right], rsiPivotHigh, " Bear ");
Text_SetStyle(lblBear, 2, 1);
Text_SetColor(lblBear, BearColor);
end;
rsiPrevPivotHigh = rsiPivotHigh;
pxPrevPivotHigh = pxPivotHigh;
end;
end;
수정부탁드립니다