커뮤니티
경과봉 조정
아래수식은 국내지수선물
데이트레이딩 수식입니다.
진입명 b1,b2로 2회 거래합니다.
요청사항
b2진입시 경과봉 필터가 있습니다.
이 경과봉에 조건을 하나 추가하고 싶습니다.
기존 경과봉은 그대로 수행됩니다.
단, b1이 트레일링스탑으로 포지션이 청산되었을 경우
b2의 기존 경과봉이 새로운 경과봉으로 조정되는 수식입니다.
ex)
input : 경과봉(150), 조정경과봉(200),b2(1),진입눌림2(0),진입돌파2(0);
항상 고맙습니다.
****************************************************************************************************************************
input : 진입시간(084500),진입제한시간(150000);
input : 거래횟수(2),누적패수(2),연속패수(2),누적패수조정(2);
input : b1(1),진입눌림1(0),진입돌파1(0);
input : 경과봉(150),b2(1),진입눌림2(0),진입돌파2(0);
input : als(21),atr1(0),atr2(999999);
input : bls(40),btr1(0),btr2(999999);
var : T1(0),entry(0),LL(0),EH(0),E1(0),H1(0),i1(0),S1(0),L1(0),V1(0);
var : Tcond(false);
var : loss(0),consecLoss(0),패수(0);
//영업일변경
if bdate != bdate[1] Then
{
//손실횟수 초기화 0
loss = 0;
//연속손실횟수 초기화 0
consecLoss = 0;
//패수는 누적패수
패수 = 누적패수;
}
//청산발생
if TotalTrades > TotalTrades[1] Then
{
//손실이면
if PositionProfit(1) < 0 Then
{
//loss 1씩 증가
loss = loss+1;
//consecLoss 1씩 증가
consecLoss = consecLoss+1;
//consecLoss이 3이면 패수를 누적패수에서 누적패수조정으로 변경
if consecLoss == 연속패수 Then
{
패수 = 누적패수조정;
}
}
Else //손실이 아니면 consecLoss으로 초기화
consecLoss = 0;
}
if (sdate != sdate[1] and stime >= 진입시간) or
(sdate == sdate[1] and stime >= 진입시간 and stime[1] < 진입시간) Then
Tcond = true;
if (sdate != sdate[1] and stime >= 진입제한시간) or
(sdate == sdate[1] and stime >= 진입제한시간 and stime[1] < 진입제한시간) Then
Tcond = false;
if (sdate != sdate[1] and stime >= 진입시간) or
(sdate == sdate[1] and stime >= 진입시간 and stime[1] < 진입시간) Then{
T1 = TotalTrades;
E1 = 0;
LL = L;
}
if stime >= 진입시간 then{
if L < LL Then
LL = L;
if MarketPosition == 0 Then
entry = TotalTrades-T1;
Else
entry = (TotalTrades-T1)+1;
if MarketPosition == 0 and entry == 0 Then{
if E1 == 0 and C >= LL+PriceScale*B1 Then{
E1 = 1;
H1 = H;
i1 = index;
V1 = LL; //시작점 종가
}
if E1 == 1 and index > i1 then{
if H > H1 Then
H1 = H;
#저가가 시작봉종가보다 클때만 눌림체크
if L >= V1 and L <= H1-PriceScale*진입눌림1 Then{
E1 = 2;
i1 = index;
S1 = H1;
}
}
//시작점 종가보다 낮은 가격이 발생하면 초기화
if E1 >= 1 and L < V1 Then{
E1 = 0;
LL = L;
}
if loss < 패수 and E1 == 2 and index > i1 and C >= S1+PriceScale*진입돌파1 and Tcond == true Then{
buy("b1");
}
}
if TotalTrades > TotalTrades[1] Then{
E1 = 0;
LL = L;
}
if L < LL Then
LL = L;
if MarketPosition == 0 and entry >= 1 and entry < 거래횟수 Then{
if E1 == 0 and C >= LL+PriceScale*B2 Then{
E1 = 1;
H1 = H;
i1 = index;
V1 = LL; //시작점 종가
}
if E1 == 1 and index > i1 then{
if H > H1 Then
H1 = H;
#저가가 시작봉종가보다 클때만 눌림체크
if L >= V1 and L <= H1-PriceScale*진입눌림2 Then{
E1 = 2;
i1 = index;
S1 = H1;
}
}
//시작점 종가보다 낮은 가격이 발생하면 초기화
if E1 >= 1 and L < V1 Then{
E1 = 0;
LL = L;
}
if loss < 패수 and (TotalTrades == 0 or (TotalTrades >= 1 and BarsSinceExit(1) > 경과봉)) and loss < 누적패수 and E1 == 2 and index > i1 and C >= S1+PriceScale*진입돌파2 and Tcond == true Then{
buy("b2");
}
}
}
if MarketPosition== 1 Then
{
if IsEntryName("b1") == true Then
{
SetStopLoss(PriceScale*als,PointStop);
SetStopTrailing(PriceScale*atr2,PriceScale*atr1,PointStop,1);
}
Else if IsEntryName("b2") == true Then
{
SetStopLoss(PriceScale*bls,PointStop);
SetStopTrailing(PriceScale*btr2,PriceScale*btr1,PointStop,1);
}
Else
{
SetStopLoss(0);
SetStopTrailing(0,0);
}
}
답변 1
예스스탁 예스스탁 답변
2026-01-23 13:31:51