답변완료
지표수식 전환부탁
다음 수식을 시스템 수식으로 전환부탁드립니다.
<1>
// Inputs
len = input(21, title="Length")
dr = roc(close,1)/sma(close,2)
lowVol = input(0.15)
bton(b) => b ? 1 : 0
// Logic
volaSD = stdev(dr,len)
runningVola = 0
for i = 1 to len-1
runningVola := runningVola + bton(volaSD[i] <= volaSD)
vswitch = (runningVola + 1)/len
// View
hline(.15, title='Pi', color=color.maroon, linestyle=hline.style_dotted, linewidth=1)
plot(vswitch, style=plot.style_columns, color=(vswitch<0.15)?color.red:color.gray,transp=0)
// END
<2>
length = input(20)
mult = input(2)
atr_ = atr(length)
max1 = max(nz(max_[1]), close)
min1 = min(nz(min_[1]), close)
is_uptrend_prev = nz(is_uptrend[1], true)
stop = is_uptrend_prev ? max1 - mult * atr_ : min1 + mult * atr_
vstop_prev = nz(vstop[1])
vstop1 = is_uptrend_prev ? max(vstop_prev, stop) : min(vstop_prev, stop)
is_uptrend = close - vstop1 >= 0
is_trend_changed = is_uptrend != is_uptrend_prev
max_ = is_trend_changed ? close : max1
min_ = is_trend_changed ? close : min1
vstop = is_trend_changed ? is_uptrend ? max_ - mult * atr_ : min_ + mult * atr_ : vstop1
plot(vstop, color = is_uptrend ? green : red, style=line, linewidth=2)
2020-04-08
1046
글번호 137727
지표
답변완료
부탁드립니다.
항상 감사드립니다.
아래와 같이 ##카운트를 추가하고 싶습니다.
1) 전략창 전체의: [(StopTrailing 개수) / (StopLoss+StopTrailing) 개수] x100
2) 청산시점 포함하여 최근 20% 개수에 대한 : [(StopTrailing 개수) / (StopLoss+StopTrailing) 개수] x100
예_1
전체 청산 개수 20개(StopTrailing 10개, StopLoss 10개)
최근20% 청산개수 4개(StopTrailing 1개, StopLoss 3개)
1) 전체 개수(20개)= 11010101001010110001 --> 수식 : [10개/(10개+10개)]x100 = 50.0
2) 20% 개수(4개)= 0001 --> 수식 : [1개/(1개+3개)]x100 = 25.0
예_2
전체 청산 개수 25개(StopTrailing 13개, StopLoss 12개)
최근20% 청산개수 5개(StopTrailing 2개, StopLoss 3개)
1) 전체 개수(25개) = 1101011010101001010110001 --> 수식 : [13/(13+12)]x100 = 52.0
2) 20% 개수(5개) = 10001 --> 수식 : [2/(2+3)]x100 = 40.0
(StopTrailing:1, StopLoss:0로 표현)
1),2)를 텍스트 표시하고 싶습니다.
텍스트는 1)이 위 2)는 아래에 위치하게 부탁드립니다.
1)값(위)
2)값(아래)
값은 소수 한자리 수까지 표현 부탁드립니다.
input : 손절(20),익절(15),익절하락(3);
input : P1(30), P2(120), p3(240);
input : StartTime(090000),EndTime(050000);
var : tt(0),tx(0),X(false);
var: Tcond(false),ht(0);
var1 = ma(C, P1);
var2 = ma(C, P2);
var3 = ma(C, P3);
if (sdate != sdate[1] and stime >= StartTime) or
(sdate == sdate[1] and stime >= StartTime and stime[1] < StartTime) Then
{
Tcond = true;
tt = 0;
X = false;
}
if (sdate != sdate[1] and stime >= EndTime) or
(sdate == sdate[1] and stime >= EndTime and stime[1] < EndTime) Then
{
Tcond = false;
if MarketPosition == 1 Then
{
ExitLong("BE6");
}
if MarketPosition == -1 Then
{
ExitShort("SE6");
}
}
if Tcond == true then
{
if marketposition == 0 and crossup(var1,var2) Then {
buy("B1");
}
if marketposition == 0 and crossdown(var1,var2) Then {
sell("S1");
}
if marketposition == 0 and crossup(var2,var3) and var3[1] < var3 Then {
buy("B2");
}
if marketposition == 0 and crossdown(var3,var4) and var3[1] > var3 Then {
sell("S2");
}
## 청산
if MarketPosition == 1 then {
SetStopTrailing(익절하락,익절,PointStop);
SetStopLoss(손절,PointStop);
}
if MarketPosition == -1 Then
{
SetStopTrailing(익절하락,익절,PointStop);
SetStopLoss(손절,PointStop);
}
}
## 카운트 (수정요청)
if TotalTrades > TotalTrades[1] then
{
if IsExitName("StopLoss",1) == true then
{
tt = tt +1 ;
if tt > ht Then
{
ht = tt;
}
Text_New(ExitDate(1),ExitTime(1),h[BarsSinceExit(1)],NumToStr(ht,0)+"◆");
Text_SetSize(tx,20);
Text_Setstyle(tx,2,20);
Text_SetColor(tx,GREEN);
}
}
if IsExitName("StopTrailing",1) == true then
{
tt = tt + 1;
ht = tt;
}
Text_New(ExitDate(1),ExitTime(1),h[BarsSinceExit(1)],NumToStr(ht,0)+"◆");
Text_SetSize(tx,20);
Text_Setstyle(tx,2,20);
Text_SetColor(tx,GREEN);
}
}
}
2020-04-09
980
글번호 137715
시스템
답변완료
문의드립니다.
66867 관련하여 답변주셔서 감사드립니다. 답변 주신 변환식에
plot(Signal_Line, title = "Signal", color = color.gray, style = plot.style_line)
을 추가하고 싶습니다.
plot3(Signal_Line,"Signal", GRAY); 로 단순히 추가 작성하여 컴파일 시켜보았지만 적용이 원래대로 되지 않습니다.
추가 수정 문의드립니다. 감사합니다.
------------------------------------------------------------------------------
(기존 답변 문의드렸던 수식입니다.)
> //@version=4
study(BB MACD)
inp_Source = input(title = "Source", type = input.source, defval = close)
inp_Sensitivity = input(title = "Sensitivity", type = input.float, defval = 0.01)
inp_HiLo_Lookback = input(title = "Hi/Lo Lookback", type = input.integer, defval = 5)
inp_Slow_MA_Period = input(title = "Slow MA: Period", type = input.integer, defval = 26)
inp_Slow_MA_Method = input(title = "Slow MA: Type", defval = 'EMA', options = ['SMA', 'EMA', 'LWMA', 'RMA'])
inp_Fast_MA_Period = input(title = "Fast MA: Period", type = input.integer, defval = 12)
inp_Fast_MA_Method = input(title = "Fast MA: Type", defval = 'EMA', options = ['SMA', 'EMA', 'LWMA', 'RMA'])
inp_Signal_MA_Period = input(title = "Signal MA: Period", type = input.integer, defval = 9)
inp_Signal_MA_Method = input(title = "Signal MA: Type", defval = 'SMA', options = ['SMA', 'EMA', 'WMA', 'RMA'])
f_Get_MA(MA_Type, MA_Source, MA_Period) =>
MA = 0.0
MA := MA_Type == 'SMA' ? sma(MA_Source, MA_Period) : MA_Type == 'EMA' ? ema(MA_Source, MA_Period) : MA_Type == 'WMA' ? wma(MA_Source, MA_Period) : MA_Type == 'RMA' ? rma(MA_Source, MA_Period) : na
MA
f_Get_Std_Dev(MA_Type, MA_Source, MA_Period) =>
MA = 0.0
MA := f_Get_MA(MA_Type, MA_Source, MA_Period)
Price = 0.0
Price := sma(MA_Source, 1)
Summation = 0.0
for i = 0 to MA_Period - 1
Summation := Summation + (Price[i] - MA) * (Price[i] - MA)
Std_Dev = 0.0
Std_Dev := sqrt(Summation / MA_Period)
Std_Dev
f_Get_TR() =>
TR = max(high, close[1]) - min(low, close[1])
TR
f_Get_ATR(Period) =>
TR = f_Get_TR()
Summation = 0.0
for i = 1 to Period
Summation := Summation + TR[i]
ATR = 0.0
ATR := Summation / Period
ATR
MA_Fast = f_Get_MA(inp_Fast_MA_Method, inp_Source, inp_Fast_MA_Period)
HiLo_Range = abs(barssince(high == highest(high, inp_HiLo_Lookback)) - barssince(low == lowest(low, inp_HiLo_Lookback))) * syminfo.mintick * 100000
MA_Slow = f_Get_MA(inp_Slow_MA_Method, inp_Source, inp_Slow_MA_Period)
MA_Slow_Deviation = f_Get_Std_Dev(inp_Slow_MA_Method, inp_Source, inp_Slow_MA_Period)
MA_Slow_ATR = f_Get_ATR(inp_Slow_MA_Period)
Histogrm = MA_Slow_Deviation - MA_Slow_ATR
Main_Line = Histogrm
Signal_Line = f_Get_MA(inp_Signal_MA_Method, Main_Line, inp_Signal_MA_Period)
Histogrm_Color = color.green
if MA_Fast >= MA_Fast[1]
if HiLo_Range >= inp_Sensitivity
Histogrm_Color := color.green
else
Histogrm_Color := color.yellow
else
if HiLo_Range >= inp_Sensitivity
Histogrm_Color := color.red
else
Histogrm_Color := color.blue
plot(Histogrm, title = "BB MACD", color = Histogrm_Color, style = plot.style_histogram)
plot(Histogrm, title = "BB MACD", color = color.blue, style = plot.style_line)
plot(Signal_Line, title = "Signal", color = color.gray, style = plot.style_line)
2020-04-08
1193
글번호 137712
지표