커뮤니티

청산수식 수정

프로필 이미지
목마와숙녀
2026-02-28 08:44:47
551
글번호 230812
답변완료

아래 수식은 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

안녕하세요 예스스탁입니다. // 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(""); // 마지막 진입명 저장 var : p1(0),p2(0),p3(0),p4(0); var : h1(0),h2(0),h3(0),h4(0); // 새 영업일 초기화 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"; p1 = c; h1 = p1; } // 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"; p2 = c; h2 = p2; } // 세번째 진입: 두번째 진입 후 양봉 양에 따른 진입 Else If entryCount == 2 And entryCount < MaxPyramids And bullCount >= 양봉1 Then { Buy("b3", onclose, Def); entryCount = 3; bullCount = 0; lastEntryName = "b3"; p3 = c; h3 = p3; } // 네번째 진입: 세번째 진입 후 양봉 양에 따른 진입 Else If entryCount == 3 And entryCount < MaxPyramids And bullCount >= 양봉2 Then { Buy("b4", onclose, Def); entryCount = 4; bullCount = 0; lastEntryName = "b4"; p4 = c; h4 = p4; } } } // 포지션이 없으면 lastEntryName 초기화 If MarketPosition == 0 Then lastEntryName = ""; // 청산(스탑) 설정: 마지막 진입명을 기준으로 적용 If MarketPosition == 1 Then { If MaxEntries > 0 Then { if h1 == 0 or (h1 > 0 and h > h1) Then h1 = h; ExitLong("bl1",AtStop,p1-als,"b1"); ExitLong("bt1",AtStop,h1-atr,"b1"); } If MaxEntries > 1 Then { if h2 == 0 or (h2 > 0 and h > h2) Then h2 = h; ExitLong("bl2",AtStop,p2-bls,"b2"); ExitLong("bt2",AtStop,h2-btr,"b2"); } If MaxEntries > 2 Then { if h3 == 0 or (h3 > 0 and h > h3) Then h3 = h; ExitLong("bl3",AtStop,P3-cls,"b3"); ExitLong("bt3",AtStop,h3-ctr,"b3"); } If MaxEntries > 3 Then { if h4 == 0 or (h4 > 0 and h > h4) Then h4 = h; ExitLong("bl4",AtStop,P4-dls,"b4"); ExitLong("bt4",AtStop,h4-dtr,"b4"); } } Else { h1 = 0; h2 = 0; h3 = 0; h4 = 0; } // 당일 종료(오후 eod에 강제 청산) SetStopEndofday(eod); 즐거운 하루되세요