예스스탁
예스스탁 답변
2019-09-10 11:32:38
안녕하세요
예스스탁입니다.
실제 계좌의 잔고에는 진입날짜나 시간을 알수가 없습니다.
별도로 시간을 저장해야 하는데 올려주신 내용에는 진입시점을 알수가 없습니다.
진입은 차트에서 Buy나 Sell을 기준으로 발생한것으로 처리해 드립니다.
아래 가이드 참고하셔서 수정보완해 완성하시기 바랍니다.
영문업데이트가 게시판 금칙어입니다.
Up*date로 중간에 *이 추가되어 있으므로 삭제하시기 바랍니다.
스크립트객체설정
차트객체추가 --> 속성에서 객체명 Chart1, 차트와 아이디연결
종목객체추가 --> 속성에서 객체명 MarketData1, 주문종목으로 지정
계좌객체추가 --> 속성에서 객체명 Account1, 주문계좌지정
var On12,On22,HHMMSS,HHMMSS1,B,S,BH,SL;
function Main_OnStart()
{
//1번 타이머
Main.SetTimer(1, 60000);//60초
}
//진입
function Chart1_OnRiseSignal(Signal)
{
var d = new Date();
HHMMSS1 = HHMMSS;
HHMMSS = d.getHours()*10000+d.getMinutes()*100+d.getSeconds();
//22시에서 04시 사이에 매수진입신호 발생
if (Signal.signalKind == 1 && (HHMMSS >= 200000 || HHMMSS < 040000) )
{
B = true;
BH = 0; //진입 후 최고가 저장변수 초기값 0
Account1.OrderBuy(Main.GetOrderCode(MarketData1.code), 1, MarketData1.current,2);
Main.SetTimer(11, 3600000);//3600초(60분)
}
//22시에서 04시 사이에 매도진입신호 발생
if (Signal.signalKind == 3 && (HHMMSS >= 200000 || HHMMSS < 040000))
{
S = true;
SL = 0; //진입 후 최저가 저장변수 초기값 0
Account1.OrderSell(Main.GetOrderCode(MarketData1.code), 1, MarketData1.current,2);
Main.SetTimer(21, 3600000);//3600초(60분)
}
}
function Main_OnTimer(nEventID)
{
var d = new Date();
HHMMSS1 = HHMMSS;
HHMMSS = d.getHours()*10000+d.getMinutes()*100+d.getSeconds();
//04시가 되면
if(nEventID == 1 && HHMMSS >= 040000 && HHMMSS1 < 040000)
{
//모든 타이머 종료
Main.KillTimer(1);
Main.KillTimer(11);
Main.KillTimer(12);
Main.KillTimer(21);
Main.KillTimer(22);
//잔고셋팅
Account1.SetBalance(Main.GetOrderCode(MarketData1.code),0);
//매수포지션 수량이 있으면
if (B == true && Account1.Balance.count > 0 && Account1.Balance.position == 2)
{
B = false;
Account1.OrderSell(Account1.Balance.code,Account1.Balance.count,MarketData1.current,2);
}
//매도포지션 수량이 있으면
if (S == true && Account1.Balance.count > 0 && Account1.Balance.position == 2)
{
S = false;
Account1.OrderBuy(Account1.Balance.code,Account1.Balance.count,MarketData1.current,2);
}
}
//매수진입후 11번 타이머 동작
if (nEventID == 11)
{
//종료
Main.KillTimer(11);
//잔고셋팅
Account1.SetBalance(Main.GetOrderCode(MarketData1.code),0);
//매수포지션 수량이 있으면
if (B == true && Account1.Balance.count > 0 && Account1.Balance.position == 2)
{
//수익일때
if (Account1.Balance.current > Account1.Balance.avgUnitCost)
{
Account1.OrderSell(Account1.Balance.code,Account1.Balance.count,MarketData1.current,2);
B = false;
}
else//아니면
{
//12번 타이머 실행
Main.SetTimer(12, 300000);//300초(5분)
On12 = 0;
}
}
}
//매수 진입 후 12번 타이머 동작
if (nEventID == 12)
{
On12 = On12+1;
//잔고셋팅
Account1.SetBalance(Main.GetOrderCode(MarketData1.code),0);
//타이머가 1~3번 동작했을때
if (On12 < 4)
{
if (B == true && Account1.Balance.count > 0 && Account1.Balance.position == 2)
{
//수익일때
if (Account1.Balance.current > Account1.Balance.avgUnitCost)
{
Account1.OrderSell(Account1.Balance.code,Account1.Balance.count,MarketData1.current,2);
B = false;
//종료
Main.KillTimer(12);
}
}
}
//4번 동작하면 종료
if (On12 == 4)
{
Main.KillTimer(12);
if (B == true && Account1.Balance.count > 0 && Account1.Balance.position == 2)
{
B = false;
Account1.OrderSell(Account1.Balance.code,Account1.Balance.count,MarketData1.current,2);
}
}
}
//매도진입후 21번 타이머 동작
if (nEventID == 21)
{
//종료
Main.KillTimer(21);
//잔고셋팅
Account1.SetBalance(Main.GetOrderCode(MarketData1.code),0);
//매도포지션 수량이 있으면
if (S == true && Account1.Balance.count > 0 && Account1.Balance.position == 1)
{
//수익일때
if (Account1.Balance.current < Account1.Balance.avgUnitCost)
{
S = false;
Account1.OrderBuy(Account1.Balance.code,Account1.Balance.count,MarketData1.current,2);
}
else//아니면
{
//22번 타이머 실행
Main.SetTimer(22, 300000);//300초(5분)
On22 = 0;
}
}
}
//매수 진입 후 22번 타이머 동작
if (nEventID == 22)
{
On22 = O22+1;
//잔고셋팅
Account1.SetBalance(Main.GetOrderCode(MarketData1.code),0);
//타이머가 1~3번 동작
if (On12 < 4)
{
if (S == true && Account1.Balance.count > 0 && Account1.Balance.position == 1)
{
//수익일때
if (Account1.Balance.current < Account1.Balance.avgUnitCost)
{
Account1.OrderBuy(Account1.Balance.code,Account1.Balance.count,MarketData1.current,2);
S = false;
//종료
Main.KillTimer(22);
}
}
}
//4번 동작하면 종료
if (On12 == 4)
{
Main.KillTimer(22);
if (S == true && Account1.Balance.count > 0 && Account1.Balance.position == 1)
{
S = false;
Account1.OrderBuy(Account1.Balance.code,Account1.Balance.count,MarketData1.current,2);
}
}
}
}
function Main_OnUp*dateMarket(sItemCode, lUp*dateID) //*삭제
{
if (B == true && lUp*dateID == 20001) //*삭제
{
Account1.SetBalance(Main.GetOrderCode(MarketData1.code),0);
if (BH == 0 || (BH > 0 && MarketData1.current > BH))
{
BH = MarketData1.current;
}
if (MarketData1.current >= Account1.Balance.avgUnitCost + MarketData1.GetTickSize()*50)
{
Account1.OrderSell(Account1.Balance.code,Account1.Balance.count,MarketData1.current,2);
B = false;
Main.KillTimer(11);
Main.KillTimer(12);
}
if (MarketData1.current <= Account1.Balance.avgUnitCost - MarketData1.GetTickSize()*30)
{
Account1.OrderSell(Account1.Balance.code,Account1.Balance.count,MarketData1.current,2);
B = false;
Main.KillTimer(11);
Main.KillTimer(12);
}
if (BH >= Account1.Balance.avgUnitCost + MarketData1.GetTickSize()*20 &&
MarketData1.current <= BH - MarketData1.GetTickSize()*5)
{
Account1.OrderSell(Account1.Balance.code,Account1.Balance.count,MarketData1.current,2);
B = false;
Main.KillTimer(11);
Main.KillTimer(12);
}
}
if (S == true && lUp*dateID == 20001)//*삭제
{
Account1.SetBalance(Main.GetOrderCode(MarketData1.code),0);
if (SL == 0 || (SL > 0 && MarketData1.current < SL))
{
SL = MarketData1.current;
}
if (MarketData1.current <= Account1.Balance.avgUnitCost - MarketData1.GetTickSize()*50)
{
Account1.OrderBuy(Account1.Balance.code,Account1.Balance.count,MarketData1.current,2);
S = false;
Main.KillTimer(21);
Main.KillTimer(22);
}
if (MarketData1.current >= Account1.Balance.avgUnitCost + MarketData1.GetTickSize()*30)
{
Account1.OrderBuy(Account1.Balance.code,Account1.Balance.count,MarketData1.current,2);
S = false;
Main.KillTimer(21);
Main.KillTimer(22);
}
if (SL <= Account1.Balance.avgUnitCost - MarketData1.GetTickSize()*20 &&
MarketData1.current >= SL + MarketData1.GetTickSize()*5)
{
Account1.OrderBuy(Account1.Balance.code,Account1.Balance.count,MarketData1.current,2);
S = false;
Main.KillTimer(21);
Main.KillTimer(22);
}
}
}
즐거운 명절되시길 바랍니다.
> 워싱턴 님이 쓴 글입니다.
> 제목 : 수식 부탁드립니다.
> 안녕하세요
항상 많은 도움에 수고많으십니다.
1) 최종목표가 익절 +50틱 / 손절 -30틱 / 트레일링 시작 +20틱 (5틱 하락시 청산)
2) 진입후 1시간 지나도 청산이 안되는 경우 (이익상태인경우 즉시 청산하고, 손실상태인 경우 5분 마다 체크하여,
이익상태이면 청산하고, 20분이 지나면 현재가에 청산한다.)
3) 거래 1계약으로만 하고, 저녁 8시부터 시작해서 다음날 4시가지만 진행하고, 4시에 잔고가 있으면 즉시 청산한다.
위의 수식을 스팟의 하나의 식으로 큰 그림으로 부탁드립니다.
감사합니다.