답변완료
수식작성 부탁드립니다.
안녕하세요. 운영자님
아래와 같은 트레이딩뷰 수식을 예스트레이더 수식으로 변환 꼭 좀 부탁드립니다.
감사합니다.
안녕하세요. 운영자님
아래와 같은 트레이딩뷰 수식을 예스트레이더 수식으로 변환 부탁드립니다.
감사합니다.
// === INPUTS ===
// rsi
rsiSource = input(defval = open, title = "RSI Source")
rsiLength = input(defval = 8, title = "RSI Length", minval = 1)
// sma
maLength = input(defval = 34, title = "MA Period", minval = 1)
// invert trade direction
tradeInvert = input(defval = false, title = "Invert Trade Direction?")
// risk management
useStop = input(defval = false, title = "Use Initial Stop Loss?")
slPoints = input(defval = 25, title = "Initial Stop Loss Points", minval = 1)
useTS = input(defval = true, title = "Use Trailing Stop?")
tslPoints = input(defval = 120, title = "Trail Points", minval = 1)
useTSO = input(defval = false, title = "Use Offset For Trailing Stop?")
tslOffset = input(defval = 20, title = "Trail Offset Points", minval = 1)
// === /INPUTS ===
// === BASE FUNCTIONS ===
// delay for direction change actions
switchDelay(exp, len) =>
average = len >= 2 ? sum(exp, len) / len : exp[1]
up = exp > average
down = exp < average
state = up ? true : down ? false : up[1]
// === /BASE FUNCTIONS ===
// === SERIES and VAR ===
// rsi
shunt = rsiSource == open ? 0 : 1
rsiUp = rma(max(change(rsiSource[shunt]), 0), rsiLength)
rsiDown = rma(-min(change(rsiSource[shunt]), 0), rsiLength)
rsi = (rsiDown == 0 ? 100 : rsiUp == 0 ? 0 : 100 - (100 / (1 + rsiUp / rsiDown))) - 50 // shifted 50 points to make 0 median
// sma of rsi
rsiMa = sma(rsi, maLength)
// self explanatory..
tradeDirection = tradeInvert ? 0 <= rsiMa ? true : false : 0 >= rsiMa ? true : false
// === /SERIES ===
// === PLOTTING ===
barcolor(color = tradeDirection ? green : red, title = "Bar Colours")
// hlines
medianLine = hline(0, title = 'Median', color = #996600, linestyle = dotted, linewidth = 1)
limitUp = hline(25, title = 'Limit Up', color = silver, linestyle = dotted, linewidth = 1)
limitDown = hline(-25, title = 'Limit Down', color = silver, linestyle = dotted, linewidth = 1)
// rsi and ma
rsiLine = plot(rsi, title = 'RSI', color = purple, linewidth = 2, style = line, transp = 50)
areaLine = plot(rsiMa, title = 'Area MA', color = silver, linewidth = 1, style = area, transp = 70)
// === /PLOTTING ===
goLong() => not tradeDirection[1] and tradeDirection
killLong() => tradeDirection[1] and not tradeDirection
strategy.entry(id = "Buy", long = true, when = goLong())
strategy.close(id = "Buy", when = killLong())
goShort() => tradeDirection[1] and not tradeDirection
killShort() => not tradeDirection[1] and tradeDirection
strategy.entry(id = "Sell", long = false, when = goShort())
strategy.close(id = "Sell", when = killShort())
if (useStop)
strategy.exit("XSL", from_entry = "Buy", loss = slPoints)
strategy.exit("XSS", from_entry = "Sell", loss = slPoints)
// if we're using the trailing stop
if (useTS and useTSO) // with offset
strategy.exit("XSL", from_entry = "Buy", trail_points = tslPoints, trail_offset = tslOffset)
strategy.exit("XSS", from_entry = "Sell", trail_points = tslPoints, trail_offset = tslOffset)
if (useTS and not useTSO) // without offset
strategy.exit("XSL", from_entry = "Buy", trail_points = tslPoints)
strategy.exit("XSS", from_entry = "Sell", trail_points = tslPoints)
2023-05-07
1439
글번호 168749
시스템
답변완료
막대그래프 표현식
안녕하세요
아래 지표식을 이용해서 첨부 그림처럼 종가가 상승시 저[1,1]이 기준선(PlotBaseLine?),RED막대, 반대로 종가가 하락시 고[1,1]이 기준선,BLUE막대로 표현되는 지표식 부탁드립니다
감사합니다
Input:length(10),종가사용여부(0),파동선두께(2),수치표시(1);
Var:j(0),jj(0),HH(0),LL(0),최종고가(0),최종저가(0),최종꼭지점(""),처리구분(""),
TL1(0),Text1(0);
Array:고[10,4](0),저[10,4](0); // 1:가격,2:Index,3:sDate,4:sTime
#==========================================#
HH = IFF(종가사용여부==1,C,H);
LL = IFF(종가사용여부==1,C,L);
If Index == 0 Then
{
고[1,1] = HH;
저[1,1] = LL;
}
Condition1 = Highest(HH,length) == HH and 최종고가 <> HH;
Condition2 = Lowest (LL,length) == LL and 최종저가 <> LL;
처리구분 = "";
If Condition1 and Condition2 Then // 기간고점과 기간저점 동시 발생
{
If 최종꼭지점 == "저점" Then
{
If 저[1,1] > LL Then 처리구분 = "저점처리";
Else 처리구분 = "고점처리";
}
Else If 최종꼭지점 == "고점" Then
{
If 고[1,1] < HH Then 처리구분 = "고점처리";
Else 처리구분 = "저점처리";
}
}
Else If Condition1 Then 처리구분 = "고점처리";
Else If Condition2 Then 처리구분 = "저점처리";
#==========================================#
If 처리구분 == "고점처리" Then
{
최종고가 = HH; // 신규고점을 체크하기 위해 저장
If 최종꼭지점 == "저점" Then
{
For j = 10 DownTo 2
{
For jj = 1 To 4
{
고[j,jj] = 고[j-1,jj];
}
}
고[1,1] = HH;
고[1,2] = Index;
고[1,3] = sDate;
고[1,4] = sTime;
TL1 = TL_New(저[1,3],저[1,4],저[1,1],고[1,3],고[1,4],고[1,1]);
If 수치표시 == 1 Then
{
Text1 = Text_New(고[1,3],고[1,4],고[1,1],NumToStr(고[1,1],2));
Text_SetStyle(Text1, 2, 1);
}
TL_SetSize(TL1,파동선두께);
TL_SetColor(TL1,RED);
}
Else If 고[1,1] < HH Then // 1번 고점보다 높은 고가 출현
{
고[1,1] = HH;
고[1,2] = Index;
고[1,3] = sDate;
고[1,4] = sTime;
TL_SetEnd(TL1,고[1,3],고[1,4],고[1,1]);
// 시작점은 변동없고 끝점의 위치가 현재 봉으로 연장된 것임
If 수치표시 == 1 Then
{
Text_SetLocation(Text1,고[1,3],고[1,4],고[1,1]);
Text_SetString(Text1,NumToStr(고[1,1],2));
}
}
최종꼭지점 = "고점";
}
#==========================================#
If 처리구분 == "저점처리" Then
{
최종저가 = LL;
If 최종꼭지점 == "고점" then
{
For j = 10 DownTo 2
{
For jj = 1 To 4
{
저[j,jj] = 저[j-1,jj];
}
}
저[1,1] = LL;
저[1,2] = Index;
저[1,3] = sDate;
저[1,4] = sTime;
TL1 = TL_New(고[1,3],고[1,4],고[1,1],저[1,3],저[1,4],저[1,1]);
If 수치표시 == 1 Then
{
Text1 = Text_New(저[1,3],저[1,4],저[1,1],NumToStr(저[1,1],2));
Text_SetStyle(Text1, 2, 0);
}
TL_SetSize(TL1,파동선두께);
TL_SetColor(TL1,BLUE);
}
Else If 저[1,1] > LL then
{
저[1,1] = LL;
저[1,2] = Index;
저[1,3] = sDate;
저[1,4] = sTime;
TL_SetEnd(TL1,저[1,3],저[1,4],저[1,1]);
If 수치표시 == 1 Then
{
Text_SetLocation(Text1,저[1,3],저[1,4],저[1,1]);
Text_SetString(Text1,NumToStr(저[1,1],2));
}
}
최종꼭지점 = "저점";
}
2023-05-07
1459
글번호 168747
지표