당일 지정한 횟수이상 익절되거나 지정한 횟수이상 손절되면
진입을 제한하는 수식입니다.
거래시간 : StartTime~EndTime, EndTime에 당일청산
예제로 진입은 이평크로스이고 익절과 손절은 20틱으로 지정되었습니다.
input : StartTime(80000),EndTime(50000);
Input : 손절틱수(10),익절틱수(10);
Input : 당일손절횟수(3),당일익절횟수(3);
input : P1(5),P2(20);
var : Tcond(false),LossCount(0),ProfitCount(0);
var : mav1(0),mav2(0);
//starttime가 Endtime보다 클때(같은날 당일청산하는 경우에는 Endtime으로 바로 지정
IF Endtime > starttime Then
SetStopEndofday(Endtime);
Else
{
//starttime가 Endtime작을때,(다음날 새벽에 청산하는 경우 0시에 Endtime으로 지정)
if sDate != sDate[1] Then
SetStopEndofday(Endtime);
}
//지정한 끝시간이 되면 거래시간 구간체크하는 변수는 false로 변경
if (sdate != sdate[1] and stime >= EndTime) or
(sdate == sdate[1] and stime >= EndTime and stime[1] < EndTime) Then
Tcond = False;
//지정한 시작시간이 되면
if (sdate != sdate[1] and stime >= StartTime) or
(sdate == sdate[1] and stime >= StartTime and stime[1] < StartTime) Then
{
//starttime가 Endtime작을때,(다음날 새벽에 청산하는 경우)
IF Endtime <= starttime Then
{
//당일청산해제
SetStopEndofday(0);
}
//거래시간 구간체크하는 변수는 초기값으로 true
Tcond = true;
}
//TotalTrades는 총거래횟수로 TotalTrades의 상승은 청산이 발생한것을 의미합니다)
if TotalTrades > TotalTrades[1] then
{
//청산명이 SetStopLoss이면 1씩 증가
if IsExitName("StopLoss",1) == true Then
LossCount = LossCount+1;
//청산명이 StopProfitTarget이면 1씩 증가
if IsExitName("StopProfitTarget",1) == true Then
ProfitCount = ProfitCount+1;
}
mav1 = ma(C,P1);
mav2 = ma(C,P2);
//지정한 시간구간 사이이고 Xcond가 False일때만 진입가능
if Tcond == true and LossCount < 당일손절횟수 and ProfitCount < 당일익절횟수 then
{
if MarketPosition <= 0 and CrossUp(mav1,mav2) Then
Buy();
if MarketPosition >= 0 and CrossDown(mav1,mav2) Then
Sell();
}
SetStopLoss(PriceScale*손절틱수,PointStop);
SetStopProfittarget(PriceScale*익절틱수,PointStop);
JavaScript
복사