DaveParticipant
Senior
Hi Robert123/nicolas,
Is it then possible to place an order if the MA has changed colour?
Dave
@Dave
Yes of course, because there are conditions that make the curve change its colour, so you’ll use these conditions values instead of the colour changing itself.
In my example in this post, I use 2 conditions named “bullish” and “bearish”, you have to define them first, what is your definition of a bullish trend that make change the color of the curve?
DaveParticipant
Senior
My thought were around it placing a small order each time the MA changes colour/direction in agreement with that of a slower MA.
Ok, but what cause the moving average to change its colour? 🙂
DaveParticipant
Senior
Nicolas, apologies for the delay, Moving average changes colour because average price of ‘x’ periods is increasing (bullish) as each candle candle forms.
FYI, I moved your request to a fresh new topic in the appropriate part of the forum.
So, about your trading strategy, it can be coded like this (bullish side only):
X = 10 //moving average period
takeprofit = 30 //takeprofit in points
stoploss = 60 //stoploss in points
ma = average[X](close)
// the moving average is changing direction from bearish to bullish
bullish = ma>ma[1] and ma[1]<ma[2]
if not longonmarket and bullish then
buy 1 share at market
endif
set target pprofit takeprofit
set stop ploss stoploss
With this code, the trade is not closed with a bearish signal (from green to red), but only with takeprofit or stoploss. But this is a good start to improve the strategy.
DaveParticipant
Senior
Thanks Nicolas, I will do my best to apply it to a couple of ideas I have when I’m back at my desk.
Dave
DaveParticipant
Senior
I dropped it on todays dax 15 chart and it took four nice trades (sl/tp reduced to 20 to see more triggers) ,could you clarify simply what line 8 means (I’m still only at ‘assisted creation’ level in logic terms!! 🙂 ), is this the reason the order is placed on the third candle after the ma has changed colour or does the indicator paint this back as it calculates?.
regards
Dave
The line 8 is the signal condition that trigger a long trade. Trades are opened at the open of the next candle that found the pattern.
DaveParticipant
Senior
It’s the braketed ma[1]& [2] part I’m struggling with?
It refers to the moving average ‘MA’ variable defined at line 5 and offset back with 1 or 2 candlesticks before the current one.
DaveParticipant
Senior
Thanks Nicolas, that’s what I guessed it was. Your patience is much appreciated.
DaveParticipant
Senior
Ok Nicolas, So if I understand correctly the line says bullish = ma greater than 1 period back and ma 1 period back is less than 2 periods back because at that point it was decreasing or bearish?.
You know where I’m going with this my friend, So if the ma was bullish turning bearish the the code should read :-
bearish = ma<ma[1] and ma[1]>ma[2]
Yes, this is the correct syntax for a new bearish reversal. Well done 🙂
DaveParticipant
Senior
OK, so here is a simple complete program with buy and sell conditions.It simply looks for a fast ma above a slow ma and places an order when the fast ma changes direction in agreement with slow ma.any ideas on improvements/filters/ma combinations etc most welcome.
dave
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
DEFPARAM FLATBEFORE = 080000
DEFPARAM FLATAFTER = 180000
takeprofit = 5 //takeprofit in points
stoploss = 10 //stoploss in points
fastma = ExponentialAverage[11](close)
slowma = ExponentialAverage[89](close)
//fastma bullish and bearish conditions
fastbullish = fastma>fastma[1] and fastma[1]<fastma[2] and fastma>slowma
fastbearish = fastma<fastma[1] and fastma[1]>fastma[2] and fastma<slowma
//conditions for long = fast ma ABOVE slow ma and turning in agreement with slow ma trend
if not longonmarket and fastbullish then
buy 1 share at market
endif
//conditions for short = fast ma BELOW slow ma and in agreement with slow ma trend
if not shortonmarket and fastbearish then
sellshort 1 share at market
endif
set target pprofit takeprofit
set stop ploss stoploss
//set stop ptrailing 12