예스스탁
예스스탁 답변
2023-09-15 10:39:13
안녕하세요
예스스탁입니다.
input : ntime(173800), xtime(230000);
input : tick_size(8);
input : line_num(20); //줄을 몇개 그을 것인지
input : num(8); // 몇번 터치하면 진입하는지.
var : Tcond(False), oo(0), k(0), PriceScale_tick_size(0);
var : 상단(0),하단(0),n1(0),daypl(0),vol(0),xcond(False);
array : up_flag[100](0), dn_flag[100](0);
array : b_cnt[100](0), b_text_display[100](0);
array : b_b_cnt[100](0), b_b_text_display[100](0);
array : b_line[100](0), b_TL_display[100](0);
array : b_b_line[100](0), b_b_TL_display[100](0);
array : u_cnt[100](0), u_text_display[100](0);
array : u_u_cnt[100](0), u_u_text_display[100](0);
array : u_line[100](0), u_TL_display[100](0);
array : u_u_line[100](0), u_u_TL_display[100](0);
if (sdate != sdate[1] and stime >= xtime) or
(sdate == sdate[1] and stime >= xtime and stime[1] < xtime) Then
Tcond = False;
if (sdate != sdate[1] and stime >= ntime) or
(sdate == sdate[1] and stime >= ntime and stime[1] < ntime) Then
{
// 변수들 초기화 해주기
Tcond = true;
oo = o;
For k = 1 to line_num
{
up_flag[k] = 0;
dn_flag[k] = 0;
u_cnt[k] = 0;
u_u_cnt[k] = 0;
b_cnt[k] = 0;
b_b_cnt[k] = 0;
PriceScale_tick_size = PriceScale*tick_size;
u_line[k] = oo + (k-1)*PriceScale_tick_size;
u_u_line[k] = oo + k*PriceScale_tick_size;
b_line[k] = oo - (k-1)*PriceScale_tick_size;
b_b_line[k] = oo - k*PriceScale_tick_size;
}
// 조건문으로 터치 카운트 하기
For k = 1 to line_num
{
if H >= u_u_line[k] Then
{
up_flag[k] = 1;
u_u_cnt[k] = u_u_cnt[k] + 1;
}
if L <= b_b_line[k] Then
{
dn_flag[k] = -1;
b_b_cnt[k] = b_b_cnt[k] + 1;
}
}
}
Else
{
if Tcond == true Then
{
if TotalTrades > TotalTrades[1] Then
{
oo = o;
For k = 1 to line_num
{
up_flag[k] = 0;
dn_flag[k] = 0;
u_cnt[k] = 0;
u_u_cnt[k] = 0;
b_cnt[k] = 0;
b_b_cnt[k] = 0;
PriceScale_tick_size = PriceScale*tick_size;
u_line[k] = oo + (k-1)*PriceScale_tick_size;
u_u_line[k] = oo + k*PriceScale_tick_size;
b_line[k] = oo - (k-1)*PriceScale_tick_size;
b_b_line[k] = oo - k*PriceScale_tick_size;
}
// 조건문으로 터치 카운트 하기
For k = 1 to line_num
{
if H >= u_u_line[k] Then
{
up_flag[k] = 1;
u_u_cnt[k] = u_u_cnt[k] + 1;
}
if L <= b_b_line[k] Then
{
dn_flag[k] = -1;
b_b_cnt[k] = b_b_cnt[k] + 1;
}
}
}
Else
{
For k = 1 to line_num
{
if dn_flag[k] <= 0 and H >= b_line[k] and H[1] < b_line[k] Then
{
dn_flag[k] = 1;
b_cnt[k] = b_cnt[k] + 1;
}
if dn_flag[k] >= 0 and L <= b_b_line[k] and L[k] > b_b_line[k] Then
{
dn_flag[k] = -1;
b_b_cnt[k] = b_b_cnt[k] + 1;
}
if up_flag[k] <= 0 and H >= u_u_line[k] and H[1] < u_u_line[k] Then
{
up_flag[k] = 1;
u_u_cnt[k] = u_u_cnt[k] + 1;
}
if up_flag[k] >= 0 and L <= u_line[k] and L[1] > u_line[k] Then
{
up_flag[k] = -1;
u_cnt[k] = u_cnt[k] + 1;
}
}
}
}
}
var : T(0);
if (sdate != sdate[1] and stime >= ntime) or
(sdate == sdate[1] and stime >= ntime and stime[1] < ntime) Then
{
T = 0;
n1 = NetProfit;
xcond = False;
}
if TotalTrades > TotalTrades[1] and (IsExitName("bp3",1) or IsExitName("sp3",1)) Then
xcond = true;
if Tcond == true and xcond == False Then
{
if T == 0 Then
{
For k = 1 to line_num
{
if u_u_cnt[k] >= num or u_cnt[k] >= num Then
{
T = k;
상단 = u_u_line[k];
하단 = u_line[k];
}
if b_b_cnt[k] >= num or b_cnt[k] >= num Then
{
T = k;
상단 = b_line[k];
하단 = b_b_line[k];
}
}
}
if T != 0 Then
{
dayPL = (NetProfit-n1)+PositionProfit(0); // n1은 초기의 NetProfit이다.
if daypl >= 0 Then
vol = 2;
Else
vol = max(Ceiling(abs(daypl)/((상단-하단)*3)),2);
ClearDebug;
MessageLog("dayPL : %.2f | NetProfit : %.2f | PositionProfit : %.2f | vol : %.f", daypl, NetProfit, PositionProfit, vol);
MessageLog("상단 : %.2f | 하단 : %.2f | 위청산 : %.2f | 아래청산 : %.2f", 상단, 하단, 상단+(상단-하단)*6, 하단-(상단-하단)*6);
MessageLog("상단 - 하단 : %.2f, T : %.f", 상단-하단, T);
if MarketPosition <= 0 and CrossUp(C,상단) Then
Buy("b1",AtMarket,Def,vol);
if MarketPosition >= 0 and CrossDown(C,하단) Then
Sell("s1",AtMarket,Def,vol);
if MarketPosition == 1 Then
{
ExitLong("Bp1",AtLimit,상단+(상단-하단)*3,"",Floor(CurrentContracts*0.5),1); // 3배수 위치에서 물량 일부 청산하기, 1은 전체에서 한번 청산, 0은 각 진입 횟수 만큼 청산
ExitLong("Bp2",AtLimit,상단+(상단-하단)*7,"",Floor(CurrentContracts*0.5),1);
ExitLong("Bp3",AtLimit,상단+(상단-하단)*10);
}
if MarketPosition == -1 Then
{
ExitShort("sp1",AtLimit,하단-(상단-하단)*3,"",Floor(CurrentContracts*0.5),1);
ExitShort("sp2",AtLimit,하단-(상단-하단)*7,"",Floor(CurrentContracts*0.5),1);
ExitShort("sp3",AtLimit,하단-(상단-하단)*10);
}
MessageLog("daypl %.2f", daypl);
}
}
즐거운 하루되세요
> 예스쟁이 님이 쓴 글입니다.
> 제목 : 진입조건에 거래 후 청산하고 다시 진입조건에 거래하기 문의
> 항상 도움에 감사드립니다.
이해를 돕기 위해 이미지를 첨부 했습니다.
아래의 수식은
여러 기준선들 중에서
상단이나 하단을 5번 먼저 터치 하면
진입이 시작되고 목표가격에서 청산 후
거래가 종료되는 수식인데요
--------------------------------------
input : ntime(173800), xtime(230000);
input : tick_size(8);
input : line_num(20); //줄을 몇개 그을 것인지
input : num(8); // 몇번 터치하면 진입하는지.
var : Tcond(False), oo(0), k(0), PriceScale_tick_size(0);
var : 상단(0),하단(0),n1(0),daypl(0),vol(0),xcond(False);
array : up_flag[100](0), dn_flag[100](0);
array : b_cnt[100](0), b_text_display[100](0);
array : b_b_cnt[100](0), b_b_text_display[100](0);
array : b_line[100](0), b_TL_display[100](0);
array : b_b_line[100](0), b_b_TL_display[100](0);
array : u_cnt[100](0), u_text_display[100](0);
array : u_u_cnt[100](0), u_u_text_display[100](0);
array : u_line[100](0), u_TL_display[100](0);
array : u_u_line[100](0), u_u_TL_display[100](0);
if (sdate != sdate[1] and stime >= xtime) or
(sdate == sdate[1] and stime >= xtime and stime[1] < xtime) Then
Tcond = False;
if (sdate != sdate[1] and stime >= ntime) or
(sdate == sdate[1] and stime >= ntime and stime[1] < ntime) Then
{
// 변수들 초기화 해주기
Tcond = true;
oo = o;
For k = 1 to line_num
{
up_flag[k] = 0;
dn_flag[k] = 0;
u_cnt[k] = 0;
u_u_cnt[k] = 0;
b_cnt[k] = 0;
b_b_cnt[k] = 0;
PriceScale_tick_size = PriceScale*tick_size;
u_line[k] = oo + (k-1)*PriceScale_tick_size;
u_u_line[k] = oo + k*PriceScale_tick_size;
b_line[k] = oo - (k-1)*PriceScale_tick_size;
b_b_line[k] = oo - k*PriceScale_tick_size;
}
// 조건문으로 터치 카운트 하기
For k = 1 to line_num
{
if H >= u_u_line[k] Then
{
up_flag[k] = 1;
u_u_cnt[k] = u_u_cnt[k] + 1;
}
if L <= b_b_line[k] Then
{
dn_flag[k] = -1;
b_b_cnt[k] = b_b_cnt[k] + 1;
}
}
}
Else
{
if Tcond == true Then
{
For k = 1 to line_num
{
if dn_flag[k] <= 0 and H >= b_line[k] and H[1] < b_line[k] Then
{
dn_flag[k] = 1;
b_cnt[k] = b_cnt[k] + 1;
}
if dn_flag[k] >= 0 and L <= b_b_line[k] and L[k] > b_b_line[k] Then
{
dn_flag[k] = -1;
b_b_cnt[k] = b_b_cnt[k] + 1;
}
if up_flag[k] <= 0 and H >= u_u_line[k] and H[1] < u_u_line[k] Then
{
up_flag[k] = 1;
u_u_cnt[k] = u_u_cnt[k] + 1;
}
if up_flag[k] >= 0 and L <= u_line[k] and L[1] > u_line[k] Then
{
up_flag[k] = -1;
u_cnt[k] = u_cnt[k] + 1;
}
}
}
}
var : T(0);
if (sdate != sdate[1] and stime >= ntime) or
(sdate == sdate[1] and stime >= ntime and stime[1] < ntime) Then
{
T = 0;
n1 = NetProfit;
xcond = False;
}
if TotalTrades > TotalTrades[1] and (IsExitName("bp3",1) or IsExitName("sp3",1)) Then
xcond = true;
if Tcond == true and xcond == False Then
{
if T == 0 Then
{
For k = 1 to line_num
{
if u_u_cnt[k] >= num or u_cnt[k] >= num Then
{
T = k;
상단 = u_u_line[k];
하단 = u_line[k];
}
if b_b_cnt[k] >= num or b_cnt[k] >= num Then
{
T = k;
상단 = b_line[k];
하단 = b_b_line[k];
}
}
}
if T != 0 Then
{
dayPL = (NetProfit-n1)+PositionProfit(0); // n1은 초기의 NetProfit이다.
if daypl >= 0 Then
vol = 2;
Else
vol = max(Ceiling(abs(daypl)/((상단-하단)*3)),2);
ClearDebug;
MessageLog("dayPL : %.2f | NetProfit : %.2f | PositionProfit : %.2f | vol : %.f", daypl, NetProfit, PositionProfit, vol);
MessageLog("상단 : %.2f | 하단 : %.2f | 위청산 : %.2f | 아래청산 : %.2f", 상단, 하단, 상단+(상단-하단)*6, 하단-(상단-하단)*6);
MessageLog("상단 - 하단 : %.2f, T : %.f", 상단-하단, T);
if MarketPosition <= 0 and CrossUp(C,상단) Then
Buy("b1",AtMarket,Def,vol);
if MarketPosition >= 0 and CrossDown(C,하단) Then
Sell("s1",AtMarket,Def,vol);
if MarketPosition == 1 Then
{
ExitLong("Bp1",AtLimit,상단+(상단-하단)*3,"",Floor(CurrentContracts*0.5),1); // 3배수 위치에서 물량 일부 청산하기, 1은 전체에서 한번 청산, 0은 각 진입 횟수 만큼 청산
ExitLong("Bp2",AtLimit,상단+(상단-하단)*7,"",Floor(CurrentContracts*0.5),1);
ExitLong("Bp3",AtLimit,상단+(상단-하단)*10);
}
if MarketPosition == -1 Then
{
ExitShort("sp1",AtLimit,하단-(상단-하단)*3,"",Floor(CurrentContracts*0.5),1);
ExitShort("sp2",AtLimit,하단-(상단-하단)*7,"",Floor(CurrentContracts*0.5),1);
ExitShort("sp3",AtLimit,하단-(상단-하단)*10);
}
MessageLog("daypl %.2f", daypl);
}
}
--------------------------------------------------------------
위의 수식을 아래와 같이 수정, 보완하고 싶습니다
1. 목표가에서 청산후 거래 종료 시점부터
2. 다시 터치 횟수를 처음부터 시작해 5번 터치하면
3. 처음 진입 조건과 같이 진입하고 목표가에서 청산하고
4. 또 목표가에서 청산하고 나면
5. 청산 시점부터 다시 터치 횟수를 시작해
6. 5번 터치 한곳에서 진입을 시작하는 수식입니다
도움 부탁드립니다