커뮤니티
TS코드 예스변환부탁드립니다.
2017-12-23 12:34:20
231
글번호 115235
TS코드 예스변환부탁드립니다.
Input:
Length(7),price((o+c)/2),mult(0.0005),
DrawHLines(true);
{ drawing related variable inputs }
Input: longDiverColor(green), longRSIColor(darkgreen), longRevDiverColor(cyan);
Input: shortDiverColor(red), shortRSIColor(darkred), shortRevDiverColor(yellow);
var:
k_15(15), k_50(50),
RSIWAvg(0),
lastRSIAtPivotLo(0),lastPriceAtPivotLo(0),lastLoAtPivotLo(0),
lastRSIAtPivotHi(0),lastPriceAtPivotHi(0),lastHiAtPivotHi(0);
{ figure out long/short threshold }
var:
idx(0), RSIAvg(0),
longThreshold(0),shrtThreshold(0),
_RSI(0);
var:
alertTextID(-1);
if barnumber = 1 then begin
alertTextID = Text_New(date,time,0,"RSI");
end;
_RSI = RSI(Price,Length);
RSIAvg = Average(_RSI,k_50);
longThreshold = 60 - (100-RSIAvg)/1.68;
shrtThreshold = 40 + (RSIAvg)/1.68;
RSIWAvg = WAverage(RSI(Price,Length),3);
{ long signal }
if RSIWAvg[1] < RSIWAvg and
RSIWAvg[1] < RSIWAvg[2] and
RSIWAvg[2] < RSIWAvg[3] and
RSIWAvg[3] < RSIWAvg[4] then begin { last bar was a RSI pivot low }
if RSIWAvg[1] < (longThreshold + k_15) and { RSI was "low enough" }
{ RSI low enough for a pivot low, look for divergence }
Price < lastPriceAtPivotLo and { price was higher in last RSI pivot low, but }
lastRSIAtPivotLo < _RSI then { RSI was lower => divergence } begin
{ plot a "significant" long signal }
Plot1(L-L*mult,"long",longDiverColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI diver long");
end;
end
else if RSIWAvg[1] < longThreshold then begin
{ no divergence, but RSI very low, and so it's worth noting }
{ plot a normal long signal }
Plot1(L-L*mult,"long",longRSIColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI long");
end;
end
else if RSIWAvg[1] > (shrtThreshold - k_15) { RSI was "high enough" }
{ a pivot low while RSI reading is high, look for rev divergence }
and Price > lastPriceAtPivotLo { price was higher in last RSI pivot low, but }
and lastRSIAtPivotLo < _RSI then { RSI was lower => rev divergence } begin
Plot1(L-L*mult,"long",longRevDiverColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI rev diver long");
end;
end;
lastPriceAtPivotLo = Price;
lastLoAtPivotLo = L;
lastRSIAtPivotLo = _RSI;
end;
if DrawHLines and lastLoAtPivotLo <> 0 then begin
plot3(lastLoAtPivotLo,"lastL@pivotL");
if lastLoAtPivotLo <> lastLoAtPivotLo[1]
and Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI support");
end;
end;
if DrawHLines and lastHiAtPivotHi <> 0 then begin
plot4(lastHiAtPivotHi,"lastH@pivotH");
if lastHiAtPivotHi <> lastHiAtPivotHi[1]
and Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI resistance");
end;
end;
{ short signal }
if RSIWAvg[1] > RSIWAvg and
RSIWAvg[1] > RSIWAvg[2] and
RSIWAvg[2] > RSIWAvg[3] and
RSIWAvg[3] > RSIWAvg[4] then begin { last bar was a RSI pivot high }
if RSIWAvg[1] > (shrtThreshold - k_15) and { RSI was "high enough" }
{ RSI high enough for a pivot high, look for divergence }
Price > lastPriceAtPivotHi and { price was higher in last RSI pivot high, but }
lastRSIAtPivotHi > _RSI then { RSI was higher => divergence } begin
{ plot a "significant" short signal }
Plot2(H+H*mult,"short",shortDiverColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI diver short");
end;
end
else begin
if RSIWAvg[1] > shrtThreshold then begin
{ no divergence, but RSI very high, and so it's worth noting }
{ plot a normal short signal }
Plot2(H+H*mult,"short",shortRSIColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI short");
end;
end;
end;
if RSIWAvg[1] < (longThreshold + k_15) and { RSI was "low enough" }
{ a pivot high while RSI reading is low, look for rev divergence }
Price < lastPriceAtPivotHi and { price was lower in last RSI pivot high, but }
lastRSIAtPivotHi > _RSI then { RSI was higher => rev divergence } begin
Plot2(H+H*mult,"short",shortRevDiverColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI rev diver short");
end;
end;
lastPriceAtPivotHi = Price;
lastHiAtPivotHi = H;
lastRSIAtPivotHi = _RSI;
end;
{
the original code follows:
}
{
Input:Length(7);
Vars: Condition99(FALSE),
Value8(15),
Value3(50);
Value1 = WAverage(RSI(Close,Length),3);
Value2 = 0;
For Value7 = 0 to Value3
Begin
Value2 = Value2 + RSI(Close,Length)[Value7];
End;
Value4 = Value2/(Value3-1);
Value5 = 100 - (100-Value4)/1.68;
Value6 = Value5 - 40;
If Value1[1] < Value1 and Value1[1] < Value1[2] and Value1[2] < Value1[3]
and Value1[3] < Value1[4] then
Begin
If Value1[1] < (Value6 + Value8) and Value9 > (Open + Close)/2 and Value10 < RSI(Close,Length) then
Begin
Plot1(L-C*0.001,"Pivot-sB");
Condition99 = FALSE;
Value9 = (Open + Close)/2;
Value10 = RSI(Close,Length);
End
Else
Begin
If Value1[1] < Value6 then
Begin
Plot2(L-C*0.001,"Pivot-B");
Condition99 = TRUE;
Value9 = (Open + Close)/2;
Value10 = RSI(Close,Length);
End;
End;
End;
}
답변 1
예스스탁 예스스탁 답변
2017-12-26 15:28:00
안녕하세요
예스스탁입니다.
Input: Length(7),price((o+c)/2),mult(0.0005),DrawHLines(true);
#{ drawing related variable inputs }
Input: longDiverColor(green), longRSIColor(CYAN), longRevDiverColor(cyan);
Input: shortDiverColor(red), shortRSIColor(MAGENTA), shortRevDiverColor(yellow);
var: k_15(15), k_50(50),RSIWAvg(0),
lastRSIAtPivotLo(0),lastPriceAtPivotLo(0),lastLoAtPivotLo(0),
lastRSIAtPivotHi(0),lastPriceAtPivotHi(0),lastHiAtPivotHi(0);
#{ figure out long/short threshold }
var:idx(0), RSIAvg(0),longThreshold(0),shrtThreshold(0),_RSI(0);
var: alertTextID(-1);
Variables: Counter(0), DownAmt(0), UpAmt(0), UpSum(0), DownSum(0), UpAvg(0), DownAvg(0),RSIv(0);
If CurrentBar == 1 AND Length > 0 Then Begin
UpSum = 0;
DownSum = 0;
For Counter = 0 To Length - 1 Begin
UpAmt = Price[Counter] - Price[Counter+1];
If UpAmt >= 0 Then
DownAmt = 0;
Else Begin
DownAmt = -UpAmt;
UpAmt = 0;
End;
UpSum = UpSum + UpAmt;
DownSum = DownSum + DownAmt;
End;
UpAvg = UpSum / Length;
DownAvg = DownSum / Length;
End
Else
If CurrentBar > 1 AND Length > 0 Then Begin
UpAmt = Price[0] - Price[1];
If UpAmt >= 0 Then
DownAmt = 0;
Else Begin
DownAmt = -UpAmt;
UpAmt = 0;
End;
UpAvg = (UpAvg[1] * (Length - 1) + UpAmt) / Length;
DownAvg = (DownAvg[1] * (Length - 1) + DownAmt) / Length;
End;
If UpAvg + DownAvg <> 0 Then
RSIv = 100 * UpAvg / (UpAvg + DownAvg);
Else
RSIv = 0;
if index == 1 then begin
alertTextID = Text_New(date,time,0,"RSI");
end;
_RSI = RSIv;
RSIAvg = Average(_RSI,k_50);
longThreshold = 60 - (100-RSIAvg)/1.68;
shrtThreshold = 40 + (RSIAvg)/1.68;
RSIWAvg = wma(RSIv,3);
#{ long signal }
if RSIWAvg[1] < RSIWAvg and
RSIWAvg[1] < RSIWAvg[2] and
RSIWAvg[2] < RSIWAvg[3] and
RSIWAvg[3] < RSIWAvg[4] then begin #{ last bar was a RSI pivot low }
if RSIWAvg[1] < (longThreshold + k_15) and #{ RSI was "low enough" }
#{ RSI low enough for a pivot low, look for divergence }
Price < lastPriceAtPivotLo and #{ price was higher in last RSI pivot low, but }
lastRSIAtPivotLo < _RSI then #{ RSI was lower => divergence }
begin
#{ plot a "significant" long signal }
Plot1(L-L*mult,"long",longDiverColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI diver long");
end;
end
else if RSIWAvg[1] < longThreshold then begin
#{ no divergence, but RSI very low, and so it's worth noting }
#{ plot a normal long signal }
Plot1(L-L*mult,"long",longRSIColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI long");
end;
end
else if RSIWAvg[1] > (shrtThreshold - k_15) #{ RSI was "high enough" }
#{ a pivot low while RSI reading is high, look for rev divergence }
and Price > lastPriceAtPivotLo #{ price was higher in last RSI pivot low, but }
and lastRSIAtPivotLo < _RSI then #{ RSI was lower => rev divergence }
begin
Plot1(L-L*mult,"long",longRevDiverColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI rev diver long");
end;
end;
lastPriceAtPivotLo = Price;
lastLoAtPivotLo = L;
lastRSIAtPivotLo = _RSI;
end;
if DrawHLines and lastLoAtPivotLo <> 0 then begin
plot3(lastLoAtPivotLo,"lastL@pivotL");
if lastLoAtPivotLo <> lastLoAtPivotLo[1]
and Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI support");
end;
end;
if DrawHLines and lastHiAtPivotHi <> 0 then begin
plot4(lastHiAtPivotHi,"lastH@pivotH");
if lastHiAtPivotHi <> lastHiAtPivotHi[1]
and Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI resistance");
end;
end;
#{ short signal }
if RSIWAvg[1] > RSIWAvg and
RSIWAvg[1] > RSIWAvg[2] and
RSIWAvg[2] > RSIWAvg[3] and
RSIWAvg[3] > RSIWAvg[4] then begin #{ last bar was a RSI pivot high }
if RSIWAvg[1] > (shrtThreshold - k_15) and #{ RSI was "high enough" }
#{ RSI high enough for a pivot high, look for divergence }
Price > lastPriceAtPivotHi and #{ price was higher in last RSI pivot high, but }
lastRSIAtPivotHi > _RSI then #{ RSI was higher => divergence }
begin
#{ plot a "significant" short signal }
Plot2(H+H*mult,"short",shortDiverColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI diver short");
end;
end
else begin
if RSIWAvg[1] > shrtThreshold then begin
#{ no divergence, but RSI very high, and so it's worth noting }
#{ plot a normal short signal }
Plot2(H+H*mult,"short",shortRSIColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI short");
end;
end;
end;
if RSIWAvg[1] < (longThreshold + k_15) and #{ RSI was "low enough" }
#{ a pivot high while RSI reading is low, look for rev divergence }
Price < lastPriceAtPivotHi and #{ price was lower in last RSI pivot high, but }
lastRSIAtPivotHi > _RSI then #{ RSI was higher => rev divergence }
begin
Plot2(H+H*mult,"short",shortRevDiverColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI rev diver short");
end;
end;
lastPriceAtPivotHi = Price;
lastHiAtPivotHi = H;
lastRSIAtPivotHi = _RSI;
end;
#{ the original code follows: }
/*{
Input:Length(7);
Vars: Condition99(FALSE),
Value8(15),
Value3(50);
Value1 = WAverage(RSI(Close,Length),3);
Value2 = 0;
For Value7 = 0 to Value3
Begin
Value2 = Value2 + RSI(Close,Length)[Value7];
End;
Value4 = Value2/(Value3-1);
Value5 = 100 - (100-Value4)/1.68;
Value6 = Value5 - 40;
If Value1[1] < Value1 and Value1[1] < Value1[2] and Value1[2] < Value1[3]
and Value1[3] < Value1[4] then
Begin
If Value1[1] < (Value6 + Value8) and Value9 > (Open + Close)/2 and Value10 < RSI(Close,Length) then
Begin
Plot1(L-C*0.001,"Pivot-sB");
Condition99 = FALSE;
Value9 = (Open + Close)/2;
Value10 = RSI(Close,Length);
End
Else
Begin
If Value1[1] < Value6 then
Begin
Plot2(L-C*0.001,"Pivot-B");
Condition99 = TRUE;
Value9 = (Open + Close)/2;
Value10 = RSI(Close,Length);
End;
End;
End;
}*/
즐거운 하루되세요
> 데프콘 님이 쓴 글입니다.
> 제목 : TS코드 예스변환부탁드립니다.
> TS코드 예스변환부탁드립니다.
Input:
Length(7),price((o+c)/2),mult(0.0005),
DrawHLines(true);
{ drawing related variable inputs }
Input: longDiverColor(green), longRSIColor(darkgreen), longRevDiverColor(cyan);
Input: shortDiverColor(red), shortRSIColor(darkred), shortRevDiverColor(yellow);
var:
k_15(15), k_50(50),
RSIWAvg(0),
lastRSIAtPivotLo(0),lastPriceAtPivotLo(0),lastLoAtPivotLo(0),
lastRSIAtPivotHi(0),lastPriceAtPivotHi(0),lastHiAtPivotHi(0);
{ figure out long/short threshold }
var:
idx(0), RSIAvg(0),
longThreshold(0),shrtThreshold(0),
_RSI(0);
var:
alertTextID(-1);
if barnumber = 1 then begin
alertTextID = Text_New(date,time,0,"RSI");
end;
_RSI = RSI(Price,Length);
RSIAvg = Average(_RSI,k_50);
longThreshold = 60 - (100-RSIAvg)/1.68;
shrtThreshold = 40 + (RSIAvg)/1.68;
RSIWAvg = WAverage(RSI(Price,Length),3);
{ long signal }
if RSIWAvg[1] < RSIWAvg and
RSIWAvg[1] < RSIWAvg[2] and
RSIWAvg[2] < RSIWAvg[3] and
RSIWAvg[3] < RSIWAvg[4] then begin { last bar was a RSI pivot low }
if RSIWAvg[1] < (longThreshold + k_15) and { RSI was "low enough" }
{ RSI low enough for a pivot low, look for divergence }
Price < lastPriceAtPivotLo and { price was higher in last RSI pivot low, but }
lastRSIAtPivotLo < _RSI then { RSI was lower => divergence } begin
{ plot a "significant" long signal }
Plot1(L-L*mult,"long",longDiverColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI diver long");
end;
end
else if RSIWAvg[1] < longThreshold then begin
{ no divergence, but RSI very low, and so it's worth noting }
{ plot a normal long signal }
Plot1(L-L*mult,"long",longRSIColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI long");
end;
end
else if RSIWAvg[1] > (shrtThreshold - k_15) { RSI was "high enough" }
{ a pivot low while RSI reading is high, look for rev divergence }
and Price > lastPriceAtPivotLo { price was higher in last RSI pivot low, but }
and lastRSIAtPivotLo < _RSI then { RSI was lower => rev divergence } begin
Plot1(L-L*mult,"long",longRevDiverColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI rev diver long");
end;
end;
lastPriceAtPivotLo = Price;
lastLoAtPivotLo = L;
lastRSIAtPivotLo = _RSI;
end;
if DrawHLines and lastLoAtPivotLo <> 0 then begin
plot3(lastLoAtPivotLo,"lastL@pivotL");
if lastLoAtPivotLo <> lastLoAtPivotLo[1]
and Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI support");
end;
end;
if DrawHLines and lastHiAtPivotHi <> 0 then begin
plot4(lastHiAtPivotHi,"lastH@pivotH");
if lastHiAtPivotHi <> lastHiAtPivotHi[1]
and Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI resistance");
end;
end;
{ short signal }
if RSIWAvg[1] > RSIWAvg and
RSIWAvg[1] > RSIWAvg[2] and
RSIWAvg[2] > RSIWAvg[3] and
RSIWAvg[3] > RSIWAvg[4] then begin { last bar was a RSI pivot high }
if RSIWAvg[1] > (shrtThreshold - k_15) and { RSI was "high enough" }
{ RSI high enough for a pivot high, look for divergence }
Price > lastPriceAtPivotHi and { price was higher in last RSI pivot high, but }
lastRSIAtPivotHi > _RSI then { RSI was higher => divergence } begin
{ plot a "significant" short signal }
Plot2(H+H*mult,"short",shortDiverColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI diver short");
end;
end
else begin
if RSIWAvg[1] > shrtThreshold then begin
{ no divergence, but RSI very high, and so it's worth noting }
{ plot a normal short signal }
Plot2(H+H*mult,"short",shortRSIColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI short");
end;
end;
end;
if RSIWAvg[1] < (longThreshold + k_15) and { RSI was "low enough" }
{ a pivot high while RSI reading is low, look for rev divergence }
Price < lastPriceAtPivotHi and { price was lower in last RSI pivot high, but }
lastRSIAtPivotHi > _RSI then { RSI was higher => rev divergence } begin
Plot2(H+H*mult,"short",shortRevDiverColor);
if Text_GetTime(alertTextID) <> time then begin
text_setLocation(alertTextID, date, time, 0);
alert("RSI rev diver short");
end;
end;
lastPriceAtPivotHi = Price;
lastHiAtPivotHi = H;
lastRSIAtPivotHi = _RSI;
end;
{
the original code follows:
}
{
Input:Length(7);
Vars: Condition99(FALSE),
Value8(15),
Value3(50);
Value1 = WAverage(RSI(Close,Length),3);
Value2 = 0;
For Value7 = 0 to Value3
Begin
Value2 = Value2 + RSI(Close,Length)[Value7];
End;
Value4 = Value2/(Value3-1);
Value5 = 100 - (100-Value4)/1.68;
Value6 = Value5 - 40;
If Value1[1] < Value1 and Value1[1] < Value1[2] and Value1[2] < Value1[3]
and Value1[3] < Value1[4] then
Begin
If Value1[1] < (Value6 + Value8) and Value9 > (Open + Close)/2 and Value10 < RSI(Close,Length) then
Begin
Plot1(L-C*0.001,"Pivot-sB");
Condition99 = FALSE;
Value9 = (Open + Close)/2;
Value10 = RSI(Close,Length);
End
Else
Begin
If Value1[1] < Value6 then
Begin
Plot2(L-C*0.001,"Pivot-B");
Condition99 = TRUE;
Value9 = (Open + Close)/2;
Value10 = RSI(Close,Length);
End;
End;
End;
}
다음글