커뮤니티
질문드립니다.
2017-07-21 10:31:12
136
글번호 111488
그림처럼 2차매도진입을 할 때 동시에 1차계약만 청산되어서 문제가 발생하는것같습니다.
청산할 때 1,2차 모두 같은 값에 청산인데 늦게 2차가 들어가 꼬이는 것 같습니다.
어떻게 하면 될까요?
수식
Input : Period4(120), shortPeriod(12), longPeriod(26);
var : Lma(0), Sma(0), MACDv(0);
Input : Period(20), D(2) ;
Var : value1(0),value2(0);
var : Benefit(0), Loss(0), addPrice(0);
var : 날짜(20170501),진입시간(70000), 종료시간(190000),진입시간2(200000),종료시간2(213000);//16 17 ,12 16
var : Tcond1(false),Tcond2(false),S(0);
var : Flag1(0),Flag11(0),Flag2(0),Flag22(0);
Lma = ma(C, Period4); // 120일 선
value1 = BollBandUp(Period,D); //볼린져 상단밴드
value2 = BollBandDown(Period,D); //볼린져 하단밴드
if sdate >= 날짜 and ((stime >= 진입시간 and stime <= 종료시간))/* or (sTIme>=진입시간2 and sTime<=종료시간2)) */ Then
Tcond1 = true;
Else
{Flag1=0;
Flag11=0;
Flag2=0;
Flag22=0;
Tcond1 = false;}
if sdate >= 날짜 and ((stime >= 진입시간2 and stime <= 종료시간2))/* or (sTIme>=진입시간2 and sTime<=종료시간2)) */ Then
Tcond2 = true;
Else
{Flag1=0;
Flag11=0;
Flag2=0;
Flag22=0;
Tcond2 = false;}
addPrice = 50/100;
Benefit = 70/100;
Loss = 450/100;
if (V>=2000 and H >= value1 and Tcond1 == true and MarketPosition == 0) or (V>=4000 and H >= value1 and Tcond2 == true and MarketPosition == 0) /*and Flag2==0 and Flag22==0*/ Then
sell("매도진입1",OnClose);
else if (V>=2000 and L <= value2 and Tcond1 == true and MarketPosition == 0) or (V>=4000 and L <= value2 and Tcond2 == true and MarketPosition == 0) /*and Flag1==0 and Flag11==0*/ Then
buy("매수진입1",OnClose);
if (LatestEntryName=="매수진입1") Then{
Flag1=1;Flag11=1;
}
if (LatestEntryName=="매도진입1") Then{
Flag2=1;Flag22=1;
}
//추가진입
if MarketPosition == -1 and CurrentEntries == 1 then{
Sell("매도진입2",AtLimit,LatestEntryPrice + addPrice);
}
if MarketPosition == -1 and CurrentEntries == 2 then{
Sell("매도진입3",AtLimit,LatestEntryPrice + addPrice);
}
if MarketPosition == -1 and CurrentEntries == 3 then{
Sell("매도진입4",AtLimit,LatestEntryPrice + addPrice);
}
if MarketPosition == -1 and CurrentEntries == 4 then{
Sell("매도진입5",AtLimit,LatestEntryPrice + addPrice);
}
if MarketPosition == -1 and CurrentEntries == 5 then{
Sell("매도진입6",AtLimit,LatestEntryPrice + addPrice);
}
if MarketPosition == -1 and CurrentEntries == 6 then{
Sell("매도진입7",AtLimit,LatestEntryPrice + addPrice);
}
if MarketPosition == -1 and CurrentEntries == 7 then{
Sell("매도진입8",AtLimit,LatestEntryPrice + addPrice);
}
//==============================매수 추가진입===================================//
if MarketPosition == 1 and CurrentEntries == 1 then{
Buy("매수진입2",AtLimit,LatestEntryPrice - addPrice);
}
if MarketPosition == 1 and CurrentEntries == 2 then{
Buy("매수진입3",AtLimit,LatestEntryPrice - addPrice);
}
if MarketPosition == 1 and CurrentEntries == 3 then{
Buy("매수진입4",AtLimit,LatestEntryPrice - addPrice);
}
if MarketPosition == 1 and CurrentEntries == 4 then{
Buy("매수진입5",AtLimit,LatestEntryPrice - addPrice);
}
if MarketPosition == 1 and CurrentEntries == 5 then{
Buy("매수진입6",AtLimit,LatestEntryPrice - addPrice);
}
if MarketPosition == 1 and CurrentEntries == 6 then{
Buy("매수진입7",AtLimit,LatestEntryPrice - addPrice);
}
if MarketPosition == 1 and CurrentEntries == 7 then{
Buy("매수진입8",AtLimit,LatestEntryPrice - addPrice);
}
////청산
//매도
//1,2차
if MarketPosition==-1 and CurrentEntries < 3 Then{
ExitShort("매도익절1",AtLimit,EntryPrice-Benefit,"매도진입1");
ExitShort("매도익절2",AtLimit,EntryPrice-Benefit,"매도진입2");
}
if MarketPosition==-1 and CurrentEntries ==3 Then{
ExitShort("매도익절1.",AtLimit,EntryPrice,"매도진입1");
ExitShort("매도익절2.",AtLimit,EntryPrice,"매도진입2");
ExitShort("매도익절3",AtLimit,EntryPrice,"매도진입3");
}
if MarketPosition==-1 and CurrentEntries ==4 Then{
ExitShort("매도익절1..",AtLimit,EntryPrice+addPrice,"매도진입1");
ExitShort("매도익절2..",AtLimit,EntryPrice+addPrice,"매도진입2");
ExitShort("매도익절3.",AtLimit,EntryPrice+addPrice,"매도진입3");
ExitShort("매도익절4",AtLimit,EntryPrice+addPrice,"매도진입4");
}
if MarketPosition == -1 and CurrentEntries >= 5 then{
ExitShort("매도평균1",AtLimit,AvgEntryPrice,"매도진입1");
ExitShort("매도평균2",AtLimit,AvgEntryPrice,"매도진입2");
ExitShort("매도평균3",AtLimit,AvgEntryPrice,"매도진입3");
ExitShort("매도평균4",AtLimit,AvgEntryPrice,"매도진입4");
ExitShort("매도평균5",AtLimit,AvgEntryPrice,"매도진입5");
ExitShort("매도평균6",AtLimit,AvgEntryPrice,"매도진입6");
ExitShort("매도평균7",AtLimit,AvgEntryPrice,"매도진입7");
ExitShort("매도평균8",AtLimit,AvgEntryPrice,"매도진입8");
ExitShort("매도손절1",AtStop,EntryPrice+Loss,"매도진입1");
ExitShort("매도손절2",AtStop,EntryPrice+Loss,"매도진입2");
ExitShort("매도손절3",AtStop,EntryPrice+Loss,"매도진입3");
ExitShort("매도손절4",AtStop,EntryPrice+Loss,"매도진입4");
ExitShort("매도손절5",AtStop,EntryPrice+Loss,"매도진입5");
ExitShort("매도손절6",AtStop,EntryPrice+Loss,"매도진입6");
ExitShort("매도손절7",AtStop,EntryPrice+Loss,"매도진입7");
ExitShort("매도손절8",AtStop,EntryPrice+Loss,"매도진입8");
}
//매수
if MarketPosition==1 and CurrentEntries <3 Then{
ExitLong("매수익절1",AtLimit,EntryPrice+Benefit,"매수진입1");
ExitLong("매수익절2",AtLimit,EntryPrice+Benefit,"매수진입2");
}
if MarketPosition== 1 and CurrentEntries==3 Then{
ExitLong("매수익절1.",AtLimit,EntryPrice,"매수진입1");
ExitLong("매수익절2.",AtLimit,EntryPrice,"매수진입2");
ExitLong("매수익절3",AtLimit,EntryPrice,"매수진입3");
}
if MarketPosition== 1 and CurrentEntries==4 Then{
ExitLong("매수익절1..",AtLimit,EntryPrice-addPrice,"매수진입1");
ExitLong("매수익절2..",AtLimit,EntryPrice-addPrice,"매수진입2");
ExitLong("매수익절3.",AtLimit,EntryPrice-addPrice,"매수진입3");
ExitLong("매수익절4",AtLimit,EntryPrice-addPrice,"매수진입4");
}
if MarketPosition == 1 and CurrentEntries >= 5 then{
ExitLong("매수평균1",AtLimit,AvgEntryPrice,"매수진입1");
ExitLong("매수평균2",AtLimit,AvgEntryPrice,"매수진입2");
ExitLong("매수평균3",AtLimit,AvgEntryPrice,"매수진입3");
ExitLong("매수평균4",AtLimit,AvgEntryPrice,"매수진입4");
ExitLong("매수평균5",AtLimit,AvgEntryPrice,"매수진입5");
ExitLong("매수평균6",AtLimit,AvgEntryPrice,"매수진입6");
ExitLong("매수평균7",AtLimit,AvgEntryPrice,"매수진입7");
ExitLong("매수평균8",AtLimit,AvgEntryPrice,"매수진입8");
ExitLong("매수손절1",AtStop,EntryPrice-Loss,"매수진입1");
ExitLong("매수손절2",AtStop,EntryPrice-Loss,"매수진입2");
ExitLong("매수손절3",AtStop,EntryPrice-Loss,"매수진입3");
ExitLong("매수손절4",AtStop,EntryPrice-Loss,"매수진입4");
ExitLong("매수손절5",AtStop,EntryPrice-Loss,"매수진입5");
ExitLong("매수손절6",AtStop,EntryPrice-Loss,"매수진입6");
ExitLong("매수손절7",AtStop,EntryPrice-Loss,"매수진입7");
ExitLong("매수손절8",AtStop,EntryPrice-Loss,"매수진입8");
}
- 1. 112045_질문.JPG (0.16 MB)
답변 1
예스스탁 예스스탁 답변
2017-07-21 14:36:55
안녕하세요
예스스탁입니다.
진입과 청산이 모두 atlimit이나 atstop 타입으로
봉완성시 값셋팅해 다음봉 미완성시에 신호가 발생되는 타입입니다.
봉미완성시에는 신호발생을 제어를 할수가 없어
수식적으로는 방법이 하나뿐이 없습니다.
진입이나 청산중 택일해서 봉완성시 신호로 변경해야만
제어가 가능합니다. 일반적으로는 진입을 완성시로 변경합니다.
//추가진입
if MarketPosition == -1 and CurrentEntries == 1 and H >= LatestEntryPrice+addPrice then{
Sell("매도진입2",OnClose);
}
if MarketPosition == -1 and CurrentEntries == 2 and H >= LatestEntryPrice+addPrice then{
Sell("매도진입3",OnClose);
}
if MarketPosition == -1 and CurrentEntries == 3 and H >= LatestEntryPrice+addPrice then{
Sell("매도진입4,"OnClose);
}
if MarketPosition == -1 and CurrentEntries == 4 and H >= LatestEntryPrice+addPrice then{
Sell("매도진입5",OnClose);
}
if MarketPosition == -1 and CurrentEntries == 5 and H >= LatestEntryPrice+addPrice then{
Sell("매도진입6",OnClose);
}
if MarketPosition == -1 and CurrentEntries == 6 and H >= LatestEntryPrice+addPrice then{
Sell("매도진입7",OnClose);
}
if MarketPosition == -1 and CurrentEntries == 7 and H >= LatestEntryPrice+addPrice then{
Sell("매도진입8",OnClose);
}
//==============================매수 추가진입===================================//
if MarketPosition == 1 and CurrentEntries == 1 and L <= LatestEntryPrice - addPrice then{
Buy("매수진입2",OnClose);
}
if MarketPosition == 1 and CurrentEntries == 2 and L <= LatestEntryPrice - addPrice then{
Buy("매수진입3",OnClose);
}
if MarketPosition == 1 and CurrentEntries == 3 and L <= LatestEntryPrice - addPrice then{
Buy("매수진입4",OnClose);
}
if MarketPosition == 1 and CurrentEntries == 4 and L <= LatestEntryPrice - addPrice then{
Buy("매수진입5",OnClose);
}
if MarketPosition == 1 and CurrentEntries == 5 and L <= LatestEntryPrice - addPrice then{
Buy("매수진입6",OnClose);
}
if MarketPosition == 1 and CurrentEntries == 6 and L <= LatestEntryPrice - addPrice then{
Buy("매수진입7",OnClose);
}
if MarketPosition == 1 and CurrentEntries == 7 and L <= LatestEntryPrice - addPrice then{
Buy("매수진입8",OnClose);
}
즐거운 하루되세요
> hanwoon 님이 쓴 글입니다.
> 제목 : 질문드립니다.
> 그림처럼 2차매도진입을 할 때 동시에 1차계약만 청산되어서 문제가 발생하는것같습니다.
청산할 때 1,2차 모두 같은 값에 청산인데 늦게 2차가 들어가 꼬이는 것 같습니다.
어떻게 하면 될까요?
수식
Input : Period4(120), shortPeriod(12), longPeriod(26);
var : Lma(0), Sma(0), MACDv(0);
Input : Period(20), D(2) ;
Var : value1(0),value2(0);
var : Benefit(0), Loss(0), addPrice(0);
var : 날짜(20170501),진입시간(70000), 종료시간(190000),진입시간2(200000),종료시간2(213000);//16 17 ,12 16
var : Tcond1(false),Tcond2(false),S(0);
var : Flag1(0),Flag11(0),Flag2(0),Flag22(0);
Lma = ma(C, Period4); // 120일 선
value1 = BollBandUp(Period,D); //볼린져 상단밴드
value2 = BollBandDown(Period,D); //볼린져 하단밴드
if sdate >= 날짜 and ((stime >= 진입시간 and stime <= 종료시간))/* or (sTIme>=진입시간2 and sTime<=종료시간2)) */ Then
Tcond1 = true;
Else
{Flag1=0;
Flag11=0;
Flag2=0;
Flag22=0;
Tcond1 = false;}
if sdate >= 날짜 and ((stime >= 진입시간2 and stime <= 종료시간2))/* or (sTIme>=진입시간2 and sTime<=종료시간2)) */ Then
Tcond2 = true;
Else
{Flag1=0;
Flag11=0;
Flag2=0;
Flag22=0;
Tcond2 = false;}
addPrice = 50/100;
Benefit = 70/100;
Loss = 450/100;
if (V>=2000 and H >= value1 and Tcond1 == true and MarketPosition == 0) or (V>=4000 and H >= value1 and Tcond2 == true and MarketPosition == 0) /*and Flag2==0 and Flag22==0*/ Then
sell("매도진입1",OnClose);
else if (V>=2000 and L <= value2 and Tcond1 == true and MarketPosition == 0) or (V>=4000 and L <= value2 and Tcond2 == true and MarketPosition == 0) /*and Flag1==0 and Flag11==0*/ Then
buy("매수진입1",OnClose);
if (LatestEntryName=="매수진입1") Then{
Flag1=1;Flag11=1;
}
if (LatestEntryName=="매도진입1") Then{
Flag2=1;Flag22=1;
}
//추가진입
if MarketPosition == -1 and CurrentEntries == 1 then{
Sell("매도진입2",AtLimit,LatestEntryPrice + addPrice);
}
if MarketPosition == -1 and CurrentEntries == 2 then{
Sell("매도진입3",AtLimit,LatestEntryPrice + addPrice);
}
if MarketPosition == -1 and CurrentEntries == 3 then{
Sell("매도진입4",AtLimit,LatestEntryPrice + addPrice);
}
if MarketPosition == -1 and CurrentEntries == 4 then{
Sell("매도진입5",AtLimit,LatestEntryPrice + addPrice);
}
if MarketPosition == -1 and CurrentEntries == 5 then{
Sell("매도진입6",AtLimit,LatestEntryPrice + addPrice);
}
if MarketPosition == -1 and CurrentEntries == 6 then{
Sell("매도진입7",AtLimit,LatestEntryPrice + addPrice);
}
if MarketPosition == -1 and CurrentEntries == 7 then{
Sell("매도진입8",AtLimit,LatestEntryPrice + addPrice);
}
//==============================매수 추가진입===================================//
if MarketPosition == 1 and CurrentEntries == 1 then{
Buy("매수진입2",AtLimit,LatestEntryPrice - addPrice);
}
if MarketPosition == 1 and CurrentEntries == 2 then{
Buy("매수진입3",AtLimit,LatestEntryPrice - addPrice);
}
if MarketPosition == 1 and CurrentEntries == 3 then{
Buy("매수진입4",AtLimit,LatestEntryPrice - addPrice);
}
if MarketPosition == 1 and CurrentEntries == 4 then{
Buy("매수진입5",AtLimit,LatestEntryPrice - addPrice);
}
if MarketPosition == 1 and CurrentEntries == 5 then{
Buy("매수진입6",AtLimit,LatestEntryPrice - addPrice);
}
if MarketPosition == 1 and CurrentEntries == 6 then{
Buy("매수진입7",AtLimit,LatestEntryPrice - addPrice);
}
if MarketPosition == 1 and CurrentEntries == 7 then{
Buy("매수진입8",AtLimit,LatestEntryPrice - addPrice);
}
////청산
//매도
//1,2차
if MarketPosition==-1 and CurrentEntries < 3 Then{
ExitShort("매도익절1",AtLimit,EntryPrice-Benefit,"매도진입1");
ExitShort("매도익절2",AtLimit,EntryPrice-Benefit,"매도진입2");
}
if MarketPosition==-1 and CurrentEntries ==3 Then{
ExitShort("매도익절1.",AtLimit,EntryPrice,"매도진입1");
ExitShort("매도익절2.",AtLimit,EntryPrice,"매도진입2");
ExitShort("매도익절3",AtLimit,EntryPrice,"매도진입3");
}
if MarketPosition==-1 and CurrentEntries ==4 Then{
ExitShort("매도익절1..",AtLimit,EntryPrice+addPrice,"매도진입1");
ExitShort("매도익절2..",AtLimit,EntryPrice+addPrice,"매도진입2");
ExitShort("매도익절3.",AtLimit,EntryPrice+addPrice,"매도진입3");
ExitShort("매도익절4",AtLimit,EntryPrice+addPrice,"매도진입4");
}
if MarketPosition == -1 and CurrentEntries >= 5 then{
ExitShort("매도평균1",AtLimit,AvgEntryPrice,"매도진입1");
ExitShort("매도평균2",AtLimit,AvgEntryPrice,"매도진입2");
ExitShort("매도평균3",AtLimit,AvgEntryPrice,"매도진입3");
ExitShort("매도평균4",AtLimit,AvgEntryPrice,"매도진입4");
ExitShort("매도평균5",AtLimit,AvgEntryPrice,"매도진입5");
ExitShort("매도평균6",AtLimit,AvgEntryPrice,"매도진입6");
ExitShort("매도평균7",AtLimit,AvgEntryPrice,"매도진입7");
ExitShort("매도평균8",AtLimit,AvgEntryPrice,"매도진입8");
ExitShort("매도손절1",AtStop,EntryPrice+Loss,"매도진입1");
ExitShort("매도손절2",AtStop,EntryPrice+Loss,"매도진입2");
ExitShort("매도손절3",AtStop,EntryPrice+Loss,"매도진입3");
ExitShort("매도손절4",AtStop,EntryPrice+Loss,"매도진입4");
ExitShort("매도손절5",AtStop,EntryPrice+Loss,"매도진입5");
ExitShort("매도손절6",AtStop,EntryPrice+Loss,"매도진입6");
ExitShort("매도손절7",AtStop,EntryPrice+Loss,"매도진입7");
ExitShort("매도손절8",AtStop,EntryPrice+Loss,"매도진입8");
}
//매수
if MarketPosition==1 and CurrentEntries <3 Then{
ExitLong("매수익절1",AtLimit,EntryPrice+Benefit,"매수진입1");
ExitLong("매수익절2",AtLimit,EntryPrice+Benefit,"매수진입2");
}
if MarketPosition== 1 and CurrentEntries==3 Then{
ExitLong("매수익절1.",AtLimit,EntryPrice,"매수진입1");
ExitLong("매수익절2.",AtLimit,EntryPrice,"매수진입2");
ExitLong("매수익절3",AtLimit,EntryPrice,"매수진입3");
}
if MarketPosition== 1 and CurrentEntries==4 Then{
ExitLong("매수익절1..",AtLimit,EntryPrice-addPrice,"매수진입1");
ExitLong("매수익절2..",AtLimit,EntryPrice-addPrice,"매수진입2");
ExitLong("매수익절3.",AtLimit,EntryPrice-addPrice,"매수진입3");
ExitLong("매수익절4",AtLimit,EntryPrice-addPrice,"매수진입4");
}
if MarketPosition == 1 and CurrentEntries >= 5 then{
ExitLong("매수평균1",AtLimit,AvgEntryPrice,"매수진입1");
ExitLong("매수평균2",AtLimit,AvgEntryPrice,"매수진입2");
ExitLong("매수평균3",AtLimit,AvgEntryPrice,"매수진입3");
ExitLong("매수평균4",AtLimit,AvgEntryPrice,"매수진입4");
ExitLong("매수평균5",AtLimit,AvgEntryPrice,"매수진입5");
ExitLong("매수평균6",AtLimit,AvgEntryPrice,"매수진입6");
ExitLong("매수평균7",AtLimit,AvgEntryPrice,"매수진입7");
ExitLong("매수평균8",AtLimit,AvgEntryPrice,"매수진입8");
ExitLong("매수손절1",AtStop,EntryPrice-Loss,"매수진입1");
ExitLong("매수손절2",AtStop,EntryPrice-Loss,"매수진입2");
ExitLong("매수손절3",AtStop,EntryPrice-Loss,"매수진입3");
ExitLong("매수손절4",AtStop,EntryPrice-Loss,"매수진입4");
ExitLong("매수손절5",AtStop,EntryPrice-Loss,"매수진입5");
ExitLong("매수손절6",AtStop,EntryPrice-Loss,"매수진입6");
ExitLong("매수손절7",AtStop,EntryPrice-Loss,"매수진입7");
ExitLong("매수손절8",AtStop,EntryPrice-Loss,"매수진입8");
}