답변완료
지표문의입니다
수고가 많으십니다.
아래 수식을 적용할려고 보니 첨부그림과 같이 그게 나타나서 실행이 안됩니다. 무엇이 문제인건지..
그리고 아래수식을 시스템으로 적용시킬수 있는 방법은 없는건지 궁금합니다. 감사합니다.
//===================================================//
Input:ChgRate(0.25),굵기(1),크기(11);
Var:TL1(0),TL2(0),TL2_exist(0),color(0),
종가사용여부(0), // 종가로 계산하려면 1로 설정한다.
TL_NewBit(0), // 1:NewLine 2:SetEndLine
slope(0),mid_idx(0),mid_val(0),text1(0);
Array:고[10,4](0),저[10,4](0); // 1:가격,2:Index,3:sDate,4:sTime
#==========================================#
Value1 = ChgRateZigZag(ChgRate,종가사용여부,고,저,TL_NewBit);
If Value1 == 1 Then
{ // 고점
If TL_NewBit == 1 Then { // 신규
If 고[2,1] < 고[1,1] Then {
slope = (고[1,1] - 저[1,1]) / (고[1,2] - 저[1,2]);
mid_idx = Floor((고[2,1] - 저[1,1]) / slope);
mid_val = slope * mid_idx + 저[1,1];
Var1 = Index - (저[1,2] + mid_idx);
TL1 = TL_New(저[1,3],저[1,4],저[1,1],sDate[Var1],sTime[Var1],mid_val);
TL2 = TL_New(sDate[Var1],sTime[Var1],mid_val,고[1,3],고[1,4],고[1,1]);
Var2 = Index - 저[1,2];
TL_SetColor(TL1,color[Var2]);
color = RED;
TL_SetColor(TL2,color);
TL2_exist = 1;
} Else {
TL1 = TL_New(저[1,3],저[1,4],저[1,1],고[1,3],고[1,4],고[1,1]);
TL_SetColor(TL1,color);
TL2_exist = 0;
}
}
If TL_NewBit == 2 Then { // 연장
TL_Delete(TL1);
If TL2_exist == 1 Then TL_Delete(TL2);
If 고[2,1] < 고[1,1] Then {
slope = (고[1,1] - 저[1,1]) / (고[1,2] - 저[1,2]);
mid_idx = Floor((고[2,1] - 저[1,1]) / slope);
mid_val = slope * mid_idx + 저[1,1];
Var1 = Index - (저[1,2] + mid_idx);
TL1 = TL_New(저[1,3],저[1,4],저[1,1],sDate[Var1],sTime[Var1],mid_val);
TL2 = TL_New(sDate[Var1],sTime[Var1],mid_val,고[1,3],고[1,4],고[1,1]);
Var2 = Index - 저[1,2];
TL_SetColor(TL1,color[Var2]);
color = RED;
TL_SetColor(TL2,color);
TL2_exist = 1;
} Else {
TL1 = TL_New(저[1,3],저[1,4],저[1,1],고[1,3],고[1,4],고[1,1]);
TL_SetColor(TL1,color);
TL2_exist = 0;
}
}
} Else If Value1 == -1 Then { // 저점
If TL_NewBit == 1 Then { // 신규
If 저[2,1] > 저[1,1] Then {
slope = (저[1,1] - 고[1,1]) / (저[1,2] - 고[1,2]);
mid_idx = Floor((저[2,1] - 고[1,1]) / slope);
mid_val = slope * mid_idx + 고[1,1];
Var1 = Index - (고[1,2] + mid_idx);
TL1 = TL_New(고[1,3],고[1,4],고[1,1],sDate[Var1],sTime[Var1],mid_val);
TL2 = TL_New(sDate[Var1],sTime[Var1],mid_val,저[1,3],저[1,4],저[1,1]);
Var2 = Index - 고[1,2];
TL_SetColor(TL1,color[Var2]);
color = BLUE;
TL_SetColor(TL2,color);
TL2_exist = 1;
} Else {
TL1 = TL_New(고[1,3],고[1,4],고[1,1],저[1,3],저[1,4],저[1,1]);
TL_SetColor(TL1,color);
TL2_exist = 0;
}
}
If TL_NewBit == 2 Then { // 연장
TL_Delete(TL1);
If TL2_exist == 1 Then TL_Delete(TL2);
If 저[2,1] > 저[1,1] Then {
slope = (저[1,1] - 고[1,1]) / (저[1,2] - 고[1,2]);
mid_idx = Floor((저[2,1] - 고[1,1]) / slope);
mid_val = slope * mid_idx + 고[1,1];
Var1 = Index - (고[1,2] + mid_idx);
TL1 = TL_New(고[1,3],고[1,4],고[1,1],sDate[Var1],sTime[Var1],mid_val);
TL2 = TL_New(sDate[Var1],sTime[Var1],mid_val,저[1,3],저[1,4],저[1,1]);
Var2 = Index - 고[1,2];
TL_SetColor(TL1,color[Var2]);
color = BLUE;
TL_SetColor(TL2,color);
TL2_exist = 1;
} Else {
TL1 = TL_New(고[1,3],고[1,4],고[1,1],저[1,3],저[1,4],저[1,1]);
TL_SetColor(TL1,color);
TL2_exist = 0;
}
}
}
TL_SetSize(TL1,굵기);
TL_SetSize(TL2,굵기);
var : Tx(0);
if value1 == 1 Then
{
if value1[1] == -1 Then
{
Tx = Text_New(고[1,3],고[1,4],고[1,1],NumToStr(고[1,1],2)+"("+NumToStr(고[1,1]-저[1,1],2)+")");
Text_SetStyle(tx,2,1);
Text_SetColor(tx,BLACK);
}
Else
{
Text_SetString(tx,NumToStr(고[1,1],2)+"("+NumToStr(고[1,1]-저[1,1],2)+")");
Text_SetLocation(tx,고[1,3],고[1,4],고[1,1]);
}
}
if value1 == -1 Then
{
if value1[1] == 1 Then
{
Tx = Text_New(저[1,3],저[1,4],저[1,1],NumToStr(저[1,1],2)+"("+NumToStr(고[1,1]-저[1,1],2)+")");
Text_SetStyle(tx,2,0);
Text_SetColor(tx,BLACK);
}
Else
{
Text_SetString(tx,NumToStr(저[1,1],2)+"("+NumToStr(고[1,1]-저[1,1],2)+")");
Text_SetLocation(tx,저[1,3],저[1,4],저[1,1]);
}
}
2021-11-05
601
글번호 153413
지표
답변완료
문의드립니다
항상 친절히 도와주심에 감사드립니다.
지난번에 진입 부분을 보완해 주신 수식입니다.
기존 종가에 진입하는 것과 별 차이가 없는거 같아 다시 문의 드립니다.
매수 매도 진입할 때 신호가 나온 캔들의 종가에 진입하는데, 바로 시장가 진입하는 것이 아니라 눌림을 받고 다시 그 종가를 돌파할 때 진입하기를 원하는 것입니다.
눌림폭을 지정해서 그 조건이 맞는 경우만 진입하도록 하는 것이 가능한지요?
예를 들면 매수 신호가 나온 종가가 25100일 경우, 반대로 10틱 이상(25090이하) 반대로 갔다가 다시 25100을 돌파하는 경우에만 25100에 매수 진입하는 것입니다.
매도는 반대의 개념입니다.
틱수를 추가해서 진입조건을 추가 가능한지요?
가능하다면 수정 부탁드립니다.
감사합니다~~
input : StartTime(101200),EndTime(114000);
input : Length(20), D1(2);
input : 익절1(30),손절1(30),청산구분시간(103000),익절2(50),손절2(30),익절연속횟수(3),손절연속횟수(2);
var : Tcond(false),profit(0),loss(0),T(0),S(0);
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
{
T = 0;
Tcond = true;
profit = 0;
loss = 0;
}
if TotalTrades > TotalTrades[1] Then
{
if IsExitName("bp1.",1) or IsExitName("bp2.",21) or IsExitName("bp1",1) or IsExitName("bp2",21) or
IsExitName("sp1.",1) or IsExitName("sp2.",1) or IsExitName("sp1",1) or IsExitName("sp2",1) Then
profit = profit+1;
Else
profit = 0;
if IsExitName("bl1.",1) or IsExitName("bl2.",1) or IsExitName("bl1",1) or IsExitName("bl2",1) or
IsExitName("sl1.",1) or IsExitName("sl2.",1) or IsExitName("sl1",1) or IsExitName("sl2",1) Then
loss = loss+1;
Else
loss = 0;
}
var1 = BollBandUp(Length,D1);
var2 = BollBandDown(Length,D1);
if Tcond == true Then
{
#매수조건만족하면 T에 1, 해당봉종가는 S에 저장
If CrossUP(H,var1) and (c > o or (C==O and C >= C[1])) then
{
T = 1;
S = C;
}
#매도조건만족하면 T에 -1, 해당봉종가는 S에 저장
If CrossDown(L,Var2) and (C < O or (C==O and C < C[1])) then
{
T = -1;
S = C;
}
#T가 1인 상태이고 S를 상향돌파하면
If T == 1 and CrossUP(c,S) then
{
#T는 2로 변경하고
T = 2;
#매수
if profit < 익절연속횟수 and loss < 손절연속횟수 then
{
Buy("b",OnClose,DEF,1);
if sTime >= StartTime and sTime < 청산구분시간 Then
{
ExitLong("bp1.",AtLimit,C+PriceScale*익절1,"",1,1);
ExitLong("bl1.",AtStop,C-PriceScale*손절1,"",1,1);
}
if sTime >= 청산구분시간 and sTime < Endtime Then
{
ExitLong("bp2.",AtLimit,C+PriceScale*익절2,"",1,1);
ExitLong("bl2.",AtStop,C-PriceScale*손절2,"",1,1);
}
}
}
#T가 -1인 상태에서 S를 하향이탈하면
If T == -1 and crossdown(C,S) then
{
#T는 -2로 변경
T = -2;
#매도
if profit < 익절연속횟수 and loss < 손절연속횟수 then
{
Sell("s",OnClose,DEF,1);
if sTime >= StartTime and sTime < 103000 Then
{
ExitShort("sp1.",AtLimit,C-PriceScale*익절1,"",1,1);
ExitShort("sl1.",AtStop,C+PriceScale*손절1,"",1,1);
}
if sTime >= 103000 and sTime < Endtime Then
{
ExitShort("sp2.",AtLimit,C-PriceScale*익절2,"",1,1);
ExitShort("sl2.",AtStop,C+PriceScale*손절2,"",1,1);
}
}
}
}
if MarketPosition == 1 Then
{
if sTime >= StartTime and sTime < 청산구분시간 Then
{
ExitLong("bp1",AtLimit,EntryPrice+PriceScale*익절1,"",1,1);
ExitLong("bl1",AtStop,EntryPrice-PriceScale*손절1,"",1,1);
}
if sTime >= 청산구분시간 and sTime < Endtime Then
{
ExitLong("bp2",AtLimit,EntryPrice+PriceScale*익절2,"",1,1);
ExitLong("bl2",AtStop,EntryPrice-PriceScale*손절2,"",1,1);
}
}
if MarketPosition == -1 Then
{
if sTime >= StartTime and sTime < 103000 Then
{
ExitShort("sp1",AtLimit,EntryPrice-PriceScale*익절1,"",1,1);
ExitShort("sl1",AtStop,EntryPrice+PriceScale*손절1,"",1,1);
}
if sTime >= 103000 and sTime < Endtime Then
{
ExitShort("sp2",AtLimit,EntryPrice-PriceScale*익절2,"",1,1);
ExitShort("sl2",AtStop,EntryPrice+PriceScale*손절2,"",1,1);
}
}
IF Endtime > starttime Then
SetStopEndofday(Endtime);
Else
{
if sDate != sDate[1] Then
SetStopEndofday(Endtime);
}
if (sdate != sdate[1] and stime >= StartTime) or
(sdate == sdate[1] and stime >= StartTime and stime[1] < StartTime) Then
{
IF Endtime <= starttime Then
{
SetStopEndofday(0);
}
}
2021-11-04
452
글번호 153407
시스템