커뮤니티

진입제한2

프로필 이미지
짱짱해야지
2019-04-04 14:18:55
197
글번호 127631
답변완료
일전에 주신 답변 감사합니다. 보내주신 코딩은 Currentcontracts에서 3개의 진입수를 합산하여 처리하는 것 같습니다. 각 진입별로 계약수를 관리하다가 매도 조건에서 매도할수 없는지요? 그리고 Daytrading말고 매수조건 이후 매도조건 발생할때까지 길게 가져가는 것으로 하고 싶습니다. 아래와 같이 작성했는데, 시작 조건일의 첫번째 조건의 진입매수와 매도 3번을 정상적으로 작동하지만, 그 이후 여러개 진입이 동시에 일어날 경우, 매도가 1,2번은 생략되고 3번 매도만 발생하는 등의 문제가 있습니다. 아마도 B1, V1, i1, M1, E1,X1,z1 등을 언제 초기화하는가에 문제가 있는 것 같습니다. 아마도 M과 E에 대한 다른 접근이 필요한 것 같기도 합니다. var : B1(0),B2(0),B3(0); var : I1(0),I2(0),I3(0); var : V1(0),V2(0),V3(0); var : M1(0),M2(0),M3(0); var : E1(0),E2(0),E3(0); var : X1(0),X2(0),X3(0); IF SDate > 20160901 then Begin # 조건변수 처리 if CurrentContracts > CurrentContracts[1] and LatestEntryName(0) == "DP_B" Then{ B1 = B1+1; i1 = index; V1 = V1+CurrentContracts-CurrentContracts[1]; #지정이름진입 수량 누적 M1 = M1+(CurrentContracts-CurrentContracts[1])*LatestEntryPrice(0); E1 = M1/V1;#평단가 } if CurrentContracts > CurrentContracts[1] and LatestEntryName(0) == "CC_B" Then{ B2 = B2+1; i2 = index; V2 = V2+CurrentContracts-CurrentContracts[1]; M2 = M2+(CurrentContracts-CurrentContracts[1])*LatestEntryPrice(0); E2 = M2/V2; } if CurrentContracts > CurrentContracts[1] and LatestEntryName(0) == "GS_B" Then{ B3 = B3+1; i3 = index; V3 = V3+CurrentContracts-CurrentContracts[1]; M3 = M3+(CurrentContracts-CurrentContracts[1])*LatestEntryPrice(0); E3 = M3/V3; } #### 매수조건 if DispBuy==1 and B1 < 2 Then{ if MarketPosition == 0 or LatestEntryName(0) != "DP_B" or (MarketPosition == 1 and LatestEntryName(0) == "DP_B" and index >= I1+20) Then buy("DP_B"); } if M_CCI == 1 and B2 < 2 Then{ if MarketPosition == 0 or LatestEntryName(0) != "CC_B" or (MarketPosition == 1 and LatestEntryName(0) == "CC_B" and index >= I2+20) Then buy("CC_B"); } iF crossDown(ma20, ma60) then CD_Check1 = index;{ if CD_Check1 + 11 < index then { if C <= 선행스팬2[52] and CrossUp(D_MA5, D_Dnline) then{ if MarketPosition == 0 or LatestEntryName(0) != "GS_B" or (MarketPosition == 1 and LatestEntryName(0) == "GS_B" and index >= I2+20) Then buy("GS_B"); } } } ### 매도 전략 if MarketPosition == 1 then{ if B1 >= 1 then{ if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "DP_S1" Then X1 = 1; if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "DP_S2" Then X1 = 2; if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "DP_S3" Then {X1 = 3; z1 = 1;} if X1 == 0 Then ExitLong("DP_S1",AtLimit,E1*1.05,"DP_B",Floor(V1*0.3),1); if X1 == 1 Then ExitLong("DP_S2",AtLimit,E1*1.10,"DP_B",Floor(V1*0.3),1); if X1 == 2 Then ExitLong("DP_S3",AtLimit,E1*1.15,"DP_B"); } } if MarketPosition == 1 then{ if B2 >= 1 then{ if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "CC_S1" Then X2 = 1; if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "CC_S2" Then X2 = 2; if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "CC_S3" Then {X2 = 3; z2 = 1;} if X2 == 0 Then ExitLong("CC_S1",AtLimit,E2*1.05,"CC_B",Floor(V2*0.3),1); if X2 == 1 Then ExitLong("CC_S2",AtLimit,E2*1.10,"CC_B",Floor(V2*0.3),1); if X2 == 2 Then ExitLong("CC_S3",AtLimit,E2*1.15,"CC_B"); } } if MarketPosition == 1 then{ if B3 >= 1 then{ if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "GS_S1" Then X3 = 1; if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "GS_S2" Then X3 = 2; if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "GS_S3" Then {X3 = 3; z3 = 1;} if X3 == 0 Then ExitLong("GS_S1",AtLimit,E3*1.05,"GS_B",Floor(V3*0.3),1); if X3 == 1 Then ExitLong("GS_S2",AtLimit,E3*1.10,"GS_B",Floor(V3*0.3),1); if X3 == 2 Then ExitLong("GS_S3",AtLimit,E3*1.15,"GS_B"); } } if CurrentContracts == 0 or z1[1] == 1 then {B1 = 0; V1 = 0; i1 = 0; M1 = 0; E1 = 0; X1 = 0; z1 = 0;} if CurrentContracts == 0 or z2[1] == 1 then {B2 = 0; V2 = 0; i2 = 0; M2 = 0; E2 = 0; X2 = 0; z2 = 0;} if CurrentContracts == 0 or z3[1] == 1 then {B3 = 0; V3 = 0; i3 = 0; M3 = 0; E3 = 0; X3 = 0; z3 = 0;}
시스템
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2019-04-05 13:53:16

