File Name: StrategyRSI.efs
Description:
The RSI & Price Trends by Kevin Luo
Formula Parameters:
StrategyRSI.efs
Length RSI: 14
Price Change, %: 20
RSI Upper Bound: 70
RSI Lower Bound: 50
Confirmed Long Zone: lime
Long Trend Color: green
Short Trend Color: red
Long Position Color: green
Short Position Color: red
Nick Color: grey
Nick Extension: 3
Nick Thickness: 3
Notes:
The related article is copyrighted material. If you are not a subscriber
of Stocks & Commodities, please visit www.traders.com.
Download File:
StrategyRSI.efs
StrategyRSI.efs
EFS Code:
Description:
The RSI & Price Trends by Kevin Luo
Formula Parameters:
StrategyRSI.efs
Length RSI: 14
Price Change, %: 20
RSI Upper Bound: 70
RSI Lower Bound: 50
Confirmed Long Zone: lime
Long Trend Color: green
Short Trend Color: red
Long Position Color: green
Short Position Color: red
Nick Color: grey
Nick Extension: 3
Nick Thickness: 3
Notes:
The related article is copyrighted material. If you are not a subscriber
of Stocks & Commodities, please visit www.traders.com.
Download File:
StrategyRSI.efs
StrategyRSI.efs
EFS Code:
PHP Code:
/*********************************
Provided By:
Interactive Data Corporation (Copyright В© 2015)
All rights reserved. This sample eSignal Formula Script (EFS)
is for educational purposes only. Interactive Data Corporation
reserves the right to modify and overwrite this EFS file with
each new release.
Description:
The RSI & Price Trends by Kevin Luo
Formula Parameters: Default:
Length RSI 14
Price Change, % 20
RSI Upper Bound 70
RSI Lower Bound 50
Confirmed Long Zone lime
Long Trend Color green
Short Trend Color red
Long Position Color green
Short Position Color red
Nick Color grey
Nick Extension 3
Nick Thickness 3
Version: 1.00 04/09/2015
Notes:
The related article is copyrighted material. If you are not a subscriber
of Stocks & Commodities, please visit www.traders.com.
**********************************/
var fpArray = new Array();
function preMain(){
setStudyTitle("StrategyRSI");
setPriceStudy(true);
setColorPriceBars(true);
setComputeOnClose(true);
var x = 0;
fpArray[x] = new FunctionParameter("fpLength", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Length RSI");
setLowerLimit(1);
setDefault(14);
};
fpArray[x] = new FunctionParameter("fpChange", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Price Change, %");
setLowerLimit(0);
setUpperLimit(100);
setDefault(20);
};
fpArray[x] = new FunctionParameter("fpRSIHighBorder", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("RSI Upper Bound");
setLowerLimit(0);
setUpperLimit(100);
setDefault(70);
};
fpArray[x] = new FunctionParameter("fpRSILowBorder", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("RSI Lower Bound");
setLowerLimit(0);
setUpperLimit(100);
setDefault(50);
};
fpArray[x] = new FunctionParameter("fpZoneColor", FunctionParameter.COLOR);
with(fpArray[x++]){
setName("Confirmed Long Zone");
setDefault(Color.lime);
};
fpArray[x] = new FunctionParameter("fpLongTrendColor", FunctionParameter.COLOR);
with(fpArray[x++]){
setName("Long Trend Color");
setDefault(Color.green);
};
fpArray[x] = new FunctionParameter("fpShortTrendColor", FunctionParameter.COLOR);
with(fpArray[x++]){
setName("Short Trend Color");
setDefault(Color.red);
};
fpArray[x] = new FunctionParameter("fpLongPosColor", FunctionParameter.COLOR);
with(fpArray[x++]){
setName("Long Position Color");
setDefault(Color.green);
};
fpArray[x] = new FunctionParameter("fpShortPosColor", FunctionParameter.COLOR);
with(fpArray[x++]){
setName("Short Position Color");
setDefault(Color.red);
};
fpArray[x] = new FunctionParameter("fpNickColor", FunctionParameter.COLOR);
with(fpArray[x++]){
setName("Nick Color");
setDefault(Color.grey);
};
fpArray[x] = new FunctionParameter("fpExtNick", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Nick Extension");
setLowerLimit(0);
setDefault(3);
};
fpArray[x] = new FunctionParameter("fpThicNick", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Nick Thickness");
setLowerLimit(1);
setUpperLimit(10)
setDefault(3);
};
}
var bInit = false;
var bVersion = null;
var xOpen = null;
var xHigh = null;
var xLow = null;
var xRSI = null;
var nChange = null;
var nHighLim = null;
var nLowLim = null;
var nDefLotSize = null;
var nTagID = 0;
var bIsTrend = false;
var bLongTrend = false;
var bShortTrend = false;
var aHignest = {};
var aLowest = {};
function main(fpLength, fpChange,
fpRSIHighBorder, fpRSILowBorder,
fpLongTrendColor, fpShortTrendColor,
fpZoneColor, fpLongPosColor, fpShortPosColor,
fpNickColor, fpExtNick, fpThicNick){
if (bVersion == null) bVersion = verify();
if (bVersion == false) return;
if (!bInit){
xOpen = open();
xHigh = high();
xLow = low();
xRSI = rsi(fpLength);
nChange = fpChange / 100;
nHighLim = 1 + nChange;
nLowLim = 1 - nChange;
nDefLotSize = Strategy.getDefaultLotSize();
bInit = true;
};
if (getBarState() == BARSTATE_ALLBARS){
nTagID = 0;
bIsTrend = false;
bLongTrend = false;
bShortTrend = false;
aHighest = {};
aLowest = {};
}
var bReverseThisBar = false;
var nNextOpen = xOpen.getValue(1);
var nOpen = xOpen.getValue(0);
var nHigh = xHigh.getValue(0);
var nLow = xLow.getValue(0);
var nPrevHigh = xHigh.getValue(-1);
var nPrevLow = xLow.getValue(-1);
var nRSI = xRSI.getValue(0);
if (nPrevHigh == null || nPrevLow == null)
return;
var nCurrentBarNumber = getCurrentBarCount();
if (bShortTrend || !bIsTrend){
if (nPrevLow < aLowest[0] || aLowest[0] == null){
aLowest[0] = nPrevLow;
aLowest[1] = nCurrentBarNumber - 1;
}
if (bIsTrend) setPriceBarColor(fpShortTrendColor);
if (nHigh >= nHighLim * aLowest[0]){
recalculate(nCurrentBarNumber - aLowest[1] + 1, function(){
setPriceBarColor(fpLongTrendColor);
})
drawLineRelative(-fpExtNick, nHighLim * aLowest[0], fpExtNick, nHighLim * aLowest[0],
null, fpThicNick, fpNickColor, nTagID++);
if (!bIsTrend) bIsTrend = true;
bLongTrend = true;
bShortTrend = false;
bReverseThisBar = true;
aHighest[0] = nHigh;
aHighest[1] = nCurrentBarNumber;
}
}
if (bLongTrend || !bIsTrend){
if (bIsTrend) setPriceBarColor(fpLongTrendColor);
if ((nPrevHigh > aHighest[0] || aHighest[0] == null) && !bReverseThisBar ){
aHighest[0] = nPrevHigh;
aHighest[1] = nCurrentBarNumber - 1;
}
if (nLow <= nLowLim * aHighest[0] && !bReverseThisBar){
recalculate(nCurrentBarNumber - aHighest[1] + 1, function(){
setPriceBarColor(fpShortTrendColor);
})
if (bIsTrend) drawLineRelative(-fpExtNick, nLowLim * aHighest[0], fpExtNick, nLowLim * aHighest[0],
null, fpThicNick, fpNickColor, nTagID++);
if (!bIsTrend) bIsTrend = true;
bLongTrend = false;
bShortTrend = true;
aLowest[0] = nLow;
aLowest[1] = nCurrentBarNumber;
var nExitPrice = Math.min(nOpen, nLowLim * aHighest[0]);
if (Strategy.isLong()){
Strategy.doSell("Exit Long", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nExitPrice);
drawShapeRelative(0, AboveBar1, Shape.DOWNTRIANGLE, null, fpShortPosColor,
Text.PRESET, nTagID++);
drawTextRelative(0, AboveBar2, "Exit Long", fpShortPosColor, null,
Text.PRESET|Text.CENTER|Text.BOLD, null, null, nTagID++);
drawTextRelative(0, AboveBar3, nDefLotSize + " @ " + formatPriceNumber(nExitPrice), fpShortPosColor, null,
Text.PRESET|Text.CENTER|Text.BOLD, null, null, nTagID++);
}
}
else if (bIsTrend){
setBarBgColor(fpZoneColor);
if (nRSI == null)
return;
if (nRSI < fpRSILowBorder && !Strategy.isLong()){
Strategy.doLong("Long", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
drawShapeRelative(1, BelowBar1, Shape.UPTRIANGLE, null, fpLongPosColor,
Text.PRESET, nTagID++);
drawTextRelative(1, BelowBar2, "Long", fpLongPosColor, null,
Text.PRESET|Text.CENTER|Text.BOLD, null, null, nTagID++);
drawTextRelative(1, BelowBar3, nDefLotSize + " @ " + formatPriceNumber(nNextOpen), fpLongPosColor, null,
Text.PRESET|Text.CENTER|Text.BOLD, null, null, nTagID++);
}
if (nRSI > fpRSIHighBorder && Strategy.isLong()){
Strategy.doSell("Exit Long", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
drawShapeRelative(1, AboveBar1, Shape.DOWNTRIANGLE, null, fpShortPosColor,
Text.PRESET, nTagID++);
drawTextRelative(1, AboveBar2, "Exit Long", fpShortPosColor, null,
Text.PRESET|Text.CENTER|Text.BOLD, null, null, nTagID++);
drawTextRelative(1, AboveBar3, nDefLotSize + " @ " + formatPriceNumber(nNextOpen), fpShortPosColor, null,
Text.PRESET|Text.CENTER|Text.BOLD, null, null, nTagID++);
}
}
}
}
function verify(){
var b = false;
if (getBuildNumber() < 3435){
drawTextAbsolute(5, 35, "This study requires version 11.8 or later.",
Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
null, 13, "error");
drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp",
Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
null, 13, "upgrade");
return b;
}
else
b = true;
return b;
}