예스스탁
예스스탁 답변
2023-01-03 11:30:02
안녕하세요
예스스탁입니다.
Input : Vector(9), Period(14), 매수선(40), 매도선(60);
input : 저가봉(5),고가봉(5),저가폭(10),고가폭(10);
Input : shortPeriod(12), longPeriod(26);
Var : rsi_(0,Data1), rsi_signal(0,Data1) ;
var : ll(0,Data1),hh(0,Data1),eh(0),el(0);
Var : MACDv(0,Data2), MACDsig(0,Data2), macdosc(0,Data2);
rsi_ = data1(RSI(Period));
rsi_signal = data1(MA(RSI(Period), Vector));
MACDv = Data2(MACD(shortPeriod, longPeriod));
//MACDsig = Data2(ema(MACDv,Period));
MACDsig = Data2(ema(Data2(MACD(shortPeriod, longPeriod)),Period));
//macdosc = Data2(MACDv-ema(MACDv,Period));
macdosc = Data2(Data2(MACD(shortPeriod, longPeriod))-ema(Data2(MACD(shortPeriod, longPeriod)),Period));
ll = data1(lowest(l,저가봉));
hh = data1(highest(h,고가봉));
if MarketPosition != 0 Then
{
if MarketPosition != MarketPosition[1] or CurrentContracts > CurrentContracts[1] Then
{
eh = hh+PriceScale*고가폭;
el = ll-PriceScale*저가폭;
}
}
if macdosc > 0 && rsi_signal < 매수선 && rsi_ > rsi_signal && rsi_[1] < rsi_signal[1] Then
{
if MarketPosition <= 0 or
(MarketPosition == 1 and (C > eh or C < el)) Then
Buy("B1");
}
if macdosc > 0 && rsi_signal < 매수선 && rsi_[1] < 30 && rsi_ > 30 Then
{
if MarketPosition <= 0 or
(MarketPosition == 1 and (C >= eh or C <= el)) Then
Buy("B2");
}
if macdosc < 0 && rsi_signal > 매도선 && rsi_ < rsi_signal && rsi_[1] > rsi_signal[1] Then
{
if MarketPosition >= 0 or
(MarketPosition == -1 and (C > eh or C < el)) Then
Sell("S1");
}
if macdosc < 0 && rsi_signal > 매도선 && rsi_[1] > 70 && rsi_ < 70 Then
{
if MarketPosition >= 0 or
(MarketPosition == -1 and (C > eh or C < el)) Then
Sell("S2");
}
if MarketPosition == 1 Then
{
Sell("BS",AtStop,el);
if IsEntryName("SB") == true Then
ExitLong("bx1",AtStop,EntryPrice+(eh-el)*1.5);
Else
ExitLong("bx2",AtStop,EntryPrice+(eh-el)*1.0);
}
if MarketPosition == -1 Then
{
Buy("SB",AtStop,eh);
if IsEntryName("BS") == true Then
ExitShort("sx1",AtStop,EntryPrice-(eh-el)*1.5);
Else
ExitShort("sx2",AtStop,EntryPrice-(eh-el)*1.0);
}
즐거운 하루되세요
> 부똘이 님이 쓴 글입니다.
> 제목 : 수식 문의
> .일전에 도움 주신 수식을 다음과 같이 수정하고 싶습니다.
아래의 수식은
진입 시그널이 발생한 캔들의 기준,
N봉의 고/저가에 +_n틱을 더해 레인지를 설정하고
해당 레인지 안에 들어오는 추가 진입 시그널을 걸러내고
손실보는 방향으로 벗어나면 손절대신 햇지로 반대시그널를 추가하는 로직입니다.
위와 같이, 진입 시그널과 / 헷지 시그널을 구분하여 볼 때,
수정 요청 :
ㄱ. 해당 레인지 안에서 반대포지션의 '진입시그널'은 허용합니다.
(ex : 매수시그널로 만들어진 레인지 안에서 추가 매수 시그널은 걸러내되 매도 진입 시그널은 발생시킴)
ㄴ. 매수진입 후 - 햇지매도 시그널이 발생한 상태라면 매도진입 시그널은 걸러내지 않고 발생시킵니다.
그 반대도 마찬가지.
(이렇게 되면 레인지 안에서 등락하여 매수-헷지-매도-헷지가 반복되더라도
해당 레인지 안에서의 총 진입 횟수는 4회를 넘지 않을 것입니다)
ㄷ. 청산로직 추가 :
현재 포지션이 '진입시그널'일 때 -
설정된 레인지값 * 1 이상 수익나면 모두 청산합니다.
현재 포지션이 '헷지 시그널' 일 때 -
설정된 레인지 값 * 1.5 이상 수익 나면 모두 청산합니다.
끝.
지표나 차트의 조건값이 아닌
포지션 변화에 따라 시그널을 구분해서 조건을 다르게 하는게 꽤 어렵네요.
부탁 좀 드리겠습니다.
새해 복많이 받으시고,
되시는 일 항상 잘 되시기 바랍니다.
감사합니다.
======= 아래 ===========
Input : Vector(9), Period(14), 매수선(40), 매도선(60);
input : 저가봉(5),고가봉(5),저가폭(10),고가폭(10);
Input : shortPeriod(12), longPeriod(26);
Var : rsi_(0), rsi_signal(0) ;
var : ll(0),hh(0),eh(0),el(0),BuyEntry(False),SellEntry(False);
Var : MACDv(0), MACDsig(0), macdosc(0);
rsi_ = RSI(Period);
rsi_signal = MA(RSI(Period), Vector);
MACDv = Data2(MACD(shortPeriod, longPeriod));
//MACDsig = Data2(ema(MACDv,Period));
MACDsig = Data2(ema(Data2(MACD(shortPeriod, longPeriod)),Period));
//macdosc = Data2(MACDv-ema(MACDv,Period));
macdosc = Data2(Data2(MACD(shortPeriod, longPeriod))-ema(Data2(MACD(shortPeriod, longPeriod)),Period));
ll = lowest(l,저가봉);
hh = highest(h,고가봉);
if MarketPosition != 0 Then
{
if MarketPosition != MarketPosition[1] or CurrentContracts > CurrentContracts[1] Then
{
eh = hh;
el = ll;
}
}
BuyEntry = true;
SellEntry = true;
if MarketPosition == 0 Then
{
if MarketPosition(1) == 1 and (C > ll[BarsSinceEntry(1)]-PriceScale*저가폭 and C < HH[BarsSinceEntry(1)]+PriceScale*고가폭) Then
BuyEntry = False;
if MarketPosition(1) == -1 and (C > ll[BarsSinceEntry(1)]-PriceScale*저가폭 and C < HH[BarsSinceEntry(1)]+PriceScale*고가폭) Then
SellEntry = False;
}
else
{
if MarketPosition == 1 and C > el-PriceScale*저가폭 and C < eh+PriceScale*고가폭 Then
BuyEntry = false;
if MarketPosition == -1 and C > el-PriceScale*저가폭 and C < eh+PriceScale*고가폭 Then
SellEntry = false;
}
if macdosc > 0 && rsi_signal < 매수선 && rsi_ > rsi_signal && rsi_[1] < rsi_signal[1] Then
{
if BuyEntry == true Then
Buy("B");
}
if macdosc > 0 && rsi_signal < 매수선 && rsi_[1] < 30 && rsi_ > 30 Then
{
Buy("1");
}
else if macdosc < 0 && rsi_signal > 매도선 && rsi_[1] > 70 && rsi_ < 70 Then
{
Sell("2");
}
if macdosc < 0 && rsi_signal > 매도선 && rsi_ < rsi_signal && rsi_[1] > rsi_signal[1] Then
{
if SellEntry == true Then
Sell("S");
}
if MarketPosition == 1 Then
Sell("bx",AtStop,ll[BarsSinceEntry]-PriceScale*저가폭);
if MarketPosition == -1 Then
BUY("sx",AtStop,hh[BarsSinceEntry]+PriceScale*고가폭);