커뮤니티
계단형(?) Trailing Stop 구현 방법 문의
2018-06-21 10:31:24
111
글번호 119931
안녕하세요,
계단형으로 청산가격이 변동되는 Trailing Stop을 구현하고 싶습니다.
예를 들어
Buy 진입가격이 100이고 TSGap을 10으로 설정한다면, (가격 90에 Stoploss 적용)
진입후 고점 100 이상 ~ 110 미만까지는 Trailing Stop을 적용하지 않고,
진입후 고점 110 이상 ~ 120 미만까지는 Trailing Stop 청산가격 100,
진입후 고점 120 이상 ~ 130 미만까지는 Trailing Stop 청산가격 110,
....
이렇게 설정하고 싶습니다.
위 아이디어를 1) ExitShort 함수로 2) SetStopTrailing 으로 각각 어떻게 구현할수 있을까요?
감사합니다.
답변 1
예스스탁 예스스탁 답변
2018-06-21 10:55:20
안녕하세요
예스스탁입니다.
SetStopTrailing으로는 가능하지 않고
Exitlong,Exitshort함수로 구현하셔야 합니다.
1 단계를 틱수로 지정
input : 수익단계틱수(10);
var : EHP(0),S1(0),nth(0);
#매수진입후
if MarketPosition == 1 Then
{
#진입이후 최고수익
EHP = highest(h,BarsSinceEntry)-EntryPrice;
#1단계 수익값
S1 = PriceScale*수익단계틱수;
#수익단계기준 몇단계인지 계산
nth = floor(EHP/S1);
ExitLong("bx",AtStop,EntryPrice+(nth-1)*S1);
}
#매도진입후
if MarketPosition == -1 Then
{
#진입이후 최고수익
EHP = EntryPrice-Lowest(l,BarsSinceEntry);
#1단계 수익값
S1 = PriceScale*수익단계틱수;
#수익단계기준 몇단계인지 계산
nth = floor(EHP/S1);
ExitShort("sx",AtStop,EntryPrice-(nth-1)*S1);
}
2 단계를 포인트로 지정
input : 수익단계포인트(1);
var : EHP(0),S1(0),nth(0);
#매수진입후
if MarketPosition == 1 Then
{
#진입이후 최고수익
EHP = highest(h,BarsSinceEntry)-EntryPrice;
#1단계 수익값
S1 = 수익단계포인트;
#수익단계기준 몇단계인지 계산
nth = floor(EHP/S1);
ExitLong("bx",AtStop,EntryPrice+(nth-1)*S1);
}
#매도진입후
if MarketPosition == -1 Then
{
#진입이후 최고수익
EHP = EntryPrice-Lowest(l,BarsSinceEntry);
#1단계 수익값
S1 = 수익단계포인트;
#수익단계기준 몇단계인지 계산
nth = floor(EHP/S1);
ExitShort("sx",AtStop,EntryPrice-(nth-1)*S1);
}
3.단계를 %로 설정
input : 수익단계퍼센트(2);
var : EHP(0),S1(0),nth(0);
#매수진입후
if MarketPosition == 1 Then
{
#진입이후 최고수익
EHP = (highest(h,BarsSinceEntry)-EntryPrice)/EntryPrice;
#1단계 수익값
S1 = 수익단계퍼센트;
#수익단계기준 몇단계인지 계산
nth = floor(EHP/S1);
ExitLong("bx",AtStop,EntryPrice*(1+((nth-1)*S1)/100));
}
#매도진입후
if MarketPosition == -1 Then
{
#진입이후 최고수익
EHP = EntryPrice-Lowest(l,BarsSinceEntry);
#1단계 수익값
S1 = 수익단계퍼센트;
#수익단계기준 몇단계인지 계산
nth = floor(EHP/S1);
ExitShort("sx",AtStop,EntryPrice*(1-((nth-1)*S1)/100));
}
즐거운 하루되세요
> 라면의비밀 님이 쓴 글입니다.
> 제목 : 계단형(?) Trailing Stop 구현 방법 문의
> 안녕하세요,
계단형으로 청산가격이 변동되는 Trailing Stop을 구현하고 싶습니다.
예를 들어
Buy 진입가격이 100이고 TSGap을 10으로 설정한다면, (가격 90에 Stoploss 적용)
진입후 고점 100 이상 ~ 110 미만까지는 Trailing Stop을 적용하지 않고,
진입후 고점 110 이상 ~ 120 미만까지는 Trailing Stop 청산가격 100,
진입후 고점 120 이상 ~ 130 미만까지는 Trailing Stop 청산가격 110,
....
이렇게 설정하고 싶습니다.
위 아이디어를 1) ExitShort 함수로 2) SetStopTrailing 으로 각각 어떻게 구현할수 있을까요?
감사합니다.