예스스탁
예스스탁 답변
2021-11-11 11:33:33
안녕하세요
예스스탁입니다.
해당 수식은 매봉 완성시에 if조건에 따라 손절이나 트레일링스탑의 셋팅이 변경되는 내용이 맞습니다.
다만 SetStopTrailing은 진입이후의 최소수익조건이 달성을 체크하는데
중간에 값이 변경이 되면 최소수익체크가 초기화가 되버립니다.
이전봉들로 돌아가 다시 진입시점부터 최소수식 달성여부를 체크하지 않습니다.
진입중에 설저잉 변경되는 내용이면 아래와 같이 풀어서 작성해서 사용하셔야 합니다.
input : 손절1(1.2),최소수익1(1.8),수익감소1(30);
input : 손절2(0.9),최소수익2(1.5),수익감소2(30);
input : 손절3(0.5),최소수익3(1.0),수익감소3(30);
var : entry_timing_band_width(0);
var : BH(0),SL(0);
if MarketPosition == 1 Then
{
BH = Highest(H,BarsSinceEntry);
if entry_timing_band_width > 8 Then
{
ExitLong("bl1",AtStop,EntryPrice*(1-손절1/100));
if BH >= EntryPrice*(1+최소수익1/100) Then
{
ExitLong("btr1",AtStop,BH-(BH-EntryPrice)*(수익감소1/100));
}
}
Else if entry_timing_band_width > 4 Then
{
ExitLong("bl2",AtStop,EntryPrice*(1-손절2/100));
if BH >= EntryPrice*(1+최소수익2/100) Then
{
ExitLong("btr2",AtStop,BH-(BH-EntryPrice)*(수익감소2/100));
}
}
Else
{
ExitLong("bl3",AtStop,EntryPrice*(1-손절3/100));
if BH >= EntryPrice*(1+최소수익3/100) Then
{
ExitLong("btr3",AtStop,BH-(BH-EntryPrice)*(수익감소3/100));
}
}
}
if MarketPosition == -1 Then
{
SL = Lowest(L,BarsSinceEntry);
if entry_timing_band_width > 8 Then
{
ExitShort("sl1",AtStop,EntryPrice*(1+손절1/100));
if SL <= EntryPrice*(1-최소수익1/100) Then
{
ExitShort("str1",AtStop,SL+(EntryPrice-SL)*(수익감소1/100));
}
}
Else if entry_timing_band_width > 4 Then
{
ExitShort("sl2",AtStop,EntryPrice*(1+손절2/100));
if SL <= EntryPrice*(1-최소수익2/100) Then
{
ExitShort("str2",AtStop,SL+(EntryPrice-SL)*(수익감소2/100));
}
}
Else
{
ExitShort("sl3",AtStop,EntryPrice*(1+손절3/100));
if SL <= EntryPrice*(1-최소수익3/100) Then
{
ExitShort("str3",AtStop,SL+(EntryPrice-SL)*(수익감소3/100));
}
}
}
즐거운 하루되세요
> 엠씨용가 님이 쓴 글입니다.
> 제목 : 조건에 따라 setstoploss 변경
> 안녕하세요 ^^ 각 조건에 따라 setstoploss, setstoptrailing 를 변경하는 코드를 짜고 있습니다
if entry_timing_band_width > 8 Then {
SetStopLoss(1.2,PercentStop);
SetStopTrailing(30,1.8,PercentStop);
}
Else if entry_timing_band_width > 4 Then {
SetStopLoss(0.9,PercentStop);
SetStopTrailing(30,1.5,PercentStop);
}
Else {
SetStopLoss(0.5,PercentStop);
SetStopTrailing(30,1,PercentStop);
}
모든 주문이 맨 마지막 조건을 충족했을 때 실행되는 코드로 실행되는것 같은데요, 어떻게 해야 할까요?