답변완료
수식
안녕하세요. 항상 감사드립니다.
하기 수식을 당일에만 적용 부탁드립니다.
input : N봉(2),pt(0.5);
var : body(0),Pcnt(0),Ncnt(0),pmax(0),nmax(0),Pi(0),Ni(0),cnt(0);
body = abs(C-O);
Pcnt = 0;
Pi = 0;
Ncnt = 0;
Pi = 0;
Pmax = 0;
Nmax = 0;
For cnt = 0 to N봉-1
{
if C[cnt] > O[cnt] and body[cnt] >= Pt Then
{
Pcnt = Pcnt+1;
if body[cnt] > Pmax Then
{
Pmax = Body[cnt];
Pi = cnt;
}
}
if C[cnt] < O[cnt] and body[cnt] >= Pt Then
{
Ncnt = Ncnt+1;
if body[cnt] > Nmax Then
{
Nmax = Body[cnt];
Ni = cnt;
}
}
}
if Pcnt == N봉 Then
{
var1 = O[Pi];
var2 = H[Pi];
var3 = L[Pi];
var4 = C[Pi];
}
if Ncnt == N봉 Then
{
var5 = O[Ni];
var6 = H[Ni];
var7 = L[Ni];
var8 = C[Ni];
}
//Plot10(Pcnt);
if var1 > 0 Then
{
Plot1(var1,"양봉 시가");
Plot2(var2,"양봉 고가");
Plot3(var3,"양봉 저가");
Plot4(var4,"양봉 종가");
}
if var5 > 0 Then
{
Plot11(var5,"음봉 시가");
Plot12(var6,"음봉 고가");
Plot13(var7,"음봉 저가");
Plot14(var8,"음봉 종가");
2021-08-11
927
글번호 151441
지표
답변완료
수식 문의 드립니다ㅠ
코스피 200 선물 분봉 거래에서
예를 들어 15분봉을 사용
4번째 Bar(DayIndex == 3)의, High, Low, DayIndex를 별개의 변수로 저장하고
5번째 이후의 Bar에서
만약 High를 돌파하면 그 지점에서 AtStop으로 "Long" 진입
만약 Low를 돌파하면 그 지점에서 AtStop으로 "Short" 진입
진입하였다면 그 봉 번호와 가격정보(OHLC)를 뒤에 봉이 진행되더라도 변하지 않게끔
변수에 저장하고 싶습니다
High도 돌파하고, Low도 돌파하면, 보유하고 있었던 포지션을 청산(어떻게 작성해야 할지 모르겠음..)
이런 수식을 아래와 같이 작성해보았는데요
========================================================
시스템 수식
Var : Bar_4_High(0), Bar_4_Low(0), Bar_4_Index(0), Buy_Target(0), Sell_Target(0);
Var : Entry_Bar_High(0), Entry_Bar_Low(0), Entry_Bar_Index(0);
If bdate != bdate[1] Then {
Bar_4_High = 0;
Bar_4_Low = 0;
Bar_4_Index = 0;
Buy_Target = 0;
Sell_Target = 0;
Entry_Bar_Index = 0;
Entry_Bar_High = 0;
Entry_Bar_Low = 0;
}
If DayIndex + 1 == 4 Then {
Bar_4_High = H;
Bar_4_Low = L;
Bar_4_Index = DayIndex + 1;
Buy_Target = Bar_4_High + PriceScale;
Sell_Target = Bar_4_Low - PriceScale;
}
If (DayIndex + 1 >= 5) and (Bar_4_High != 0) and (Close >= Bar_4_High) and !(Close <= Bar_4_Low) then {
Buy("Buy", AtStop, Buy_Target);
Entry_Bar_Index = DayIndex + 1;
}
If (DayIndex + 1 >= 5) and (Bar_4_High != 0) and !(Close >= Bar_4_High) and (Close <= Bar_4_Low) then {
Sell("Sell", AtStop, Sell_Target);
Entry_Bar_Index = DayIndex + 1;
}
If DayIndex + 1 == Entry_Bar_Index Then {
Entry_Bar_High = H;
Entry_Bar_Low = L;
}
SetStopEndofday(1510);
===================================================
지표 수식
Var : Bar_4_High(0), Bar_4_Low(0), Bar_4_Index(0), Buy_Target(0), Sell_Target(0);
Var : Entry_Bar_High(0), Entry_Bar_Low(0), Entry_Bar_Index(0);
If bdate != bdate[1] Then {
Bar_4_High = 0;
Bar_4_Low = 0;
Bar_4_Index = 0;
Buy_Target = 0;
Sell_Target = 0;
Entry_Bar_Index = 0;
Entry_Bar_High = 0;
Entry_Bar_Low = 0;
}
If DayIndex + 1 == 4 Then {
Bar_4_High = H;
Bar_4_Low = L;
Bar_4_Index = DayIndex + 1;
Buy_Target = Bar_4_High + PriceScale;
Sell_Target = Bar_4_Low - PriceScale;
}
If (DayIndex + 1 >= 5) and (Bar_4_High != 0) and (Close >= Bar_4_High) and !(Close <= Bar_4_Low) then {
//Buy("Buy", AtStop, Buy_Target);
Entry_Bar_Index = DayIndex + 1;
}
If (DayIndex + 1 >= 5) and (Bar_4_High != 0) and !(Close >= Bar_4_High) and (Close <= Bar_4_Low) then {
//Sell("Sell", AtStop, Sell_Target);
Entry_Bar_Index = DayIndex + 1;
}
If DayIndex + 1 == Entry_Bar_Index Then {
Entry_Bar_High = H;
Entry_Bar_Low = L;
}
Plot1(Bar_4_High);
Plot2(Bar_4_Low);
Plot3(Bar_4_Index);
plot4(Buy_Target);
plot5(Sell_Target);
plot6(Entry_Bar_Index);
plot7(Entry_Bar_High);
plot8(Entry_Bar_Low);
=====================================================
이렇게 작성을 한다면 이르면 바로 다음 봉에서라도 진입이 일어나야 할 것 같은데
진입이 늦어지고 또한 첫 번째 봉에서도 진입이 일어나는 현상을 보고 있습니다
제가 무언가를 잘못 파악하고 있는데 도움좀 주시면 감사하겠습니다
예를 들어 위의 산식 복사해서 KP200 선물 15분봉에 적용해보면
8월 10일자 기준
첫 번째 봉에서 BUY 진입이 일어나는 것도 이상하고..
4번봉의 Low지점을 뚫었으니까 6번봉에서 바로 AtStop으로 주문이 나가야 할 것 같은데
7번봉에서 주문이 나가는 것으로 되어있더라고요..
지표를 출력해보면 Entry_Bar_Index가 계속 DayIndex가 증가함에 따라 따라서 증가하고 있어서 High, Low도 계속 바귀네요..
Buy, Sell 주문을 넣는 If 문이 딱 한 번만 실행되게 해야 하는데..
For 문 안에 If문을 넣어야 하나요..?
해결책좀 주시기 바랍니다ㅠ
2021-08-11
966
글번호 151431
지표