커뮤니티

부탁 드립니다.

프로필 이미지
고운무지개
2013-11-18 10:04:37
197
글번호 69567
답변완료
안녕하세요. 오늘은 질문과 내용이 아주 깁니다. 생각나는대로 질문드려서 수식을 넣어봤는데 원하는 대로 작동을 안하네요. 전체적으로 점검 부탁드리고요, 틀린 코멘트 있는지 살펴주세요. 신규로 작성해주시는 수식엔 코멘트 부탁 드리고요. 진입조건은 세가지인데 다 똑같이 macd로 통일하고 1분봉으로 했습니다. 신호가 자주나오게 해서 수식이 제대로 작동하는지 확인하려고 합니다. 진입하고 손절가가 오면 손절과 동시에 스위칭을하고 계약 수에 따라 분할 청산. 그리고 마지막 남은 1계약은 익절로 마무리. 세번이상 스위칭을 하고 분할 청산도 나왔는데 익절이 나오지 않으면 지금까지의 손절값을 포함한 본절+1에 트레일링 스탑. 네번이상 스위칭을 하면 분할 청산이 나오지 않아도 지금까지의 손절값을 포함한 본절+1에 트레일링 스탑. 다섯번 스위칭을 하면 분할 청산이 나오지 않아도 지금까지의 손절값을 포함한 본절+1에 트레일링 스탑하거나 손절. 다섯번 스위칭 후 손절이 나온 경우 진입 조건이 나오면 진입할수도 안할수도 있도록 변수를 조정하게 함. 당일 1계약의 익절 거래가 1번일 때, 2번일 때, 3번일 때 등을 Profit(3)변수를 조정해서 사용함. 진입부터 제대로 잘 안됩니다. 첫 번째 진입 후 익절은 하면 두 번째 진입이 와야하는데 건너뛰고 세 번째 진입이 나옵니다. 13/11/5 역시 익절 후 macd 골드에 두 번째 진입이 나오지 않습니다. 13/11/7 알려주신 수식으로 트레일링 스탑이 나오지 않아서 #일부 청산 후 본절을 위한 수식 Condition1 = EntryDate(4) == sdate and (IsEntryName("sb4",4) == true or IsExitName("bs4",4) == true) and (IsEntryName("sb4",3) == true or IsExitName("bs4",3) == true) And (IsEntryName("sb4",2) == true or IsExitName("bs4",2) == true) And (IsEntryName("sb4",1) == true or IsExitName("bs4",1) == true); 이런식으로 or 조건을 넣어봤는데도 나오지 않네요. bx,sx,btr,str로 끝나는 청산이 하나도 안나옵니다. 지난번에 33407번에서 질문에 답변 주신 내용을 이해 못했습니다. #Condition1이 true이면 청산후 30분 경과후에 #조건 만족하면 매수나 매도 진입 if Condition1 == false or (Condition1 == true and TimeToMinutes(stime) >= TimeToMinutes(ExitTime(1))+60) Then{ if 매수조건 Then buy(); if 매도조건 Then sell(); } 청산후 30분 경과후에는 왜 나온건지, 30분인데 수식엔 60이 들어가는게 맞는건지. 청산조건의 var2는 뭔지. 도대체 모르겠습니다. ●두 가지 조건을 더 추가하고 싶습니다. 하나는 진입하고 스위칭이 없었을 때 30분 내에 분할청산이 나오지 않으면 본절. 스위칭이 있었으면 30분 내에 분할 청산이 나오지 않으면 진입가격 + 스위칭 손절가격에 청산 또는 스위칭 없이 10틱 손절. 익절까지 나와서 모든 포지션이 청산되면 마지막 청산값+원하는 가격에 주문을 넣을 수 있나요? 트레일링 스탑이 작동을 안해서 진행안되고 멈춰있는 상태입니다. 주문부터 원하는대로 안되는 상태지만요. 바쁘시더라도 작동안하는 수식없게 잘 살펴주세요. 부탁 드립니다. //**수식**// Input : shortPeriod(12), longPeriod(26), Period(9),Profit(3); Input : 일부청산(10); var : MACDV(0),MACDS(0),cnt(0),count(0),cnt1(0),count1(0),xcond(false); var : Pcnt(0); value1 = TRIX(shortPeriod); value2 = ema(value1, Period); if date != date[1] Then Pcnt = 0; MACDV = MACD(shortPeriod, longPeriod);#MACD MACDS = ema(MACDV, Period);#MACD시그널 #당일 최근5번 거래의 진입이 sb1,sb2,sb3,sb4,sb5,sb6,sb7,bs1,bs2,bs3,bs4,bs5,bs6,bs7 인 횟수 count = 0; for cnt = 0 to 4{ if sdate == EntryDate(cnt) And (IsExitName("sb1") == true Or IsExitName("sb2") == true Or IsExitName("sb3") == true Or IsExitName("sb4") == true Or IsExitName("sb5") == true Or IsExitName("sb6") == true Or IsExitName("sb7") == true Or IsExitName("bs1") == true Or IsExitName("bs2") == true Or IsExitName("bs3") == true Or IsExitName("bs4") == true Or IsExitName("bs5") == true Or IsExitName("bs6") == true Or IsExitName("bs7") == true) Then count = count+1; } #bx나 sx청산이 나오면 true아니면 false xcond = ExitDate(1) == sdate and (IsExitName("bx",1) ==true or IsExitName("sx",1) == true); #익절청산횟수 if ExitDate(1) == sdate and MarketPosition == 0 and MarketPosition[1] != 0 Then Pcnt = Pcnt+1; #당일 진입횟수 카운트 count1 = 0; for cnt1 = 0 to 20{ if sdate == EntryDate(cnt1) Then count1 = count1+1; } #일부 청산 후 본절을 위한 수식 Condition1 = EntryDate(4) == sdate and (IsEntryName("sb4",4) == true or IsExitName("bs4",4) == true) and (IsEntryName("sb4",3) == true or IsExitName("bs4",3) == true) And (IsEntryName("sb4",2) == true or IsExitName("bs4",2) == true) And (IsEntryName("sb4",1) == true or IsExitName("bs4",1) == true); #무포지션 If MarketPosition == 0 and #청산이 발생한 봉에서 동시에 진입을 하지 못하게하는내용 (ExitDate(1) != sdate or (ExitDate(1) == sdate and BarsSinceExit(1) != 0)) and #수익청산 횟수 제어 Pcnt < Profit and #5번연속 손절발생시 더이상 추가진입을 하지 못하게 함 Xcond == false Then{ #첫 진입 macd if count1 == 0 Then{ #골든크로스이면 매수 if CrossUP(MACDV, MACDS) Then Buy("b첫매수",OnClose,def,1); #데드크로스이면 매도 if CrossDown(MACDV, MACDS) and Xcond == false Then Sell("s첫매도",OnClose,def,1); } #두 번째 진입 if count1 == 1 Then{ if CrossUP(MACDV, MACDS) Then Buy("b두번째매수",OnClose,def,2); if CrossDown(MACDV, MACDS) Then Sell("s두번째매도",OnClose,def,2); } #세 번째 진입 if count1 == 2 Then{ if CrossUP(MACDV, MACDS) Then Buy("b세번째매수",OnClose,def,3); if CrossDown(MACDV, MACDS) Then Sell("s세번째매도",OnClose,def,3); } } #매수포지션 진입 후 if MarketPosition == 1 Then{ #포지션 최대계약수가 3이상일때 첫번째 청산 if (CurrentContracts == MaxContracts and MaxContracts >= 3) Then ExitLong("매수일부청산1",Atlimit,EntryPrice+PriceScale*(일부청산+5),"",MaxContracts-2,1); #포지션 최대계약수가 3이상일때 두번째 청산 if CurrentContracts < MaxContracts and MaxContracts >= 3 and CurrentContracts == 2 then ExitLong("매수일부청산2",Atlimit,EntryPrice+PriceScale*(일부청산+7),"",1,1); #포지션 최대계약수가 2일때 첫번째 청산 if (CurrentContracts == MaxContracts and MaxContracts == 2) Then ExitLong("매수청산a",Atlimit,EntryPrice+PriceScale*(일부청산+5),"",1,1); #마지막 청산 if CurrentContracts == 1 Then ExitLong("매수잔량익절",Atlimit,EntryPrice+PriceScale*(일부청산+15)); //나머지 전량청산 if MarketPosition == 1 and Condition1 == true and (IsEntryName("sb1",0) == true or IsEntryName("sb2",0) == true or IsEntryName("sb3",0) == true or IsEntryName("sb4",0) == true) And countif(CurrentContracts < CurrentContracts[1],BarsSinceEntry) >= 1 Then ExitLong("btr",AtStop,EntryPrice); #손절 후 스위칭이 연속 8번미만일때 if count < 8 Then{ #현재 남은 수량이 7계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 7 if CurrentContracts == 7 Then sell("bs7",AtStop,EntryPrice-PriceScale*10,7); #현재 남은 수량이 6계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 6 if CurrentContracts == 6 Then sell("bs6",AtStop,EntryPrice-PriceScale*10,6); #현재 남은 수량이 5계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 5 if CurrentContracts == 5 Then sell("bs5",AtStop,EntryPrice-PriceScale*10,5); #현재 남은 수량이 4계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 4 if CurrentContracts == 4 Then sell("bs4",AtStop,EntryPrice-PriceScale*10,4); #현재 남은 수량이 3계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 3 if CurrentContracts == 3 Then sell("bs3",AtStop,EntryPrice-PriceScale*10,3); #현재 남은 수량이 2계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 2 if CurrentContracts == 2 Then sell("bs2",AtStop,EntryPrice-PriceScale*10,2); #현재 남은 수량이 1계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 1 if CurrentContracts == 1 Then sell("bs1",AtStop,EntryPrice-PriceScale*10,1); } #스위칭3번연속일때 10틱 손실이면 청산 if count == 3 Then ExitLong("bx",AtStop,EntryPrice-PriceScale*10); } #매도포지션 진입 후 if MarketPosition == -1 Then{ #포지션 최대계약수가 3이상일때 첫번째 청산 if (CurrentContracts == MaxContracts and MaxContracts >= 3) Then ExitShort("매도일부청산1",Atlimit,EntryPrice-PriceScale*(일부청산+5),"",MaxContracts-2,1); #포지션 최대계약수가 3이상일때 두번째 청산 if CurrentContracts < MaxContracts and MaxContracts >= 3 and CurrentContracts == 2 then ExitShort("매도일부청산2",Atlimit,EntryPrice-PriceScale*(일부청산+7),"",1,1); #포지션 최대계약수가 2일때 첫번째 청산 if (CurrentContracts == MaxContracts and MaxContracts == 2) Then ExitShort("매도청산a",Atlimit,EntryPrice-PriceScale*(일부청산+5),"",1,1); #마지막 청산 if CurrentContracts == 1 Then ExitShort("매도잔량익절",Atlimit,EntryPrice-PriceScale*(일부청산+15)); //나머지 전량청산 #트레일링 스탑 if MarketPosition == -1 and Condition1 == true and (IsEntryName("bs1",0) == true or IsEntryName("bs2",0) == true or IsEntryName("bs3",0) == true or IsEntryName("bs4",0) == true) And countif(CurrentContracts < CurrentContracts[1],BarsSinceEntry) >= 1 Then ExitShort("str",AtStop,EntryPrice); #손절 후 연속스위칭8번미만일때 if count < 8 Then{ #현재 남은 수량이 7계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 7 if CurrentContracts == 7 Then Buy("sb7",AtStop,EntryPrice+PriceScale*10,7); #현재 남은 수량이 6계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 6 if CurrentContracts == 6 Then Buy("sb6",AtStop,EntryPrice+PriceScale*10,6); #현재 남은 수량이 5계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 5 if CurrentContracts == 5 Then Buy("sb5",AtStop,EntryPrice+PriceScale*10,5); #현재 남은 수량이 4계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 4 if CurrentContracts == 4 Then Buy("sb4",AtStop,EntryPrice+PriceScale*10,4); #현재 남은 수량이 3계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 3 if CurrentContracts == 3 Then Buy("sb3",AtStop,EntryPrice+PriceScale*10,3); #현재 남은 수량이 2계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 2 if CurrentContracts == 2 Then Buy("sb2",AtStop,EntryPrice+PriceScale*10,2); #현재 남은 수량이 1계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 1 if CurrentContracts == 1 Then Buy("sb1",AtStop,EntryPrice+PriceScale*10,1); } #스위칭3번연속일때 10틱 손실이면 청산 if count == 3 Then ExitShort("sx",AtStop,EntryPrice+PriceScale*10); }
시스템
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2013-11-19 11:26:59

