예스스탁
예스스탁 답변
2020-04-29 15:47:30
안녕하세요
예스스탁입니다.
아래 가이드 수식 내용을 참고하셔서 수정보완해 사용하시기 바랍니다.
영문 업데이트가 게시판 금칙어라 Up*date와 같이 중간에 *이 삽입되어 있습니다.
*제거 하시기 바랍니다.
var n = 20;
var p1 = 2,p2 = 3, p3 = 4;
var T1 = 150000;
var Count;
//배열변수들
//잔고에 추가되는 순서로 동일배열방에 종목코드,최고가,종목객체,주문제한1,주무제한2,주문제한3을 저장
//주문제한은 최고상승기준으로 각 주문이 한번만 발생하게 위해 사용
var blist = [],hlist=[],mlist=[],olist1 = [],olist2 = [],olist3 = [];
//스팟시작
function Main_OnStart()
{
//카운트는 최초 0
Count = 0;
//타이머 5초
Main.SetTimer(1, 5000);
}
//계좌알림
function Main_OnUp*dateAccount(sAccntNum, sItemCode, lUp*dateID)//*제거
{
//신규종목 추가
if (lUp*dateID == 30001) //*제거
{
//지정한 관심그룹의 종목수
var num = Main.GetItemCountOfInterest("관심그룹이름");
//신규종목이 관심그룹리스트에 있는지 확인
var newitem = false;
for (var i = 0; i < num; i++)
{
if (sItemCode == Main.GetItemCodeInInterest("관심그룹이름", i))
{
newitem = true;
}
}
//있으면
if (newitem == true)
{
//카운트 1씩 증가
Count = count+1;
//각 배열의 count번호방에
blist[count] = sItemCode; //종목코드 저장
mlist[count] = 0; //종목객체저장, 초기값0
hlist[count] = 0; //최고가저장, 초기값 0
olist1[count] = 0; //주문구분1, 초기값0
olist2[count] = 0; //주문구분2, 초기값0
olist3[count] = 0; //주문구분3, 초기값0
//종목객체 요청
Main.ReqMarketData(blist[count], 0, 0);
}
}
}
//종목객체가 수신되면
function Main_OnRcvMarketData(MarketData)
{
if (blist[count] == MarketData.code)
{
//mlist변수의 count번호방에 종목객체 저장
mlist[count] = MarketData;
//hlist 변수의 count번호방에 현재가 저장
hlist[count] = mlist[count].current;
}
}
//타이머 종작(5초)
function Main_OnTimer(nEventID)
{
var d = new Date();
var HHMMSS = d.getHours()*10000+d.getMinutes()*100+d.getSeconds();
//T1시간 이전이고 한종목이상 발생한 이후에
if (HHMMSS < T1 && Count >= 1)
{
//저장된 모든 종목들 루프돌면서
for (var i = 1; i <= mlist.length;i++ )
{
//현재가가 저장된 최고가보다 크면
//저장값을 현재가로 변경
if (mlist[i].current > hlist[i])
{
hlist[i] = mlist[i].current;
}
//잔고셋팅
Account1.SetBalance(mlist[i].code,0);
//수량이 있으면
if (Account1.Balance.count > 0)
{
//최고가가 n%미만이면
if (hlist[i] < Account1.Balance.avgUnitCost*(1+n/100))
{
//현재가가 최고가-(n/2)%이하이면 절반청산
//olist1는 1로 변경해서 한번만 실행하게 함
if (olist1[i] == 0 && mlist[i].current <= hlist[i]*(1-(n/2)/100))
{
olist1[i] = 1;
if (Math.floor(Account1.Balance.count*0.5) >= 1)
{
Account1.OrderSell(Account1.Balance.code,Math.floor(Account1.Balance.count*0.5),mlist[i].current,0);
}
}
//현재가가 최고가-n%이하이면 전량청산
//olist1[i]는 2로 변경 한번만 실행하게 함
if (olist1[i] == 1 && mlist[i].current <= hlist[i]*(1-n/100))
{
olist1[i] = 2;
Account1.OrderSell(Account1.Balance.code,Account1.Balance.count,mlist[i].current,0);
}
}
//최고가가 n%~(2*n)% 사이이면
else if (hlist[i] >= Account1.Balance.avgUnitCost *(1+n/100) && hlist[i] < Account1.Balance.avgUnitCost*(1+(2*n)/100))
{
//현재가가 최고가-n%이하이면 절반청산
//olist2는 1로 변경해서 한번만 실행하게 함
if (olist2[i] == 0 && mlist[i].current <= hlist[i]*(1-n/100))
{
olist2[i] = 1;
if (Math.floor(Account1.Balance.count*0.5) >= 1)
{
Account1.OrderSell(Account1.Balance.code,Math.floor(Account1.Balance.count*0.5),mlist[i].current,0);
}
}
//현재가가 평단가-(n/2)%이하이면 전량청산
//olist2는 2로 변경 한번만 실행하게 함
if (olist2[i] == 1 && mlist[i].current <= Account1.Balance.avgUnitCost*(1-(n/2)/100))
{
olist2[i] = 2;
Account1.OrderSell(Account1.Balance.code,Account1.Balance.count,mlist[i].current,0);
}
}
else //최고가가 (2*n)% 이상
{
//최고가에서 - n%이면 전량청
Account1.OrderSell(Account1.Balance.code,Account1.Balance.count*0.5,mlist[i].current,0);
}
//현재가가 평단가+2%이상이면 15% 청산
//olist은 1로 변경해서 한번만 실행하게 함
if (olist3[i] == 0 && mlist[i].current >= Account1.Balance.avgUnitCost*(1+p1/100))
{
olist3[i] = 1;
if (Math.floor(Account1.Balance.count*0.5) >= 1)
{
Account1.OrderSell(Account1.Balance.code,Math.floor(Account1.Balance.count*0.15),mlist[i].current,0);
}
}
//현재가가 평단가+3%이상이면 15% 청산
//olist3은 2로 변경해서 한번만 실행하게 함
if (olist3[i] == 1 && mlist[i].current >= Account1.Balance.avgUnitCost*(1+p2/100))
{
olist3[i] = 2;
if (Math.floor(Account1.Balance.count*0.5) >= 1)
{
Account1.OrderSell(Account1.Balance.code,Math.floor(Account1.Balance.count*0.15),mlist[i].current,0);
}
}
//현재가가 평단가+4%이상이면 15% 청산
//olist3은 3으로 변경해서 한번만 실행하게 함
if (olist3[i] == 2 && mlist[i].current >= Account1.Balance.avgUnitCost*(1+p3/100))
{
olist3[i] = 3;
if (Math.floor(Account1.Balance.count*0.5) >= 1)
{
Account1.OrderSell(Account1.Balance.code,Math.floor(Account1.Balance.count*0.15),mlist[i].current,0);
}
}
}
}
}
//T1시간이후가 되면ㄴ
if (HHMMSS >= T1 && Count >= 1)
{
//타이머 종류
Main.KillTimer(1);
//리스트 종목의 매도 미체결이 있으면 모두 취소
var num = Account1.GetTheNumberOfUnfills();
if (num > 0 && Count > 0)
{
for (var a = 0; a < num; a++)
{
Account1.SetUnfill(a);
for (var b = 1; b <= blist.length; a++)
{
if (Account1.Unfill.count > 0 && Account1.Unfill.orderKind == 1 && Account1.Unfill.code == blist[b])
{
Account1.OrderCancel(Account1.Unfill.orderNum);
}
}
}
}
//리스트 종목이 잔고에 있으면 전량 시장가 매도
var num = Account1.GetTheNumberOfBalances();
if (num > 0 && Count > 0)
{
for (var a = 0; a < num; a++)
{
Account1.SetBalance(a);
for (var b = 1; b <= blist.length; a++)
{
if (Account1.Balance.count > 0 && Account1.Balance.code == blist[b])
{
Account1.OrderSell(Account1.Balance.code,Account1.Balance.count,0,1);
}
}
}
}
}
}
즐거운 하루되세요
> cs아빠 님이 쓴 글입니다.
> 제목 : 매도식 부탁드립니다.
> 1. 관심종목의 종목이 매수되면 감시시작
2. 매수 이후 최고 상승이 n% 미만일 경우
2-1. 현재가 < 매수후_최고가*[1 - (n/2)/100] ==> 잔고의 50% 매도
2-2. 현재가 < 매수가*[1 - n/100] ==> 전량 매도
3. 매수 이후 최고 상승이 n% ~ (2*n) % 일경우
3-1 현재가 < 매수후_최고가*[1 - n/100] ==> 잔고의 50% 매도
3-2 현재가 < 매수가*[1 - (n/2)/100] ==> 전량 매도
4. 매수 이후 최고 상승이 (2*n) % 이상일 경우
4-1 현재가 < 매수후_최고가*[1 - n/100] ==> 전량 매도
5. 2~4번과 상관없이 매수가대비 2%, 3%, 4% 상승시 최초 잔고의 15% 씩 매도
6. T1 시간이후 1번에서 감시한 종목의 미체결 매도 취소후 전량 시장가 매도
감사합니다.