Hi everyone, I had a problem about result on strategy tester. The detail is like this, I want to create an EA using SAR indi. Since this is the first time I'm using indicator that is non-line indicator I tried a simple condition to show when SAR indi change it direction. So I use this code to achieve that:
In here I use both OnInit to show the alert function and OnTick for strategy tester.
The problem that I faced is when I used CheckOpenPosition() (shift 0) the strategy tester is somewhat broken (should return "buy signal" and "sell signal" continuously, log attached), but when I used CheckOpenPosition(1) (shift 1) strategy tester accept it and working properly (log attached). Is there anyone knows why using shift 0 would result in broken result but when using 1 shift before working perfectly?
Move variables preTime=0,curTime; to global scope.
If you put it on OnTick(), every time there is a new tick, the values of preTime and curTime will always be different, and newBar will always be true.
And as a result it will always return "buy signal" and "sell signal" continuously.
You are only checking the first tick of a new bar. It is unlikely to have changed.
that's the purpose of the code is to send buy signal when SAR indi change from above to under the price and vice versa. The time length of the two logs is the same. The problem is that the result for "sar shift 0 log" should be like the "sar shift 1 log" but it just print 3 signal and end it. What I don't understand is why "sar shift 1" is working fine while "sar shift 0" only print 3 signal and stop.
Move variables preTime=0,curTime; to global scope.
If you put it on OnTick(), every time there is a new tick, the values of preTime and curTime will always be different, and newBar will always be true.
And as a result it will always return "buy signal" and "sell signal" continuously.
The code for newBar is working like it should intended. if you see the log it is printing "buy signal" and "sell signal" when the indi change from above to under and vice versa. The problem that I facing is not about the signal return continuously but rather that with "sar shift 0" it only print 3 signal. The correct result for "sar shift 0" log should be similar with "sar shift 1" log with 30 minutes time difference.
in short, this code is working with SAR indi:
int CheckOpenPosition(int shift=0) { int result=0; if(sar(2)>Open[2] && sar(1)<Open[1]) result=1; if(sar(2)<Open[2] && sar(1)>Open[1]) result=2; return result;
while this code isn't:
int CheckOpenPosition(int shift=0) { int result=0; if(sar(1)>Open[1] && sar()<Open[0]) result=1; if(sar(1)<Open[1] && sar()>Open[0]) result=2; return result;
*the difference only in shift
I don't understand why the second code isn't working in strategy tester while using script it works fine.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone, I had a problem about result on strategy tester. The detail is like this, I want to create an EA using SAR indi. Since this is the first time I'm using indicator that is non-line indicator I tried a simple condition to show when SAR indi change it direction. So I use this code to achieve that:
In here I use both OnInit to show the alert function and OnTick for strategy tester.
The problem that I faced is when I used CheckOpenPosition() (shift 0) the strategy tester is somewhat broken (should return "buy signal" and "sell signal" continuously, log attached), but when I used CheckOpenPosition(1) (shift 1) strategy tester accept it and working properly (log attached). Is there anyone knows why using shift 0 would result in broken result but when using 1 shift before working perfectly?