Hi
I previously used TS Easy Language but have decided to see what moving over to EFS is like -
I have looked at a lot of the various examples studies provided in the forum and incorporated some of what was set out in some test EFSs
I have written an EFS study “TEST-1” which plots OK up to a point
However I have been trying to call “TEST-1”into another EFS “TEST-2” and calculate a moving average in “TEST-2” based on the “TEST-1” output
I have encountered a couple of problems with using the data from “TEST-1” in “TEST-2”
1. I believe this is because “TEST-1” data output is calculated only for selected bars (ie not all bars) so there are gaps /zeros in the data output generated by the study when compared against the underlying market price data –
I would like to fill these gaps in the “TEST-1” output with the last price that was calculated in “TEST-1” (ie the last number that was generated that wasn’t null or zero -
I understand that this will mean that the same price will be used to fill in data in extended gaps and there will therefore be flat line output by “TEST-2” for extended periods of time on the chart )
2. I have noticed that while a moving average is calculated by “TEST-2” it is not based on the output of “TEST-1” but rather it appears to be based on the closing price of each bar (ie not the data from “TEST-1”) –
I guess this may be because of the gaps in the “TEST-1” data output and that in some way EFS defaults to using the closing price when it doesn’t know what else to do
3. Going back to point 2 above is there some way I can do calculations on the “TEST-1” output that generates results other than zero –
ie how can I extract the last 3, 10 or 20 etc numbers greater than zero and do a calculation on them – for example a moving average –
please note the frequency at which data is calculated/output by “TEST-1” that produces results other than zero is not regular
The Studies “TEST-1”and “TEST-2” are below
Study “Test-1”
function preMain() {
setPriceStudy(true);
setComputeOnClose()
setStudyTitle("FunctionParameter: TEST-1");
setPlotType(PS_DASH);
setCursorLabelName("Upper Env", 0);
setCursorLabelName("Lower Env", 1);
setDefaultBarFgColor(Color.red, 0);
setDefaultBarFgColor(Color.blue, 1);
var fp1 = new FunctionParameter("Test", FunctionParameter.BOOLEAN);
fp1.setName("Envelope");
fp1.setPriceStudy(true);
}
function main(Test) {
if ((sma(30) < sma(20)) && (sma(15) < sma(20))) {var FlagA = sma(20)}
return (FlagA);
}
Study “Test-2”
function preMain(){
setPriceStudy(true);
setStudyTitle("TEST-2");
setCursorLabelName("myStudy",0);
setCursorLabelName("myAvg",1);
setCursorLabelName("myAvgTEST",2);
setDefaultBarFgColor(Color.blue,0);
setDefaultBarFgColor(Color.red,1);
setDefaultBarFgColor(Color.green,2);
setDefaultBarThickness(3, 0);
setDefaultBarThickness(3, 1);
setDefaultBarThickness(5, 2);
setPlotType(PS_DASH,0);
setPlotType(PS_DASH,1);
setPlotType(PS_DASH,2);
}
function main(){
//the following line calls the separate function and creates the series object
var myStudy = efsExternal("TEST-1.efs");
//the following line creates a simple moving average of length 3 using myStudy as the source
var myStudyAvg = sma(3, "myStudy".getabsValue);
//the following line was an attempt to pull out the previously calculated prices from myStudy and myStudyAvg
var xyz = (myStudy[-1]/3+myStudy[-2]/3+myStudy[-3]/3);
//var xyz1 = (myStudy(-1)/3+myStudy(-2)/3+myStudy(-3)/3);
// var aaa = new Array (myStudy(-1)/3+myStudy(-2)/3+myStudy(-3)/3);
return new Array (myStudy, myStudyAvg, xyz);
}
Lastly could you advise me how I can call a previously calculated value from “myStudy” or “myStudyAvg”above and use it in another calculation –
By way of example I tried doing
var bbb = (myStudy Avg(-10)/ myStudy (-3));
or
var bbb = myStudy Avg(-10)/ myStudy (-3);
but this just resulted in all the data plotted by the Test-2 disappearing (even if I didn’t try to plot bbb) until I removed the bbb code
As a more practical simple example if I could extract the last three values for “myStudy” I could then calculate the moving average generated by “myStudyAvg” and verify that the two ways of calculating matters corresponded
var xyz = (myStudy (-1)/3+myStudy (-2)/3+myStudy (-3)/3);
(ie this is just a simple test to see that I have managed to / can pull out the data but there are other things I would like to do with the data once I can extract it)
I tried to address matters as follows
var xyz = new Array(myStudy[1], myStudy[2], myStudy[3]);
or
var xyz = (myStudy (-1)/3+myStudy (-2)/3+myStudy (-3)/3);
or
var xyz1 = (myStudyAvg(-1)/3+myStudyAvg(-2)/3+myStudyAvg(-3)/3);
The results of my attempts have varied from
A. all the “TEST-2”plot data disappearing (not the market prices just the study data) if I include var “xyz1” to
B. there being no data plotted for the two var “xyz” attempts though the other data for “myStudy” and “myStudyAvg” was plotted even though the var “xyz” data didn’t show
In some earlier attempts at resolving this matter by creating an array I received a message saying no properties or length had been defined or were invalid (ie “Range error invalid array length”) for xyz if the array contained only one item or if it had more than one item nothing was plotted for xyz but the other items in the array were plotted
Thanks for any help
Robert
I previously used TS Easy Language but have decided to see what moving over to EFS is like -
I have looked at a lot of the various examples studies provided in the forum and incorporated some of what was set out in some test EFSs
I have written an EFS study “TEST-1” which plots OK up to a point
However I have been trying to call “TEST-1”into another EFS “TEST-2” and calculate a moving average in “TEST-2” based on the “TEST-1” output
I have encountered a couple of problems with using the data from “TEST-1” in “TEST-2”
1. I believe this is because “TEST-1” data output is calculated only for selected bars (ie not all bars) so there are gaps /zeros in the data output generated by the study when compared against the underlying market price data –
I would like to fill these gaps in the “TEST-1” output with the last price that was calculated in “TEST-1” (ie the last number that was generated that wasn’t null or zero -
I understand that this will mean that the same price will be used to fill in data in extended gaps and there will therefore be flat line output by “TEST-2” for extended periods of time on the chart )
2. I have noticed that while a moving average is calculated by “TEST-2” it is not based on the output of “TEST-1” but rather it appears to be based on the closing price of each bar (ie not the data from “TEST-1”) –
I guess this may be because of the gaps in the “TEST-1” data output and that in some way EFS defaults to using the closing price when it doesn’t know what else to do
3. Going back to point 2 above is there some way I can do calculations on the “TEST-1” output that generates results other than zero –
ie how can I extract the last 3, 10 or 20 etc numbers greater than zero and do a calculation on them – for example a moving average –
please note the frequency at which data is calculated/output by “TEST-1” that produces results other than zero is not regular
The Studies “TEST-1”and “TEST-2” are below
Study “Test-1”
function preMain() {
setPriceStudy(true);
setComputeOnClose()
setStudyTitle("FunctionParameter: TEST-1");
setPlotType(PS_DASH);
setCursorLabelName("Upper Env", 0);
setCursorLabelName("Lower Env", 1);
setDefaultBarFgColor(Color.red, 0);
setDefaultBarFgColor(Color.blue, 1);
var fp1 = new FunctionParameter("Test", FunctionParameter.BOOLEAN);
fp1.setName("Envelope");
fp1.setPriceStudy(true);
}
function main(Test) {
if ((sma(30) < sma(20)) && (sma(15) < sma(20))) {var FlagA = sma(20)}
return (FlagA);
}
Study “Test-2”
function preMain(){
setPriceStudy(true);
setStudyTitle("TEST-2");
setCursorLabelName("myStudy",0);
setCursorLabelName("myAvg",1);
setCursorLabelName("myAvgTEST",2);
setDefaultBarFgColor(Color.blue,0);
setDefaultBarFgColor(Color.red,1);
setDefaultBarFgColor(Color.green,2);
setDefaultBarThickness(3, 0);
setDefaultBarThickness(3, 1);
setDefaultBarThickness(5, 2);
setPlotType(PS_DASH,0);
setPlotType(PS_DASH,1);
setPlotType(PS_DASH,2);
}
function main(){
//the following line calls the separate function and creates the series object
var myStudy = efsExternal("TEST-1.efs");
//the following line creates a simple moving average of length 3 using myStudy as the source
var myStudyAvg = sma(3, "myStudy".getabsValue);
//the following line was an attempt to pull out the previously calculated prices from myStudy and myStudyAvg
var xyz = (myStudy[-1]/3+myStudy[-2]/3+myStudy[-3]/3);
//var xyz1 = (myStudy(-1)/3+myStudy(-2)/3+myStudy(-3)/3);
// var aaa = new Array (myStudy(-1)/3+myStudy(-2)/3+myStudy(-3)/3);
return new Array (myStudy, myStudyAvg, xyz);
}
Lastly could you advise me how I can call a previously calculated value from “myStudy” or “myStudyAvg”above and use it in another calculation –
By way of example I tried doing
var bbb = (myStudy Avg(-10)/ myStudy (-3));
or
var bbb = myStudy Avg(-10)/ myStudy (-3);
but this just resulted in all the data plotted by the Test-2 disappearing (even if I didn’t try to plot bbb) until I removed the bbb code
As a more practical simple example if I could extract the last three values for “myStudy” I could then calculate the moving average generated by “myStudyAvg” and verify that the two ways of calculating matters corresponded
var xyz = (myStudy (-1)/3+myStudy (-2)/3+myStudy (-3)/3);
(ie this is just a simple test to see that I have managed to / can pull out the data but there are other things I would like to do with the data once I can extract it)
I tried to address matters as follows
var xyz = new Array(myStudy[1], myStudy[2], myStudy[3]);
or
var xyz = (myStudy (-1)/3+myStudy (-2)/3+myStudy (-3)/3);
or
var xyz1 = (myStudyAvg(-1)/3+myStudyAvg(-2)/3+myStudyAvg(-3)/3);
The results of my attempts have varied from
A. all the “TEST-2”plot data disappearing (not the market prices just the study data) if I include var “xyz1” to
B. there being no data plotted for the two var “xyz” attempts though the other data for “myStudy” and “myStudyAvg” was plotted even though the var “xyz” data didn’t show
In some earlier attempts at resolving this matter by creating an array I received a message saying no properties or length had been defined or were invalid (ie “Range error invalid array length”) for xyz if the array contained only one item or if it had more than one item nothing was plotted for xyz but the other items in the array were plotted
Thanks for any help
Robert
Comment