커뮤니티
수식 검증 부탁드립니다!!
2013-10-08 02:56:55
178
글번호 68211
안녕하세요. 아직 완전 초보 시스템트레이더입니다.
간단한 이평선 크로스 전략을 짜봤는데요.
수식을 맞게 썼는지 검증부탁드립니다.
전략:
1) 매수 진입
a) 9개 봉의 단기 이평선이 18개 봉의 장기 이평선을 상향 교차 시 이전 12개 봉의 최고가를 찾고 여기에 1.03을 곱한다. 이 값이 매수진입가격
b) 이동평균선 상향 교차가 나타나면 진입가에 buy stop 주문. 이 주문은 교차 이후 12개의 봉이 완성될때까지 유효
c) 만약 매수포지션을 가지고 있다가 매수 청산 규칙에 의해서 청산을 하였다면, 최근 10개 봉의 최고가에 buy stop주문을 걸고 청산 이후 15개 봉까지 이 주문이 유효하도록 한다.
2) 매도 진입
a)  9개 봉의 단기 이평선이 18개 봉의 장기 이평선을 하향 교차 시 이전 12개 봉의 최저가를 찾고 여기에 0.97을 곱한다. 이 값이 매도진입가격
b) 이동평균선 하향 교차가 나타나면 진입가에 sell stop 주문. 이 주문은 교차 이후 12개의 봉이 완성될때까지 유효
c) 만약 매도포지션을 가지고 있다가 매도 청산 규칙에 의해서 청산을 하였다면, 최근 10개 봉의 최저가에 sell stop주문을 걸고 청산 이후 15개 봉까지 이 주문이 유효하도록 한다.
3) 청산
a) 이전 8개 봉의 최저가에 도달하면 매수 포지션 청산
b) 이전 8개 봉의 최고가에 도달하면 매도 포지션 청산
수식:
Input : shortperiod(9), longperiod(18), chlen(12), trailbar(8), rebars(15) ;
vars: shortma(0), longma(0), lentryprice(0), sentryprice(0), lcnt(0), scnt(0), reentrycount(0), lstopprice(0), sstopprice(0), lreentryprice(0),sreentryprice(0);
shortma = ma(c, shortperiod);
longma = ma(c, longperiod);
##매수주문
if crossup(shortma, longma) and BarIndex > 1 then {
lentryprice=highest(h, chlen)*1.03;
lcnt=BarIndex;
}
if marketposition <> 1 and BarIndex < lcnt+chlen Then
buy("b",atstop,lentryprice,0);
##매도주문
if crossdown(shortma, longma) and BarIndex > 1 then {
sentryprice=lowest(l, chlen)[1]*0.97;
scnt=BarIndex;
}
if marketposition <> 1 and BarIndex < scnt+chlen Then
sell("s",atstop,sentryprice,0);
##trailing stop
if marketposition == 1 then {
lstopprice=lowest(l,trailbar);
exitlong("longstop",atlimit,lstopprice);
}
if marketposition == -1 then {
sstopprice=highest(h,trailbar);
exitshort("shortstop",atlimit,sstopprice);
}
##Reentry
if marketposition == 0 and marketposition[1] == -1 Then
reentrycount = 1;
if marketposition == 0 and marketposition[1] == 1 Then
reentrycount = 1;
if marketposition == 0 and marketposition[1] == 1 and reentrycount < rebars then {
reentrycount = reentrycount + 1;
lreentryprice=highest(h,10);
buy("long reentry",atstop,lreentryprice,0);
}
if marketposition == 0 and marketposition[1] == -1 and reentrycount < rebars then {
reentrycount = reentrycount + 1;
sreentryprice=lowest(l,10);
sell("short reentry",atstop,sreentryprice,0);
}
변수라든가, 수식의 순서라든가 이런게 맞는지 모르겠네요.
그리고 만약 이 조건에 덧붙여서 MACD Ocillator(종가,12,26,9,지수이평)지표를 추가해서 MACD Oci.가 0 이상일때만 매수, MACD Oci.가 0 이하일때만 매도 라는 조건을 붙인다면 수식이 어떻게 추가가 되는지도 궁금합니다.
감사합니다
답변 1
예스스탁 예스스탁 답변
2013-10-08 15:12:17
안녕하세요
예스스탁입니다.
식을 약간 수정했습니다.
1.
직전의 진입포지션은 marketposition(1)로 값을 가져와 확인하셔야 합니다.
marketposition[1]은 한봉전의 포지션상태입니다.
2. 청산이후의 봉수는 BarsSinceExit(1)으로 값을 불러와 사용하시면 됩니다.
3. 수정한 식입니다.
Input : shortperiod(9), longperiod(18), chlen(12), trailbar(8), rebars(15) ;
vars: shortma(0), longma(0), lentryprice(0), sentryprice(0), lcnt(0), scnt(0), reentrycount(0), lstopprice(0), sstopprice(0), lreentryprice(0),sreentryprice(0);
shortma = ma(c, shortperiod);
longma = ma(c, longperiod);
##매수주문
if crossup(shortma, longma) and BarIndex > 1 then {
lentryprice=highest(h, chlen)*1.03;
lcnt=BarIndex;
}
if marketposition <> 1 and BarIndex > 0 and BarIndex < lcnt+chlen Then
buy("b",atstop,lentryprice,0);
##매도주문
if crossdown(shortma, longma) and BarIndex > 1 then {
sentryprice=lowest(l, chlen)[1]*0.97;
scnt=BarIndex;
}
if marketposition <> 1 and BarIndex > 0 and BarIndex < scnt+chlen Then
sell("s",atstop,sentryprice,0);
##trailing stop
if marketposition == 1 then {
lstopprice=lowest(l,trailbar);
exitlong("longstop",atlimit,lstopprice);
}
if marketposition == -1 then {
sstopprice=highest(h,trailbar);
exitshort("shortstop",atlimit,sstopprice);
}
if marketposition == 0 and marketposition(1) == 1 and BarsSinceExit(1) < rebars then {
lreentryprice=highest(h,10);
buy("long reentry",atstop,lreentryprice);
}
if marketposition == 0 and marketposition(1) == -1 and BarsSinceExit(1) < rebars then {
sreentryprice=lowest(l,10);
sell("short reentry",atstop,sreentryprice);
}
4. MACD오실레이터 추가한 식입니다.
Input : shortperiod(9), longperiod(18), chlen(12), trailbar(8), rebars(15) ;
input : Short(12),long(26),Sig(9);
vars: shortma(0), longma(0), lentryprice(0), sentryprice(0), lcnt(0), scnt(0), reentrycount(0), lstopprice(0), sstopprice(0), lreentryprice(0),sreentryprice(0);
var : MACDOsc(0);
shortma = ma(c, shortperiod);
longma = ma(c, longperiod);
MACDOsc = MACD_OSC(Short,long,sig);
##매수주문
if crossup(shortma, longma) and BarIndex > 1 then {
lentryprice=highest(h, chlen)*1.03;
lcnt=BarIndex;
}
if marketposition <> 1 and BarIndex > 0 and BarIndex < lcnt+chlen and MACDOsc > 0 Then
buy("b",atstop,lentryprice,0);
##매도주문
if crossdown(shortma, longma) and BarIndex > 1 then {
sentryprice=lowest(l, chlen)[1]*0.97;
scnt=BarIndex;
}
if marketposition <> 1 and BarIndex > 0 and BarIndex < scnt+chlen and MACDOsc < 0 Then
sell("s",atstop,sentryprice,0);
##trailing stop
if marketposition == 1 then {
lstopprice=lowest(l,trailbar);
exitlong("longstop",atlimit,lstopprice);
}
if marketposition == -1 then {
sstopprice=highest(h,trailbar);
exitshort("shortstop",atlimit,sstopprice);
}
if marketposition == 0 and marketposition(1) == 1 and BarsSinceExit(1) < rebars and MACDOsc > 0 then {
lreentryprice=highest(h,10);
buy("long reentry",atstop,lreentryprice);
}
if marketposition == 0 and marketposition(1) == -1 and BarsSinceExit(1) < rebars and MACDOsc < 0 then {
sreentryprice=lowest(l,10);
sell("short reentry",atstop,sreentryprice);
}
즐거운 하루되세요
> jacobs 님이 쓴 글입니다.
> 제목 : 수식 검증 부탁드립니다!!
> 안녕하세요. 아직 완전 초보 시스템트레이더입니다.
간단한 이평선 크로스 전략을 짜봤는데요.
수식을 맞게 썼는지 검증부탁드립니다.
전략:
1) 매수 진입
a) 9개 봉의 단기 이평선이 18개 봉의 장기 이평선을 상향 교차 시 이전 12개 봉의 최고가를 찾고 여기에 1.03을 곱한다. 이 값이 매수진입가격
b) 이동평균선 상향 교차가 나타나면 진입가에 buy stop 주문. 이 주문은 교차 이후 12개의 봉이 완성될때까지 유효
c) 만약 매수포지션을 가지고 있다가 매수 청산 규칙에 의해서 청산을 하였다면, 최근 10개 봉의 최고가에 buy stop주문을 걸고 청산 이후 15개 봉까지 이 주문이 유효하도록 한다.
2) 매도 진입
a)  9개 봉의 단기 이평선이 18개 봉의 장기 이평선을 하향 교차 시 이전 12개 봉의 최저가를 찾고 여기에 0.97을 곱한다. 이 값이 매도진입가격
b) 이동평균선 하향 교차가 나타나면 진입가에 sell stop 주문. 이 주문은 교차 이후 12개의 봉이 완성될때까지 유효
c) 만약 매도포지션을 가지고 있다가 매도 청산 규칙에 의해서 청산을 하였다면, 최근 10개 봉의 최저가에 sell stop주문을 걸고 청산 이후 15개 봉까지 이 주문이 유효하도록 한다.
3) 청산
a) 이전 8개 봉의 최저가에 도달하면 매수 포지션 청산
b) 이전 8개 봉의 최고가에 도달하면 매도 포지션 청산
수식:
Input : shortperiod(9), longperiod(18), chlen(12), trailbar(8), rebars(15) ;
vars: shortma(0), longma(0), lentryprice(0), sentryprice(0), lcnt(0), scnt(0), reentrycount(0), lstopprice(0), sstopprice(0), lreentryprice(0),sreentryprice(0);
shortma = ma(c, shortperiod);
longma = ma(c, longperiod);
##매수주문
if crossup(shortma, longma) and BarIndex > 1 then {
lentryprice=highest(h, chlen)*1.03;
lcnt=BarIndex;
}
if marketposition <> 1 and BarIndex < lcnt+chlen Then
buy("b",atstop,lentryprice,0);
##매도주문
if crossdown(shortma, longma) and BarIndex > 1 then {
sentryprice=lowest(l, chlen)[1]*0.97;
scnt=BarIndex;
}
if marketposition <> 1 and BarIndex < scnt+chlen Then
sell("s",atstop,sentryprice,0);
##trailing stop
if marketposition == 1 then {
lstopprice=lowest(l,trailbar);
exitlong("longstop",atlimit,lstopprice);
}
if marketposition == -1 then {
sstopprice=highest(h,trailbar);
exitshort("shortstop",atlimit,sstopprice);
}
##Reentry
if marketposition == 0 and marketposition[1] == -1 Then
reentrycount = 1;
if marketposition == 0 and marketposition[1] == 1 Then
reentrycount = 1;
if marketposition == 0 and marketposition[1] == 1 and reentrycount < rebars then {
reentrycount = reentrycount + 1;
lreentryprice=highest(h,10);
buy("long reentry",atstop,lreentryprice,0);
}
if marketposition == 0 and marketposition[1] == -1 and reentrycount < rebars then {
reentrycount = reentrycount + 1;
sreentryprice=lowest(l,10);
sell("short reentry",atstop,sreentryprice,0);
}
변수라든가, 수식의 순서라든가 이런게 맞는지 모르겠네요.
그리고 만약 이 조건에 덧붙여서 MACD Ocillator(종가,12,26,9,지수이평)지표를 추가해서 MACD Oci.가 0 이상일때만 매수, MACD Oci.가 0 이하일때만 매도 라는 조건을 붙인다면 수식이 어떻게 추가가 되는지도 궁금합니다.
감사합니다
다음글
이전글