안녕하세요 예스스탁입니다. 식을 수정했습니다. 1. 진입명들인데 청산명으로 오인하셔서 작성한 부분이 있어 수정을 했고 스위칭을 제외한 진입명으로 횟수를 카운트 하게 작성했습니다. 2 작성하신 식에서 condition1의 용도를 모르겠습니다. condition1은 가장 최근 4개 진입들이 모두 sb4나 bs4일때 true가 되는데 condition1 == true가 트레일링스탑의 조건문에 있어 해당 청산이 신호가 발생하지 않습니다. 해당 조건은 우선 주석처리로 막았습니다. 3. count = 0; for cnt = 0 to 4{ if sdate == EntryDate(cnt) And (IsEntryName("sb1",cnt) == true Or IsEntryName("sb2",cnt) == true Or IsEntryName("sb3",cnt) == true Or IsEntryName("sb4",cnt) == true Or IsEntryName("sb5",cnt) == true Or IsEntryName("sb6",cnt) == true Or IsEntryName("sb7",cnt) == true Or IsEntryName("bs1",cnt) == true Or IsEntryName("bs2",cnt) == true Or IsEntryName("bs3",cnt) == true Or IsEntryName("bs4",cnt) == true Or IsEntryName("bs5",cnt) == true Or IsEntryName("bs6",cnt) == true Or IsEntryName("bs7",cnt) == true) Then count = count+1; } 위식은 단순 최근 5개거래의 진입명이 위에 적힌 이름과 같은 것이 몇개 있는지를 나타냅니다. 3이라고 나오면 최근 5개중 3개가 해당이름이라는 내용으로 연속을 의미하지는 않습니다. 연속을 의미하실 려면 아래와 같이 작성하셔야 합니다. count = 0; for cnt = 4 downto 0{ if sdate == EntryDate(cnt) And (IsEntryName("sb1",cnt) == true Or IsEntryName("sb2",cnt) == true Or IsEntryName("sb3",cnt) == true Or IsEntryName("sb4",cnt) == true Or IsEntryName("sb5",cnt) == true Or IsEntryName("sb6",cnt) == true Or IsEntryName("sb7",cnt) == true Or IsEntryName("bs1",cnt) == true Or IsEntryName("bs2",cnt) == true Or IsEntryName("bs3",cnt) == true Or IsEntryName("bs4",cnt) == true Or IsEntryName("bs5",cnt) == true Or IsEntryName("bs6",cnt) == true Or IsEntryName("bs7",cnt) == true) Then count = count+1; else count = 0; } 4. 수정한 식입니다. Input : shortPeriod(12), longPeriod(26), Period(9),Profit(3); Input : 일부청산(10); var : MACDV(0),MACDS(0),cnt(0),count(0),cnt1(0),count1(0),xcond(false); var : Pcnt(0),EntryCount(0); value1 = TRIX(shortPeriod); value2 = ema(value1, Period); if date != date[1] Then{ Pcnt = 0; EntryCount = 0; } #진입신호 나오고 첫봉에서 EntryCount 산정 if MarketPosition != MarketPosition[1] and MarketPosition != 0 Then{ #진입명이 b첫매수나 s첫매도이면 1 if (IsEntryName("b첫매수") == true or IsEntryName("s첫매도") == true) Then EntryCount = 1; #진입명이 b두번매수나 s두번매도아면 2 if (IsEntryName("b두번째매수") == true or IsEntryName("s두번째매도") == true) Then EntryCount = 2; #진입명이 b세번째매수나 s세번째매도이면 3 if (IsEntryName("b세번째매수") == true or IsEntryName("s세번째매도") == true) Then EntryCount = 3; } MACDV = MACD(shortPeriod, longPeriod);#MACD MACDS = ema(MACDV, Period);#MACD시그널 #당일 최근5번 거래의 진입이 sb1,sb2,sb3,sb4,sb5,sb6,sb7,bs1,bs2,bs3,bs4,bs5,bs6,bs7 인 횟수 #스위칭은 반대포지션을 청산하고 진입하므로 위 이름은 모두 진입명입니다. #진입명으로 최근 5개의 거래이므로 0 to 4입니다. count = 0; for cnt = 4 downto 0{ if sdate == EntryDate(cnt) And (IsEntryName("sb1",cnt) == true Or IsEntryName("sb2",cnt) == true Or IsEntryName("sb3",cnt) == true Or IsEntryName("sb4",cnt) == true Or IsEntryName("sb5",cnt) == true Or IsEntryName("sb6",cnt) == true Or IsEntryName("sb7",cnt) == true Or IsEntryName("bs1",cnt) == true Or IsEntryName("bs2",cnt) == true Or IsEntryName("bs3",cnt) == true Or IsEntryName("bs4",cnt) == true Or IsEntryName("bs5",cnt) == true Or IsEntryName("bs6",cnt) == true Or IsEntryName("bs7",cnt) == true) Then count = count+1; else count = 0; } #bx나 sx청산이 나오면 true아니면 false xcond = ExitDate(1) == sdate and (IsExitName("bx",1) ==true or IsExitName("sx",1) == true); #익절청산횟수 if ExitDate(1) == sdate and MarketPosition == 0 and MarketPosition[1] != 0 Then Pcnt = Pcnt+1; #당일 진입횟수 카운트 count1 = 0; for cnt1 = 0 to 20{ if sdate == EntryDate(cnt1) Then count1 = count1+1; } #일부 청산 후 본절을 위한 수식 Condition1 = EntryDate(4) == sdate and (IsEntryName("sb4",4) == true or IsEntryName("bs4",4) == true) and (IsEntryName("sb4",3) == true or IsEntryName("bs4",3) == true) And (IsEntryName("sb4",2) == true or IsEntryName("bs4",2) == true) And (IsEntryName("sb4",1) == true or IsEntryName("bs4",1) == true); #무포지션 If MarketPosition == 0 and #청산이 발생한 봉에서 동시에 진입을 하지 못하게하는내용 (ExitDate(1) != sdate or (ExitDate(1) == sdate and BarsSinceExit(1) != 0)) and #수익청산 횟수 제어 Pcnt < Profit and #5번연속 손절발생시 더이상 추가진입을 하지 못하게 함 Xcond == false Then{ #첫 진입 macd if EntryCount == 0 Then{ #골든크로스이면 매수 if CrossUP(MACDV, MACDS) Then Buy("b첫매수",OnClose,def,3); #데드크로스이면 매도 if CrossDown(MACDV, MACDS) and Xcond == false Then Sell("s첫매도",OnClose,def,3); } #두 번째 진입 if EntryCount == 1 Then{ if CrossUP(MACDV, MACDS) Then Buy("b두번째매수",OnClose,def,4); if CrossDown(MACDV, MACDS) Then Sell("s두번째매도",OnClose,def,4); } #세 번째 진입 if EntryCount == 2 Then{ if CrossUP(MACDV, MACDS) Then Buy("b세번째매수",OnClose,def,5); if CrossDown(MACDV, MACDS) Then Sell("s세번째매도",OnClose,def,5); } } #매수포지션 진입 후 if MarketPosition == 1 Then{ #포지션 최대계약수가 3이상일때 첫번째 청산 if (CurrentContracts == MaxContracts and MaxContracts >= 3) Then ExitLong("매수일부청산1",Atlimit,EntryPrice+PriceScale*(일부청산+5),"",MaxContracts-2,1); #포지션 최대계약수가 3이상일때 두번째 청산 if CurrentContracts < MaxContracts and MaxContracts >= 3 and CurrentContracts == 2 then ExitLong("매수일부청산2",Atlimit,EntryPrice+PriceScale*(일부청산+7),"",1,1); #포지션 최대계약수가 2일때 첫번째 청산 if (CurrentContracts == MaxContracts and MaxContracts == 2) Then ExitLong("매수청산a",Atlimit,EntryPrice+PriceScale*(일부청산+5),"",1,1); #마지막 청산 if CurrentContracts == 1 Then ExitLong("매수잔량익절",Atlimit,EntryPrice+PriceScale*(일부청산+15)); //나머지 전량청산 if MarketPosition == 1 and //Condition1 == true and (IsEntryName("sb1",0) == true or IsEntryName("sb2",0) == true or IsEntryName("sb3",0) == true or IsEntryName("sb4",0) == true) And countif(CurrentContracts < CurrentContracts[1],BarsSinceEntry) >= 1 Then ExitLong("btr",AtStop,EntryPrice); #스위칭카운트가 최근 5번이므로 해당 회수 이내의 값으로 지정해서야 합니다. #손절 후 스위칭이 연속 5번미만일때 if count < 5 Then{ #현재 남은 수량이 7계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 7 if CurrentContracts == 7 Then sell("bs7",AtStop,EntryPrice-PriceScale*10,7); #현재 남은 수량이 6계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 6 if CurrentContracts == 6 Then sell("bs6",AtStop,EntryPrice-PriceScale*10,6); #현재 남은 수량이 5계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 5 if CurrentContracts == 5 Then sell("bs5",AtStop,EntryPrice-PriceScale*10,5); #현재 남은 수량이 4계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 4 if CurrentContracts == 4 Then sell("bs4",AtStop,EntryPrice-PriceScale*10,4); #현재 남은 수량이 3계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 3 if CurrentContracts == 3 Then sell("bs3",AtStop,EntryPrice-PriceScale*10,3); #현재 남은 수량이 2계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 2 if CurrentContracts == 2 Then sell("bs2",AtStop,EntryPrice-PriceScale*10,2); #현재 남은 수량이 1계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 1 if CurrentContracts == 1 Then sell("bs1",AtStop,EntryPrice-PriceScale*10,1); } #스위칭3번연속일때 10틱 손실이면 청산 if count == 3 Then ExitLong("bx",AtStop,EntryPrice-PriceScale*10); } #매도포지션 진입 후 if MarketPosition == -1 Then{ #포지션 최대계약수가 3이상일때 첫번째 청산 if (CurrentContracts == MaxContracts and MaxContracts >= 3) Then ExitShort("매도일부청산1",Atlimit,EntryPrice-PriceScale*(일부청산+5),"",MaxContracts-2,1); #포지션 최대계약수가 3이상일때 두번째 청산 if CurrentContracts < MaxContracts and MaxContracts >= 3 and CurrentContracts == 2 then ExitShort("매도일부청산2",Atlimit,EntryPrice-PriceScale*(일부청산+7),"",1,1); #포지션 최대계약수가 2일때 첫번째 청산 if (CurrentContracts == MaxContracts and MaxContracts == 2) Then ExitShort("매도청산a",Atlimit,EntryPrice-PriceScale*(일부청산+5),"",1,1); #마지막 청산 if CurrentContracts == 1 Then ExitShort("매도잔량익절",Atlimit,EntryPrice-PriceScale*(일부청산+15)); //나머지 전량청산 #트레일링 스탑 if MarketPosition == -1 and //Condition1 == true and (IsEntryName("bs1",0) == true or IsEntryName("bs2",0) == true or IsEntryName("bs3",0) == true or IsEntryName("bs4",0) == true) And countif(CurrentContracts < CurrentContracts[1],BarsSinceEntry) >= 1 Then ExitShort("str",AtStop,EntryPrice); #손절 후 연속스위칭8번미만일때 if count < 8 Then{ #현재 남은 수량이 7계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 7 if CurrentContracts == 7 Then Buy("sb7",AtStop,EntryPrice+PriceScale*10,7); #현재 남은 수량이 6계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 6 if CurrentContracts == 6 Then Buy("sb6",AtStop,EntryPrice+PriceScale*10,6); #현재 남은 수량이 5계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 5 if CurrentContracts == 5 Then Buy("sb5",AtStop,EntryPrice+PriceScale*10,5); #현재 남은 수량이 4계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 4 if CurrentContracts == 4 Then Buy("sb4",AtStop,EntryPrice+PriceScale*10,4); #현재 남은 수량이 3계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 3 if CurrentContracts == 3 Then Buy("sb3",AtStop,EntryPrice+PriceScale*10,3); #현재 남은 수량이 2계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 2 if CurrentContracts == 2 Then Buy("sb2",AtStop,EntryPrice+PriceScale*10,2); #현재 남은 수량이 1계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 1 if CurrentContracts == 1 Then Buy("sb1",AtStop,EntryPrice+PriceScale*10,1); } #스위칭3번연속일때 10틱 손실이면 청산 if count == 3 Then ExitShort("sx",AtStop,EntryPrice+PriceScale*10); } 5. 우선 위식이 의도맞게 나오는지 확인하시고 내용을 추가하시기 바랍니다. 문의하신 내용 중 경과시간이 30분이면 TimeToMinutes(stime) >= TimeToMinutes(ExitTime(1))+30 이 되어야 합니다. 즐거운 하루되세요 > 고운무지개 님이 쓴 글입니다. > 제목 : 부탁 드립니다. > 안녕하세요. 오늘은 질문과 내용이 아주 깁니다. 생각나는대로 질문드려서 수식을 넣어봤는데 원하는 대로 작동을 안하네요. 전체적으로 점검 부탁드리고요, 틀린 코멘트 있는지 살펴주세요. 신규로 작성해주시는 수식엔 코멘트 부탁 드리고요. 진입조건은 세가지인데 다 똑같이 macd로 통일하고 1분봉으로 했습니다. 신호가 자주나오게 해서 수식이 제대로 작동하는지 확인하려고 합니다. 진입하고 손절가가 오면 손절과 동시에 스위칭을하고 계약 수에 따라 분할 청산. 그리고 마지막 남은 1계약은 익절로 마무리. 세번이상 스위칭을 하고 분할 청산도 나왔는데 익절이 나오지 않으면 지금까지의 손절값을 포함한 본절+1에 트레일링 스탑. 네번이상 스위칭을 하면 분할 청산이 나오지 않아도 지금까지의 손절값을 포함한 본절+1에 트레일링 스탑. 다섯번 스위칭을 하면 분할 청산이 나오지 않아도 지금까지의 손절값을 포함한 본절+1에 트레일링 스탑하거나 손절. 다섯번 스위칭 후 손절이 나온 경우 진입 조건이 나오면 진입할수도 안할수도 있도록 변수를 조정하게 함. 당일 1계약의 익절 거래가 1번일 때, 2번일 때, 3번일 때 등을 Profit(3)변수를 조정해서 사용함. 진입부터 제대로 잘 안됩니다. 첫 번째 진입 후 익절은 하면 두 번째 진입이 와야하는데 건너뛰고 세 번째 진입이 나옵니다. 13/11/5 역시 익절 후 macd 골드에 두 번째 진입이 나오지 않습니다. 13/11/7 알려주신 수식으로 트레일링 스탑이 나오지 않아서 #일부 청산 후 본절을 위한 수식 Condition1 = EntryDate(4) == sdate and (IsEntryName("sb4",4) == true or IsExitName("bs4",4) == true) and (IsEntryName("sb4",3) == true or IsExitName("bs4",3) == true) And (IsEntryName("sb4",2) == true or IsExitName("bs4",2) == true) And (IsEntryName("sb4",1) == true or IsExitName("bs4",1) == true); 이런식으로 or 조건을 넣어봤는데도 나오지 않네요. bx,sx,btr,str로 끝나는 청산이 하나도 안나옵니다. 지난번에 33407번에서 질문에 답변 주신 내용을 이해 못했습니다. #Condition1이 true이면 청산후 30분 경과후에 #조건 만족하면 매수나 매도 진입 if Condition1 == false or (Condition1 == true and TimeToMinutes(stime) >= TimeToMinutes(ExitTime(1))+60) Then{ if 매수조건 Then buy(); if 매도조건 Then sell(); } 청산후 30분 경과후에는 왜 나온건지, 30분인데 수식엔 60이 들어가는게 맞는건지. 청산조건의 var2는 뭔지. 도대체 모르겠습니다. ●두 가지 조건을 더 추가하고 싶습니다. 하나는 진입하고 스위칭이 없었을 때 30분 내에 분할청산이 나오지 않으면 본절. 스위칭이 있었으면 30분 내에 분할 청산이 나오지 않으면 진입가격 + 스위칭 손절가격에 청산 또는 스위칭 없이 10틱 손절. 익절까지 나와서 모든 포지션이 청산되면 마지막 청산값+원하는 가격에 주문을 넣을 수 있나요? 트레일링 스탑이 작동을 안해서 진행안되고 멈춰있는 상태입니다. 주문부터 원하는대로 안되는 상태지만요. 바쁘시더라도 작동안하는 수식없게 잘 살펴주세요. 부탁 드립니다. //**수식**// Input : shortPeriod(12), longPeriod(26), Period(9),Profit(3); Input : 일부청산(10); var : MACDV(0),MACDS(0),cnt(0),count(0),cnt1(0),count1(0),xcond(false); var : Pcnt(0); value1 = TRIX(shortPeriod); value2 = ema(value1, Period); if date != date[1] Then Pcnt = 0; MACDV = MACD(shortPeriod, longPeriod);#MACD MACDS = ema(MACDV, Period);#MACD시그널 #당일 최근5번 거래의 진입이 sb1,sb2,sb3,sb4,sb5,sb6,sb7,bs1,bs2,bs3,bs4,bs5,bs6,bs7 인 횟수 count = 0; for cnt = 0 to 4{ if sdate == EntryDate(cnt) And (IsExitName("sb1") == true Or IsExitName("sb2") == true Or IsExitName("sb3") == true Or IsExitName("sb4") == true Or IsExitName("sb5") == true Or IsExitName("sb6") == true Or IsExitName("sb7") == true Or IsExitName("bs1") == true Or IsExitName("bs2") == true Or IsExitName("bs3") == true Or IsExitName("bs4") == true Or IsExitName("bs5") == true Or IsExitName("bs6") == true Or IsExitName("bs7") == true) Then count = count+1; } #bx나 sx청산이 나오면 true아니면 false xcond = ExitDate(1) == sdate and (IsExitName("bx",1) ==true or IsExitName("sx",1) == true); #익절청산횟수 if ExitDate(1) == sdate and MarketPosition == 0 and MarketPosition[1] != 0 Then Pcnt = Pcnt+1; #당일 진입횟수 카운트 count1 = 0; for cnt1 = 0 to 20{ if sdate == EntryDate(cnt1) Then count1 = count1+1; } #일부 청산 후 본절을 위한 수식 Condition1 = EntryDate(4) == sdate and (IsEntryName("sb4",4) == true or IsExitName("bs4",4) == true) and (IsEntryName("sb4",3) == true or IsExitName("bs4",3) == true) And (IsEntryName("sb4",2) == true or IsExitName("bs4",2) == true) And (IsEntryName("sb4",1) == true or IsExitName("bs4",1) == true); #무포지션 If MarketPosition == 0 and #청산이 발생한 봉에서 동시에 진입을 하지 못하게하는내용 (ExitDate(1) != sdate or (ExitDate(1) == sdate and BarsSinceExit(1) != 0)) and #수익청산 횟수 제어 Pcnt < Profit and #5번연속 손절발생시 더이상 추가진입을 하지 못하게 함 Xcond == false Then{ #첫 진입 macd if count1 == 0 Then{ #골든크로스이면 매수 if CrossUP(MACDV, MACDS) Then Buy("b첫매수",OnClose,def,1); #데드크로스이면 매도 if CrossDown(MACDV, MACDS) and Xcond == false Then Sell("s첫매도",OnClose,def,1); } #두 번째 진입 if count1 == 1 Then{ if CrossUP(MACDV, MACDS) Then Buy("b두번째매수",OnClose,def,2); if CrossDown(MACDV, MACDS) Then Sell("s두번째매도",OnClose,def,2); } #세 번째 진입 if count1 == 2 Then{ if CrossUP(MACDV, MACDS) Then Buy("b세번째매수",OnClose,def,3); if CrossDown(MACDV, MACDS) Then Sell("s세번째매도",OnClose,def,3); } } #매수포지션 진입 후 if MarketPosition == 1 Then{ #포지션 최대계약수가 3이상일때 첫번째 청산 if (CurrentContracts == MaxContracts and MaxContracts >= 3) Then ExitLong("매수일부청산1",Atlimit,EntryPrice+PriceScale*(일부청산+5),"",MaxContracts-2,1); #포지션 최대계약수가 3이상일때 두번째 청산 if CurrentContracts < MaxContracts and MaxContracts >= 3 and CurrentContracts == 2 then ExitLong("매수일부청산2",Atlimit,EntryPrice+PriceScale*(일부청산+7),"",1,1); #포지션 최대계약수가 2일때 첫번째 청산 if (CurrentContracts == MaxContracts and MaxContracts == 2) Then ExitLong("매수청산a",Atlimit,EntryPrice+PriceScale*(일부청산+5),"",1,1); #마지막 청산 if CurrentContracts == 1 Then ExitLong("매수잔량익절",Atlimit,EntryPrice+PriceScale*(일부청산+15)); //나머지 전량청산 if MarketPosition == 1 and Condition1 == true and (IsEntryName("sb1",0) == true or IsEntryName("sb2",0) == true or IsEntryName("sb3",0) == true or IsEntryName("sb4",0) == true) And countif(CurrentContracts < CurrentContracts[1],BarsSinceEntry) >= 1 Then ExitLong("btr",AtStop,EntryPrice); #손절 후 스위칭이 연속 8번미만일때 if count < 8 Then{ #현재 남은 수량이 7계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 7 if CurrentContracts == 7 Then sell("bs7",AtStop,EntryPrice-PriceScale*10,7); #현재 남은 수량이 6계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 6 if CurrentContracts == 6 Then sell("bs6",AtStop,EntryPrice-PriceScale*10,6); #현재 남은 수량이 5계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 5 if CurrentContracts == 5 Then sell("bs5",AtStop,EntryPrice-PriceScale*10,5); #현재 남은 수량이 4계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 4 if CurrentContracts == 4 Then sell("bs4",AtStop,EntryPrice-PriceScale*10,4); #현재 남은 수량이 3계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 3 if CurrentContracts == 3 Then sell("bs3",AtStop,EntryPrice-PriceScale*10,3); #현재 남은 수량이 2계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 2 if CurrentContracts == 2 Then sell("bs2",AtStop,EntryPrice-PriceScale*10,2); #현재 남은 수량이 1계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 1 if CurrentContracts == 1 Then sell("bs1",AtStop,EntryPrice-PriceScale*10,1); } #스위칭3번연속일때 10틱 손실이면 청산 if count == 3 Then ExitLong("bx",AtStop,EntryPrice-PriceScale*10); } #매도포지션 진입 후 if MarketPosition == -1 Then{ #포지션 최대계약수가 3이상일때 첫번째 청산 if (CurrentContracts == MaxContracts and MaxContracts >= 3) Then ExitShort("매도일부청산1",Atlimit,EntryPrice-PriceScale*(일부청산+5),"",MaxContracts-2,1); #포지션 최대계약수가 3이상일때 두번째 청산 if CurrentContracts < MaxContracts and MaxContracts >= 3 and CurrentContracts == 2 then ExitShort("매도일부청산2",Atlimit,EntryPrice-PriceScale*(일부청산+7),"",1,1); #포지션 최대계약수가 2일때 첫번째 청산 if (CurrentContracts == MaxContracts and MaxContracts == 2) Then ExitShort("매도청산a",Atlimit,EntryPrice-PriceScale*(일부청산+5),"",1,1); #마지막 청산 if CurrentContracts == 1 Then ExitShort("매도잔량익절",Atlimit,EntryPrice-PriceScale*(일부청산+15)); //나머지 전량청산 #트레일링 스탑 if MarketPosition == -1 and Condition1 == true and (IsEntryName("bs1",0) == true or IsEntryName("bs2",0) == true or IsEntryName("bs3",0) == true or IsEntryName("bs4",0) == true) And countif(CurrentContracts < CurrentContracts[1],BarsSinceEntry) >= 1 Then ExitShort("str",AtStop,EntryPrice); #손절 후 연속스위칭8번미만일때 if count < 8 Then{ #현재 남은 수량이 7계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 7 if CurrentContracts == 7 Then Buy("sb7",AtStop,EntryPrice+PriceScale*10,7); #현재 남은 수량이 6계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 6 if CurrentContracts == 6 Then Buy("sb6",AtStop,EntryPrice+PriceScale*10,6); #현재 남은 수량이 5계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 5 if CurrentContracts == 5 Then Buy("sb5",AtStop,EntryPrice+PriceScale*10,5); #현재 남은 수량이 4계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 4 if CurrentContracts == 4 Then Buy("sb4",AtStop,EntryPrice+PriceScale*10,4); #현재 남은 수량이 3계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 3 if CurrentContracts == 3 Then Buy("sb3",AtStop,EntryPrice+PriceScale*10,3); #현재 남은 수량이 2계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 2 if CurrentContracts == 2 Then Buy("sb2",AtStop,EntryPrice+PriceScale*10,2); #현재 남은 수량이 1계약일때 10틱 손실이면 매도로 스위칭하고 진입수량은 1 if CurrentContracts == 1 Then Buy("sb1",AtStop,EntryPrice+PriceScale*10,1); } #스위칭3번연속일때 10틱 손실이면 청산 if count == 3 Then ExitShort("sx",AtStop,EntryPrice+PriceScale*10); }