답변완료
수정부탁드립니다.
안녕하세요?
아래 세가지 수식 모두 동일하게 수정부탁드려요.
현재 스위칭은 매매횟수에 포함이 되지않습니다.
이부분을 매매횟수에 포함을시켜서 지정한 매매횟수만큼만 딱 될수있게 부탁드립니다.
감사합니다.
[1]
input : 매수전봉양봉틱수(5),매수현재양봉틱수(5);
input : 매도전봉음봉틱수(5),매도현재음봉틱수(5);
input : 진입횟수(5);
input : 익절틱수(50),손절틱수(50);
var : entry(0);
if bdate != bdate[1] Then
entry = 0;
if MarketPosition != 0 and MarketPosition != MarketPosition[1] Then
entry = entry+1;
if entry < 진입횟수 and
bdate == bdate[1] and
MarketPosition == 0 and
C[1] == O[1]-매도전봉음봉틱수*PriceScale and
C[0] == O[0]-매도현재음봉틱수*PriceScale Then
sell("s");
if entry < 진입횟수 and
bdate == bdate[1] and
MarketPosition == 0 and
C[1] == O[1]+매수전봉양봉틱수*PriceScale and
C[0] == O[0]+매수현재양봉틱수*PriceScale Then
buy("b");
if MarketPosition == 1 Then
sell("bs",AtStop,EntryPrice-PriceScale*손절틱수);
if MarketPosition == -1 Then
buy("sb",AtStop,EntryPrice+PriceScale*손절틱수);
SetStopProfittarget(PriceScale*익절틱수,PointStop);
[2]
input : 매수전봉양봉틱수(5),매수현재양봉틱수(5);
input : 매도전봉음봉틱수(5),매도현재음봉틱수(5);
input : 진입횟수(5);
input : 익절틱수(50),손절틱수(4);
input : P1(5),P2(20);
var : entry(0),mav1(0),mav2(0),T1(0);
mav1 = ma(C,P1);
mav2 = ma(C,P2);
#영업일 변경
if bdate != bdate[1] Then
{
T1 = TotalTrades;
}
if MarketPosition == 0 Then
entry = TotalTrades-T1;
Else
entry = TotalTrades-T1+1;
if mav1 > mav2 and #정배열
entry < 진입횟수 and #진입횟수가 지정한 값 이하
bdate == bdate[1] and
MarketPosition == 0 and #매수나 무포지션 상태
C[1] == O[1]-매도전봉음봉틱수*PriceScale and
C[0] == O[0]-매도현재음봉틱수*PriceScale Then
{
sell("s");
if entry < 진입횟수-1 then
buy("bs1",AtStop,C+PriceScale*4);
Else
ExitShort("sx1",AtStop,C+PriceScale*4);
}
if mav1 < mav2 and #역배열
entry < 진입횟수 and #진입횟수가 지정한 값 이하
bdate == bdate[1] and
MarketPosition == 0 and #매도나 무포지션 상태
C[1] == O[1]+매수전봉양봉틱수*PriceScale and
C[0] == O[0]+매수현재양봉틱수*PriceScale Then
{
buy("b");
if entry < 진입횟수-1 Then
sell("sb1",AtStop,C-PriceScale*4);
Else
ExitShort("bx1",AtStop,C-PriceScale*4);
}
#매수진입 후 손절되면 매도로 스위칭
if MarketPosition == 1 Then
{
if entry < 진입횟수 Then
sell("bs",AtStop,EntryPrice-PriceScale*손절틱수);
Else
ExitLong("bsx",AtStop,EntryPrice-PriceScale*손절틱수);
}
#매도진입 후 손절되면 매수로 스위칭
if MarketPosition == -1 and entry < 진입횟수 Then
{
if entry < 진입횟수 Then
buy("sb",AtStop,EntryPrice+PriceScale*손절틱수);
Else
ExitShort("sbx",AtStop,EntryPrice+PriceScale*손절틱수);
}
#목표수익 설정
SetStopProfittarget(PriceScale*익절틱수,PointStop);
[3]
input : 매수전봉양봉틱수(5),매수현재양봉틱수(5);
input : 매도전봉음봉틱수(5),매도현재음봉틱수(5);
input : 진입횟수(5);
input : 익절틱수(50),손절틱수(4);
input : P1(5),P2(20);
var : entry(0),mav1(0),mav2(0),T1(0);
mav1 = ma(C,P1);
mav2 = ma(C,P2);
#영업일 변경
if bdate != bdate[1] Then
{
T1 = TotalTrades;
}
if MarketPosition == 0 Then
entry = TotalTrades-T1;
Else
entry = TotalTrades-T1+1;
if mav1 < mav2 and #역배열
entry < 진입횟수 and #진입횟수가 지정한 값 이하
bdate == bdate[1] and
MarketPosition == 0 and #매수나 무포지션 상태
C[1] == O[1]-매도전봉음봉틱수*PriceScale and
C[0] == O[0]-매도현재음봉틱수*PriceScale Then
{
sell("s");
if entry < 진입횟수-1 then
buy("bs1",AtStop,C+PriceScale*4);
Else
ExitShort("sx1",AtStop,C+PriceScale*4);
}
if mav1 > mav2 and #정배열
entry < 진입횟수 and #진입횟수가 지정한 값 이하
bdate == bdate[1] and
MarketPosition == 0 and #매도나 무포지션 상태
C[1] == O[1]+매수전봉양봉틱수*PriceScale and
C[0] == O[0]+매수현재양봉틱수*PriceScale Then
{
buy("b");
if entry < 진입횟수-1 Then
sell("sb1",AtStop,C-PriceScale*4);
Else
ExitShort("bx1",AtStop,C-PriceScale*4);
}
#매수진입 후 손절되면 매도로 스위칭
if MarketPosition == 1 Then
{
if entry < 진입횟수 Then
sell("bs",AtStop,EntryPrice-PriceScale*손절틱수);
Else
ExitLong("bsx",AtStop,EntryPrice-PriceScale*손절틱수);
}
#매도진입 후 손절되면 매수로 스위칭
if MarketPosition == -1 and entry < 진입횟수 Then
{
if entry < 진입횟수 Then
buy("sb",AtStop,EntryPrice+PriceScale*손절틱수);
Else
ExitShort("sbx",AtStop,EntryPrice+PriceScale*손절틱수);
}
#목표수익 설정
SetStopProfittarget(PriceScale*익절틱수,PointStop);
2020-03-31
580
글번호 137403
시스템
답변완료
함수 사용 문의드립니다.
수고하십니다.
다른 함수값을 동시에 읽어오고 싶은데, 잘 안되서 글을 쓰게되었네요.
------------------------------------------
func_test 함수
------------------------------------------
inputs : num(Numeric);
var1 = cci(num);
var2 = rsi(num);
func_test = NumToStr(var1,2) + " " + NumToStr(var2,2);
------------------------------------------
------------------------------------------
호출 시스템
------------------------------------------
var : num(0), r_str("");
if ((Date == 20200330) && (Time == 141500)) then
Begin
r_str = func_test(9);
MessageLog( r_str );
buy();
end;
------------------------------------------
예를 들어 위와 같이, 사용자정의 함수를 func_test 로 만들었다고 가정할때에
cci 값과 rsi값을 리턴하게 됩니다.
그런데 문제가 있습니다,
이전봉의 CCI값을 가져오려면 CCI[1] [2] ... 이런식으로 번호를 붙이게 되는데
사용자 함수 호출에는 이것이 안먹히는것 같습니다,.
func_test(9)[1] 이와같이 호출하면 아래와 같은 오류가 나옵니다.
"프로그램오류 : 아직 컴파일되지 않았거나, 실행코드가 없습니다."
리턴값을 스트링으로 한 이유는 : 여러값을 받기위함입니다. 구분자로 분리.. (return ex : 123+456+789)
여러개의 값을 받는 부분은 배열을 써 봤지만, 배열을 써도 [0] 값만 불러오지 [1] [2] 값에는.. [0]값이 불러와집니다.
input : arr[n](NumericArrayRef); 을 이용..
정리하자면,
1. 사용자함수를 만들때에 한번 호출시, 여러개의 리턴값을 받고싶다. (rsi cci 등..)
2. 사용자함수 호출시, 인덱스 봉을 [0] [1] [2] 이런식으로 지정하여, 해당되는 값을 불러오고 싶다.
만약, 위의 예제로 예를 든다면 func_test(9)[2] 호출하면 현재봉 -2 의 값의 CCI, RSI 값을 리턴 받고 싶습니다.
도움을 부탁드립니다.
2020-03-31
566
글번호 137402
사용자 함수
답변완료
알려주신 수식(매수버전)을 매도 버전으로 변경했는데... 수식에는 이상이 없다고 나?
알려주신 수식(매수버전)을 매도 버전으로 제가 임의로 변경해 보았는데 ...
수식에는 이상이 없다고 나오는데 거래이력이 나오질 않네요...
어떤것을 바꿨냐면
buySetup --> sellSetup
data2(c>sarv) --> data2(c<sarv)
변경하였는데...또 바꿀게 있나요?
사용은 하고 있는데 잘모르겠어요..맞게 사용하고 있는지..ㅠㅠ
Input : RSIPeriod(7),RSI매수값(65),SimPeriod(7),심리도값(45);
Input : N1(1),초기화(7);
Input : CCI기간(20),CCI값(400);
Input : 하락틱수(5);
Input : 즉시익절1(180),즉시손절1(60);
Input : 분할매수횟수(1),분할매수틱수(50);
Input : RSIPeriod1(8),A(40),B(25);
Input : N2(0.6),N3(0.02);
Input : tr수익(150),tr하락(25);
Input : 거래량1(0),거래량2(14000);
Input : 저점손절틱수(0);
Input : N4(0.6);
Input : 본전생각틱(32);
input : af(0.02),maxaf(0.2);
var : BBup(0,data1),cond1(false,data1),cond2(false,data1),v1(0,data1),v2(0,data1);
var : cnt(0,data1),SigSum(0,data1),count2(0,data1),RSIsig(0,data1);
Var : Counter(0,data1), DownAmt(0,data1), UpAmt(0,data1), UpSum(0,data1), DownSum(0,data1), UpAvg(0,data1), DownAvg(0,data1);
var : idx(0,data1), PreUpAvg(0,data1), preDownAvg(0,data1),RSIVv(0,data1);
var : CCIv(0,data1),RSIv(0,data1),Simri(0,data1),sellSetup(false,data1),DD(0,data1),entry(0,data1);
var : sarv(0,data2);
Array : C1[100](0,data1);
CCIv = data1(CCI(CCI기간));
RSIV = data1(RSI(RSIPeriod));
Simri = data1(Simrido(SimPeriod));
sarv = data2(sar(af,maxaf));
if Bdate != Bdate[1] Then
{
for cnt = 1 to 99
{
C1[cnt] = C1[cnt-1][1];
}
PreUpAvg = UpAvg[1];
preDownAvg = DownAvg[1];
idx = idx + 1;
}
C1[0] = C;
If idx == RSIPeriod1+2 Then
{
UpSum = 0;
DownSum = 0;
For Counter = 0 To RSIPeriod1 - 1
{
UpAmt = C1[Counter] - C1[Counter+1];
If UpAmt >= 0 Then
DownAmt = 0;
Else
{
DownAmt = -UpAmt;
UpAmt = 0;
}
UpSum = UpSum + UpAmt;
DownSum = DownSum + DownAmt;
}
UpAvg = UpSum / RSIPeriod1;
DownAvg = DownSum / RSIPeriod1;
}
If idx > RSIPeriod1+2 Then
{
UpAmt = C1[0] - C1[1];
If UpAmt >= 0 Then
DownAmt = 0;
Else
{
DownAmt = -UpAmt;
UpAmt = 0;
}
UpAvg = (PreUpAvg * (RSIPeriod1 - 1) + UpAmt) / RSIPeriod1;
DownAvg = (preDownAvg * (RSIPeriod1 - 1) + DownAmt) / RSIPeriod1;
}
If UpAvg + DownAvg <> 0 Then
RSIvv = 100 * UpAvg / (UpAvg + DownAvg);
Else
RSIvv = 0;
if data1(bdate != bdate[1]) Then
{
Entry = 0;
Cond2 = true;
}
if MarketPosition != 0 and MarketPosition != MarketPosition[1] Then
entry = entry+1;
if TotalTrades > TotalTrades[1] and
(IsExitName("즉시손절1",1) == true or IsExitName("본전청산1",1)) then
Condition2 = false;
Condition1 = RSIv > RSI매수값 and Simri > 심리도값 and RSIVV < A and RSIVV > B and v > 거래량1 and v < 거래량2 ;
if bdate != bdate[1] Then
{
DD = DD+1;
if var2 > 0 and DD == var2+초기화 Then
SellSetup = false;
}
if SellSetup == false and Condition1 == true and Condition1[1] == false Then
{
v1 = data1(C);
v2 = DD;
SellSetup = true;
}
if Condition2 == true and MarketPosition == 0 and SellSetup == true and C > O and entry == 0 and data2(c<sarv) Then
sell("매도",AtStop,var1+PriceScale*하락틱수);
2020-03-31
559
글번호 137401
시스템
답변완료
수식수정부탁드립니다
Input:Period1(17),Period2(17),Period3(17),n1(0),n2(0),n3(0), multi1(1),multi2(2),multi3(2);
Var:기울기1(0),절편1(0),회귀선1(0),회귀선tmp(0),
기울기2(0),절편2(0),회귀선2(0),
기울기3(0),절편3(0),회귀선3(0),
채널폭(0),j(0),표준오차(0),표준편차(0);
Var : nn1(0),xx1(0),yy1(0),Intercept1(0);
Var : nn2(0),xx2(0),yy2(0),Intercept2(0);
Var : nn3(0),xx3(0),yy3(0),Intercept3(0);
var: y4(0),x4(0),n4(0),j4(0),∑y(0),∑y²(0),∑x(0),∑x²(0),∑xy(0),StdErr(0);
nn1 = Period1;
xx1 = Index;
yy1 = c;
Intercept1 = ma(yy1,nn1) - (ma(xx1*yy1, nn1) - ma(xx1,nn1) * ma(yy1,nn1)) /
(ma(xx1^2,nn1) - (ma(xx1,nn1)^2)) * ma(xx1,nn1);
nn2 = Period2;
xx2 = Index;
yy2 = c;
Intercept2 = ma(yy2,nn2) - (ma(xx2*yy2, nn2) - ma(xx2,nn2) * ma(yy2,nn2)) /
(ma(xx2^2,nn2) - (ma(xx2,nn2)^2)) * ma(xx2,nn2);
nn3 = Period2;
xx3 = Index;
yy3 = c;
Intercept3 = ma(yy3,nn3) - (ma(xx3*yy3, nn3) - ma(xx3,nn3) * ma(yy3,nn3)) /
(ma(xx3^2,nn3) - (ma(xx3,nn3)^2)) * ma(xx3,nn3);
y4 = c;
n4 = Period2;
∑y = accumN(y4,n4);
∑y² = accumN(y4^2,n4);
∑x = 0;
∑x² = 0;
∑xy = 0;
for j4 = 1 to n4{
∑x = ∑x + j4;
∑x² = ∑x² + j4^2;
∑xy = ∑xy + (j4 * y4[n4-j4]);
}
StdErr = sqrt(1/(n4*(n4-2)) * (n4*∑y² - ∑y^2 - (n4*∑xy - ∑x*∑y)^2 / (n4*∑x² - ∑x^2)));
기울기1 = LRS(C, Period1)[n1];
절편1 = Intercept1[n1];
회귀선1 = 기울기1 * Index + 절편1;
채널폭 = 0;
for j = n1 to Period1 + n1 - 1 {
회귀선tmp = 기울기1 * Index[j] + 절편1;
채널폭 = max(채널폭,max(abs(H[j] - 회귀선tmp),abs(회귀선tmp - L[j])));
}
기울기2 = LRS(C, Period2)[n2];
절편2 = intercept2[n2];
회귀선2 = 기울기2 * Index + 절편2;
표준오차 = StdErr[n2];
기울기3 = LRS(C, Period3)[n3];
절편3 = intercept3[n3];
회귀선3 = 기울기3 * Index + 절편3;
표준편차 = STD(C,Period3)[n3];
value1=기울기3;
value2=절편3;
상기수식을 지표수식(라인 혹은 오실레이터)으로 부탁드립니다.
2020-03-31
856
글번호 137399
지표
답변완료
문의 드립니다.
안녕하세요
항상 빠른 답변 감사드립니다.
오전에 전화 문의 드렸던
하루에 한번만 시스템 매수식이 작동하는 진입회수에 관한 문의들 드린바
아래와 같이 시스템식에 , 1%로스컷 설정을 적용 하였으나
제대로 적용이 안되어 재차 문의 드립니다.
1분봉상 가비아 1분봉에 적용하여 두번의 매수진입과 손절이 발생하였습니다.
그럼 좋은 하루 되세요
#당일진입횟수 카운트
var : entry(0);
if bdate != bdate[1] Then
entry = 0;
if MarketPosition != 0 and MarketPosition != MarketPosition[1] Then
entry = entry+1;
Input : 투입금액(10000000);
Var : 진입수량(0);
진입수량 = int(투입금액/C);
##################################################################################################
var : bbup1(0),bbup2(0);
var : bbdn1(0),bbdn2(0);
var : mav1(0),mav2(0),mav3(0);
bbup1 = BollBandUp(20,1);
bbdn1 = BollBandDown(20,1);
bbup2 = BollBandUp(20,2);
bbdn2 = BollBandDown(20,2);
mav1 = ma(C,1);
mav2 = ma(C,5);
mav3 = ma(c,240);
##################################################################################################
If CrossUp(C, DayOpen) && CountIF(H < DayOpen,5) > 0 && (C > ma(c,240)*0.95 or C < ma(c,240)*1.05) && (C < DayClose(1)*1.20) &&
MarketPosition == 0 and entry < 1 && mav3[1] <= mav3 && CurrentDate == sDate Then
buy("시초돌파",OnClose,def,진입수량);
##################################################################################################
if mav1 > mav2 and
C >= bbup1 and
bbup2 > c and C > bbdn2 and
countif(crossup(c,bbup2),5) >= 1 && Condition1 == false && (C < DayClose(1)*1.25) &&
MarketPosition == 0 and entry < 1 && CurrentDate == sDate then
buy("눌림",OnClose,def,진입수량);
##################################################################################################
If CurrentContracts == MaxContracts
&& C >= EntryPrice*1.05 // 1%이상
Then
ExitLong("5%일부익절",OnClose,def,"",int(MaxContracts*(40/100)),2);
If CurrentContracts == MaxContracts
&& C >= EntryPrice*1.10 // 1%이상
Then
ExitLong("10%일부익절",OnClose,def,"",int(MaxContracts*(40/100)),2);
If CurrentContracts == MaxContracts
&& C >= EntryPrice*1.15 // 1%이상
Then
ExitLong("15%일부익절",OnClose,def,"",int(MaxContracts*(40/100)),2);
If sTime > 150500 Then ExitLong("장마감",atlimit,def);
##################################################################################################
var : 상한가(0), UpLimit(0);
var : up1(0), up2(0), up3(0), up4(0), up5(0),up6(0),Up7(0);
if date >= 19981207 then {
if date < 20050328 && CodeCategory() == 2 then
UpLimit = (BP[0] * 1.12);
Else if date >= 20050328 and date < 20150615 Then
UpLimit = (BP[0] * 1.15);
Else
UpLimit = (BP[0] * 1.30);
if CodeCategory() == 2 then
{
if date >= 20030721 then
{
up1 = int(UpLimit/100+0.00001)*100;
up2 = int(UpLimit/100+0.00001)*100;
up3 = int(UpLimit/100+0.00001)*100;
up4 = int(UpLimit/50+0.00001)*50;
up5 = int(UpLimit/10+0.00001)*10;
up6 = int(UpLimit/5+0.00001)*5;
up7 = int(UpLimit/1+0.00001)*1;
}
else
{
up1 = int(UpLimit/1000+0.00001)*1000;
up2 = int(UpLimit/500+0.00001)*500;
up3 = int(UpLimit/100+0.00001)*100;
up4 = int(UpLimit/50+0.00001)*50;
up5 = int(UpLimit/10+0.00001)*10;
up6 = int(UpLimit/10+0.00001)*10;
up7 = int(UpLimit/1+0.00001)*1;
}
}
Else
{
up1 = int(UpLimit/1000+0.00001)*1000;
up2 = int(UpLimit/500+0.00001)*500;
up3 = int(UpLimit/100+0.00001)*100;
up4 = int(UpLimit/50+0.00001)*50;
up5 = int(UpLimit/10+0.00001)*10;
up6 = int(UpLimit/5+0.00001)*5;
up7 = int(UpLimit/1+0.00001)*1;
}
if CodeCategory() == 1 || CodeCategory() == 2 then
{
if sdate < 20101004 Then
{
If BP >= 500000 Then
상한가 = up1;
Else If BP >= 100000 Then
상한가 = iff(up2>=500000, up1, up2);
Else If BP >= 50000 Then
상한가 = iff(up3>=100000, up2, up3);
Else If BP >= 10000 Then
상한가 = iff(up4>=50000, up3, up4);
Else If BP >= 5000 Then
상한가 = iff(up5>=10000, up4, up5);
Else If BP >= 1000 Then
상한가 = iff(up5>=5000, up5, up6);
Else
상한가 = iff(up6>=1000, up6, up6);
}
Else
{
If BP >= 500000 Then
상한가 = up1;
Else If BP >= 100000 Then
상한가 = iff(up2>=500000, up1, up2);
Else If BP >= 50000 Then
상한가 = iff(up3>=100000, up2, up3);
Else If BP >= 10000 Then
상한가 = iff(up4>=50000, up3, up4);
Else If BP >= 5000 Then
상한가 = iff(up5>=10000, up4, up5);
Else If BP >= 1000 Then
상한가 = iff(up5>=5000, up5, up6);
Else
상한가 = iff(up6>=1000, up6, up7);
}
}
else if CodeCategory() == 8 || CodeCategory() == 9 then { // ETF
상한가 = up6;
}
}
if MarketPosition == 1 Then
{
ExitLong("상한가",atlimit,상한가);
if CurrentContracts == MaxContracts and C >= EntryPrice*1.03 Then
ExitLong("3%익절",atlimit,def,"",int(MaxContracts*(50/100)),2);
if CurrentContracts < MaxContracts then
{
if highest(c,BarsSinceEntry) >= EntryPrice*1.10 and
highest(c,BarsSinceEntry) < EntryPrice*1.15 and
C < EntryPrice*1.10 Then
ExitLong("10%");
if highest(c,BarsSinceEntry) >= EntryPrice*1.15 and
highest(c,BarsSinceEntry) < EntryPrice*1.20 and
C < EntryPrice*1.15 Then
ExitLong("15%");
if highest(c,BarsSinceEntry) >= EntryPrice*1.20 and
C < EntryPrice*1.20 Then
ExitLong("20%");
}
}
2020-03-31
564
글번호 137383
시스템