커뮤니티
시스템 매매 관련 수정문의 합니다...
아래수식은 ai 기반으로 작성된 수식입니다...
시작시간하고 종료시간이 조금 이상해서 수정부탁합니다..
시작시간은 91500
종료시간은 151500
입니다..
그리고 손절은 없고 익절만 가능하도록 수정부탁드립니다..
// FLI Force Index 기반 역전 스탑앤리버스 전략 (비용 및 수량 변수 지정 포함)
Input : FIPeriod(13), FISmooth(13), ATRPeriod(14), StopATR(3.0), ProfitATR(6.0);
Input : ScaleParts(20), ScaleIntervalMin(15), TotalQty(20);
// 거래 허용 기간 입력 (YYYYMMDD 형식 날짜, 분 단위 시간)
Input : StartDate(20260101), StartTimeMin(930), EndDate(20261231), EndTimeMin(1530);
// 비용 및 수량 변수
Input : CommissionPerUnit(0.0), SlippagePerUnit(0.0);
Var : FI(0), FIs(0), tr(0), atr(0), longStop(0), longProfit(0), shortStop(0), shortProfit(0);
Var : partsDoneLong(0), partsDoneShort(0), lastScaleTime(0);
Var : totalAllocatedLong(0), totalAllocatedShort(0), targetCumulative(0), nextPartQty(0), partIndex(0);
Var : curMin(0), curDate(0), allowTrade(false);
Var : estCost(0), executedQty(0);
FI = (C - C[1]) * V;
FIs = EMA(FI, FISmooth);
tr = TrueRange;
atr = EMA(tr, ATRPeriod);
longStop = Close - StopATR * atr;
longProfit = Close + ProfitATR * atr;
shortStop = Close + StopATR * atr;
shortProfit = Close - ProfitATR * atr;
// 현재 날짜/시간
curMin = TimeToMinutes(sTime);
curDate = Bdate; // 봉의 거래일(YYYYMMDD)
// 거래 허용 여부 판단
allowTrade = (curDate >= StartDate) And (curDate <= EndDate) And (curMin >= StartTimeMin) And (curMin <= EndTimeMin);
If CrossUp(FIs, 0) Then
{
partsDoneLong = 0;
partsDoneShort = 0;
lastScaleTime = 0;
totalAllocatedLong = 0;
totalAllocatedShort = 0;
}
//If CrossDown(FIs, 0) Then
{
// partsDoneShort = 0;
// partsDoneLong = 0;
// lastScaleTime = 0;
// totalAllocatedLong = 0;
// totalAllocatedShort = 0;
}
// 롱 분할 진입 (총수량 대비 비율 방식) - 시간/날짜 필터 적용
If allowTrade And FIs > 0 And partsDoneLong < ScaleParts Then
{
partIndex = partsDoneLong + 1; // 1-based
targetCumulative = Ceiling(TotalQty * partIndex / ScaleParts);
nextPartQty = targetCumulative - totalAllocatedLong;
If nextPartQty < 0 Then nextPartQty = 0;
If nextPartQty > 0 And (lastScaleTime == 0 Or (curMin - lastScaleTime) >= ScaleIntervalMin) Then
{
// 예상 비용 계산(간단): (수량 * (Commission + Slippage))
estCost = nextPartQty * (CommissionPerUnit + SlippagePerUnit);
Buy("FLI_Long_Part", onclose, Def, nextPartQty);
partsDoneLong = partsDoneLong + 1;
totalAllocatedLong = totalAllocatedLong + nextPartQty;
lastScaleTime = curMin;
// 추적용: 실행 누적 수량(실제 체결은 플랫폼에서 결정되므로 근사값)
executedQty = executedQty + nextPartQty;
}
}
// 숏 분할 진입 (총수량 대비 비율 방식) - 시간/날짜 필터 적용
If allowTrade And FIs < 0 And partsDoneShort < ScaleParts Then
{
partIndex = partsDoneShort + 1;
targetCumulative = Ceiling(TotalQty * partIndex / ScaleParts);
nextPartQty = targetCumulative - totalAllocatedShort;
If nextPartQty < 0 Then nextPartQty = 0;
If nextPartQty > 0 And (lastScaleTime == 0 Or (curMin - lastScaleTime) >= ScaleIntervalMin) Then
{
estCost = nextPartQty * (CommissionPerUnit + SlippagePerUnit);
Sell("FLI_Short_Part", onclose, Def, nextPartQty);
partsDoneShort = partsDoneShort + 1;
totalAllocatedShort = totalAllocatedShort + nextPartQty;
lastScaleTime = curMin;
executedQty = executedQty + nextPartQty;
}
}
// 손절/익절 로직 유지 (청산 주문은 거래허용시간 외에도 실행될 수 있도록 허용)
If MarketPosition == 1 Then
{
If High < longStop And NextBarBdate == Bdate Then
ExitLong("FLI_L_Stop", AtStop, longStop);
If High < longProfit And NextBarBdate == Bdate Then
ExitLong("FLI_L_Profit", AtLimit, longProfit);
}
If MarketPosition == -1 Then
{
If Low > shortStop And NextBarBdate == Bdate Then
ExitShort("FLI_S_Stop", AtStop, shortStop);
If Low > shortProfit And NextBarBdate == Bdate Then
ExitShort("FLI_S_Profit", AtLimit, shortProfit);
}
// 참고 출력용: 실행 누적 수량 및 예상 비용을 내장 변수에 저장 (플랫폼에서 확인 가능)
Var : reportedExecutedQty(0), reportedEstCost(0);
reportedExecutedQty = executedQty;
reportedEstCost = executedQty * (CommissionPerUnit + SlippagePerUnit);
답변 1
예스스탁 예스스탁 답변
2026-03-31 13:07:41