complete Moving Average Cross Over function
Posted: Apr 06 2014
Hi all,
tpyicall the condition to detect a cross over event looks like this:
or so:
I used the first version.
My goal is to create only 1 order directly after a cross over event occurrs.
And a certain time frame shall be used. For example five minute bars shall be used for the calculation of the moving averages.
Without further precautions this code snippet will not work in the following cases:
I encountered the problem that in the cases above var[0] and var[1] must not be subsequent in time and could be separated by 1 hour or any other gap
So I wonder how a complete function could look like, which ensures that only close bars of the intended time frame are used and that always two subsequent bars are used without a gap or the last data from the day before.
my idea is:
Or should instead crosses over be used ?
Are all conditions above covered by 'crosses over'?
Any help on this will be appreciated.
tpyicall the condition to detect a cross over event looks like this:
Code: Select all
MA9 = XAverage( Price5, 9) ;
MA13 = XAverage( Price5, 13) ;
MA9_Shows_Up = MA9 > MA13;
MA5_Penetrated_Up = CurrentBar > 1 and MA9_Shows_Up and (MA9_Shows_Up[1] = false);
Code: Select all
inputs:
Price( Close ),
variables:
var0( 0 ) ;
var0 = XAverage( Price, 9) ;
condition1 = Price > var0 and var0 > var0[1] and var0[1] <= var0[2] ;
My goal is to create only 1 order directly after a cross over event occurrs.
And a certain time frame shall be used. For example five minute bars shall be used for the calculation of the moving averages.
Without further precautions this code snippet will not work in the following cases:
- 1) intraday system shall only buy/sell during certain hours
- 2) the system is started after the market opening time, e.g. 11.00 CET
- 3) a gap of the market data occurs, eg. due to a problem of the internet provider
- 4) options in Strategy properties: Recalculate on Broker Events Signal like Market Position Change or Order Filled
- 5)IOG on and/or Bar Magifier enabled
Code: Select all
if time >= SessionStartTime( 0, 1 ) and time < SessionEndTime( 0, 1 ) then
RegularMarketHours = true;
So I wonder how a complete function could look like, which ensures that only close bars of the intended time frame are used and that always two subsequent bars are used without a gap or the last data from the day before.
my idea is:
Code: Select all
inputs:
Price( Close ),
variables:
MA9 = XAverage( Price, 9) ;
MA13 = XAverage( Price, 13) ;
StartTime (0830);
if BarStatus(1)[0] = 2 and BarStatus(1)[1] = 2 and (CurrentBar - CurrentBar[1] =1 ) and (Time <> StartTime) Then
condition1 = MA9 > MA13 and MA9[1] <= MA13[1] ;
Code: Select all
condition1 = var0 crosses over var1 ;
Any help on this will be appreciated.