I have the robot (combination of SAR and MA), which is doing the following (attaching the code):
1. enter into position using MA crossover confirmed with SAR.
2. exit and enter the opposite direction whenever the signal changes (hence you always have one position opened).
However, the problem is that it's trading on the third bar after the signal triggers (not on the bar the signal triggers). For instance, please see the image example attached.
Thanks a lot Vladimir for your reply. I was trying to narrow down the issue and removed the SAR completely from the trading strategy, hence now it just performs the MA crossover (attaching the code):
1. MA crossover signal (open position if there is no opened position with the same direction already);
2. Exit if the signal changes the opposite direction and enter the new one.
I am attaching example from the backtest, where you can clearly see that the issue persist (and buy/sell happens consistently on the third bar after the signal triggers, while I would expect trade to happen at the time of the signal), hence the issue doesn't seem to be driven by SAR. I would appreciate if you can suggest.
I saw this: creating a handle ON EVERY TEAK.
After that I threw out this code.
Read the help! See examples from help! DO NOT CREATE AN INDICATOR HANDLE ON EACH TEAK !!! The indicator handle must be created ONCE (this is done in OnInit) !!!
Correct this gross mistake. Until you correct this gross mistake, I will not be able to help you with anything.
Added: do not use variables of type 'static' - it is forbidden for you (until you gain experience).
int indicator_handle, // indicator handle
int buffer_num, // indicator buffer number
int start_pos, // start position
int count, // amount to copy
double buffer // target array to copy
Please enable the necessary setting in your browser, otherwise you will not be able to log in.