Hi Nicolas
I am interested in trend-following the DAX on IG using PRC using a 5 minute timeframe using couple moving averages.
My main issue is that on PRT it goes to 5 decimal places when a MA value is displayed. Hence a cross-over is activated even if one MA value is just say 0.1
For example on the DAX you often get, what I call a ‘touch/kiss’ of moving averages, so technically a cross-over has occurred, but at a level in my opinion, of <0.5 is irrelevant: I would not want to exit this trade, I would want to stay in, till the next 5 minute candle has finished. That candle may indeed confirm that I do have to exit that trade and open a new trade but also often, the trade carries on in the same direction. The result here is that we do not have to exit and then re-enter the trade, which can cost us quite a bit sometimes. I need the code to reflect this difference of at least 0.5 before we exit that trade and re-enter a new one. I have actually attached a picture of a DAX screenshot (red arrow) of a typical MA ‘touch/kiss’ on November 14th, these happen at least 3 times per week on a 5 min chart. The majority of these are ‘false’ cross-overs i.e. the trade is still going in your desired direction, but the PRC would activate and you’d have to exit and then re-enter, so costing you points.
I really do hope you can help !
OSCARDAX / UK
// --- settings
amount = 1 //amount of lots/shares/contracts for each order
fastEMAperiod = 5 //fast EMA period
slowEMAperiod = 20 // slow EMA period
starthour = 070000 //start hour for trading (hhmmss format)
endhour = 210000 //end hour for trading (hhmmss format)
preOpenMaxDistance = 35 //previous starthour distance in points to initiate the 'starthour' trade or not
overnight = 1 //keep overnight orders or close them at "endhour" (1=true / 0=false)
// --- end of settings
//indicators
fast = exponentialaverage[fastEMAperiod](close)
slow = exponentialaverage[slowEMAperiod](close)
//trading conditions
bull = fast crosses over slow
bear = fast crosses under slow
//distance from last cross
if bull then
lastcross=1
crossprice=close
maxdistance=0
endif
if bear then
lastcross=-1
crossprice=close
maxdistance=0
endif
if lastcross=1 then
maxdistance=max(high-crossprice,maxdistance)
endif
if lastcross=-1 then
maxdistance=max(crossprice-low,maxdistance)
endif
//starthour trade
if time=starthour and maxdistance<preOpenMaxDistance*pointsize then
if lastcross=1 and not longonmarket then
buy amount contract at market
endif
if lastcross=-1 and not shortonmarket then
sellshort amount contract at market
endif
endif
//next orders
if time>starthour and time<endhour then
if bull then
buy amount contract at market
endif
if bear then
sellshort amount contract at market
endif
endif
//overnight orders or not?
if onmarket and overnight=0 and time>=endhour then
sell at market
exitshort at market
endif
//graph maxdistance
LeoParticipant
Veteran
you can use a bollinger band with a very narrow width betwwen bands.
Thanks for that but I want to keep it as simple as possible, once you start adding indicators there is no end to it really.
One possibility is to take the high of the candle (or low for short) when the cross over takes place as the trigger.
When the croosing happens you can decide to ignore it, till the next event, if the difference between the two MAs is less than “n” pips!
Roberto
Hi Roberto,
Thanks for your comment, but I want the rule to be based upon the difference between the moving averages themselves and not the actual price / pips. The reason I say this is that often you will get a price ‘spurt’ up or down within a certain timeframe but that is strictly that, a temporary phenomenon, the price then carries on doing what it was doing. I think the worse thing is that you exit because of say ‘n pips crossover’ and guess what….the actual MA itself – because its an average – stays in the same position. You have now exited the trade because of a price jump, but the MA is still in the same direction ! the psychological impact on you as a MACO trader will not be good, you’ll be kicking yourself. IMHO me personally, I have to stick to the core principle and that’s the average price and not the actual.
As always in trading we need to think of our mindsets and not just the outcome itself….
OSCARDAX
Please try with this modified code and give feedbacks here:
// --- settings
amount = 1 //amount of lots/shares/contracts for each order
fastEMAperiod = 5 //fast EMA period
slowEMAperiod = 20 // slow EMA period
starthour = 070000 //start hour for trading (hhmmss format)
endhour = 210000 //end hour for trading (hhmmss format)
preOpenMaxDistance = 35 //previous starthour distance in points to initiate the 'starthour' trade or not
overnight = 1 //keep overnight orders or close them at "endhour" (1=true / 0=false)
// --- end of settings
//indicators
fast = exponentialaverage[fastEMAperiod](close)
slow = exponentialaverage[slowEMAperiod](close)
//trading conditions
bull = fast crosses over slow
bear = fast crosses under slow
//orders exit management
if longonmarket and bear and slow-fast>0.5*pointsize then
sell at market
endif
if shortonmarket and bull and fast-slow>0.5*pointsize then
exitshort at market
endif
//distance from last cross
if bull then
lastcross=1
crossprice=close
maxdistance=0
endif
if bear then
lastcross=-1
crossprice=close
maxdistance=0
endif
if lastcross=1 then
maxdistance=max(high-crossprice,maxdistance)
endif
if lastcross=-1 then
maxdistance=max(crossprice-low,maxdistance)
endif
//starthour trade
if time=starthour and maxdistance<preOpenMaxDistance*pointsize then
if lastcross=1 and not onmarket then
buy amount contract at market
endif
if lastcross=-1 and not onmarket then
sellshort amount contract at market
endif
endif
//next orders
if time>starthour and time<endhour and not onmarket then
if bull then
buy amount contract at market
endif
if bear then
sellshort amount contract at market
endif
endif
//overnight orders or not?
if onmarket and overnight=0 and time>=endhour then
sell at market
exitshort at market
endif
Before entering a new trade, the code checks if we are actually on market or not. At the beginning of the code, orders are closed accordingly to the 0.5 points MA differences if a new MA cross over/under has occurred.
Hi Roberto, Thanks for your comment, but I want the rule to be based upon the difference between the moving averages themselves and not the actual price / pips. The reason I say this is that often you will get a price ‘spurt’ up or down within a certain timeframe but that is strictly that, a temporary phenomenon, the price then carries on doing what it was doing. I think the worse thing is that you exit because of say ‘n pips crossover’ and guess what….the actual MA itself – because its an average – stays in the same position. You have now exited the trade because of a price jump, but the MA is still in the same direction ! the psychological impact on you as a MACO trader will not be good, you’ll be kicking yourself. IMHO me personally, I have to stick to the core principle and that’s the average price and not the actual. As always in trading we need to think of our mindsets and not just the outcome itself…. OSCARDAX
Moving averages by themselves DON’T exist. They always represent price. If, at the closing of a bar, average[10] is 12300 and average[20] is 12295 the difference can only be measured using price or pips (they are the same thing, only expressed in different ways).