커뮤니티
수정부탁드립니다.
2015-06-11 16:42:58
125
글번호 87108
봉이 바뀔때마다 최근 1000봉의 최적변수를 구하려고합니다.
//If Index >= 1500 && Index <= 2500 Then 처럼 직접 숫자를 넣어주니, 한번이지만 올바르게 작동은합니다. 매봉마다 구하려고 하다가 막혔습니다.
=============================================================
Input: 시작변수(1),종료변수(19),수수료(0),슬리피지(0),참조봉갯수(1000);
Var: cnt(0),n(0),shortPeriod(0),longPeriod(0),longMa(0),최적변수(0);
Array: shortMa[501](0),
MP[501](0),BuySellEntryPrice[501](0),OpenPP[501](0),NP[501](0),TP[501](0);
If Index >= cnt && Index <= cnt + 참조봉갯수 Then
//If Index >= 1500 && Index <= 2500 Then
For n = 0 to 종료변수-시작변수 {
shortPeriod = n+시작변수;
longPeriod = 20;
shortMa[n] = ma(C,shortPeriod);
longMa = ma(C,longPeriod);
If MP[n] == 1 Then {
OpenPP[n] = (C-BuySellEntryPrice[n]);
}
Else If MP[n] == -1 Then {
OpenPP[n] = (BuySellEntryPrice[n]-C);
}
Else {
OpenPP[n] = 0;
}
If MP[n] <= 0 and shortMa[n] > longMa Then {
// If shortMa[n] > longMa Then {
if MP[n] == -1 Then {
NP[n] = NP[n]+OpenPP[n];
}
BuySellEntryPrice[n] = C;
MP[n] = 1;
}
If MP[n] >= 0 and shortMa[n] < longMa Then {
// If shortMa[n] < longMa Then {
if MP[n] == 1 Then{
NP[n] = NP[n]+OpenPP[n];
}
BuySellEntryPrice[n] = C;
MP[n] = -1;
}
TP[n] = NP[n] + OpenPP[n];
If TP[최적변수] < TP[n] Then {
최적변수 = n;
}
}
cnt = cnt + 1;
MessageLog("시가,%.4f,종가,%.4f,MP,%.0f,NP,%.4f,OpenPP,%.4f,TP,%.4f,최적변수,%.0f,cnt,%.0f",open,close,MP[최적변수],NP[최적변수],OpenPP[최적변수],TP[최적변수],최적변수+1,cnt);
답변 1
예스스탁 예스스탁 답변
2015-06-12 09:46:51
안녕하세요
예스스탁입니다.
수식은 차트에 적용되면 차트 첫봉부터 현재봉쪽으로 계산을 해서 옵니다.
수식안에서 봉이 새로 생길때마다 index 조건을 바꿔 재계산해서 오게는 작성이 되지 않습니다.
수작업으로 하시는 방법뿐이 없습니다.
도움을 드리지 못해 죄송합니다.
즐거운 하루되세요
> 9단 님이 쓴 글입니다.
> 제목 : 수정부탁드립니다.
> 봉이 바뀔때마다 최근 1000봉의 최적변수를 구하려고합니다.
//If Index >= 1500 && Index <= 2500 Then 처럼 직접 숫자를 넣어주니, 한번이지만 올바르게 작동은합니다. 매봉마다 구하려고 하다가 막혔습니다.
=============================================================
Input: 시작변수(1),종료변수(19),수수료(0),슬리피지(0),참조봉갯수(1000);
Var: cnt(0),n(0),shortPeriod(0),longPeriod(0),longMa(0),최적변수(0);
Array: shortMa[501](0),
MP[501](0),BuySellEntryPrice[501](0),OpenPP[501](0),NP[501](0),TP[501](0);
If Index >= cnt && Index <= cnt + 참조봉갯수 Then
//If Index >= 1500 && Index <= 2500 Then
For n = 0 to 종료변수-시작변수 {
shortPeriod = n+시작변수;
longPeriod = 20;
shortMa[n] = ma(C,shortPeriod);
longMa = ma(C,longPeriod);
If MP[n] == 1 Then {
OpenPP[n] = (C-BuySellEntryPrice[n]);
}
Else If MP[n] == -1 Then {
OpenPP[n] = (BuySellEntryPrice[n]-C);
}
Else {
OpenPP[n] = 0;
}
If MP[n] <= 0 and shortMa[n] > longMa Then {
// If shortMa[n] > longMa Then {
if MP[n] == -1 Then {
NP[n] = NP[n]+OpenPP[n];
}
BuySellEntryPrice[n] = C;
MP[n] = 1;
}
If MP[n] >= 0 and shortMa[n] < longMa Then {
// If shortMa[n] < longMa Then {
if MP[n] == 1 Then{
NP[n] = NP[n]+OpenPP[n];
}
BuySellEntryPrice[n] = C;
MP[n] = -1;
}
TP[n] = NP[n] + OpenPP[n];
If TP[최적변수] < TP[n] Then {
최적변수 = n;
}
}
cnt = cnt + 1;
MessageLog("시가,%.4f,종가,%.4f,MP,%.0f,NP,%.4f,OpenPP,%.4f,TP,%.4f,최적변수,%.0f,cnt,%.0f",open,close,MP[최적변수],NP[최적변수],OpenPP[최적변수],TP[최적변수],최적변수+1,cnt);
다음글
이전글