답변완료
수식 부탁드립니다.
**지그재그 신호에 즉시 전부 매수매도하는 시스템입니다.
1. bl은 손절시 나오는 건가요?
2. 직전 분홍선보다 높은 분홍선값일때만 매수진입
직전 파란선보다 낮은 파란선값일때만 매도진입
하는 시스템을 만들고 싶어요
금요일이라 너무 늦은거 같은데, 오늘 될까요?
====================================================
Input:전환비율(2);
input : StartTime(070000),EndTime(055500);
Input :익절(30),손절(26),당일수익(100),당일손실(80);
Var : N1(0),dayPl(0),Tcond(false),Xcond(false);
Var : j(0),jj(0),HH(0),LL(0),hiBar(0),loBar(0),최종꼭지점(""),처리구분("");
var : TL1(0),Text1(0),ADXV1(0),tl2(0),tl3(0),tx2(0),tx3(0),t(0);
var : TL4(0),TX4(0),TL5(0),TX5(0);
Array:고[10,4](0),저[10,4](0);
HH = H;
LL = L;
If Index == 0 Then
{
고[1,1] = HH;
고[1,2] = 0;
고[1,3] = sDate;
고[1,4] = sTime;
저[1,1] = LL;
저[1,2] = 0;
저[1,3] = sDate;
저[1,4] = sTime;
}
If Index > 0 Then
{
hiBar = hiBar + 1;
loBar = loBar + 1;
}
If HH[hiBar] < HH Then hiBar = 0;
If LL[loBar] > LL Then loBar = 0;
Condition1 = 저[1,1] * (1 + (전환비율/100)) < HH and hiBar == 0;
Condition2 = 고[1,1] * (1 - (전환비율/100)) > LL and loBar == 0;
처리구분 = "";
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
{
T = 1;
If 최종꼭지점 == "저점" Then
{
TL_SetEnd(TL2,저[1,3],저[1,4],value2);
Text_SetLocation(TX2,저[1,3],저[1,4],Value2 );
TL_SetEnd(TL4,저[1,3],저[1,4],value3);
Text_SetLocation(TX4,저[1,3],저[1,4],Value3 );
For j = 10 DownTo 2
{
For jj = 1 To 4
{
고[j,jj] = 고[j-1,jj];
}
}
고[1,1] = HH[hiBar];
고[1,2] = Index - hiBar;
고[1,3] = sDate[hiBar];
고[1,4] = sTime[hiBar];
hiBar = -1;
loBar = -1;
TL1 = TL_New(저[1,3],저[1,4],저[1,1],고[1,3],고[1,4],고[1,1]);
TL_SetSize(TL1,1);
TL_SetColor(TL1,RED);
value1 = 저[1,1]*(1+(전환비율/100));
value2 = 고[1,1]*(1-(전환비율/100));
value3 = (value1+Value2)/2;
TL2 = TL_New(고[1,3],고[1,4],value2 ,NextBarSdate,NextBarStime,value2);
TL_SetColor(TL2,Cyan);
TL_SetStyle(TL2,3);
Tx2 = Text_New(NextBarSdate,NextBarStime,value2,NumToStr(value2,2));
Text_SetColor(Tx2,Cyan);
//TL4 = TL_New(고[1,3],고[1,4],value3 ,NextBarSdate,NextBarStime,value3);
TL_SetColor(TL4,Orange);
TL_SetStyle(TL4,3);
//Tx4 = Text_New(NextBarSdate,NextBarStime,value3,NumToStr(value3,2));
Text_SetColor(Tx4,Orange);
}
Else If 고[1,1] < HH[hiBar] Then // 1번 고점보다 높은 고가 출현
{
고[1,1] = HH[hiBar];
고[1,2] = Index - hiBar;
고[1,3] = sDate[hiBar];
고[1,4] = sTime[hiBar];
hiBar = -1;
loBar = -1;
TL_SetEnd(TL1,고[1,3],고[1,4],고[1,1]);
value2 = 고[1,1]*(1-(전환비율/100));
value3 = (value1+Value2)/2;
TL_SetBegin(TL2,고[1,3],고[1,4],value2);
Text_SetString(TX2,NumToStr(value2,2));
TL_SetBegin(TL4,고[1,3],고[1,4],value3);
Text_SetString(TX4,NumToStr(value3,2));
}
최종꼭지점 = "고점";
}
If 처리구분 == "저점처리" Then
{
t = -1;
If 최종꼭지점 == "고점" Then
{
TL_SetEnd(TL3,고[1,3],고[1,4],value5 );
Text_SetLocation(TX3,고[1,3],고[1,4],value5);
TL_SetEnd(TL5,고[1,3],고[1,4],value6 );
Text_SetLocation(TX5,고[1,3],고[1,4],value6);
For j = 10 DownTo 2
{
For jj = 1 To 4
{
저[j,jj] = 저[j-1,jj];
}
}
저[1,1] = LL[loBar];
저[1,2] = Index - loBar;
저[1,3] = sDate[loBar];
저[1,4] = sTime[loBar];
hiBar = -1;
loBar = -1;
TL1 = TL_New(고[1,3],고[1,4],고[1,1],저[1,3],저[1,4],저[1,1]);
TL_SetSize(TL1,1);
TL_SetColor(TL1,BLUE);
value4 = 고[1,1]*(1-(전환비율/100));
value5 = 저[1,1]*(1+(전환비율/100));
value6 = (value4+Value5)/2;
TL3 = TL_New(저[1,3],저[1,4],value5,NextBarSdate,NextBarStime,value5 );
TL_SetColor(TL3,Magenta);
TL_SetStyle(TL3,3);
TX3 = Text_New(NextBarSdate,NextBarStime,value5,NumToStr(value5,2));
Text_SetColor(TX3,Magenta);
//TL5 = TL_New(저[1,3],저[1,4],value6,NextBarSdate,NextBarStime,value6 );
TL_SetColor(TL5,Orange);
TL_SetStyle(TL5,3);
//TX5 = Text_New(NextBarSdate,NextBarStime,value5,NumToStr(value5,2));
Text_SetColor(TX5,Orange);
}
Else If 저[1,1] > LL[loBar] Then
{
저[1,1] = LL[loBar];
저[1,2] = Index - loBar;
저[1,3] = sDate[loBar];
저[1,4] = sTime[loBar];
hiBar = -1;
loBar = -1;
TL_SetEnd(TL1,저[1,3],저[1,4],저[1,1]);
value5 = 저[1,1]*(1+(전환비율/100));
value6 = (value4+Value5)/2;
TL_SetBegin(TL3,저[1,3],저[1,4],value5 );
Text_SetString(TX3,NumToStr(value5,2));
TL_SetBegin(TL5,저[1,3],저[1,4],value6 );
Text_SetString(TX5,NumToStr(value6,2));
}
최종꼭지점 = "저점";
}
TL_SetEnd(TL2,NextBarSdate,NextBarStime,Value2);
Text_SetLocation(TX2,NextBarSdate,NextBarStime,Value2);
TL_SetEnd(TL3,NextBarSdate,NextBarStime,Value5 );
Text_SetLocation(TX3,NextBarSdate,NextBarStime,Value5 );
TL_SetEnd(TL4,NextBarSdate,NextBarStime,Value3);
Text_SetLocation(TX4,NextBarSdate,NextBarStime,Value3);
TL_SetEnd(TL5,NextBarSdate,NextBarStime,Value6);
Text_SetLocation(TX5,NextBarSdate,NextBarStime,Value6);
IF Endtime > starttime Then
SetStopEndofday(Endtime);
Else
{
if sDate != sDate[1] Then
SetStopEndofday(Endtime);
}
if (sdate != sdate[1] and stime >= EndTime) or
(sdate == sdate[1] and stime >= EndTime and stime[1] < EndTime) Then
Tcond = False;
if (sdate != sdate[1] and stime >= StartTime) or
(sdate == sdate[1] and stime >= StartTime and stime[1] < StartTime) Then
{
Tcond = true;
Xcond = false;
N1 = NetProfit;
IF Endtime <= starttime Then
{
SetStopEndofday(0);
}
}
daypl = NetProfit-N1;
if TotalTrades > TotalTrades[1] then
{
if daypl >= 당일수익 or daypl <= -당일손실 Then
Xcond = true;
if (IsExitName("dbp",1) == true or IsExitName("dbl",1) == true or
IsExitName("dsp",1) == true or IsExitName("dsl",1) == true) then
Xcond = true;
}
if Tcond == true and Xcond == false then
{
if MarketPosition >= 0 and T == 1 and L > 고[1,1]* (1 - (전환비율/100)) Then
Sell("s",AtStop,고[1,1]* (1 - (전환비율/100)));
if MarketPosition <= 0 and T == -1 and H < 저[1,1]* (1 + (전환비율/100)) Then
Buy("b",AtStop,저[1,1]* (1 + (전환비율/100)));
}
if MarketPosition == 1 then
{
ExitLong("bl",AtStop, max(EntryPrice-손절,고[1,1]* (1 - (전환비율/100))));
ExitLong("dbp",atlimit,EntryPrice+((당일수익-daypl)/CurrentContracts));
ExitLong("dbl",AtStop,EntryPrice-((당일손실+daypl)/CurrentContracts));
}
if MarketPosition == -1 then
{
ExitShort("sl",AtStop, min(EntryPrice+손절,저[1,1]* (1 + (전환비율/100))));
ExitShort("dsp",atlimit,EntryPrice-((당일수익-daypl)/CurrentContracts));
ExitShort("dsl",AtStop,EntryPrice+((당일손실+daypl)/CurrentContracts));
}
SetStopProfittarget(익절,PointStop);
2022-09-23
1112
글번호 162469
시스템
답변완료
부탁합니다
아래 글 올렸었는데...제가 수식은 꽝이라..ㅜ
다시한번 부탁드립니다.
예스 수식으로 부탁합니다.
// input
lrg = 'Linear Regression'
linreg1 = input(true, 'Longterm Linear Regression On / Off', group=lrg)
linreg2 = input(true, 'Shorterm Linear Regression On / Off', group=lrg)
periodTrend = input.int(100, 'Longterm Linear Regression Period', minval=4, group=lrg)
periodTrend2 = input.int(25, 'Shorterm Linear Regression Period', minval=4, group=lrg)
deviationsAmnt = input.float(2, 'Deviation', minval=0.1, step=0.1, group=lrg)
estimatorType = input.string('Unbiased', 'Estimator', options=['Biased', 'Unbiased'], group=lrg)
var extendType = input.string('Right', 'Extend', options=['Right', 'Segment'], group=lrg) == 'Right' ? extend.right : extend.none
// drawline configuration
drawLine(X1, Y1, X2, Y2, ExtendType, Color, LineStyle) =>
var line Line = na
Line := linreg1 ? line.new(X1, Y1, X2, Y2, xloc.bar_index, ExtendType, Color, LineStyle, width=2) : na
line.delete(Line[1])
drawLine2(X1, Y1, X2, Y2, ExtendType, Color, LineStyle) =>
var line Line = na
Line := linreg2 ? line.new(X1, Y1, X2, Y2, xloc.bar_index, ExtendType, Color, LineStyle, width=2) : na
line.delete(Line[1])
rsdcr2(PeriodMinusOne, Deviations, Estimate) =>
var period = PeriodMinusOne + 1
var devDenominator = Estimate == 'Unbiased' ? PeriodMinusOne : period
Ex = 0.0
Ex2 = 0.0
Exy = 0.0
Ey = 0.0
for i = 0 to PeriodMinusOne by 1
closeI = nz(rsia[i])
Ex := Ex + i
Ex2 := Ex2 + i * i
Exy := Exy + closeI * i
Ey := Ey + closeI
Ey
ExEx = Ex * Ex
slope = Ex2 == ExEx ? 0.0 : (period * Exy - Ex * Ey) / (period * Ex2 - ExEx)
linearRegression = (Ey - slope * Ex) / period
intercept = linearRegression + bar_index * slope
deviation = 0.0
for i = 0 to PeriodMinusOne by 1
deviation := deviation + math.pow(nz(rsia[i]) - (intercept - bar_index[i] * slope), 2.0)
deviation
deviation := Deviations * math.sqrt(deviation / devDenominator)
correlate = ta.correlation(rsia, bar_index, period)
r2 = math.pow(correlate, 2.0)
[linearRegression, slope, deviation, correlate, r2]
periodMinusOne = periodTrend - 1
[linReg, slope, deviation, correlate, r2] = rsdcr2(periodMinusOne, deviationsAmnt, estimatorType)
endPointBar = bar_index - periodTrend + 1
endPointY = linReg + slope * periodMinusOne
endPointBar2 = bar_index - periodTrend2 + 1
// drawline plot
drawLine(endPointBar, endPointY + deviation, bar_index, linReg + deviation, extendType, #e91e63, line.style_solid)
drawLine(endPointBar, endPointY, bar_index, linReg, extendType, #e91e63, line.style_dotted)
drawLine(endPointBar, endPointY - deviation, bar_index, linReg - deviation, extendType, #e91e63, line.style_solid)
drawLine2(endPointBar2, endPointY + deviation, bar_index, linReg + deviation, extendType, color.blue, line.style_solid)
drawLine2(endPointBar2, endPointY, bar_index, linReg, extendType, color.blue, line.style_dotted)
drawLine2(endPointBar2, endPointY - deviation, bar_index, linReg - deviation, extendType, color.blue, line.style_solid)
2022-09-23
1058
글번호 162460
지표