// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = MACDline[37,77,9](close)
indicator2 = MACDSignal[37,77,9](close)
c1 = (indicator1 CROSSES OVER indicator2)
indicator3 = RSI[14](close)
c2 = (indicator3 <= 55)
indicator4 = MACDSignal[37,77,9](close)
indicator5 = MACD[37,77,9](close)
c3 = (indicator4 < indicator5)
indicator6 = MACDline[37,77,9](close)
indicator7 = MACD[37,77,9](close)
c4 = (indicator6 < indicator7)
IF c1 AND c2 AND c3 AND c4 THEN
BUY 10 SHARES AT MARKET
ENDIF
// Conditions to enter short positions
indicator8 = MACDSignal[37,77,9](close)
indicator9 = MACDline[37,77,9](close)
c5 = (indicator8 CROSSES OVER indicator9)
indicator10 = RSI[14](close)
c6 = (indicator10 >= 45)
indicator11 = MACDSignal[37,77,9](close)
indicator12 = MACD[37,77,9](close)
c7 = (indicator11 > indicator12)
indicator13 = MACDline[37,77,9](close)
indicator14 = MACD[37,77,9](close)
c8 = (indicator13 > indicator14)
IF c5 AND c6 AND c7 AND c8 THEN
SELLSHORT 10 SHARES AT MARKET
ENDIF
// Stops and targets
SET STOP pTRAILING 20
SET TARGET pPROFIT 60
Hello,
This is my first time posting here and I am slowly getting to grips with the world of coding. I used the simple programming option to create an algorithm that uses the MACD and have had some good results depending on the timeframe; currently I’, on a 10 minute on the S&P 500. I have since read that there are alternatives to the standard MACD and would like to see whether anyone would be able to help me modify the code to use the Zero Lag MACD. I would also be more than grateful for any other suggestions or changes that I should try to implement.
Thank you
Well done ErrorCodeT !
Try your code on DJI 3 min TF over 10K bars using SL and TP with separate values for Buy and SellShort.
Hello, thank you for the suggestion. I’ll try out DJI as soon as I’m home and on the laptop.
In regards for separate SL and TP for buy and sell short, how would you code this please?
As below, where A19 and A20 are variable values to be optimised as min = 0.1 max = 1 step = 0.1 .
Do same fo SellShort.
IF c1 AND c2 AND c3 AND c4 THEN
BUY 1 SHARES AT MARKET
SET STOP %LOSS A19
SET TARGET %PROFIT A20
ENDIF
I could attach my version, but you will be more chuffed if you do it yourself?
Thank you, I’ll get on with finding out about optimisation. I presume the optimisation function will find the best combination.
I certainly would be more chuffed if I did it myself but equally grateful for your version too.
I assumed you had used the Optimiser to arrive at these values MACDline[37,77,9](close) as these are not standard MACD parameters.
Do below (as you won’t need them) when you follow my example (with % SL and % TP) in previous post.
//SET STOP pTRAILING 20
//SET TARGET pPROFIT 60
It was a code I got from a friend that used these values, it proved good results and I thought I’d modify it with short trades as well.
Do you know if can just type ZeroLagMACD to use that indicator instead of the current lines?
ZeroLagMACD is not a standard / default PRT Indicator and so you would need to …
- Include code for MACDZeroLag into the strategy (easiest way maybe).
OR
- Add the MACDZeroLag as an Indicator to your Platform and then you would need to ‘call’ the MACDZeroLag as below (more complex) …
MACDZL = CALL "MACDZeroLag"[12, 26, 9]
- Here is a link to the MACDZeroLag Indicator.
ZeroLag MACD
You have a lot of excitement to get through tonight when you get home!!?? 😉
The call of MACDZeroLag may need to be something like this …
myZeroLagMACD, mySignalMACD, myMyHistogram = CALL "MACDZeroLag"[12, 26, 9]
It be best to get familiar with the PRT default MACD and use of the Optimiser etc before getting too ambitious?
Classic, ‘Don’t run before you can walk.’
I used your (ErrorCodeT) code and tried to add the suggestions of GraHal. Looks good in the short perspective (10k bars @3min) but I find it hard to get a good equity curve over longer times..
I’ve also imported the file and can’t seem to get any trades executing. I must be doing something completely wrong as I’d be more than happy with the above results.
lnskrlssn .itf file has position size set at 0.2 at Line 12. This works for backtest on Demo Account (I think? ) but for backtesting on Live Account position size min = 1.
Ah my bad, IGs minimum for DOW in Sweden is 0.2 but I think that its higher in other countries, at least for you guys in UK.