안녕하세요 예스스탁입니다. 모든 수량이 청산되면 MarketPosition이 0으로 되므로 MarketPosition == 1 조건으로 들어가지 않으므로 x변수에 3을 할당하지 못합니다. 그러므로 포지션진행 중에 x가 3이 될때와 모든 수량이 청산되어 포지션이 끝났을때 최종 청산명으로 구분해 아래와 같이 변경하시면 될것 같습니다. if (MarketPosition == 1 and X1 == 3) or MarketPosition == 0 and LatestExitName(1) == "DP_S3" Then {B1 = 0; V1 = 0; i1 = 0; M1 = 0; E1 = 0; X1 = 0; z1 = 0;} if (MarketPosition == 1 and X2 == 3) or MarketPosition == 0 and LatestExitName(1) == "CC_S3" Then {B2 = 0; V2 = 0; i2 = 0; M2 = 0; E2 = 0; X2 = 0; z2 = 0;} if (MarketPosition == 1 and X3 == 3) or MarketPosition == 0 and LatestExitName(1) == "GS_S3" Then {B3 = 0; V3 = 0; i3 = 0; M3 = 0; E3 = 0; X3 = 0; z3 = 0;} 즐거운 하루되세요 > 짱짱해야지 님이 쓴 글입니다. > 제목 : 진입제한2 > 일전에 주신 답변 감사합니다. 보내주신 코딩은 Currentcontracts에서 3개의 진입수를 합산하여 처리하는 것 같습니다. 각 진입별로 계약수를 관리하다가 매도 조건에서 매도할수 없는지요? 그리고 Daytrading말고 매수조건 이후 매도조건 발생할때까지 길게 가져가는 것으로 하고 싶습니다. 아래와 같이 작성했는데, 시작 조건일의 첫번째 조건의 진입매수와 매도 3번을 정상적으로 작동하지만, 그 이후 여러개 진입이 동시에 일어날 경우, 매도가 1,2번은 생략되고 3번 매도만 발생하는 등의 문제가 있습니다. 아마도 B1, V1, i1, M1, E1,X1,z1 등을 언제 초기화하는가에 문제가 있는 것 같습니다. 아마도 M과 E에 대한 다른 접근이 필요한 것 같기도 합니다. var : B1(0),B2(0),B3(0); var : I1(0),I2(0),I3(0); var : V1(0),V2(0),V3(0); var : M1(0),M2(0),M3(0); var : E1(0),E2(0),E3(0); var : X1(0),X2(0),X3(0); IF SDate > 20160901 then Begin # 조건변수 처리 if CurrentContracts > CurrentContracts[1] and LatestEntryName(0) == "DP_B" Then{ B1 = B1+1; i1 = index; V1 = V1+CurrentContracts-CurrentContracts[1]; #지정이름진입 수량 누적 M1 = M1+(CurrentContracts-CurrentContracts[1])*LatestEntryPrice(0); E1 = M1/V1;#평단가 } if CurrentContracts > CurrentContracts[1] and LatestEntryName(0) == "CC_B" Then{ B2 = B2+1; i2 = index; V2 = V2+CurrentContracts-CurrentContracts[1]; M2 = M2+(CurrentContracts-CurrentContracts[1])*LatestEntryPrice(0); E2 = M2/V2; } if CurrentContracts > CurrentContracts[1] and LatestEntryName(0) == "GS_B" Then{ B3 = B3+1; i3 = index; V3 = V3+CurrentContracts-CurrentContracts[1]; M3 = M3+(CurrentContracts-CurrentContracts[1])*LatestEntryPrice(0); E3 = M3/V3; } #### 매수조건 if DispBuy==1 and B1 < 2 Then{ if MarketPosition == 0 or LatestEntryName(0) != "DP_B" or (MarketPosition == 1 and LatestEntryName(0) == "DP_B" and index >= I1+20) Then buy("DP_B"); } if M_CCI == 1 and B2 < 2 Then{ if MarketPosition == 0 or LatestEntryName(0) != "CC_B" or (MarketPosition == 1 and LatestEntryName(0) == "CC_B" and index >= I2+20) Then buy("CC_B"); } iF crossDown(ma20, ma60) then CD_Check1 = index;{ if CD_Check1 + 11 < index then { if C <= 선행스팬2[52] and CrossUp(D_MA5, D_Dnline) then{ if MarketPosition == 0 or LatestEntryName(0) != "GS_B" or (MarketPosition == 1 and LatestEntryName(0) == "GS_B" and index >= I2+20) Then buy("GS_B"); } } } ### 매도 전략 if MarketPosition == 1 then{ if B1 >= 1 then{ if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "DP_S1" Then X1 = 1; if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "DP_S2" Then X1 = 2; if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "DP_S3" Then {X1 = 3; z1 = 1;} if X1 == 0 Then ExitLong("DP_S1",AtLimit,E1*1.05,"DP_B",Floor(V1*0.3),1); if X1 == 1 Then ExitLong("DP_S2",AtLimit,E1*1.10,"DP_B",Floor(V1*0.3),1); if X1 == 2 Then ExitLong("DP_S3",AtLimit,E1*1.15,"DP_B"); } } if MarketPosition == 1 then{ if B2 >= 1 then{ if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "CC_S1" Then X2 = 1; if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "CC_S2" Then X2 = 2; if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "CC_S3" Then {X2 = 3; z2 = 1;} if X2 == 0 Then ExitLong("CC_S1",AtLimit,E2*1.05,"CC_B",Floor(V2*0.3),1); if X2 == 1 Then ExitLong("CC_S2",AtLimit,E2*1.10,"CC_B",Floor(V2*0.3),1); if X2 == 2 Then ExitLong("CC_S3",AtLimit,E2*1.15,"CC_B"); } } if MarketPosition == 1 then{ if B3 >= 1 then{ if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "GS_S1" Then X3 = 1; if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "GS_S2" Then X3 = 2; if CurrentContracts < CurrentContracts[1] and LatestExitName(0) == "GS_S3" Then {X3 = 3; z3 = 1;} if X3 == 0 Then ExitLong("GS_S1",AtLimit,E3*1.05,"GS_B",Floor(V3*0.3),1); if X3 == 1 Then ExitLong("GS_S2",AtLimit,E3*1.10,"GS_B",Floor(V3*0.3),1); if X3 == 2 Then ExitLong("GS_S3",AtLimit,E3*1.15,"GS_B"); } } if CurrentContracts == 0 or z1[1] == 1 then {B1 = 0; V1 = 0; i1 = 0; M1 = 0; E1 = 0; X1 = 0; z1 = 0;} if CurrentContracts == 0 or z2[1] == 1 then {B2 = 0; V2 = 0; i2 = 0; M2 = 0; E2 = 0; X2 = 0; z2 = 0;} if CurrentContracts == 0 or z3[1] == 1 then {B3 = 0; V3 = 0; i3 = 0; M3 = 0; E3 = 0; X3 = 0; z3 = 0;}