iMA: What's the difference between shift and ma_shift???

 

I'm using iMA to create a crossover (of course!).

I'm trying to understand the difference between the parameters shift and ma_shift. Obviously, I'm trying to find out the current MA and then one for the previous period of whatever the chart time is. It *looks* like I can use 0 for shift and only modify ma_shift but I've seen some code that modifies both.

Can someone please clarify if ma_shift=1 is the current period and ma_shift=2 is the previous period? Can I just leave shift at 0???

 

Shift is which bar the calculation is being performed upon. You should generally perfrom the calculation for each bar at least once.

ma_shift moves the resulting line into the future or the past, imagine grabbing the MA line on the chart and moving it left or right.

 
If that's right, then that means that my earlier statement was incorrect. ma_shift should always be 0 (present time) and then I should use shift=0 for my current MA and shift=-1 for my previous MA. Does that sound right?
 
The current bar is bar 0. Bars are numbered 1 2 3 4 5 6 7 as you go back in time on the chart.
 

In the strategy tester I am looking for a way to get the price of an instrument in the future. E.g. I need to get the price of the next day.

I tried the following:

iOpen(Symbol(), PERIOD_D1, -1)

I had hoped that -1 would do it. But it always returns zero. Is this somehow possible?

Thank you!

 

LOL...is that all we have to do in order to predict future pricing? just use a shift value? Brilliant!

 

I don't want to predict the future ;)

Anybody knows why iOpen(Symbol(), PERIOD_D1, -1) does not work?

How can I achieve it?

 

Ah, you are dealing with issues of strategy tester, now I understand. You can't access price data in the future, even in strategy tester. The way to account for it would be to clear the stoploss on your order (set it to zero) prior to the gap (prior to friday close) and then after the market has gapped have your EA close the trade at the current price on that first tick of the market open.

 

Yes. You are right and that is exactly what I wanted to do. But in order to clear it I would first have to know that I have to clear it! Thats the circle.

I can't believe it. I can't be the only one who has this issue, can I?

 

If the timing of the gap is systematic, for example it happens on market open after the weekend, then it is simple to code for checking the time of day and day of week and setting the SL to zero before the market closes. If there is no weekend gap then there is no weekend gap, set your SL again and be on your way.

Strategy tester is a steaming pile, the people who don't know this probably also don't realize how badly it mishandles stoploss violations when the market gaps. The people who do know it also know how to program their EA to act more real-world-like within the virtual trading environment created by the strategy tester.

 

The gaps appear randomly.

I also tried to clear the s/l order just before it gets executed but it appears that strategy tester executes s/l orders even before jumping into the start() function.

Reason: