Hello.
I have been trying to get this working for some time now but to no avail. Tried this on various Indices with various time frames but still does not work.
I logged a ticket with IG/PRTG but they don’t have an answer as well.
Hope any of you can help with this please.
Only thing I can think of why the code does not trigger at the right time is because I use MA ZeroLagExponential (-2) Horizontal shift and MA ZeroLagExponential (in general)
Anyway… that’s just a thought…
The idea is to have an Indicator and/or if possible a strategy using the parameters below.
Indicators used:
MA20 Zero Lag Exponential (Horizontal shift -2)
MA50 Zero Lag Exponential (Horizontal shift 0)
Strategy:
Buy when MA20(-2) crosser over MA50 AND MACD Line > MACD Signal
Sell when MA20(-2) crosser under MA50 AND MACD Line < MACD Signal
Indicator:
Draw arrow with txt when these occurs.
Thank you.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = Average[20](totalPrice)
indicator2 = Average[50](totalPrice)
c1 = (indicator1 CROSSES OVER indicator2)
indicator3 = MACDline[12,26,9](close)
indicator4 = ExponentialAverage[9](MACDline[12,26,9](close))
c2 = (indicator3 > indicator4)
IF c1 AND c2 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 10
SET TARGET pPROFIT 1
IF ExponentialAverage[20](close) CROSSES OVER ExponentialAverage[50](close) THEN
DRAWTEXT("20 > 50", barindex, high, Dialog, Bold, 12) COLOURED(255,10,10,255)
endif
The main code uses SMA’s while the last three lines posted use EMA’s.
Yes, there’s no shift coded in your strategy.
Shifting cannot be coded automatically.
What do you mean by shifted -2, that the current bar needs to use data from two bars ago (there’s no other shifting possible)?
Robert.
Yes there are differences in the code published. Error on my side.
I changed the code to use “ExponentialAverage” in all lines. Still the same results.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = ExponentialAverage[20](totalPrice)
indicator2 = ExponentialAverage[50](totalPrice)
c1 = (indicator1 CROSSES OVER indicator2)
indicator3 = MACDline[12,26,9](close)
indicator4 = ExponentialAverage[9](MACDline[12,26,9](close))
c2 = (indicator3 > indicator4)
IF c1 AND c2 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 10
SET TARGET pPROFIT 1
Robert.
To answer your question “What do you mean by shifted -2, that the current bar needs to use data from two bars ago (there’s no other shifting possible)?”
I set the horizontal shift to ‘-2’. Yes that changes it to 2 two bars ago.
My thought is the code should read when the line crosses no matter the horizontal shit. Or do I want what’s not possible?
Thank you.
The EMA20 from 2 bars ago is:
indicator1 = ExponentialAverage[20](totalPrice)[2]
Nicolas.
indicator1 = ExponentialAverage[20](totalPrice)[2]
Now I get more accurate results but it does not seem to work all the time but there are still times when the code activates the indicator and/or buy signal when conditions are not met.
Thank you.
Topic moved to ProOrder support (Vonasi spotted the incorrect support forum).