DAKParticipant
Average
Hi everyone,
I would need some help for a little code.
I am trying to code the following strategy :
- Wait for EMA 5 AND EMA 10 to cross but don’t enter
- After a certain number of bars, if EMA 5 is still above EMA 10 then you can enter the market
The number of bars to wait is issued from a third indicator and this value is changing over time.
I tried but didn’t manage to code properly this strategy. Any help would be very appreciated. If it really works I will publish it.
Many thanks.
// Indicators
ind1 = ExponentialAverage[5](close)
ind2 = ExponentialAverage[10](close)
ind3 = customvalue
// IF ind1 CROSSES OVER ind2 THEN BUY AFTER "customvalue" number of bars IF ind1 still > ind2
Try this one (I didn ‘t):
DEFPARAM CumulateOrders = False
ONCE NumberOfBars = 0 //Initial value
IF OnMarket OR (ExponentialAverage[5] CROSSES UNDER ExponentialAverage[10]) THEN//Reset counter to ZERO
NumberOfBars = 0 // while trade is open OR
ENDIF // Ema's cross the other way round
IF NumberOfBars THEN //If previously CROSSED, add
NumberOfBars = NumberOfBars + 1 // add 1 at each bar
ENDIF
IF ExponentialAverage[5] CROSSES OVER ExponentialAverage[10] THEN
NumberOfBars = 1 //Start counting after crossing up
ENDIF
IF NumberOfBars >= your_indicator_value THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
DAKParticipant
Average
Thanks very much it works like a charm !