커뮤니티
청산수식 수정
아래 수식은 4개 까지 피라미딩하는 수식입니다.
문제점
청산수식이 진입명대로 작동하지 않습니다.
b1 진입시 손절과 트레일링스탑
b2 진입시 손절과 트레일링스탑
b3 진입시 손절과 트레일링스탑
b4 진입시 손절과 트레일링스탑
위 내용이 구분되어 작동될 수 있도록 청산수식 수정바랍니다.
항상 고맙습니다.
**********************************************************************************************************************
// Data2 기반 피라미딩 전략 (개선된 청산명 식별)
Input : MaxPyramids(4), 양봉1(7), 양봉2(3);
input : als(500),atr(1000);
input : bls(1000),btr(1500);
input : cls(1500),ctr(2000);
input : dls(2000),dtr(2500);
input : eod(151900);
Var : entryCount(0), bullCount(0), b1Placed(false);
Var : lastEntryName(""); // 마지막 진입명 저장
// 새 영업일 초기화
If data2(Bdate) != data2(Bdate[1]) Then
{
entryCount = 0;
bullCount = 0;
b1Placed = False;
lastEntryName = "";
}
// 1) 초회 진입: data1와 data2 영업일 같고 data2 첫 양봉일 때
If MarketPosition == 0 And data1(Bdate) == data2(Bdate) And b1Placed == False And data2(C) > data2(O) Then
{
Buy("b1", onclose, Def);
entryCount = 1;
bullCount = 0;
b1Placed = True;
lastEntryName = "b1";
}
// 2) 피라미딩 로직 (최대 MaxPyramids)
If MarketPosition >= 1 Then
{
// data2 양봉/음봉 카운트 업데이트
If data2(C) > data2(O) Then
bullCount = bullCount + 1;
// 음봉 발생 시 다음 진입 조건 확인
If data2(C) < data2(O) Then
{
// 두번째 진입: b1 진입 이후 첫 음봉
If entryCount == 1 And entryCount < MaxPyramids Then
{
Buy("b2", onclose, Def);
entryCount = 2;
bullCount = 0;
lastEntryName = "b2";
}
// 세번째 진입: 두번째 진입 후 양봉 양에 따른 진입
Else If entryCount == 2 And entryCount < MaxPyramids And bullCount >= 양봉1 Then
{
Buy("b3", onclose, Def);
entryCount = 3;
bullCount = 0;
lastEntryName = "b3";
}
// 네번째 진입: 세번째 진입 후 양봉 양에 따른 진입
Else If entryCount == 3 And entryCount < MaxPyramids And bullCount >= 양봉2 Then
{
Buy("b4", onclose, Def);
entryCount = 4;
bullCount = 0;
lastEntryName = "b4";
}
}
}
// 포지션이 없으면 lastEntryName 초기화
If MarketPosition == 0 Then
lastEntryName = "";
// 청산(스탑) 설정: 마지막 진입명을 기준으로 적용
If MarketPosition == 1 Then
{
If lastEntryName == "b1" Then
{
SetStopLoss(als,PointStop);
SetStopTrailing(atr,0,PointStop,1);
}
Else If lastEntryName == "b2" Then
{
SetStopLoss(bls,PointStop);
SetStopTrailing(btr,0,PointStop,1);
}
Else If lastEntryName == "b3" Then
{
SetStopLoss(cls,PointStop);
SetStopTrailing(ctr,0,PointStop,1);
}
Else If lastEntryName == "b4" Then
{
SetStopLoss(dls,PointStop);
SetStopTrailing(dtr,0,PointStop,1);
}
Else
{
SetStopLoss(0);
SetStopTrailing(0,0);
}
}
// 당일 종료(오후 eod에 강제 청산)
SetStopEndofday(eod);
답변 1
예스스탁 예스스탁 답변
2026-03-03 11:16:03