답변완료
전에 문의했던 사항인데 잘 안되어 다시 부탁드리겠습니다. (매수진입 및 매도 진입)
해당 수식으로 손절을 적용하고 있는데요...
ExitLong("즉시손절1",AtStop,EntryPrice-PriceScale*즉시손절1);
매수 진입한 봉한개에서 에서 하락 틱수가 "즉시손절1"틱수를 넘어서더라도
손절처리가 안되요... 매수한 다음봉부터 인지를 한다고 들었습니다.
그러면 진입하자마자 해당봉에서 손실을 제한하는 수식을 알려주시면 감사하겠습니다.
수식은 다음과 같습니다.
변수중 "즉시손절1" 값에 도달시 청산하는 수식 부탁드려요~~ 그봉에
# 매수 진입 조건 변수
Input : RSIPeriod(7),RSI매수값(28),SimPeriod(14),심리도값(36); # RSI와 심리도 기간 및 값 변수
Input : N1(1),초기화(3); # 위 해당 조건 발생후 진입 유효 기간, 7일경과후 초기화
Input : 하락틱수(2); # 해당 조건 발생후 하락틱수만큼 하락후 진입 변수
Input : RSIPeriod1(6),A(0),B(4),D(48),E(72); # 일봉기준 RSI값이 해당변수안에 속해있을때 진입 변수
Input : 거래량1(600),거래량평균봉수(55),거래량평균봉수비율(3.6); # 해당 거래량1,2 사이에 속해 있을때 진입되는 변수 18000
# 1일 1회 거래
# 청산 조건 변수
Input : CCI기간(20),CCI값(500); # CCI값에 의해 청산 수식 변수
Input : 즉시익절1(70),즉시손절1(90); # 익절값 손절값 변수
Input : N2(0.6),N3(0.15); # 상승후 본절청산 관련 수식
Input : tr수익(70),tr하락(25); # 트레일링 관련 수식
Input : N4(0.7),본전생각틱(10); # 하락후 본절청산 관련 수식
Input : N5(0.8),CCI값1(120); # 약 손절 관련 수식
Input : 터치익절(105);
var : cnt(0),SigSum(0),count2(0),RSIsig(0);
Var : Counter(0), DownAmt(0), UpAmt(0), UpSum(0), DownSum(0), UpAvg(0), DownAvg(0);
var : idx(0), PreUpAvg(0), preDownAvg(0),RSIVv(0);
Array : C1[100](0);
var : CCIv(0),RSIv(0),Simri(0),BuySetup(false),DD(0),entry(0);
CCIv = CCI(CCI기간);
RSIV = RSI(RSIPeriod);
Simri = Simrido(SimPeriod);
var4 = ma(V,20);
if Bdate != Bdate[1] Then
{
for cnt = 1 to 99
{
C1[cnt] = C1[cnt-1][1];
}
PreUpAvg = UpAvg[1];
preDownAvg = DownAvg[1];
idx = idx + 1;
}
C1[0] = C;
If idx == RSIPeriod1+2 Then
{
UpSum = 0;
DownSum = 0;
For Counter = 0 To RSIPeriod1 - 1
{
UpAmt = C1[Counter] - C1[Counter+1];
If UpAmt >= 0 Then
DownAmt = 0;
Else
{
DownAmt = -UpAmt;
UpAmt = 0;
}
UpSum = UpSum + UpAmt;
DownSum = DownSum + DownAmt;
}
UpAvg = UpSum / RSIPeriod1;
DownAvg = DownSum / RSIPeriod1;
}
If idx > RSIPeriod1+2 Then
{
UpAmt = C1[0] - C1[1];
If UpAmt >= 0 Then
DownAmt = 0;
Else
{
DownAmt = -UpAmt;
UpAmt = 0;
}
UpAvg = (PreUpAvg * (RSIPeriod1 - 1) + UpAmt) / RSIPeriod1;
DownAvg = (preDownAvg * (RSIPeriod1 - 1) + DownAmt) / RSIPeriod1;
}
If UpAvg + DownAvg <> 0 Then
RSIvv = 100 * UpAvg / (UpAvg + DownAvg);
Else
RSIvv = 0;
if bdate != bdate[1] Then
{
Entry = 0;
Condition2 = true;
}
if MarketPosition != 0 and MarketPosition != MarketPosition[1] Then
entry = entry+1;
if TotalTrades > TotalTrades[1] and
(IsExitName("즉시손절1",1) == true or IsExitName("본전청산1",1)) then
Condition2 = false;
Condition1 = RSIv < RSI매수값 and Simri < 심리도값 and ((RSIVV > A and RSIVV < B) or (RSIVV > D and RSIVV < E)) ;
if bdate != bdate[1] Then
{
DD = DD+1;
if var2 > 0 and DD == var2+초기화 Then
BuySetup = false;
}
if BuySetup == false and Condition1 == true and Condition1[1] == false Then
{
var1 = C;
var2 = DD;
BuySetup = true;
}
if Condition2 == true and MarketPosition == 0 and C < O and C[1] < O and BuySetup == true and entry == 0
and v < ma(v,거래량평균봉수)*거래량평균봉수비율 and v > 거래량1 Then # and C < O
buy("매수",AtLimit,var1-PriceScale*하락틱수);
if MarketPosition == 1 then
{
BuySetup = false;
SetStopProfittarget(PriceScale*터치익절,PointStop);
if countif(CrossDown(CCIv,CCI값),BarsSinceEntry) >= 1 and
CCIv < CCI값 and C < O Then
ExitLong("매수cci청산",OnClose);
if highest(H,BarsSinceEntry) >= EntryPrice+PriceScale*즉시익절1 and C < O Then
ExitLong("즉시익절1",OnClose);
if highest(H,BarsSinceEntry) >= (EntryPrice+PriceScale*즉시익절1*N2) Then
ExitLong("본전청산1",AtStop,EntryPrice+PriceScale*즉시익절1*N3);
Else
{
ExitLong("즉시손절1",AtStop,EntryPrice-PriceScale*즉시손절1);
}
if highest(H,BarsSinceEntry) >= EntryPrice+PriceScale*tr수익 Then
ExitLong("tr",AtStop, highest(H,BarsSinceEntry)-PriceScale*tr하락);
if lowest(L,BarsSinceEntry) <= EntryPrice-PriceScale*즉시손절1*N4 and C < O Then
ExitLong("저점에서 올라와서 본전 청산",atlimit,EntryPrice+PriceScale*본전생각틱);
if lowest(L,BarsSinceEntry) <= EntryPrice-PriceScale*즉시손절1 *N5 and CCIv >= CCI값1 and C < O Then
ExitLong("저점에서 올라와서 약손절",OnClose);
}
=====================================================================================
매도 진입 및 청산 수식
# 매도 진입 조건 변수
Input : RSIPeriod(7),RSI매수값(65),SimPeriod(7),심리도값(45);
Input : N1(1),초기화(2);
Input : 하락틱수(5);
Input : RSIPeriod1(6),A(14),B(40),D(88),E(100);
Input : 거래량1(100),거래량평균봉수(60),거래량평균봉수비율(4); # Input : 거래량1(100),거래량2(22000);
# 청산 조건 변수
Input : 즉시익절1(70),즉시손절1(70);
Input : N2(0.25),N3(-0.75);
Input : tr수익(75),tr하락(55);
Input : N4(0.45),본전생각틱(55);
Input : 터치익절(115);
var : cnt(0),SigSum(0),count2(0),RSIsig(0);
Var : Counter(0), DownAmt(0), UpAmt(0), UpSum(0), DownSum(0), UpAvg(0), DownAvg(0);
var : idx(0), PreUpAvg(0), preDownAvg(0),RSIVv(0);
Array : C1[100](0);
var : CCIv(0),RSIv(0),Simri(0),SellSetup(false),DD(0),entry(0);
RSIV = RSI(RSIPeriod);
Simri = Simrido(SimPeriod);
if Bdate != Bdate[1] Then
{
for cnt = 1 to 99
{
C1[cnt] = C1[cnt-1][1];
}
PreUpAvg = UpAvg[1];
preDownAvg = DownAvg[1];
idx = idx + 1;
}
C1[0] = C;
If idx == RSIPeriod1+2 Then
{
UpSum = 0;
DownSum = 0;
For Counter = 0 To RSIPeriod1 - 1
{
UpAmt = C1[Counter] - C1[Counter+1];
If UpAmt >= 0 Then
DownAmt = 0;
Else
{
DownAmt = -UpAmt;
UpAmt = 0;
}
UpSum = UpSum + UpAmt;
DownSum = DownSum + DownAmt;
}
UpAvg = UpSum / RSIPeriod1;
DownAvg = DownSum / RSIPeriod1;
}
If idx > RSIPeriod1+2 Then
{
UpAmt = C1[0] - C1[1];
If UpAmt >= 0 Then
DownAmt = 0;
Else
{
DownAmt = -UpAmt;
UpAmt = 0;
}
UpAvg = (PreUpAvg * (RSIPeriod1 - 1) + UpAmt) / RSIPeriod1;
DownAvg = (preDownAvg * (RSIPeriod1 - 1) + DownAmt) / RSIPeriod1;
}
If UpAvg + DownAvg <> 0 Then
RSIvv = 100 * UpAvg / (UpAvg + DownAvg);
Else
RSIvv = 0;
if bdate != bdate[1] Then
{
Entry = 0;
Condition2 = true;
}
if MarketPosition != 0 and MarketPosition != MarketPosition[1] Then
entry = entry+1;
if TotalTrades > TotalTrades[1] and
(IsExitName("즉시손절1",1) == true or IsExitName("본전청산1",1)) then
Condition2 = false;
Condition1 = RSIv > RSI매수값 and Simri > 심리도값 and ((RSIVV > A and RSIVV < B) or (RSIVV > D and RSIVV < E)) ;
if bdate != bdate[1] Then
{
DD = DD+1;
if var2 > 0 and DD == var2+초기화 Then
SellSetup = false;
}
if SellSetup == false and Condition1 == true and Condition1[1] == false Then
{
var1 = C;
var2 = DD;
SellSetup = true;
}
if Condition2 == true and MarketPosition == 0 and SellSetup == true and C > O and entry == 0 and v > 거래량1
and v < ma(v,거래량평균봉수)*거래량평균봉수비율 Then
sell("매도",AtStop,var1+PriceScale*하락틱수);
if MarketPosition == -1 then
{
SellSetup = false;
SetStopProfittarget(PriceScale*터치익절,PointStop);
if Lowest(L,BarsSinceEntry) <= EntryPrice-PriceScale*즉시익절1 and C > O Then
ExitShort("s즉시익절1",OnClose);
if Lowest(L,BarsSinceEntry) <= (EntryPrice-PriceScale*즉시익절1*N2) Then
ExitShort("s본전청산1",AtStop,EntryPrice-PriceScale*즉시익절1*N3);
Else
ExitShort("s즉시손절1",AtStop,EntryPrice+PriceScale*즉시손절1);
if Lowest(L,BarsSinceEntry) <= EntryPrice-PriceScale*tr수익 Then
ExitShort("str",AtStop, Lowest(L,BarsSinceEntry)+PriceScale*tr하락);
if Highest(H,BarsSinceEntry) >= EntryPrice+PriceScale*즉시손절1*N4 and C > O Then
ExitShort("s고점에서 내려와서 본전 청산",atlimit,EntryPrice-PriceScale*본전생각틱);
}
2020-04-21
611
글번호 138195
시스템
답변완료
매수가 안 되는 문제
아래와 같이 장후반에 매수하고, 그 다음날 장 시작 부근에 매도하는 수식입니다. (주식 매매)
전략실행차트[6101]을 이용하여 시스템식을 실행하고, 자동주문을 설정합니다.
1분봉 차트를 사용하고, 매수 함수가 호출되어서 실제 로그가 출력되는는데 매수는 되지 않습니다. 거래내역에도 나오지 않습니다.
시스템 모니터에서 보면 매수신호가 발생하였는데 실제 주문은 들어가지 않았습니다.
왜 그런지 이유를 모르겠습니다.
Input: buyTime(1515), startTime(901);
Variables: accountNum(""), deposit(0), buyCount(0), sellCount(0), stockCode(""), profit(0);
# 포지션이 있으면 청산
if (stime == startTime*100) and (sdate >= EntryDate(0) + 1) then
{
accountNum = GetAccount(0);
stockCode = GetPositionSymbol(0, accountNum);
sellCount = GetPositionQuantity(stockCode, accountNum);
profit = GetPositionOpenPL(stockCode,accountNum);
MessageLog("Sell: %.f, count: %.f, entrydate: %.f, entry price: %.f, profit: %.f", close, sellCount, EntryDate(0), EntryPrice(0), profit);
if (sellCount > 0) Then
{
MessageLog("Real Sell: %.f, count: %.f", close, sellCount);
ExitLong("Sell", OnClose, DEF, "Buy", sellCount, 1);
}
}
# 장마감 시간에 매수
if (stime == buyTime * 100) and (MarketPosition == 0) then
{
accountNum = GetAccount(0);
buyCount = floor(GetUnclearedDeposits(accountNum)/C);
MessageLog("Buy: %.f, count: %.f", close, buyCount);
if (buyCount > 0) Then
{
MessageLog("Real Buy: %.f, count: %.f", close, buyCount);
Buy("Buy", OnClose, DEF, buyCount);
}
}
2020-04-21
631
글번호 138188
시스템