커뮤니티

수식 부탁드립니다.

프로필 이미지
spek
2015-05-11 21:11:34
128
글번호 85918
답변완료
매번 답변 감사드립니다. 이번에 트레일링스탑을 적용해 보고 싶은데 잘 안되네요. 예전에 짜주셨던 식(약간 변형함)은 아래와 같습니다. (잘 작동 하는 듯 합니다.) (해외 선물이라 16시 ~ 익일 16시로 적용.) if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then var1 = O; 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 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); SetStopLoss(1,PercentStop); 이 식에 추가해서 트레일링 스탑을 적용하고 싶습니다. 예를들어, 최소 10% 수익 이후에 수익의 50%가 감소하면 청산, (즉, 수익이 10~20% 사이) 20% 수익 이후에는 수익의 60% 감소하면 청산, (즉, 수익이 20~30% 사이) 30% 수익 이후에는 수익의 70% 감소하면 청산, (즉, 수익이 30% 이상) 그리고 여기에, 100% 수익 이후에는 최고가 대비 10% 하락하는 순간 즉시 청산. 아래와 같이 짜서 위 식 아래에 그대로 붙여 봤는데 적용이 안되더군요. (맨 끝문장만 적용 되는듯 하네요.) if marketposition == 1 and entryprice*1.1 then setstoptrailing(50,10); if marketposition == 1 and entryprice*1.2 then setstoptrailing(60,20); if marketposition == 1 and entryprice*1.3 then setstoptrailing(70,30); if marketposition == 1 and entryprice*2 then setstoptrailing(10,100,PercentStop,1); if marketposition == -1 and entryprice*0.99 then setstoptrailing(100,1); if marketposition == -1 and entryprice*0.98 then setstoptrailing(70,2); if marketposition == -1 and entryprice*0.97 then setstoptrailing(40,3); if marketposition == -1 and entryprice*0.97 then setstoptrailing(10,100,PercentStop,1); 그리고 이 식이 원하는 가격을 때리는 그 순간 바로 시장가 주문이 나갔으면 합니다. 예를들어 100 에 매수한 종목이 150 이 되었습니다. 그렇다면 위 원칙에 따라 청산을 원하는 가격은 >>> {(150-100)*0.3}+100 = 115 가 되는데, 현재가가 이 115를 때리는 순간 그 즉시 시장가로 주문이 나갔으면 합니다.
시스템
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2015-05-12 13:34:03

안녕하세요 예스스탁입니다. 강제청산은 한번셋팅이 되면 다음조건만족시 까지 설정된 값이 유지가 됩니다. 또한 작성하신 if문 내용은 조건문이 아닙니다. 문의하신 내용은 아래와 같이 풀어서 작성하셔야 합니다. 주문가격은 수식안에서는 지정되지 않습니다. 수식에 따라 신호가 발생하면 주문가격은 시스템 트레이딩 설정창의 매매탭에서 지정한 가격으로 주문이 집행됩니다. 시스템 트레이딩 설정창의 매매탭에서 주문가격을 시장가로 지정하셔야 합니다. var : HH(0),LL(0); if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then var1 = O; 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 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.10 and HH < EntryPrice*1.20 Then ExitLong("bx1",AtStop,HH-(HH-EntryPrice)*0.5); if HH >= EntryPrice*1.20 and HH < EntryPrice*1.30 Then ExitLong("bx2",AtStop,HH-(HH-EntryPrice)*0.6); if HH >= EntryPrice*1.30 and HH < EntryPrice*2.00 Then ExitLong("bx3",AtStop,HH-(HH-EntryPrice)*0.7); if HH >= EntryPrice*2.00 Then ExitLong("bx4",AtStop,HH*0.9); } SetStopLoss(1,PercentStop); 즐거운 하루되세요 > spek 님이 쓴 글입니다. > 제목 : 수식 부탁드립니다. > 매번 답변 감사드립니다. 이번에 트레일링스탑을 적용해 보고 싶은데 잘 안되네요. 예전에 짜주셨던 식(약간 변형함)은 아래와 같습니다. (잘 작동 하는 듯 합니다.) (해외 선물이라 16시 ~ 익일 16시로 적용.) if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then var1 = O; 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 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); SetStopLoss(1,PercentStop); 이 식에 추가해서 트레일링 스탑을 적용하고 싶습니다. 예를들어, 최소 10% 수익 이후에 수익의 50%가 감소하면 청산, (즉, 수익이 10~20% 사이) 20% 수익 이후에는 수익의 60% 감소하면 청산, (즉, 수익이 20~30% 사이) 30% 수익 이후에는 수익의 70% 감소하면 청산, (즉, 수익이 30% 이상) 그리고 여기에, 100% 수익 이후에는 최고가 대비 10% 하락하는 순간 즉시 청산. 아래와 같이 짜서 위 식 아래에 그대로 붙여 봤는데 적용이 안되더군요. (맨 끝문장만 적용 되는듯 하네요.) if marketposition == 1 and entryprice*1.1 then setstoptrailing(50,10); if marketposition == 1 and entryprice*1.2 then setstoptrailing(60,20); if marketposition == 1 and entryprice*1.3 then setstoptrailing(70,30); if marketposition == 1 and entryprice*2 then setstoptrailing(10,100,PercentStop,1); if marketposition == -1 and entryprice*0.99 then setstoptrailing(100,1); if marketposition == -1 and entryprice*0.98 then setstoptrailing(70,2); if marketposition == -1 and entryprice*0.97 then setstoptrailing(40,3); if marketposition == -1 and entryprice*0.97 then setstoptrailing(10,100,PercentStop,1); 그리고 이 식이 원하는 가격을 때리는 그 순간 바로 시장가 주문이 나갔으면 합니다. 예를들어 100 에 매수한 종목이 150 이 되었습니다. 그렇다면 위 원칙에 따라 청산을 원하는 가격은 >>> {(150-100)*0.3}+100 = 115 가 되는데, 현재가가 이 115를 때리는 순간 그 즉시 시장가로 주문이 나갔으면 합니다.