답변완료
수식 변환 부탁드립니다.
안녕하세요?
수고 많으십니다.
트레이딩뷰 아래 지표를 수식변환 부탁드리겠습니다.
감사합니다.
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=5
indicator("Range Sentiment Profile [LuxAlgo]", overlay = true, max_boxes_count = 500)
//------------------------------------------------------------------------------
//Tooltips
//-----------------------------------------------------------------------------{
widthTooltip = "Bin width percentage. Determine the length of the returned profile bin as a percentage of the Length setting"
offsetTooltip = "Determine the amount of bars each graphical elements are shifted by"
//-----------------------------------------------------------------------------}
//Settings
//-----------------------------------------------------------------------------{
length = input.int(80, minval = 2)
rows = input.int(20, minval = 2)
useIb = input(false, 'Use Intrabar', inline = 'intrabar')
tf = input.timeframe('1', '' , inline = 'intrabar')
//Style
width = input.float(20, 'Width %', minval = 0, maxval = 100, group = 'Style', tooltip = widthTooltip)
showRange = input(true, 'Show Range Levels', inline = 'range', group = 'Style')
rangeCss = input(color.gray, '' , inline = 'range', group = 'Style')
bullBin = input(#2157f3, 'Bullish Bin', inline = 'bull', group = 'Style')
bullMax = input(true, 'Maximum' , inline = 'bull', group = 'Style')
bearBin = input(#ff5d00, 'Bearish Bin', inline = 'bear', group = 'Style')
bearMax = input(true, 'Minimum' , inline = 'bear', group = 'Style')
showFill = input(true, 'Show Fill' , inline = 'fill', group = 'Style')
bullFill = input(color.new(#2157f3, 90), '' , inline = 'fill', group = 'Style')
bearFill = input(color.new(#ff5d00, 90), '' , inline = 'fill', group = 'Style')
offset = input.int(8, group = 'Style', tooltip = offsetTooltip)
//-----------------------------------------------------------------------------}
//Function
//-----------------------------------------------------------------------------{
get_data() => [close, open]
//-----------------------------------------------------------------------------}
//Main variables
//-----------------------------------------------------------------------------{
var boxes = array.new<box>(0)
//Populate bins array
if barstate.isfirst
for i = 0 to rows-1
boxes.push(box.new(na,na,na,na,na
, text_valign = text.align_center
, text_color = color.white))
n = bar_index
upper = ta.highest(length)
lower = ta.lowest(length)
sumad = math.sum(math.abs(close - open), length)
//Get intrabar data
[get_close, get_open] = request.security_lower_tf(syminfo.tickerid, tf, get_data())
//-----------------------------------------------------------------------------}
//Set profile
//-----------------------------------------------------------------------------{
//Range levels
var ltop = line.new(na,na,na,na, color = rangeCss)
var l75 = line.new(na,na,na,na, color = rangeCss, style = line.style_dashed)
var l50 = line.new(na,na,na,na, color = rangeCss)
var l25 = line.new(na,na,na,na, color = rangeCss, style = line.style_dashed)
var lbtm = line.new(na,na,na,na, color = rangeCss)
var fill = linefill.new(ltop, lbtm, na)
//Max / Min levels
var bull_max = line.new(na,na,na,na, color = bullBin)
var bear_min = line.new(na,na,na,na, color = bearBin)
//Set profile
if barstate.islast
avg = math.avg(upper, lower)
avg75 = math.avg(upper, avg)
avg25 = math.avg(lower, avg)
//Set lines coordinates
ltop.set_xy1(n - length, upper), ltop.set_xy2(n + offset, upper)
lbtm.set_xy1(n - length, lower), lbtm.set_xy2(n + offset, lower)
//Display range levels
if showRange
l75.set_xy1(n - length, avg75) , l75.set_xy2(n + offset, avg75)
l50.set_xy1(n - length, avg) , l50.set_xy2(n + offset, avg)
l25.set_xy1(n - length, avg25) , l25.set_xy2(n + offset, avg25)
else
ltop.set_color(na)
lbtm.set_color(na)
//Get bullish/absolute delta sums for each row
up = upper
dn = upper
sums = array.new_float(0)
sums_abs = array.new_float(0)
//Loop trough each rows
for i = 0 to rows-1
dn -= (upper - lower) / rows
sum = 0.
den = 0.
//Loop trough most recent bars
for j = 0 to length-1
if useIb //Loop trough intrabar prices
for k = 0 to (get_close[j]).size()-1
c = (get_close[j]).get(k)
o = (get_open[j]).get(k)
sum += math.max(c, o) <= up and math.min(c, o) >= dn ? c - o : 0
else
sum += high[j] > dn and low[j] < up ? close[j] - open[j] : 0
sums.push(sum)
sums_abs.push(math.abs(sum))
up := dn
//Set profile bins
max = sums_abs.max()
up := upper
dn := upper
for [index, element] in sums
dn -= (upper - lower) / rows
x2 = n + int(element / max * length * (width / 100))
css = element > 0 ? color.new(bullBin, 50) : color.new(bearBin, 50)
//Set box coordinates
get_bx = boxes.get(index)
get_bx.set_lefttop(n + offset, .9 * up + .1 * dn)
get_bx.set_rightbottom(x2 + offset, .9 * dn + .1 * up)
get_bx.set_bgcolor(css)
get_bx.set_text(str.tostring(element / sumad * 100, format.percent))
//Set area MAX/MIN levels
if element == sums.max() and bullMax
bull_max_val = math.avg(up, dn)
bull_max.set_xy1(n + offset, bull_max_val)
bull_max.set_xy2(n - length, bull_max_val)
if element == sums.min() and bearMax
bear_min_val = math.avg(up, dn)
bear_min.set_xy1(x2 + offset, bear_min_val)
bear_min.set_xy2(n - length, bear_min_val)
up := dn
//Fill Area
if showFill
fill.set_color(sums.sum() > 0 ? color.new(bullBin, 90) : color.new(bearBin, 90))
//-----------------------------------------------------------------------------}
2025-03-01
430
글번호 188697
지표
답변완료
30분봉 BOX의 시간 불일치
수고하십니다!
1. 위 그림 파일(5분봉차트)에서 보시는 것 같이 30분Box와 선으로 그린 30분 사각형(선사작형)에서 Box는 끝나는 시간이 5분 늦게 끝나고, 선사각형은 9시 이후 부터 5분 늦게 선이 그려집니다.
2. 8시 45분에서 9시까지 Box와 선사각형 각 1개 그리고 9시 이후부터는 30분 단위로 Box와 선사각형을 30분 단위로 정확한 시간에 일치시키고 싶습니다.
감사합니다.
// 30분 Box
input : ntime1(30),PP(5);
var : SS1(0),DD1(0),TTM(0),TTF(0);
var : SM1(0),box(0), m3var(0), Bx3Higt(0), m3L(0), cnt(0);
Array : Mb30[100](0);
if Bdate != Bdate[1] Then{
SS1 = TimeToMinutes(0);
DD1 = sdate;
}
if DD1 > 0 then{
if sdate == DD1 Then
TTM = TimeToMinutes(stime)-SS1;
Else
TTM = TimeToMinutes(stime)+1440-SS1;
TTF = TTM%ntime1;
if Bdate != Bdate[1] or sTime == 90000 or // 90000
(Bdate == Bdate[1] && ntime1 > 1 && TTF < TTF[1]) or
(Bdate == Bdate[1] && ntime1 > 1 && TTM >= TTM[1]+ntime1) or
(Bdate == Bdate[1] && ntime1 == 1 && TTM > TTM[1]) Then
{
m3L = 1;
for cnt = 99 downto 1{
Mb30[cnt] = Mb30[cnt-1];
}
m3var = O;
box = box_new(sDate,sTime,m3var,NextBarSdate,NextBarStime,C);
}
else m3L = 0;
Mb30[0] = C;
Box_SetEnd(box,NextBarSdate,NextBarStime,C);
if Mb30[0] > m3var Then{
Box_SetColor(box,red );
Bx3Higt = 1;}
Else{
Box_SetColor(box,Blue);
Bx3Higt = -1;
}
Box_SetFill(box,true, 10);
}
// 30봉 선 그리기
var : TL11(0),TL12(0),TL13(0),TL14(0),idx2(-1);
var : M3date(0), M3time(0), StrtV(0), m3UD(0), mrCl(0);
if m3L == 1 Then{
idx2 = 0;
StrtV = O; //O;
M3date = sdate;
M3time = stime;
}
else{
idx2 = idx2+1;
if idx2 > 0 then{
if idx2 == 1 then{
TL11 = TL_New(sdate[1],stime[1],StrtV, sdate, stime, StrtV);
TL12 = TL_New(M3date, M3time, O, sdate, stime, C);
TL13 = TL_New(M3date, M3time, StrtV, M3date,M3time,C);
TL14 = TL_New(sdate, stime, StrtV, sdate, stime, C);
}
else {
TL_SetEnd(TL11,sdate,stime,StrtV);
TL_SetBegin(TL12,M3date, M3time,C);
TL_SetEnd( TL12,sdate,stime,C);
TL_SetBegin(TL13,M3date,M3time,StrtV);
TL_SetEnd( TL13,M3date,M3time,C);
TL_SetBegin(TL14,sdate,stime,StrtV);
TL_SetEnd( TL14,sdate,stime,C);
}
if C > StrtV Then{
m3UD = 1;
TL_SetColor(TL11,RGB(235,000,000));
TL_SetColor(TL12,RGB(235,000,000));
TL_SetColor(TL13,RGB(235,000,000));
TL_SetColor(TL14,RGB(235,000,000));
TL_SetSize(TL11,0); TL_SetSize(TL12,0); TL_SetSize(TL13,0); TL_SetSize(TL14,0);
}
else {
m3UD = 0;
TL_SetColor(TL11,RGB(000,000,235));
TL_SetColor(TL12,RGB(000,000,235));
TL_SetColor(TL13,RGB(000,000,235));
TL_SetColor(TL14,RGB(000,000,235));
TL_SetSize(TL11,0); TL_SetSize(TL12,0); TL_SetSize(TL13,0); TL_SetSize(TL14,0);
}
}
}
2025-03-01
391
글번호 188693
지표
답변완료
시스템식 요청드립니다.
아래의 식에서 수정이 필요한데 자꾸 오류가 생겨 요청드립니다.
아래의 시스템식은 주가가 14 이평선위에 있다가 해당 이평선을 하향돌파했을때
매수하는 시스템식으로 5% 하락할때마다 분할매수 하고
매도는 매수평단에서 3% 4% 5% 분할매도 하는 시스템 식입니다.
그림파일 1번이 보시면 현재 작성되어있는 식으로 제대로 작동하고 있습니다.
--수정하고 싶은 내용은--
4차 매수 이후부터는 각 차수(4,5,6차)에 매수한 평단에서 4%가 상승하면,
각 차수(4,5,6차)에 매수한 금액(수량) 만큼만 매도 하고,
다시 각 차수(4,5,6차) 매수자리에 오면 매수하는 시스템식으로 수정하고 싶습니다.
예를 들면 그림파일 2번 을 보시면
4차 매수 이후에 4차에 매수한 평단에서 4% 가 상승했을때, 4차에 매수한 금액(수량) 만큼만
매도 해야하고 다시 떨어졌을때, 4차에서 매수하고 싶습니다.
그래서 아래와 같이 4차매수 이후 분할매도식을 수정을 했는데,
4차이후 4% 상승했을때, 전부다 팔리는 상황이 벌어지는데
어떻게 수정을 해야 할지 몰라 요청드립니다.
if Condition1 == False AND ((LatestEntryName(0) == "4차매수"))Then
ExitLong("분할4익절",AtLimit,LatestEntryPrice(0)*1.04,"",Floor(금액*1.25/min(NextBarOpen,mav)));
if Condition1 == False AND ((LatestEntryName(0) == "5차매수"))Then
ExitLong("분할5익절",AtLimit,LatestEntryPrice(0)*1.04,"",Floor(금액*1.3/min(NextBarOpen,mav)));
if Condition1 == False AND ((LatestEntryName(0) == "6차매수"))Then
ExitLong("분할6익절",AtLimit,LatestEntryPrice(0)*1.04,"",Floor(금액*1.35/min(NextBarOpen,mav)));
---------------------------------------------------------------
input : N(14),금액(2000000);
input : 시작날짜 (20250109);
Input : 기준선기간(120);
Var : 기준선(0);
var : cntt(0),H1(0),L1(0);
var : cnt(0),sum(0),mav(0),DD(0);
var : AP(0),TT(0),entry(False);
var : LL(0),RR(0),rate(0);
var : 저항(0), B1(0) ;
Var : day(0),EntryDay(0),ddd(0),ED(0);
#-------------------------------------
if sDate >= 시작날짜 Then
{
if Bdate != Bdate[1] Then
{
entry = true;
day = day+1;
dd = dd+1;
}
}
if TotalTrades > TotalTrades[1] Then
entry = False;
#-------------------------------------
#-------------------------------------
sum = 0;
For cnt = 0 to N-1
{
sum = sum + DayClose(cnt);
}
mav = (sum/N);
#-------------------------------------
#---------------------------------------
if (MarketPosition == 0) and (entry == true) and L > mav Then
Buy("1차매수",AtLimit,mav,Floor(금액/min(NextBarOpen,mav)));
if (LatestEntryName(0) == "1차매수") Then
Buy("2차매수",AtLimit,LatestEntryPrice(0)*0.95,Floor(금액*1.15/min(NextBarOpen,mav)));
if (LatestEntryName(0) == "2차매수") Then
Buy("3차매수",AtLimit,LatestEntryPrice(0)*0.95,Floor(금액*1.2/min(NextBarOpen,mav)));
if (LatestEntryName(0) == "3차매수") Then
Buy("4차매수",AtLimit,LatestEntryPrice(0)*0.95,Floor(금액*1.25/min(NextBarOpen,mav)));
if (LatestEntryName(0) == "4차매수") Then
Buy("5차매수",AtLimit,LatestEntryPrice(0)*0.95,Floor(금액*1.3/min(NextBarOpen,mav)));
if (LatestEntryName(0) == "5차매수") Then
Buy("6차매수",AtLimit,LatestEntryPrice(0)*0.95,Floor(금액*1.35/min(NextBarOpen,mav)));
#-----------------------------------
if MarketPosition == 1 Then
{
#전봉대비 수량 감소(일부 청산발생을 위미)
if CurrentContracts < CurrentContracts[1] Then
{
#청산가 저장
var1 = LatestExitPrice(0);
if LatestExitName(0) == "3%익절" or LatestExitName(0) == "3-D%익절" or LatestExitName(0) == "3-E%익절" Then
Condition1 = true;
if LatestExitName(0) == "4%익절" or LatestExitName(0) == "4-D%익절" or LatestExitName(0) == "4-E%익절" Then
Condition2 = true;
if LatestExitName(0) == "5%익절" or LatestExitName(0) == "5-D%익절" or LatestExitName(0) == "5-E%익절" Then
Condition3 = true;
if LatestExitName(0) == "7%익절" or LatestExitName(0) == "7-D%익절" Then
Condition4 = true;
}
#전봉대비 수량 증가(추가 진입발생을 의미)
if CurrentContracts > CurrentContracts[1] AND ((LatestEntryName(0) == "1차매수") OR (LatestEntryName(0) == "2차매수") or (LatestEntryName(0) == "3차매수") ) Then
{
#현재수량 저장
Var3 = CurrentContracts;
Var4 = AvgEntryPrice;
Condition1 = False;
Condition2 = False;
Condition3 = False;
Condition4 = False;
}
if CurrentContracts > CurrentContracts[1] AND ((LatestEntryName(0) == "4차매수")) Then
{
#현재수량 저장
Var3 = CurrentContracts;
Var4 = AvgEntryPrice;
Condition1 = False;
Condition2 = False;
Condition3 = False;
Condition4 = False;
}
if CurrentContracts > CurrentContracts[1] AND ((LatestEntryName(0) == "6차매수") or (LatestEntryName(0) == "5차매수")) Then
{
#현재수량 저장
Var3 = CurrentContracts;
Var4 = AvgEntryPrice;
Condition1 = False;
Condition2 = False;
Condition3 = False;
Condition4 = False;
}
if var1 > 0 and C < Var4 then
ExitLong("bx");
if Condition1 == False AND ((LatestEntryName(0) == "1차매수") OR (LatestEntryName(0) == "2차매수") or (LatestEntryName(0) == "3차매수") )Then
ExitLong("3%익절",AtLimit,Var4*1.03,"",Floor(Var3*0.2),1);
if Condition2 == False AND ((LatestEntryName(0) == "1차매수") OR (LatestEntryName(0) == "2차매수") or (LatestEntryName(0) == "3차매수") ) Then
ExitLong("4%익절",AtLimit,Var4*1.04,"",Floor(Var3*0.3),1);
if Condition3 == False AND ((LatestEntryName(0) == "1차매수") OR (LatestEntryName(0) == "2차매수") or (LatestEntryName(0) == "3차매수") ) Then
ExitLong("5%익절",AtLimit,Var4*1.05,"",Floor(Var3*0.4),1);
if Condition4 == False AND ((LatestEntryName(0) == "1차매수") OR (LatestEntryName(0) == "2차매수") or (LatestEntryName(0) == "3차매수") ) Then
ExitLong("7%익절",AtLimit,Var4*1.07,"",Floor(Var3*0.1),1);
ExitLong("10%익절",AtLimit,Var4*1.10);
if Condition1 == False AND ((LatestEntryName(0) == "4차매수"))Then
ExitLong("3-D%익절",AtLimit,Var4*1.03,"",Floor(Var3*0.5),1);
if Condition2 == False AND ((LatestEntryName(0) == "4차매수")) Then
ExitLong("4-D%익절",AtLimit,Var4*1.04,"",Floor(Var3*0.45),1);
if Condition3 == False AND ((LatestEntryName(0) == "4차매수")) Then
ExitLong("5-D%익절",AtLimit,Var4*1.05,"",Floor(Var3*0.1),1);
if Condition1 == False AND ((LatestEntryName(0) == "6차매수") or (LatestEntryName(0) == "5차매수"))Then
ExitLong("3-E%익절",AtLimit,Var4*1.03,"",Floor(Var3*0.5),1);
if Condition2 == False AND ((LatestEntryName(0) == "6차매수") or (LatestEntryName(0) == "5차매수")) Then
ExitLong("4-E%익절",AtLimit,Var4*1.04,"",Floor(Var3*0.45),1);
if Condition3 == False AND ((LatestEntryName(0) == "6차매수") or (LatestEntryName(0) == "5차매수")) Then
ExitLong("5-E%익절",AtLimit,Var4*1.05,"",Floor(Var3*0.1),1);
}
Else#매수진입중이 아니면
{
#변수 0으로 초기화
var1 = 0;
Var2 = 0;
}
2025-03-04
410
글번호 188692
시스템
답변완료
수식 변경 부탁드립니다.
InputS: Length(50), Fcast(50);
InputS: FMode("Similarity"), CMode("Cumulative");
VAR: EvalWindowHigh(0), EvalWindowLow(0), RefWindowHigh(0), RefWindowLow(0);
VAR:CorrWindowHigh(0), CorrWindowLow(0), Correlation(0);
VAR: K(0), Alpha(0), Beta(0), E(0), Prev(0), Current(0);
VAR: A(0),B(0),X(0),D(0),I(0);
VAR: R(0),StandardDev(0),Covariance(0),BarNumber(0);
VAR: ShowArea(0);
// Initialize series for forecast and calculation windows
Array: A/ Cthe high and low of the evaluation window
EvalWindowHigh = Highest(High, Length + Fcast * 2);
EvalWindowLow = Lowest(Low, Length + Fcast * 2);
// Loop through and populate arrays for calculations
For I = 0 To Fcast * 2 + Length - 1 Begin
A[I] = Close[I];
If CMode = "Linreg" Then
X[I] = BarNumber[I];
End;
// Reference window
A[0] = A[Length];
// Calculate correlation
For I = 0 To Length - 1 Begin
B[I] = A[Fcast + I];
R = Covariance(A, B) / (StandardDev(A, Length) * StandardDev(B, Length));
// Maximize or minimize correlation based on FMode
If FMode = "Similarity" Then Begin
If R >= Correlation Then Begin
Correlation = R;
K = I;
End;
End
Else Begin
If R <= Correlation Then Begin
Correlation = R;
K = I;
End;
End;
End;
// Set ECHO forecast
Prev = Close;
Current = Close;
For I = 0 To Fcast - 1 Begin
E = D[Fcast + K + (Fcast - I - 1)];
// Calculate forecast point
If CMode = "Mean" Then
Current = Average(A, Fcast) + E;
Else If CMode = "Linreg" Then Begin
Alpha = Covariance(A, X) / Variance(X);
Beta = Average(A) - Alpha * Average(X);
Current = Alpha * (BarNumber + I + 1) + Beta + E;
End
Else
Current = Current + E;
Plot1(Current, "Forecast" + NumToStr(I, 0)); // Plot forecast
Prev = Current;
End;
// Optional: Visualize area for reference, evaluation, and correlation windows
If ShowArea Then Begin
// This part would involve drawing boxes or shaded areas on the chart
// EasyLanguage doesn't have a direct equivalent to boxes, so consider plotting lines or marks
End;
선행지표를 만들어볼려고 하는데 어렵네요. 도와주세여ㅠㅠ
2025-03-01
428
글번호 188691
지표