I've been trying all weekend to produce and EFS study with the Bollinger Bands in order to use it as a DDEOutput into Excel. I've been able to successfully do this for RSI and MACD, but can't seem to get it right for the Bollinger Bands to work. I basically just want to be able to write this EFS so by DDE it sends the values for the Upper, Basis and Lower bands into Excel. Can you help me at all with this?? Thanks!
Announcement
Collapse
No announcement yet.
Bollinger Bands and Excel DDE
Collapse
X
-
Thanks Alexis, I've been trying to post this response for a couple days so hopefully it works this time. I'm not sure how good or bad this code is, but if you could tweak it so that it works that would be really great. Here it is:
PHP Code:var ddeUpper = null;
var ddeMiddle = null;
var ddeLower = null;
var vBollingerStudy = null;
function preMain() {
setPriceStudy(true);
setStudyTitle("DDE Bollinger");
setShowCursorLabel(false);
}
function main() {
if (ddeUpper == null) {
var sName = "UpperBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
//debugPrintIn(sName);
ddeUpper = new DDEOutput(sName);
sName = "MiddleBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
//debugPrintIn(sName);
ddeMiddle = new DDEOutput(sName);
sName = "LowerBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
//debugPrintIn(sName);
ddeLower = new DDEOutput(sName);
}
if(vBollingerStudy == null) vBollingerStudy = new BollingerStudy(20, "Close", 2.0);
var Upper = study.getValue(BollingerStudy.UPPER);
var Middle = study.getValue(BollingerStudy.BASIS);
var Lower = study.getValue(BollingerStudy.LOWER);
if (vUpper !=null) ddeUpper.set(vUpper);
if (vMiddle !=null) ddeMiddle.set(vMiddle);
if (vLower !=null) ddeLower.set(vUpper);
return;
}
Comment
-
stulgis
There are a couple of syntax errors in the code you posted (these can also be found using the syntax checker).
One is that you used study.getValue(BollingerStudy...) instead of vBollingerStudy(BollingerStudy...). Another is that you added a v to vUpper, vLower, etc but when you declared those variables you named them Upper, Lower, etc.
Once you fix these errors the script should work fine
Alex
Comment
-
Thanks for the help, next time I'll make sure to use that syntax check before I try and run anything. When I made those changes it ran fine on Esignal, but then when I went to pull up one of the values in Excel it always gave me a value of 0 for the upper, lower and basis. I typed it into Excel like:
=eSignal|EFS!UpperBollingerABC3
I was using a 3 minute chart of ABC so I think that was the correc thing to type into Excel. I'll post the corrected code here for you to see, so if you can let me know if I'm doing anything wrong with Excel I'd appreciate it. thanks!
PHP Code:var ddeUpper = null;
var ddeMiddle = null;
var ddeLower = null;
var vBollingerStudy = null;
function preMain() {
setPriceStudy(true);
setStudyTitle("DDE Bollinger");
setShowCursorLabel(false);
}
function main() {
if (ddeUpper == null) {
var sName = "UpperBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
//debugPrintIn(sName);
ddeUpper = new DDEOutput(sName);
sName = "MiddleBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
//debugPrintIn(sName);
ddeMiddle = new DDEOutput(sName);
sName = "LowerBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
//debugPrintIn(sName);
ddeLower = new DDEOutput(sName);
}
if(vBollingerStudy == null) vBollingerStudy = new BollingerStudy(20, "Close", 2.0);
var Upper = vBollingerStudy(BollingerStudy.UPPER);
var Middle = vBollingerStudy(BollingerStudy.BASIS);
var Lower = vBollingerStudy(BollingerStudy.LOWER);
if (Upper !=null) ddeUpper.set(vUpper);
if (Middle !=null) ddeMiddle.set(vMiddle);
if (Lower !=null) ddeLower.set(vUpper);
return;
}
Comment
-
So now is the only code I need to change the part near the very end? I changed the last part so when it said:
ddeUpper.set(vUpper) I changed it to ddeUpper(vUpper)
Is this correct? I'll post the new code that I tried. When I ran it in Excel I still got values of zero for everything. Thanks again for your help!
var ddeUpper = null;
var ddeMiddle = null;
var ddeLower = null;
var vBollingerStudy = null;
function preMain() {
setPriceStudy(true);
setStudyTitle("DDE Bollinger");
setShowCursorLabel(false);
}
function main() {
if (ddeUpper == null) {
var sName = "UpperBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
//debugPrintIn(sName);
ddeUpper = new DDEOutput(sName);
sName = "MiddleBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
//debugPrintIn(sName);
ddeMiddle = new DDEOutput(sName);
sName = "LowerBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
//debugPrintIn(sName);
ddeLower = new DDEOutput(sName);
}
if(vBollingerStudy == null) vBollingerStudy = new BollingerStudy(20, "Close", 2.0);
var Upper = vBollingerStudy(BollingerStudy.UPPER);
var Middle = vBollingerStudy(BollingerStudy.BASIS);
var Lower = vBollingerStudy(BollingerStudy.LOWER);
if (Upper !=null) ddeUpper(vUpper);
if (Middle !=null) ddeMiddle(vMiddle);
if (Lower !=null) ddeLower(vLower);
return;
}
Comment
-
Thanks, I changed those three lines to:
if (Upper !=null) ddeUpper.set(Upper);
if (Middle !=null) ddeMiddle.set(Middle);
if (Lower !=null) ddeLower.set(Lower);
I still get the same result though with everything showing up as 0 in Excel. Here is the entire code again and thanks for the help, I've been working at this for a few days and really appreciate it.
PHP Code:var ddeUpper = null;
var ddeMiddle = null;
var ddeLower = null;
var vBollingerStudy = null;
function preMain() {
setPriceStudy(true);
setStudyTitle("DDE Bollinger");
setShowCursorLabel(false);
}
function main() {
if (ddeUpper == null) {
var sName = "UpperBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
//debugPrintIn(sName);
ddeUpper = new DDEOutput(sName);
sName = "MiddleBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
//debugPrintIn(sName);
ddeMiddle = new DDEOutput(sName);
sName = "LowerBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
//debugPrintIn(sName);
ddeLower = new DDEOutput(sName);
}
if(vBollingerStudy == null) vBollingerStudy = new BollingerStudy(20, "Close", 2.0);
var Upper = vBollingerStudy(BollingerStudy.UPPER);
var Middle = vBollingerStudy(BollingerStudy.BASIS);
var Lower = vBollingerStudy(BollingerStudy.LOWER);
if (Upper !=null) ddeUpper.set(Upper);
if (Middle !=null) ddeMiddle.set(Middle);
if (Lower !=null) ddeLower.set(Lower);
return;
}
Comment
-
jstulgis
The reason it is returning 0 is due to an error I introduced when suggesting one of the initial fixes.
var Upper = vBollingerStudy(BollingerStudy.UPPER); should be var Upper = vBollingerStudy.getValue(BollingerStudy.UPPER); The same applies to the two lines that follow.
Alex
Comment
-
jstulgis
You are most welcome.
As an aside you could simplify the following section of your code (shown here without all the debugPrintln())
PHP Code:if (ddeUpper == null) {
var sName = "UpperBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
ddeUpper = new DDEOutput(sName);
sName = "MiddleBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
ddeMiddle = new DDEOutput(sName);
sName = "LowerBollinger" + getSymbol() + getInterval();
sName = sName.replace(" ","_");
ddeLower = new DDEOutput(sName);
}
PHP Code:if (ddeUpper == null) {
var sName = getSymbol() + getInterval();
sName = sName.replace(" ","_");
ddeUpper = new DDEOutput("UpperBollinger"+sName);
ddeMiddle = new DDEOutput("MiddleBollinger"+sName);
ddeLower = new DDEOutput("LowerBollinger"+sName);
}
Alex
Comment
Comment