커뮤니티

수식 부탁드립니다.

프로필 이미지
spek
2015-06-01 21:38:07
160
글번호 86668
답변완료
안녕하세요? 매번 성의있는 답변 감사드립니다. 1. 과거 섬머타임 관련 질문을 드린적이 있는데, 아래와 같이 수정해 주신적이 있습니다. *수정 전 if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; Loss = 0; } *수정 후 (서머타임 적용) if Bdate != Bdate[1] Then{ var1 = O; Loss = 0; } 그런데 증권사 기준의 영업일 시작 시간은 10시(섬머타임 아닐 때), 9시(섬머타임 때) 이라서 그 때 시가가 기준으로 삼아집니다. 하지만 제가 원하는 하루의 주기는 16시를 시작으로 다음날 16시 까지 입니다. (섬머타임 아닐 때는 17시 ~ 17시) 그래서 제가 if TimeToMinutes(stime) >= TimeToMinutes(Bdate != Bdate[1])+480 Then{ var1 = O; Loss = 0; } 이런식으로 짜봤는데 안되네요. 이 부분은 그냥 섬머타임 때 마다 직접 변경하는 수 밖에 없나요? 이것 때문에 장기간 시뮬레이션 할 때에 동일 시간대를 일괄적용 할 수가 없네요. 2. 아래식은 손절인 Bx, Sx 뿐만아니라, bx1, sx1 이 발생했을 때도 당일 진입을 금지하는 식을 부탁드려서 받았던 답변입니다. 단, Bx, Sx 의 경우는 언제든 발생했을 경우 당일의 진입을 금지 하지만, bx1, sx1 의 경우는 당일 진입해서 당일 발생 했을 경우만 금지하고, 며칠 전 진입해서 당일 발행했을 경우에는, 당일의 시가를 기준으로 재진입을 허용하는 식입니다. 그런데 아래와 같은 식은 다른 부분은 생각했던 대로 잘 작동하지만, 밤 열두시를 넘어서 발생한 bx1, sx1 에 대해서는 재진입을 하더군요. 예를들어, 22일 16시 시가를 기준으로 23일 02시에 진입했다가 23일 03시에 bx1 또는 sx1 이 발생하면 23일 16시 전까지는 재진입 해서는 안됩니다. 그런데 하네요. 여기서 제가 말하는 당일, 하루는 16시 ~ 16시 입니다. 이는 해당 증권사의 영업시간 기준과 다릅니다. 그래서 Bdate 를 쓰면 안되는 것 같습니다. 그리고 아래식에서 변수로 BD(0) 가 선언 되었는데, 막상 식에서는 사용을 안하는데 왜 그런가요? Input : N(1); Var : HH(0), LL(0), Loss(0),BD(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; BD = Bdate; } if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and Bdate[BarsSinceEntry(1)] == Bdate and (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 3. 손절(Bx, Sx)이나 bx1, sx1 가 발생했을 경우에는 10분 내에 재진입을 금지하는 식을 부탁드립니다. (예전에 한번 부정확하게 질문을 드려서 최근에 다시 질문드렸는데, 답변을 빠뜨리신 듯 합니다.) Input : N(3); Var : HH(0), LL(0), Loss(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then var1 = O; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 4. 위 3번의 식에서 때때로 "LL <= EntryPrice*0.9" 와 같은 부분을 빼고 시뮬레이션 해보기 위해 "LL <= EntryPrice*0.9*ZZZ" 와 같이 변형해서, ZZZ 를 외부변서 1로 잡은 후 빼고 싶을 때는 ZZZ 에 0을 대입하곤 합니다. 그런데, 때때로 아래와 같은 식을 추가해서 bx1, sx1 도 손절인 Bx, Sx 처럼 발생하면 당일(하루 기준 16시~16시) 은 거래를 금지하도록 시뮬레이션 하기도 합니다. if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true) Then loss = loss+1; 그런데 이 식을 추가해보거나 빼보거나 하면서 시뮬레이션 할 때 일일히 수식에서 삭제, 붙여넣기를 반복해야 되는데, 방금 바로 위에 말씀드린 외부변서 ZZZ 처럼 외부변수 하나를 잡아놓고, 그 부분만 바꿔서 넣었다 뺐다 할 수 있게 하는 방법이 없나요? 단순히 (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true)*ZZZ 를 했더니 오류가 나더군요.
시스템
답변 5
프로필 이미지

예스스탁 예스스탁 답변

2015-06-02 11:38:42

안녕하세요 예스스탁입니다. 2,3,4번 내용 올려드립니다. 내일 오후 이후에 편하신 시간에 전화주시기 바랍니다. 2. BD는 사용하지 않습니다. 제거했습니다. 구분중 잘못된 부분이 있어 수정했습니다.bx1만 지정이 되어 있어 sx1도 추가했습니다. Input : N(1); Var : HH(0), LL(0), Loss(0),BD(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; } if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and Bdate[BarsSinceEntry(1)] == Bdate and (IsExitName("bx1",1) == true or IsExitName("sx1",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 3. Input : N(3); Var : HH(0), LL(0), Loss(0),dcnt(0),TF(0),TF1(0),EE(0),XX(false),TT(0),entry(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; dcnt = dcnt+1; Entry = 0; } if date != date[1] Then TF1 = TF[1]; if stime >= 160000 Then TF = TimeToMinutes(time)-TimeToMinutes(160000); Else TF = TimeToMinutes(time)+TF1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition != 0 and MarketPosition != MarketPosition[1] Then{ Entry = Entry+1; } #청산이 발생하면 청산명,청산시간을 저장 if Dcnt == EE and CurrentContracts < CurrentContracts[1] and MarketPosition != MarketPosition[1] Then{ if IsExitName("bx1",1) or IsExitName("bx1",1) or IsExitName("bx1",1) or IsExitName("bx1",1) Then XX = true; Else XX = false; TT = TF; } if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if ((MarketPosition == -1) or (MarketPosition == 0 and Entry >= 1 and XX == false) or (MarketPosition == 0 and Entry >= 1 and XX == true and TF >= TT+10)) and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if ((MarketPosition == 1) or (MarketPosition == 0 and Entry >= 1 and XX == false) or (MarketPosition == 0 and Entry >= 1 and XX == true and TF >= TT+10)) and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 4. 아래와 같이 ZZZ가 1이면 해당 구분을 사용하고 1이 아닌 값을 지정하면 동작하지 않게 하시면 됩니다. input : ZZZ(1); if ZZZ ==1 and MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true) Then loss = loss+1; 즐거운 하루되세요 > spek 님이 쓴 글입니다. > 제목 : 수식 부탁드립니다. > 안녕하세요? 매번 성의있는 답변 감사드립니다. 1. 과거 섬머타임 관련 질문을 드린적이 있는데, 아래와 같이 수정해 주신적이 있습니다. *수정 전 if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; Loss = 0; } *수정 후 (서머타임 적용) if Bdate != Bdate[1] Then{ var1 = O; Loss = 0; } 그런데 증권사 기준의 영업일 시작 시간은 10시(섬머타임 아닐 때), 9시(섬머타임 때) 이라서 그 때 시가가 기준으로 삼아집니다. 하지만 제가 원하는 하루의 주기는 16시를 시작으로 다음날 16시 까지 입니다. (섬머타임 아닐 때는 17시 ~ 17시) 그래서 제가 if TimeToMinutes(stime) >= TimeToMinutes(Bdate != Bdate[1])+480 Then{ var1 = O; Loss = 0; } 이런식으로 짜봤는데 안되네요. 이 부분은 그냥 섬머타임 때 마다 직접 변경하는 수 밖에 없나요? 이것 때문에 장기간 시뮬레이션 할 때에 동일 시간대를 일괄적용 할 수가 없네요. 2. 아래식은 손절인 Bx, Sx 뿐만아니라, bx1, sx1 이 발생했을 때도 당일 진입을 금지하는 식을 부탁드려서 받았던 답변입니다. 단, Bx, Sx 의 경우는 언제든 발생했을 경우 당일의 진입을 금지 하지만, bx1, sx1 의 경우는 당일 진입해서 당일 발생 했을 경우만 금지하고, 며칠 전 진입해서 당일 발행했을 경우에는, 당일의 시가를 기준으로 재진입을 허용하는 식입니다. 그런데 아래와 같은 식은 다른 부분은 생각했던 대로 잘 작동하지만, 밤 열두시를 넘어서 발생한 bx1, sx1 에 대해서는 재진입을 하더군요. 예를들어, 22일 16시 시가를 기준으로 23일 02시에 진입했다가 23일 03시에 bx1 또는 sx1 이 발생하면 23일 16시 전까지는 재진입 해서는 안됩니다. 그런데 하네요. 여기서 제가 말하는 당일, 하루는 16시 ~ 16시 입니다. 이는 해당 증권사의 영업시간 기준과 다릅니다. 그래서 Bdate 를 쓰면 안되는 것 같습니다. 그리고 아래식에서 변수로 BD(0) 가 선언 되었는데, 막상 식에서는 사용을 안하는데 왜 그런가요? Input : N(1); Var : HH(0), LL(0), Loss(0),BD(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; BD = Bdate; } if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and Bdate[BarsSinceEntry(1)] == Bdate and (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 3. 손절(Bx, Sx)이나 bx1, sx1 가 발생했을 경우에는 10분 내에 재진입을 금지하는 식을 부탁드립니다. (예전에 한번 부정확하게 질문을 드려서 최근에 다시 질문드렸는데, 답변을 빠뜨리신 듯 합니다.) Input : N(3); Var : HH(0), LL(0), Loss(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then var1 = O; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 4. 위 3번의 식에서 때때로 "LL <= EntryPrice*0.9" 와 같은 부분을 빼고 시뮬레이션 해보기 위해 "LL <= EntryPrice*0.9*ZZZ" 와 같이 변형해서, ZZZ 를 외부변서 1로 잡은 후 빼고 싶을 때는 ZZZ 에 0을 대입하곤 합니다. 그런데, 때때로 아래와 같은 식을 추가해서 bx1, sx1 도 손절인 Bx, Sx 처럼 발생하면 당일(하루 기준 16시~16시) 은 거래를 금지하도록 시뮬레이션 하기도 합니다. if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true) Then loss = loss+1; 그런데 이 식을 추가해보거나 빼보거나 하면서 시뮬레이션 할 때 일일히 수식에서 삭제, 붙여넣기를 반복해야 되는데, 방금 바로 위에 말씀드린 외부변서 ZZZ 처럼 외부변수 하나를 잡아놓고, 그 부분만 바꿔서 넣었다 뺐다 할 수 있게 하는 방법이 없나요? 단순히 (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true)*ZZZ 를 했더니 오류가 나더군요.
프로필 이미지

예스스탁 예스스탁 답변

2015-06-03 18:16:41

안녕하세요 예스스탁입니다. 식을 수정했습니다. 다르신 부분 있으시면 전화주시기 바랍니다. 1. Input : N(1); Var : HH(0), LL(0), Loss(0),BD(0),dcnt(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; Dcnt = Dcnt+1; Loss = 0; } if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and Dcnt[BarsSinceEntry(1)] == Dcnt and (IsExitName("bx1",1) == true or IsExitName("sx1",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 2. Input : N(3); Var : HH(0), LL(0), Loss(0),dcnt(0),TF(0),TF1(0),EE(0),XX(false),TT(0),Xcond(false); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; dcnt = dcnt+1; } if date != date[1] Then TF1 = TF[1]; if stime >= 160000 Then TF = TimeToMinutes(stime)-TimeToMinutes(160000); Else TF = TimeToMinutes(stime)+TF1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); #직전 청산이 같은 날짜수(Dcnt)이고 청산명이 Bx,Sx,bx1,sx1이면 true 아니면 false Xcond = Dcnt[BarsSinceExit(1)] == Dcnt and IsExitName("Bx",1) == true or IsExitName("Sx",1) == true or IsExitName("bx1",1) == true or IsExitName("sx1",1) == true; if loss < N then{ if ((MarketPosition == -1) or (MarketPosition == 0 and Xcond == false) or (MarketPosition == 0 and Xcond == true and TF >= TT+10)) and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if ((MarketPosition == 1) or (MarketPosition == 0 and Xcond == false) or (MarketPosition == 0 and Xcond == true and TF >= TT+10)) and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 3. 16시 이후에 경과된 분수는 아래 지표 적용해 보시면 됩니다. Input : N(3); Var : HH(0), LL(0), Loss(0),dcnt(0),TF(0),TF1(0),EE(0),XX(false),TT(0),entry(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; dcnt = dcnt+1; Entry = 0; } if date != date[1] Then TF1 = TF[1]; if stime >= 160000 Then TF = TimeToMinutes(time)-TimeToMinutes(160000); Else TF = TimeToMinutes(time)+TF1; plot1(TF); 즐거운 하루되세요 > 예스스탁 님이 쓴 글입니다. > 제목 : Re : 수식 부탁드립니다. > 안녕하세요 예스스탁입니다. 2,3,4번 내용 올려드립니다. 내일 오후 이후에 편하신 시간에 전화주시기 바랍니다. 2. BD는 사용하지 않습니다. 제거했습니다. 구분중 잘못된 부분이 있어 수정했습니다.bx1만 지정이 되어 있어 sx1도 추가했습니다. Input : N(1); Var : HH(0), LL(0), Loss(0),BD(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; } if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and Bdate[BarsSinceEntry(1)] == Bdate and (IsExitName("bx1",1) == true or IsExitName("sx1",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 3. Input : N(3); Var : HH(0), LL(0), Loss(0),dcnt(0),TF(0),TF1(0),EE(0),XX(false),TT(0),entry(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; dcnt = dcnt+1; Entry = 0; } if date != date[1] Then TF1 = TF[1]; if stime >= 160000 Then TF = TimeToMinutes(time)-TimeToMinutes(160000); Else TF = TimeToMinutes(time)+TF1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition != 0 and MarketPosition != MarketPosition[1] Then{ Entry = Entry+1; } #청산이 발생하면 청산명,청산시간을 저장 if Dcnt == EE and CurrentContracts < CurrentContracts[1] and MarketPosition != MarketPosition[1] Then{ if IsExitName("bx1",1) or IsExitName("bx1",1) or IsExitName("bx1",1) or IsExitName("bx1",1) Then XX = true; Else XX = false; TT = TF; } if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if ((MarketPosition == -1) or (MarketPosition == 0 and Entry >= 1 and XX == false) or (MarketPosition == 0 and Entry >= 1 and XX == true and TF >= TT+10)) and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if ((MarketPosition == 1) or (MarketPosition == 0 and Entry >= 1 and XX == false) or (MarketPosition == 0 and Entry >= 1 and XX == true and TF >= TT+10)) and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 4. 아래와 같이 ZZZ가 1이면 해당 구분을 사용하고 1이 아닌 값을 지정하면 동작하지 않게 하시면 됩니다. input : ZZZ(1); if ZZZ ==1 and MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true) Then loss = loss+1; 즐거운 하루되세요 > spek 님이 쓴 글입니다. > 제목 : 수식 부탁드립니다. > 안녕하세요? 매번 성의있는 답변 감사드립니다. 1. 과거 섬머타임 관련 질문을 드린적이 있는데, 아래와 같이 수정해 주신적이 있습니다. *수정 전 if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; Loss = 0; } *수정 후 (서머타임 적용) if Bdate != Bdate[1] Then{ var1 = O; Loss = 0; } 그런데 증권사 기준의 영업일 시작 시간은 10시(섬머타임 아닐 때), 9시(섬머타임 때) 이라서 그 때 시가가 기준으로 삼아집니다. 하지만 제가 원하는 하루의 주기는 16시를 시작으로 다음날 16시 까지 입니다. (섬머타임 아닐 때는 17시 ~ 17시) 그래서 제가 if TimeToMinutes(stime) >= TimeToMinutes(Bdate != Bdate[1])+480 Then{ var1 = O; Loss = 0; } 이런식으로 짜봤는데 안되네요. 이 부분은 그냥 섬머타임 때 마다 직접 변경하는 수 밖에 없나요? 이것 때문에 장기간 시뮬레이션 할 때에 동일 시간대를 일괄적용 할 수가 없네요. 2. 아래식은 손절인 Bx, Sx 뿐만아니라, bx1, sx1 이 발생했을 때도 당일 진입을 금지하는 식을 부탁드려서 받았던 답변입니다. 단, Bx, Sx 의 경우는 언제든 발생했을 경우 당일의 진입을 금지 하지만, bx1, sx1 의 경우는 당일 진입해서 당일 발생 했을 경우만 금지하고, 며칠 전 진입해서 당일 발행했을 경우에는, 당일의 시가를 기준으로 재진입을 허용하는 식입니다. 그런데 아래와 같은 식은 다른 부분은 생각했던 대로 잘 작동하지만, 밤 열두시를 넘어서 발생한 bx1, sx1 에 대해서는 재진입을 하더군요. 예를들어, 22일 16시 시가를 기준으로 23일 02시에 진입했다가 23일 03시에 bx1 또는 sx1 이 발생하면 23일 16시 전까지는 재진입 해서는 안됩니다. 그런데 하네요. 여기서 제가 말하는 당일, 하루는 16시 ~ 16시 입니다. 이는 해당 증권사의 영업시간 기준과 다릅니다. 그래서 Bdate 를 쓰면 안되는 것 같습니다. 그리고 아래식에서 변수로 BD(0) 가 선언 되었는데, 막상 식에서는 사용을 안하는데 왜 그런가요? Input : N(1); Var : HH(0), LL(0), Loss(0),BD(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; BD = Bdate; } if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and Bdate[BarsSinceEntry(1)] == Bdate and (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 3. 손절(Bx, Sx)이나 bx1, sx1 가 발생했을 경우에는 10분 내에 재진입을 금지하는 식을 부탁드립니다. (예전에 한번 부정확하게 질문을 드려서 최근에 다시 질문드렸는데, 답변을 빠뜨리신 듯 합니다.) Input : N(3); Var : HH(0), LL(0), Loss(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then var1 = O; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 4. 위 3번의 식에서 때때로 "LL <= EntryPrice*0.9" 와 같은 부분을 빼고 시뮬레이션 해보기 위해 "LL <= EntryPrice*0.9*ZZZ" 와 같이 변형해서, ZZZ 를 외부변서 1로 잡은 후 빼고 싶을 때는 ZZZ 에 0을 대입하곤 합니다. 그런데, 때때로 아래와 같은 식을 추가해서 bx1, sx1 도 손절인 Bx, Sx 처럼 발생하면 당일(하루 기준 16시~16시) 은 거래를 금지하도록 시뮬레이션 하기도 합니다. if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true) Then loss = loss+1; 그런데 이 식을 추가해보거나 빼보거나 하면서 시뮬레이션 할 때 일일히 수식에서 삭제, 붙여넣기를 반복해야 되는데, 방금 바로 위에 말씀드린 외부변서 ZZZ 처럼 외부변수 하나를 잡아놓고, 그 부분만 바꿔서 넣었다 뺐다 할 수 있게 하는 방법이 없나요? 단순히 (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true)*ZZZ 를 했더니 오류가 나더군요.
프로필 이미지

spek

2015-06-03 23:24:50

안녕하십니까? 고생 많으십니다. 매번 감사드립니다. 새로 작성해주신 10분내 재진입 금지식도 작동을 하지 않네요. 제 생각인데, 저번에 작성해주신 것이나 새로 수정해 주신 것이나, 둘다 16시를 주기로 한 것에는 이상이 없는 것 같습니다. 다만, *수정전 if ((MarketPosition == 0) or (MarketPosition == 0 and Entry >= 1 and XX == false) or (MarketPosition == 0 and Entry >= 1 and XX == true and TF >= TT+10)) *수정후 if ((MarketPosition == 0) or (MarketPosition == 0 and Xcond == false) or (MarketPosition == 0 and Xcond == true and TF >= TT+10)) 이 부분이 문제인 것 같습니다. 식 자체는 수정 전이나 후나 동일한 듯 합니다. 그보다는 and 나 or 의 문제가 아닌가 싶습니다. 왜냐하면 위의 식대로라면 세가지 조건 중 아무것이나 맞으면 진입하게 되어있기 때문입니다. 그러니 첫번째 그림에서 처럼 bx1 이 발생한 후에도 세 조건 중 하나가 맞으니, 그냥 바로 진입한 것 같습니다. 그러니 bx1, sx1 이 발생했을 때는 아래와 같은 조건이 발생해도, (MarketPosition == 0) or (MarketPosition == 0 and Entry >= 1 and XX == false) 10분간은 진입을 금지하도록 하는 부분이 추가되어야 될 듯 합니다. 나름 그 부분을 추가하려고 여러 시도를 해봤는데 잘 안되네요. 두번째 그림은 plot1(bdate); 해서 나온 그래프입니다. 보시다시피 날짜는 매일 9시에 바뀌며 겨울에는 10시에 바뀝니다. (9시 10분, 10시 10분으로 나온이유는 한투 예스트레이더에서는 10분씩 늦게 표시가 됩니다.) 서머타임도 저 bdate 를 기준으로 할 수 없는건가요? 예를들어 9시 + 420분 = 16시, 10시 + 420분 = 17시. 이런식으로 되면 좋겠네요. > 예스스탁 님이 쓴 글입니다. > 제목 : Re : Re : 수식 부탁드립니다. > 안녕하세요 예스스탁입니다. 식을 수정했습니다. 다르신 부분 있으시면 전화주시기 바랍니다. 1. Input : N(1); Var : HH(0), LL(0), Loss(0),BD(0),dcnt(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; Dcnt = Dcnt+1; Loss = 0; } if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and Dcnt[BarsSinceEntry(1)] == Dcnt and (IsExitName("bx1",1) == true or IsExitName("sx1",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 2. Input : N(3); Var : HH(0), LL(0), Loss(0),dcnt(0),TF(0),TF1(0),EE(0),XX(false),TT(0),Xcond(false); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; dcnt = dcnt+1; } if date != date[1] Then TF1 = TF[1]; if stime >= 160000 Then TF = TimeToMinutes(stime)-TimeToMinutes(160000); Else TF = TimeToMinutes(stime)+TF1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); #직전 청산이 같은 날짜수(Dcnt)이고 청산명이 Bx,Sx,bx1,sx1이면 true 아니면 false Xcond = Dcnt[BarsSinceExit(1)] == Dcnt and IsExitName("Bx",1) == true or IsExitName("Sx",1) == true or IsExitName("bx1",1) == true or IsExitName("sx1",1) == true; if loss < N then{ if ((MarketPosition == -1) or (MarketPosition == 0 and Xcond == false) or (MarketPosition == 0 and Xcond == true and TF >= TT+10)) and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if ((MarketPosition == 1) or (MarketPosition == 0 and Xcond == false) or (MarketPosition == 0 and Xcond == true and TF >= TT+10)) and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 3. 16시 이후에 경과된 분수는 아래 지표 적용해 보시면 됩니다. Input : N(3); Var : HH(0), LL(0), Loss(0),dcnt(0),TF(0),TF1(0),EE(0),XX(false),TT(0),entry(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; dcnt = dcnt+1; Entry = 0; } if date != date[1] Then TF1 = TF[1]; if stime >= 160000 Then TF = TimeToMinutes(time)-TimeToMinutes(160000); Else TF = TimeToMinutes(time)+TF1; plot1(TF); 즐거운 하루되세요 > 예스스탁 님이 쓴 글입니다. > 제목 : Re : 수식 부탁드립니다. > 안녕하세요 예스스탁입니다. 2,3,4번 내용 올려드립니다. 내일 오후 이후에 편하신 시간에 전화주시기 바랍니다. 2. BD는 사용하지 않습니다. 제거했습니다. 구분중 잘못된 부분이 있어 수정했습니다.bx1만 지정이 되어 있어 sx1도 추가했습니다. Input : N(1); Var : HH(0), LL(0), Loss(0),BD(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; } if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and Bdate[BarsSinceEntry(1)] == Bdate and (IsExitName("bx1",1) == true or IsExitName("sx1",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 3. Input : N(3); Var : HH(0), LL(0), Loss(0),dcnt(0),TF(0),TF1(0),EE(0),XX(false),TT(0),entry(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; dcnt = dcnt+1; Entry = 0; } if date != date[1] Then TF1 = TF[1]; if stime >= 160000 Then TF = TimeToMinutes(time)-TimeToMinutes(160000); Else TF = TimeToMinutes(time)+TF1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition != 0 and MarketPosition != MarketPosition[1] Then{ Entry = Entry+1; } #청산이 발생하면 청산명,청산시간을 저장 if Dcnt == EE and CurrentContracts < CurrentContracts[1] and MarketPosition != MarketPosition[1] Then{ if IsExitName("bx1",1) or IsExitName("bx1",1) or IsExitName("bx1",1) or IsExitName("bx1",1) Then XX = true; Else XX = false; TT = TF; } if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if ((MarketPosition == -1) or (MarketPosition == 0 and Entry >= 1 and XX == false) or (MarketPosition == 0 and Entry >= 1 and XX == true and TF >= TT+10)) and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if ((MarketPosition == 1) or (MarketPosition == 0 and Entry >= 1 and XX == false) or (MarketPosition == 0 and Entry >= 1 and XX == true and TF >= TT+10)) and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 4. 아래와 같이 ZZZ가 1이면 해당 구분을 사용하고 1이 아닌 값을 지정하면 동작하지 않게 하시면 됩니다. input : ZZZ(1); if ZZZ ==1 and MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true) Then loss = loss+1; 즐거운 하루되세요 > spek 님이 쓴 글입니다. > 제목 : 수식 부탁드립니다. > 안녕하세요? 매번 성의있는 답변 감사드립니다. 1. 과거 섬머타임 관련 질문을 드린적이 있는데, 아래와 같이 수정해 주신적이 있습니다. *수정 전 if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; Loss = 0; } *수정 후 (서머타임 적용) if Bdate != Bdate[1] Then{ var1 = O; Loss = 0; } 그런데 증권사 기준의 영업일 시작 시간은 10시(섬머타임 아닐 때), 9시(섬머타임 때) 이라서 그 때 시가가 기준으로 삼아집니다. 하지만 제가 원하는 하루의 주기는 16시를 시작으로 다음날 16시 까지 입니다. (섬머타임 아닐 때는 17시 ~ 17시) 그래서 제가 if TimeToMinutes(stime) >= TimeToMinutes(Bdate != Bdate[1])+480 Then{ var1 = O; Loss = 0; } 이런식으로 짜봤는데 안되네요. 이 부분은 그냥 섬머타임 때 마다 직접 변경하는 수 밖에 없나요? 이것 때문에 장기간 시뮬레이션 할 때에 동일 시간대를 일괄적용 할 수가 없네요. 2. 아래식은 손절인 Bx, Sx 뿐만아니라, bx1, sx1 이 발생했을 때도 당일 진입을 금지하는 식을 부탁드려서 받았던 답변입니다. 단, Bx, Sx 의 경우는 언제든 발생했을 경우 당일의 진입을 금지 하지만, bx1, sx1 의 경우는 당일 진입해서 당일 발생 했을 경우만 금지하고, 며칠 전 진입해서 당일 발행했을 경우에는, 당일의 시가를 기준으로 재진입을 허용하는 식입니다. 그런데 아래와 같은 식은 다른 부분은 생각했던 대로 잘 작동하지만, 밤 열두시를 넘어서 발생한 bx1, sx1 에 대해서는 재진입을 하더군요. 예를들어, 22일 16시 시가를 기준으로 23일 02시에 진입했다가 23일 03시에 bx1 또는 sx1 이 발생하면 23일 16시 전까지는 재진입 해서는 안됩니다. 그런데 하네요. 여기서 제가 말하는 당일, 하루는 16시 ~ 16시 입니다. 이는 해당 증권사의 영업시간 기준과 다릅니다. 그래서 Bdate 를 쓰면 안되는 것 같습니다. 그리고 아래식에서 변수로 BD(0) 가 선언 되었는데, 막상 식에서는 사용을 안하는데 왜 그런가요? Input : N(1); Var : HH(0), LL(0), Loss(0),BD(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; BD = Bdate; } if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and Bdate[BarsSinceEntry(1)] == Bdate and (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 3. 손절(Bx, Sx)이나 bx1, sx1 가 발생했을 경우에는 10분 내에 재진입을 금지하는 식을 부탁드립니다. (예전에 한번 부정확하게 질문을 드려서 최근에 다시 질문드렸는데, 답변을 빠뜨리신 듯 합니다.) Input : N(3); Var : HH(0), LL(0), Loss(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then var1 = O; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 4. 위 3번의 식에서 때때로 "LL <= EntryPrice*0.9" 와 같은 부분을 빼고 시뮬레이션 해보기 위해 "LL <= EntryPrice*0.9*ZZZ" 와 같이 변형해서, ZZZ 를 외부변서 1로 잡은 후 빼고 싶을 때는 ZZZ 에 0을 대입하곤 합니다. 그런데, 때때로 아래와 같은 식을 추가해서 bx1, sx1 도 손절인 Bx, Sx 처럼 발생하면 당일(하루 기준 16시~16시) 은 거래를 금지하도록 시뮬레이션 하기도 합니다. if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true) Then loss = loss+1; 그런데 이 식을 추가해보거나 빼보거나 하면서 시뮬레이션 할 때 일일히 수식에서 삭제, 붙여넣기를 반복해야 되는데, 방금 바로 위에 말씀드린 외부변서 ZZZ 처럼 외부변수 하나를 잡아놓고, 그 부분만 바꿔서 넣었다 뺐다 할 수 있게 하는 방법이 없나요? 단순히 (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true)*ZZZ 를 했더니 오류가 나더군요.
프로필 이미지

예스스탁 예스스탁 답변

2015-06-04 17:30:43

안녕하세요 예스스탁입니다. Input : N(3); Var : HH(0), LL(0), Loss(0),dcnt(0),TF(0),TF1(0),EE(0),XX(false),Xcond(false); var : Start(0); if Bdate != Bdate[1] Then{ if stime >= 100000 Then Start = 170000; Else Start = 160000; } if stime == Start or (stime > Start and stime[1] < Start) Then{ var1 = O; dcnt = dcnt+1; } if date != date[1] Then TF1 = TF[1]; if stime >= Start Then TF = TimeToMinutes(stime)-TimeToMinutes(Start); Else TF = TimeToMinutes(stime)+TF1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); #직전 청산이 같은 날짜수(Dcnt)이고 청산명이 Bx,Sx,bx1,sx1이면 true 아니면 false Xcond = Dcnt[BarsSinceExit(1)] == Dcnt and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true or IsExitName("bx1",1) == true or IsExitName("sx1",1) == true); if loss < N then{ if ((MarketPosition == 0 and Xcond == false) or (MarketPosition == 0 and Xcond == true and TF >= TF[BarsSinceExit(1)]+20)) and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if ((MarketPosition == 0 and Xcond == false) or (MarketPosition == 0 and Xcond == true and TF >= TF[BarsSinceExit(1)]+20)) and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 즐거운 하루되세요 > spek 님이 쓴 글입니다. > 제목 : Re : Re : Re : 수식 부탁드립니다. > 안녕하십니까? 고생 많으십니다. 매번 감사드립니다. 새로 작성해주신 10분내 재진입 금지식도 작동을 하지 않네요. 제 생각인데, 저번에 작성해주신 것이나 새로 수정해 주신 것이나, 둘다 16시를 주기로 한 것에는 이상이 없는 것 같습니다. 다만, *수정전 if ((MarketPosition == 0) or (MarketPosition == 0 and Entry >= 1 and XX == false) or (MarketPosition == 0 and Entry >= 1 and XX == true and TF >= TT+10)) *수정후 if ((MarketPosition == 0) or (MarketPosition == 0 and Xcond == false) or (MarketPosition == 0 and Xcond == true and TF >= TT+10)) 이 부분이 문제인 것 같습니다. 식 자체는 수정 전이나 후나 동일한 듯 합니다. 그보다는 and 나 or 의 문제가 아닌가 싶습니다. 왜냐하면 위의 식대로라면 세가지 조건 중 아무것이나 맞으면 진입하게 되어있기 때문입니다. 그러니 첫번째 그림에서 처럼 bx1 이 발생한 후에도 세 조건 중 하나가 맞으니, 그냥 바로 진입한 것 같습니다. 그러니 bx1, sx1 이 발생했을 때는 아래와 같은 조건이 발생해도, (MarketPosition == 0) or (MarketPosition == 0 and Entry >= 1 and XX == false) 10분간은 진입을 금지하도록 하는 부분이 추가되어야 될 듯 합니다. 나름 그 부분을 추가하려고 여러 시도를 해봤는데 잘 안되네요. 두번째 그림은 plot1(bdate); 해서 나온 그래프입니다. 보시다시피 날짜는 매일 9시에 바뀌며 겨울에는 10시에 바뀝니다. (9시 10분, 10시 10분으로 나온이유는 한투 예스트레이더에서는 10분씩 늦게 표시가 됩니다.) 서머타임도 저 bdate 를 기준으로 할 수 없는건가요? 예를들어 9시 + 420분 = 16시, 10시 + 420분 = 17시. 이런식으로 되면 좋겠네요. > 예스스탁 님이 쓴 글입니다. > 제목 : Re : Re : 수식 부탁드립니다. > 안녕하세요 예스스탁입니다. 식을 수정했습니다. 다르신 부분 있으시면 전화주시기 바랍니다. 1. Input : N(1); Var : HH(0), LL(0), Loss(0),BD(0),dcnt(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; Dcnt = Dcnt+1; Loss = 0; } if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and Dcnt[BarsSinceEntry(1)] == Dcnt and (IsExitName("bx1",1) == true or IsExitName("sx1",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 2. Input : N(3); Var : HH(0), LL(0), Loss(0),dcnt(0),TF(0),TF1(0),EE(0),XX(false),TT(0),Xcond(false); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; dcnt = dcnt+1; } if date != date[1] Then TF1 = TF[1]; if stime >= 160000 Then TF = TimeToMinutes(stime)-TimeToMinutes(160000); Else TF = TimeToMinutes(stime)+TF1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); #직전 청산이 같은 날짜수(Dcnt)이고 청산명이 Bx,Sx,bx1,sx1이면 true 아니면 false Xcond = Dcnt[BarsSinceExit(1)] == Dcnt and IsExitName("Bx",1) == true or IsExitName("Sx",1) == true or IsExitName("bx1",1) == true or IsExitName("sx1",1) == true; if loss < N then{ if ((MarketPosition == -1) or (MarketPosition == 0 and Xcond == false) or (MarketPosition == 0 and Xcond == true and TF >= TT+10)) and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if ((MarketPosition == 1) or (MarketPosition == 0 and Xcond == false) or (MarketPosition == 0 and Xcond == true and TF >= TT+10)) and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 3. 16시 이후에 경과된 분수는 아래 지표 적용해 보시면 됩니다. Input : N(3); Var : HH(0), LL(0), Loss(0),dcnt(0),TF(0),TF1(0),EE(0),XX(false),TT(0),entry(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; dcnt = dcnt+1; Entry = 0; } if date != date[1] Then TF1 = TF[1]; if stime >= 160000 Then TF = TimeToMinutes(time)-TimeToMinutes(160000); Else TF = TimeToMinutes(time)+TF1; plot1(TF); 즐거운 하루되세요 > 예스스탁 님이 쓴 글입니다. > 제목 : Re : 수식 부탁드립니다. > 안녕하세요 예스스탁입니다. 2,3,4번 내용 올려드립니다. 내일 오후 이후에 편하신 시간에 전화주시기 바랍니다. 2. BD는 사용하지 않습니다. 제거했습니다. 구분중 잘못된 부분이 있어 수정했습니다.bx1만 지정이 되어 있어 sx1도 추가했습니다. Input : N(1); Var : HH(0), LL(0), Loss(0),BD(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; } if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and Bdate[BarsSinceEntry(1)] == Bdate and (IsExitName("bx1",1) == true or IsExitName("sx1",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 3. Input : N(3); Var : HH(0), LL(0), Loss(0),dcnt(0),TF(0),TF1(0),EE(0),XX(false),TT(0),entry(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; dcnt = dcnt+1; Entry = 0; } if date != date[1] Then TF1 = TF[1]; if stime >= 160000 Then TF = TimeToMinutes(time)-TimeToMinutes(160000); Else TF = TimeToMinutes(time)+TF1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition != 0 and MarketPosition != MarketPosition[1] Then{ Entry = Entry+1; } #청산이 발생하면 청산명,청산시간을 저장 if Dcnt == EE and CurrentContracts < CurrentContracts[1] and MarketPosition != MarketPosition[1] Then{ if IsExitName("bx1",1) or IsExitName("bx1",1) or IsExitName("bx1",1) or IsExitName("bx1",1) Then XX = true; Else XX = false; TT = TF; } if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if ((MarketPosition == -1) or (MarketPosition == 0 and Entry >= 1 and XX == false) or (MarketPosition == 0 and Entry >= 1 and XX == true and TF >= TT+10)) and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if ((MarketPosition == 1) or (MarketPosition == 0 and Entry >= 1 and XX == false) or (MarketPosition == 0 and Entry >= 1 and XX == true and TF >= TT+10)) and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 4. 아래와 같이 ZZZ가 1이면 해당 구분을 사용하고 1이 아닌 값을 지정하면 동작하지 않게 하시면 됩니다. input : ZZZ(1); if ZZZ ==1 and MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true) Then loss = loss+1; 즐거운 하루되세요 > spek 님이 쓴 글입니다. > 제목 : 수식 부탁드립니다. > 안녕하세요? 매번 성의있는 답변 감사드립니다. 1. 과거 섬머타임 관련 질문을 드린적이 있는데, 아래와 같이 수정해 주신적이 있습니다. *수정 전 if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; Loss = 0; } *수정 후 (서머타임 적용) if Bdate != Bdate[1] Then{ var1 = O; Loss = 0; } 그런데 증권사 기준의 영업일 시작 시간은 10시(섬머타임 아닐 때), 9시(섬머타임 때) 이라서 그 때 시가가 기준으로 삼아집니다. 하지만 제가 원하는 하루의 주기는 16시를 시작으로 다음날 16시 까지 입니다. (섬머타임 아닐 때는 17시 ~ 17시) 그래서 제가 if TimeToMinutes(stime) >= TimeToMinutes(Bdate != Bdate[1])+480 Then{ var1 = O; Loss = 0; } 이런식으로 짜봤는데 안되네요. 이 부분은 그냥 섬머타임 때 마다 직접 변경하는 수 밖에 없나요? 이것 때문에 장기간 시뮬레이션 할 때에 동일 시간대를 일괄적용 할 수가 없네요. 2. 아래식은 손절인 Bx, Sx 뿐만아니라, bx1, sx1 이 발생했을 때도 당일 진입을 금지하는 식을 부탁드려서 받았던 답변입니다. 단, Bx, Sx 의 경우는 언제든 발생했을 경우 당일의 진입을 금지 하지만, bx1, sx1 의 경우는 당일 진입해서 당일 발생 했을 경우만 금지하고, 며칠 전 진입해서 당일 발행했을 경우에는, 당일의 시가를 기준으로 재진입을 허용하는 식입니다. 그런데 아래와 같은 식은 다른 부분은 생각했던 대로 잘 작동하지만, 밤 열두시를 넘어서 발생한 bx1, sx1 에 대해서는 재진입을 하더군요. 예를들어, 22일 16시 시가를 기준으로 23일 02시에 진입했다가 23일 03시에 bx1 또는 sx1 이 발생하면 23일 16시 전까지는 재진입 해서는 안됩니다. 그런데 하네요. 여기서 제가 말하는 당일, 하루는 16시 ~ 16시 입니다. 이는 해당 증권사의 영업시간 기준과 다릅니다. 그래서 Bdate 를 쓰면 안되는 것 같습니다. 그리고 아래식에서 변수로 BD(0) 가 선언 되었는데, 막상 식에서는 사용을 안하는데 왜 그런가요? Input : N(1); Var : HH(0), LL(0), Loss(0),BD(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{ var1 = O; BD = Bdate; } if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and Bdate[BarsSinceEntry(1)] == Bdate and (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 3. 손절(Bx, Sx)이나 bx1, sx1 가 발생했을 경우에는 10분 내에 재진입을 금지하는 식을 부탁드립니다. (예전에 한번 부정확하게 질문을 드려서 최근에 다시 질문드렸는데, 답변을 빠뜨리신 듯 합니다.) Input : N(3); Var : HH(0), LL(0), Loss(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then var1 = O; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); if loss < N then{ if MarketPosition <= 0 and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if MarketPosition >= 0 and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 4. 위 3번의 식에서 때때로 "LL <= EntryPrice*0.9" 와 같은 부분을 빼고 시뮬레이션 해보기 위해 "LL <= EntryPrice*0.9*ZZZ" 와 같이 변형해서, ZZZ 를 외부변서 1로 잡은 후 빼고 싶을 때는 ZZZ 에 0을 대입하곤 합니다. 그런데, 때때로 아래와 같은 식을 추가해서 bx1, sx1 도 손절인 Bx, Sx 처럼 발생하면 당일(하루 기준 16시~16시) 은 거래를 금지하도록 시뮬레이션 하기도 합니다. if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true) Then loss = loss+1; 그런데 이 식을 추가해보거나 빼보거나 하면서 시뮬레이션 할 때 일일히 수식에서 삭제, 붙여넣기를 반복해야 되는데, 방금 바로 위에 말씀드린 외부변서 ZZZ 처럼 외부변수 하나를 잡아놓고, 그 부분만 바꿔서 넣었다 뺐다 할 수 있게 하는 방법이 없나요? 단순히 (IsExitName("bx1",1) == true or IsExitName("bx1",1) == true)*ZZZ 를 했더니 오류가 나더군요.
프로필 이미지

예스스탁 예스스탁 답변

2015-06-04 17:31:32

아래식 이용하시면 됩니다. Input : N(3); Var : HH(0), LL(0), Loss(0),dcnt(0),TF(0),TF1(0),EE(0),XX(false),Xcond(false); var : Start(0); if Bdate != Bdate[1] Then{ if stime >= 100000 Then Start = 170000; Else Start = 160000; } if stime == Start or (stime > Start and stime[1] < Start) Then{ var1 = O; dcnt = dcnt+1; } if date != date[1] Then TF1 = TF[1]; if stime >= Start Then TF = TimeToMinutes(stime)-TimeToMinutes(Start); Else TF = TimeToMinutes(stime)+TF1; if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true) Then loss = loss+1; if MarketPosition <= 0 and stime == 155000 Then buy("b1",AtStop,NextBarOpen*1.01); if MarketPosition >= 0 and stime == 155000 Then sell("s1",AtStop,NextBarOpen*0.99); #직전 청산이 같은 날짜수(Dcnt)이고 청산명이 Bx,Sx,bx1,sx1이면 true 아니면 false Xcond = Dcnt[BarsSinceExit(1)] == Dcnt and (IsExitName("Bx",1) == true or IsExitName("Sx",1) == true or IsExitName("bx1",1) == true or IsExitName("sx1",1) == true); if loss < N then{ if ((MarketPosition == 0 and Xcond == false) or (MarketPosition == 0 and Xcond == true and TF >= TF[BarsSinceExit(1)]+20)) and H < var1*1.01 Then buy("b",AtStop,var1*1.01); if ((MarketPosition == 0 and Xcond == false) or (MarketPosition == 0 and Xcond == true and TF >= TF[BarsSinceExit(1)]+20)) and L > var1*0.99 Then sell("s",AtStop,var1*0.99); } if MarketPosition == 1 Then{ HH = highest(H,BarsSinceEntry); if HH >= EntryPrice*1.1 and HH < EntryPrice*1.2 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.2 and HH < EntryPrice*1.3 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.3 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); } if MarketPosition == -1 Then{ LL = lowest(L,BarsSinceEntry); if LL <= EntryPrice*0.9 and LL > EntryPrice*0.8 Then ExitShort("sx1",AtStop,LL+(EntryPrice-LL)*0.5); if LL <= EntryPrice*0.8 and LL > EntryPrice*0.7 Then ExitShort("sx2",AtStop,LL+(EntryPrice-LL)*0.6); if LL <= EntryPrice*0.7 Then ExitShort("sx3",AtStop,LL+(EntryPrice-LL)*0.7); } if MarketPosition == 1 Then ExitLong("Bx",AtStop,Round(EntryPrice*0.99,2)); if MarketPosition == -1 Then ExitShort("Sx",AtStop,Round(EntryPrice*1.01,2)); 즐거운 하루되세요