I would appreciate any help or guidance on this one. I am trying to use the ErgodicCSI.efs that is in file sharing as an external function. As I read it, it returns two values. I am trying to use these two values as variables in another efs study. I have not been able to figure out how to get it to return a series that I can access. Any suggestions?
Announcement
Collapse
No announcement yet.
Help on efsExternal
Collapse
X
-
hmmerritt
After you have called the external efs using the efsExternal() function you use the getSeries() function to retrieve the individual series. See the example in the last post of this thread
For the description and syntax of the functions see the linked articles in the EFS KnowledgeBase
Alex
-
Alexis, thanks for the guidance. I have read your posts, but I am obviously not getting something.
My calling efs is:
var myVar = efsExternal("/Downloads/ErgodicCSI Histogram.efs", (32,5,5,1,Color.green,Color.blue,2), sym("AB #F,3"));
var nECSI = getSeries( myVar, 0 );
var nSigLine = getSeries( myVar, 1 );
var nECSI_0 = nECSI.getValue(0);
var nSigLine_0 = nSigLine.getValue(0);
The external efs is:
/************************************************** ******************
Title: Ergodic CSI for eSignal 7.x
Coded By: Chris D. Kryza (Divergence Software, Inc.)
Email: [email protected]
Incept: 11/02/2003
Version: 1.0.0
================================================== ===================
Fix History:
11/02/2003 - Initial Release
1.0.0
================================================== ===================
Dislaimer: For educational purposes only! Obviously, no guarantees
whatsoever and use at your own risk.
************************************************** ********************/
//Global Variables
var nBarCounter = 0;
var nCoeff1 = 0;
var nCoeff2 = 0;
var nCoeff3 = 0;
var aEMA1 = new Array();
var aEMA2 = new Array();
var aEMA3 = new Array();
var aEMA4 = new Array();
var aEMA5 = new Array();
var aFPArray = new Array();
var bInitialized = false;
//== PreMain function required by eSignal to set things up
function preMain() {
var x;
setPriceStudy(false);
setStudyTitle("Ergodic CSI Histogram");
setCursorLabelName("egCSI", 0);
setCursorLabelName("egSIG", 1);
setDefaultBarFgColor( Color.blue, 0 );
setDefaultBarFgColor( Color.red, 1 );
setPlotType(PLOTTYPE_HISTOGRAM, 0);
addBand( 0, PS_SOLID, 1, Color.black, -99999 );
//initialize formula parameters
x=0;
aFPArray[x] = new FunctionParameter( "Period1", FunctionParameter.NUMBER );
with( aFPArray[x] ) {
setName( "Long MA" );
setLowerLimit( 2 );
setUpperLimit( 200 );
setDefault( 32 );
}
x++;
aFPArray[x] = new FunctionParameter( "Period2", FunctionParameter.NUMBER );
with( aFPArray[x] ) {
setName( "Short MA" );
setLowerLimit( 2 );
setUpperLimit( 200 );
setDefault( 5 );
}
x++;
aFPArray[x] = new FunctionParameter( "SigPeriod", FunctionParameter.NUMBER );
with( aFPArray[x] ) {
setName( "Signal Period" );
setLowerLimit( 2 );
setUpperLimit( 200 );
setDefault( 5 );
}
x++;
aFPArray[x] = new FunctionParameter( "Period3", FunctionParameter.NUMBER );
with( aFPArray[x] ) {
setName( "Momentum Period" );
setLowerLimit( 1 );
setUpperLimit( 200 );
setDefault( 1 );
}
x++;
aFPArray[x] = new FunctionParameter( "lineColor", FunctionParameter.COLOR );
with( aFPArray[x] ) {
setName( "Line Color" );
setDefault( Color.green );
}
x++;
aFPArray[x] = new FunctionParameter( "sigColor", FunctionParameter.COLOR );
with( aFPArray[x] ) {
setName( "Signal Line Color" );
setDefault( Color.blue );
}
x++;
aFPArray[x] = new FunctionParameter( "lineThick", FunctionParameter.NUMBER );
with( aFPArray[x] ) {
setName( "Line Thickness" );
setLowerLimit( 1 );
setUpperLimit( 10 );
setDefault( 2 );
}
for (x=0; x<20; x++) {
aEMA1[x] = 0.0;
aEMA2[x] = 0.0;
aEMA3[x] = 0.0;
aEMA4[x] = 0.0;
aEMA5[x] = 0.0;
}
}
//== Main processing function
function main( Period1, Period2, SigPeriod, Period3, lineColor, sigColor, lineThick ) {
var x;
//script initializing
if (getBarState() == BARSTATE_ALLBARS) {
return null;
}
if ( bInitialized == false ) {
//determine exponential moving average coefficients
nCoeff1 = 2 / (Period1+1);
nCoeff2 = 2 / (Period2+1);
nCoeff3 = 2 / (SigPeriod+1);
//setDefaultBarFgColor( lineColor, 0 );
//setDefaultBarFgColor( sigColor, 1 );
//setDefaultBarThickness( lineThick, 0 );
//setDefaultBarThickness( lineThick, 1 );
bInitialized = true;
}
//shift storage arrays on new bar
if (getBarState() == BARSTATE_NEWBAR) {
nBarCounter++;
aEMA1.pop();
aEMA1.unshift( 0 );
aEMA2.pop();
aEMA2.unshift( 0 );
aEMA3.pop();
aEMA3.unshift( 0 );
aEMA4.pop();
aEMA4.unshift( 0 );
aEMA5.pop();
aEMA5.unshift( 0 );
}
//X-Day ROC
nValue1 = close()-open();
nValue2 = high()-low();
//calc the exponential averages
aEMA1[0] = ( nValue1 * nCoeff1 ) + ( aEMA1[1] * ( 1.0-nCoeff1 ) );
aEMA2[0] = ( aEMA1[0] * nCoeff2 ) + ( aEMA2[1] * ( 1.0-nCoeff2 ) );
aEMA3[0] = ( nValue2 * nCoeff1 ) + ( aEMA3[1] * ( 1.0-nCoeff1 ) );
aEMA4[0] = ( aEMA3[0] * nCoeff2 ) + ( aEMA4[1] * ( 1.0-nCoeff2 ) );
nCSI = 100.0 * ( aEMA2[0] / aEMA4[0] );
//calc signal line as exp average of TSI
aEMA5[0] = ( nCSI * nCoeff3 ) + ( aEMA5[1] * (1.0-nCoeff3) );
if ( nCSI > 0 ){
setDefaultBarFgColor( Color.green, 0 );
}
if ( nCSI < 0 ){
setDefaultBarFgColor( Color.red, 0 );
}
if ( nBarCounter > Period1+Period2 ) {
return new Array( nCSI, aEMA5[0] );
}
}
/*************************************************
SUPPORT FUNCTIONS
**************************************************/
function p( a, b ) {
debugPrint( a + ": " + b + "\n" );
}
I am expecting to obtain series from the return array for nCSI and aEMA[0], but that's not happening. Where am I going wrong?
Thanks in advance.
Comment
-
hmmeritt
In the efsExternal() call remove the parenthesis that are enclosing the parameters ie replace
PHP Code:var myVar = efsExternal("/Downloads/ErgodicCSI Histogram.efs", (32,5,5,1,Color.green,Color.blue,2), sym("AB #F,3"));
PHP Code:var myVar = efsExternal("/Downloads/ErgodicCSI Histogram.efs", 32,5,5,1,Color.green,Color.blue,2, sym("AB #F,3"));
Alex
Comment
-
hmmeritt
You are most welcome.
If you want to slightly simplify your code you can skip using getSeries(myVar.0) to retrieve the first series returned by the efsExternal() call since the variable to which you assigned the function returns the first series by default (if more than one is called by the function). You only need to use getSeries() to retrieve additional series called by the efsExternal() [or efsInternal()] function. The same block of code could be written as follows and it will work the same
PHP Code:var myVar = efsExternal("/Downloads/ErgodicCSI Histogram.efs", 32,5,5,1,Color.green,Color.blue,2, sym("AB #F,3"));
//var nECSI = getSeries( myVar, 0 );
var nSigLine = getSeries( myVar, 1 );
var nECSI_0 = myVar.getValue(0);
var nSigLine_0 = nSigLine.getValue(0);
Hope this helps
Alex
Comment
-
Alexis, thanks for the tips. I have been trying to implement your suggestion regarding putting the efsExternal inside of an initialization routine, but I have not been able to make it work. When I do put it inside of an init statement, I get the error nECSI has no properties, then I put in a null test, but that seemed to prevent the series from being obtained. I've posted the code below:
var nNewTrade; // New Trade Trigger 0 = OFF / 1 = ON
var nsignal; // returns the direction of the trading signal
var nTradeEntryPrice;
var ProfitTarget1 = 5.0;
var nStopLevel;
var nTriggerLong;
var nTriggerShort;
var bInit = false;
var myVar = null;
var nECSI = null;
var nSigLine = null;
function preMain() {
setPriceStudy(true);
setStudyTitle("Bolze Method");
setCursorLabelName("Profit Target", 0); //ADDED
setCursorLabelName("Stop Target", 1); //ADDED
setDefaultBarFgColor(Color.green, 0); //ADDED
setDefaultBarFgColor(Color.red, 1); //ADDED
setPlotType(PLOTTYPE_FLATLINES, 0); //ADDED
setPlotType(PLOTTYPE_FLATLINES, 1); //ADDED
setColorPriceBars(true); //ADDED
setDefaultPriceBarColor(Color.grey); //ADDED
var fp1 = new FunctionParameter("nProfitAmt", FunctionParameter.NUMBER); //ADDED
fp1.setName("Profit Target Amount"); //ADDED
fp1.setLowerLimit(0.01); //ADDED
fp1.setDefault(3); //ADDED
var fp2 = new FunctionParameter("nStopAmt", FunctionParameter.NUMBER); //ADDED
fp2.setName("Stop Target Amount"); //ADDED
fp2.setLowerLimit(0.01); //ADDED
fp2.setDefault(1); //ADDED
}
//ADDED formula parameters nProfitAmt and nStopAmt to allow
// user defined amounts for various symbols.
function main(nProfitAmt, nStopAmt) {
ProfitTarget1 = nProfitAmt; //ADDED
if (bInit == false){
var myVar = efsExternal("/Downloads/ErgodicCSI Histogram.efs",32,5,5,1,Color.green,Color.red,1, sym("AB #F,3"));
var nECSI = getSeries(myVar,0);
var nSigLine = getSeries(myVar,1);
if (nECSI==null) return;
if (nSigLine==null) return;
var nECSI_0 = nECSI.getValue(0);
var nSigLine_0 = nSigLine.getValue(0);
bInit = true;
}
// debugPrint(getHour() + ":" +getMinute() + ":" + getSecond() + ", " + getMonth() + "/" + getDay() + " eCSI= " + nECSI_0 + ", SigLine=" + nSigLine_0 + "\n");
debugPrint("1st "+ getHour() + ":" +getMinute() + ":" + getSecond() + ", " + getMonth() + "/" + getDay()
+ " nStopLevel= " + nStopLevel + ", InTrade=" + Strategy.isInTrade() + ", newTrade=" + nNewTrade
+ ", Position=" + Strategy.getPositionSize() + ", bPosition=" + bPosition + "\n");
setDefaultBarFgColor(Color.green, 0); //ADDED
setDefaultBarFgColor(Color.red, 1); //ADDED
if (nECSI == null || nSigLine == null) return; //ADDED
/*----------------------------------------------------------------
// If new trade, get entry price - used for our profit target
----------------------------------------------------------
This portion of the code identifies if a new trade has been issued
and records the entry price of our trade. If no new trade has been
triggered (nNewTrade == 1), then this portion of the code is ignored.
----------------------------------------------------------*/
var bPosition = false; //ADDED
if (Strategy.isInTrade() == true && (nNewTrade == 1)) {
// This sets the expected entry price of the current short trade
nTradeEntryPrice = open();
// This switches off the nNewTrade variable
nNewTrade = 0; // Turn off NEW TRADE switch
bPosition = true; // ADDED
}
var nDisplayStop = null; //ADDED
if (Strategy.isInTrade() == true) { //ADDED
nDisplayStop = nStopLevel; //ADDED
var bPosition = true;
if (Strategy.isLong() == true) setPriceBarColor(Color.green); //ADDED
if (Strategy.isShort() == true) setPriceBarColor(Color.red); //ADDED
} else { //ADDED
nStopLevel = null; //ADDED
} //ADDED
debugPrint("2nd "+ getHour() + ":" +getMinute() + ":" + getSecond() + ", " + getMonth() + "/" + getDay()
+ " nStopLevel= " + nStopLevel + ", InTrade=" + Strategy.isInTrade() + ", newTrade=" + nNewTrade
+ ", Position=" + Strategy.getPositionSize() + ", L/S=" + Strategy.isLong() + ", bPosition=" + bPosition + "\n");
The code seems to execute through the 2nd debug statement on the first bar, then seems to encounter null values on the called series from then on. It seems like I'm not getting a series, but a single value.
Any ideas?
Thanks in advance.
Comment
-
hmmeritt
The reason your are getting a value only on the first iteration of the script is because you are retrieving the value from the series and assigning it to the variable inside the bInit routine which is executed only once the first time that the script is run. You need to move the following two lines of code out of the bInit routine
PHP Code:var nECSI_0 = nECSI.getValue(0);
var nSigLine_0 = nSigLine.getValue(0);
Alex
Originally posted by hmmerritt
Alexis, thanks for the tips. I have been trying to implement your suggestion regarding putting the efsExternal inside of an initialization routine, but I have not been able to make it work. When I do put it inside of an init statement, I get the error nECSI has no properties, then I put in a null test, but that seemed to prevent the series from being obtained. I've posted the code below:
var nNewTrade; // New Trade Trigger 0 = OFF / 1 = ON
var nsignal; // returns the direction of the trading signal
var nTradeEntryPrice;
var ProfitTarget1 = 5.0;
var nStopLevel;
var nTriggerLong;
var nTriggerShort;
var bInit = false;
var myVar = null;
var nECSI = null;
var nSigLine = null;
function preMain() {
setPriceStudy(true);
setStudyTitle("Bolze Method");
setCursorLabelName("Profit Target", 0); //ADDED
setCursorLabelName("Stop Target", 1); //ADDED
setDefaultBarFgColor(Color.green, 0); //ADDED
setDefaultBarFgColor(Color.red, 1); //ADDED
setPlotType(PLOTTYPE_FLATLINES, 0); //ADDED
setPlotType(PLOTTYPE_FLATLINES, 1); //ADDED
setColorPriceBars(true); //ADDED
setDefaultPriceBarColor(Color.grey); //ADDED
var fp1 = new FunctionParameter("nProfitAmt", FunctionParameter.NUMBER); //ADDED
fp1.setName("Profit Target Amount"); //ADDED
fp1.setLowerLimit(0.01); //ADDED
fp1.setDefault(3); //ADDED
var fp2 = new FunctionParameter("nStopAmt", FunctionParameter.NUMBER); //ADDED
fp2.setName("Stop Target Amount"); //ADDED
fp2.setLowerLimit(0.01); //ADDED
fp2.setDefault(1); //ADDED
}
//ADDED formula parameters nProfitAmt and nStopAmt to allow
// user defined amounts for various symbols.
function main(nProfitAmt, nStopAmt) {
ProfitTarget1 = nProfitAmt; //ADDED
if (bInit == false){
var myVar = efsExternal("/Downloads/ErgodicCSI Histogram.efs",32,5,5,1,Color.green,Color.red,1, sym("AB #F,3"));
var nECSI = getSeries(myVar,0);
var nSigLine = getSeries(myVar,1);
if (nECSI==null) return;
if (nSigLine==null) return;
var nECSI_0 = nECSI.getValue(0);
var nSigLine_0 = nSigLine.getValue(0);
bInit = true;
}
// debugPrint(getHour() + ":" +getMinute() + ":" + getSecond() + ", " + getMonth() + "/" + getDay() + " eCSI= " + nECSI_0 + ", SigLine=" + nSigLine_0 + "\n");
debugPrint("1st "+ getHour() + ":" +getMinute() + ":" + getSecond() + ", " + getMonth() + "/" + getDay()
+ " nStopLevel= " + nStopLevel + ", InTrade=" + Strategy.isInTrade() + ", newTrade=" + nNewTrade
+ ", Position=" + Strategy.getPositionSize() + ", bPosition=" + bPosition + "\n");
setDefaultBarFgColor(Color.green, 0); //ADDED
setDefaultBarFgColor(Color.red, 1); //ADDED
if (nECSI == null || nSigLine == null) return; //ADDED
/*----------------------------------------------------------------
// If new trade, get entry price - used for our profit target
----------------------------------------------------------
This portion of the code identifies if a new trade has been issued
and records the entry price of our trade. If no new trade has been
triggered (nNewTrade == 1), then this portion of the code is ignored.
----------------------------------------------------------*/
var bPosition = false; //ADDED
if (Strategy.isInTrade() == true && (nNewTrade == 1)) {
// This sets the expected entry price of the current short trade
nTradeEntryPrice = open();
// This switches off the nNewTrade variable
nNewTrade = 0; // Turn off NEW TRADE switch
bPosition = true; // ADDED
}
var nDisplayStop = null; //ADDED
if (Strategy.isInTrade() == true) { //ADDED
nDisplayStop = nStopLevel; //ADDED
var bPosition = true;
if (Strategy.isLong() == true) setPriceBarColor(Color.green); //ADDED
if (Strategy.isShort() == true) setPriceBarColor(Color.red); //ADDED
} else { //ADDED
nStopLevel = null; //ADDED
} //ADDED
debugPrint("2nd "+ getHour() + ":" +getMinute() + ":" + getSecond() + ", " + getMonth() + "/" + getDay()
+ " nStopLevel= " + nStopLevel + ", InTrade=" + Strategy.isInTrade() + ", newTrade=" + nNewTrade
+ ", Position=" + Strategy.getPositionSize() + ", L/S=" + Strategy.isLong() + ", bPosition=" + bPosition + "\n");
The code seems to execute through the 2nd debug statement on the first bar, then seems to encounter null values on the called series from then on. It seems like I'm not getting a series, but a single value.
Any ideas?
Thanks in advance.
Comment
Comment