When an EFS study gets loaded into the chart at startup, or when I manually reload them, a tradesignal gets sent to a DLL I have loaded into the study when there shouldn't be a tradesignal. Is there a reason the study does this and what can I do to prevent this?
Announcement
Collapse
No announcement yet.
Tradesignal at startup when there shouldn't be one
Collapse
X
-
I'm using setComputeOnClose(true) and when I do this;
if(getCurrentBarIndex()==-1) {
tradesignal
}
I get a tradesignal at startup and when I reload the strategy. But when I use setComputeOnClose(true) and this;
if(getCurrentBarIndex()==0)
tradesignal
}
I don't get a tradesignal at startup or reload. Is this the way it's supposed to be?
Comment
-
This is the way I configured it:
preMain();
setComputeOnClose(true);
main()
condition is true
if(getCurrentBarIndex()==-1(){
tradesignal
}
I get a sound alert at startup but no tradesignal sent to the DLL.
Before, when I didn't have the if(getCurrentBarIndex()==-1() in the code, I got a tradesignal sent to the DLL at startup but no sound alert. That's weird, but I did it the way you said Alexis and it's working good right now. Thanks for the help.
Comment
-
kimosabe
Glad to hear that it is working now.
The reason why if(getCurrentBarIndex()==0) will not trigger any events with setComputeOnClose() is that bar index 0 is never processed. The most current bar being processed in that case is bar index -1.
As to the alerts if you do not want them to trigger while the efs is being loaded then include them inside the if(getCurrentBarIndex()==0) statement (or -1 if using setComputeOnClose())
Alex
Comment
-
I'm still having a problem with tradesignals on initial startup. This is what I have:
preMain();
setComputeOnClose(true);
main()
if(condition is true){
if(getCurrentBarIndex()==-1){
audio alert
tradesignal to DLL
}
}
When I first start the program I get a tradesignal to DLL and audio alert. Afterward when I reload the study, I just get an audio alert. I knew this was strange that I got the audio alert but not the tradesignal on reload.
This is far from resolved since all configurations I try I still get the tradesignals on startup. The condition isn't really true at the bar at startup. It must read back to find the last true condition and send the signal. Any possible way to correct this?Last edited by kimosabe; 04-21-2005, 02:25 PM.
Comment
-
Possible Solution..
What sounds like is happening is...
your code is identifying a trading signal before it reaches the most recent bar.. Then, when it gets to the most recent bar, it fires off a trade signal that is not correct..
Here is what I would do to fix it...
PHP Code:preMain();
setComputeOnClose(true);
main()
if(getCurrentBarIndex()==-1){
if(condition is true for SELL signal){
audio alert
tradesignal to DLL SELL
}
if(condition is true for BUY signal){
audio alert
tradesignal to DLL BUY
}
}
If your code is more complex than this (*ie: setting triggers from past price bars and carrying those triggers to the current bar)... then we'll need to address these issues in a different manner.
BBrad Matheny
eSignal Solution Provider since 2000
Comment
-
oops - one more thing..
PHP Code:
// You probably need control variables to track the condition of your code.
var StrategyisLong = false;
var StrategyisShort = false;
preMain();
setComputeOnClose(true);
main()
//
if(getCurrentBarIndex()==-1){
if ((condition is true for SELL signal) && (!StrategyisShort)) {
audio alert
tradesignal to DLL SELL
StrategyisShort = true;
}
if(condition is true for BUY signal) && (!StrategyisLong)){
audio alert
tradesignal to DLL BUY
StrategyisLong = true;
}
}
This will prevent multiple trading signals..
BBrad Matheny
eSignal Solution Provider since 2000
Comment
-
I put in the code you have but it didn't solve the problem. I'm not getting multiple signals, just one. It happens when I first start my trading software and then esignal. If I start eSignal first and then my software I don't get the signal until I reload the study. The first time I reload there is both the DLL signal and audio but thereafter I just get the audio alert when the study is reloaded.
Comment
-
Ok, here is the code. It should give an audio alert every time you reload.
var fast = new MAStudy(1, 0, "Close", MAStudy.SIMPLE);
var slow = new MAStudy(55, 0, "Close", MAStudy.SIMPLE);
var condition1;
var condition2;
var condition3;
var condition4;
function preMain() {
setPriceStudy(true);
setStudyTitle("MA1Min");
setComputeOnClose(true);
}
function main() {
var f = fast.getValue(MAStudy.MA);
var s = slow.getValue(MAStudy.MA);
if(f == null || s == null)
return;
if(f > s && getMostRecentTrade() > s)
condition1 = 1;
if(f < s && getMostRecentTrade() < s)
condition2 = -1;
if(getCurrentBarIndex() == -1) {
if((condition1 == 1) && (condition4 == -1)) {
condition4 = 0;
Alert.playSound( "c:\\program files\\eSignal\\Sounds\\pow.wav" );
}
if((condition2 == -1) && (condition3 == 1) ) {
condition3 = 0;
Alert.playSound( "c:\\program files\\eSignal\\Sounds\\pow.wav" );
}
}
if(f > s && getMostRecentTrade() > s)
condition3 = 1;
if(f < s && getMostRecentTrade() < s )
condition4 = -1;
condition1 = 0;
condition2 = 0;
return new Array(f,s);
}
Last edited by kimosabe; 04-23-2005, 05:58 AM.
Comment
-
kimosabe
Actually it does not always do that. Sometimes it does and sometimes it does not depending on the state of the conditions at the time of reload.
Insert the following debug line right below the first conditional statement ie below if(getCurrentBarIndex()==-1)
PHP Code:debugPrintln("barIndex="+getCurrentBarIndex()+" cond1="+condition1+" cond2="+condition2+
" cond3="+condition3+" cond4="+condition4+" trade="+getMostRecentTrade()+" s="+s.toFixed(2)+
" long="+StrategyisLong+" short="+StrategyisShort);
In this first case upon reload the audio alert was triggered. Note in fact that the returned values match the conditions for the first set ie condition1 = 1 AND condition4 = -1 AND f > s (not shown because condition1 already includes that) AND getMostRecentTrade > s AND strategy false (or not true)
On this reload instead the alert was not triggered. The returned values in fact do not match either set of conditional statements because both conditions 1 AND 2 are 0.
So the alerts are being triggered correctly on the last processed bar as far as I can see.
Alex
Comment
-
Every time I reload this program I get an audio alert. First of all, looking at the formula output I can see it is reading condition3 and condition4 incorrectly.
if(f > s && getMostRecentTrade() > s)
condition3 = 1;
if(f < s && getMostRecentTrade() < s)
condition4 = -1;
At reload both these conditions can't be true but it's reading them both true every time. That's why it is giving the audio alert.
Comment
-
I think having 4 conditions was confusing the program so I simplified it to only have 2 conditions and it is working for now with no audio signals at reload. I will test it for a while and see how it works. Having use of the Formula Output window is very handy at debugging. Thanks for the help.
Comment
Comment