커뮤니티
선물에서 난 신호를 옵션적용
// ====================================================================
// ★ [사용자 지정 변수 설정 (Input 값)] ★
// ====================================================================
var MyVolume = 1; // 진입할 고정 계약수
// [중요] 현재 코스피 선물 지수(예: 390.50) 흐름에 맞추어 숫자를 적어주셔야 작동합니다!
// 콜옵션(MarketData1) 매매 기준 선물 가격 설정
var CallEntryIdx = 1084.00; // 위/아래 관계없이 선물 가격이 이 가격을 지나가거나 닿으면 콜 매수!
var CallTargetIdx = 1088.00; // 선물 가격이 이 가격 '이상' 올라가면 지정 콜옵션 익절!
var CallLossIdx = 388.00; // 선물 가격이 이 가격 '이하'로 떨어지면 지정 콜옵션 손절!
// 풋옵션(MarketData2) 매매 기준 선물 가격 설정
var PutEntryIdx = 1094.00; // 위/아래 관계없이 선물 가격이 이 가격을 지나가거나 닿으면 풋 매수!
var PutTargetIdx = 1080.00; // 선물 가격이 이 가격 '이하'로 떨어지면 지정 풋옵션 익절!
var PutLossIdx = 397.00; // 선물 가격이 이 가격 '이상' 올라가면 지정 풋옵션 손절!
// ====================================================================
// 중복 주문 및 오류 방지를 위한 내부 변수
var IsCallOrdered = 0;
var IsPutOrdered = 0;
// 실시간 선물 체결가를 오차 없이 저장하기 위한 내부 저장소
var RealtimeLastPrice = 0;
function Main_OnStart()
{
Main.MessageLog("★ [2초봉 해결] 선물 마켓데이터3 다이렉트 틱 감시 시스템 가동 ★");
Main.MessageLog("현재 감시 중인 선물 종목명: " + MarketData3.name);
}
function GetThreeTicks(currentPrice)
{
if (currentPrice >= 3.00) { return 0.15; } else { return 0.03; }
}
// 시장 전체에서 내가 등록한 마켓데이터(선물/옵션)들의 시세가 단 1틱이라도 변하면 호출되는 실시간 엔진
function Main_OnUpdateMarketData(MarketData)
{
// 새로 등록한 MarketData3(선물 종목)의 진짜 실시간 체결 현재가를 다이렉트로 가져옵니다.
var CurrentFuturePrice = MarketData3.current;
// 최초 실행 시 이전 가격 정보 채우기
if (RealtimeLastPrice == 0) {
RealtimeLastPrice = CurrentFuturePrice;
return;
}
// ----------------------------------------------------------------
// [파트 1] 지정 콜옵션(MarketData1) 매매 감시
// ----------------------------------------------------------------
var TargetCallCode = MarketData1.code;
Account1.SetBalanceItem(TargetCallCode, 0);
var CallCount = Account1.Balance.count;
if (CallCount == 0 && IsCallOrdered == 0)
{
// 2초봉 차트가 미처 읽지 못하고 점프한 가격 영역을 실시간 선물 틱 시세(MarketData3)로 완벽히 추적합니다.
if ((RealtimeLastPrice >= CallEntryIdx && CallEntryIdx >= CurrentFuturePrice) ||
(RealtimeLastPrice <= CallEntryIdx && CallEntryIdx <= CurrentFuturePrice))
{
IsCallOrdered = 1; // 중복 진입 방지 ??
var OrderPrice = MarketData1.current + GetThreeTicks(MarketData1.current);
Account1.OrderBuy(TargetCallCode, MyVolume, OrderPrice, 0);
Main.MessageLog("?? [콜 진입 성공] 선물 실시간 틱 관통 완료 -> " + MarketData1.name + " 매수");
}
}
else if (CallCount > 0 && IsCallOrdered == 1)
{
if (CurrentFuturePrice >= CallTargetIdx)
{
IsCallOrdered = 2;
var OrderPrice = MarketData1.current - GetThreeTicks(MarketData1.current);
Account1.OrderSell(TargetCallCode, CallCount, OrderPrice, 0);
Main.MessageLog("?? [콜 익절완료] 선물 실시간 현재가: " + CurrentFuturePrice);
}
else if (CurrentFuturePrice <= CallLossIdx)
{
IsCallOrdered = 2;
var OrderPrice = MarketData1.current - GetThreeTicks(MarketData1.current);
Account1.OrderSell(TargetCallCode, CallCount, OrderPrice, 0);
Main.MessageLog("?? [콜 손절완료] 선물 실시간 현재가: " + CurrentFuturePrice);
}
}
// ----------------------------------------------------------------
// [파트 2] 지정 풋옵션(MarketData2) 매매 감시
// ----------------------------------------------------------------
var TargetPutCode = MarketData2.code;
Account1.SetBalanceItem(TargetPutCode, 0);
var PutCount = Account1.Balance.count;
if (PutCount == 0 && IsPutOrdered == 0)
{
if ((RealtimeLastPrice >= PutEntryIdx && PutEntryIdx >= CurrentFuturePrice) ||
(RealtimeLastPrice <= PutEntryIdx && PutEntryIdx <= CurrentFuturePrice))
{
IsPutOrdered = 1;
var OrderPrice = MarketData2.current + GetThreeTicks(MarketData2.current);
Account1.OrderBuy(TargetPutCode, MyVolume, OrderPrice, 0);
Main.MessageLog("?? [풋 진입 성공] 선물 실시간 틱 관통 완료 -> " + MarketData2.name + " 매수");
}
}
else if (PutCount > 0 && IsPutOrdered == 1)
{
if (CurrentFuturePrice <= PutTargetIdx)
{
IsPutOrdered = 2;
var OrderPrice = MarketData2.current - GetThreeTicks(MarketData2.current);
Account1.OrderSell(TargetPutCode, PutCount, OrderPrice, 0);
Main.MessageLog("?? [풋 익절완료] 선물 실시간 현재가: " + CurrentFuturePrice);
}
else if (CurrentFuturePrice >= PutLossIdx)
{
IsPutOrdered = 2;
var OrderPrice = MarketData2.current - GetThreeTicks(MarketData2.current);
Account1.OrderSell(TargetPutCode, PutCount, OrderPrice, 0);
Main.MessageLog("?? [풋 손절완료] 선물 실시간 현재가: " + CurrentFuturePrice);
}
}
// 다음 틱 시세와 비교하기 위해 현재 가격을 이전 가격 저장소에 실시간 업데이트합니다.
RealtimeLastPrice = CurrentFuturePrice;
}
function Main_OnUpdateOrder(UpdateOrder)
{
Account1.SetBalanceItem(MarketData1.code, 0);
if (Account1.Balance.count == 0) IsCallOrdered = 0;
Account1.SetBalanceItem(MarketData2.code, 0);
if (Account1.Balance.count == 0) IsPutOrdered = 0;
}
이렇게 하는데 신호가 안나옵니다.
늘 감사하는 마음으로 글을 씁니다.
답변 1
예스스탁 예스스탁 답변
2026-09-30 12:32:46