JSParticipant
Senior
Hi
@Trader Sab
When I use your new code (Dow Jones, TF 5 min) it does exactly what it’s supposed to do:
He opens a long position when “Close Crosses Over indicator1”
He opens a short position when “Close Crosses Under indicator1”
The “Set Stop Trailing 10” works as it should.
The indicated times “FlatBefore / FlatAfter” also work well.
So, I don’t get random positions being opened?
The last comments about “C3 = True / 1” are based on a misunderstanding with GraHal.
GraHal tried to explain something completely different, namely the use of the “Graph” instruction.
Line 27 (with “True” or “1”) can be completely cancelled because line 29 already says “If c3 Then” and that is sufficient…
however I got a dismal result
It can happen, especially when using
– close crosses under / over averages – which are notorious for optimisation to quickly turn from profit to loss.
In my version code / .itf I posted … try optimising a variable for the EA period (in place of period = 20) and you will see what I mean.
Let us know how you get on?
@GraHal
Good morning. Thank you so much for your encouraging words and all the support. I like the optimization you have on the code to make profit and stops more dynamic.
I tested both system this morning again and got the results below. I added the DEFPARAM flatbefore / after back into your code which did not improve the result.
I think I have to test it a bit longer to see more results. Compared to the codes you write this very simple and if it is going to work I’d be cuffed. 🙂
@GraHal
Just to show you what I mean, the code opened a long position at 11 am, where the condition of crossing over EMA20 was not given. I have to specify more clearly the signal but I am not sure how.
BTW sorry for the gazillion attachments in the last post, not sure how this happened.
If you post the code you are analysing above then I will try it on my platform and we can compare
like with like.
@GraHal
I hope this works, not with the attachments. Thank you in advance for helping me out.
where the condition of crossing over EMA20 was not given
Your Buy entry condition (in EMA 20 SYSTEm DJI you posted) is NOT crossing over (as you say above); it is >= … see Line 8 below in your full code.
Also Set Stop Trailing 10 will never work on DJI … it will whipsaw you in and out of loads of trades and make an overall loss. Remove the TS for now, until you get the rest of the code understood / working.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
DEFPARAM FLATBEFORE = 083000
DEFPARAM FLATAFTER = 220000
// Conditions to enter long positions
indicator1 = ExponentialAverage[20](close)
c1 = (close >= indicator1[1])
IF c1 THEN
BUY 0.5 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
indicator2 = ExponentialAverage[20](close)
c2 = (close CROSSES UNDER indicator2[1])
IF c2 THEN
SELL AT MARKET
ENDIF
SET STOP TRAILING 10
// Conditions to enter short positions
indicator1 = ExponentialAverage[20](close)
c1 = (close <= indicator1[1])
IF c1 THEN
SELLSHORT 0.5 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
indicator2 = ExponentialAverage[20](close)
c2 = (close > indicator2)
IF c2 THEN
EXITSHORT AT MARKET
ENDIF
SET STOP TRAILING 10
Remove the TS for now
Or optimise the TS value using min = 25, max = 250, step = 25
Work to the premise that your code will be working correctly and functioning as the code is written.
Have you tried / understood what to do with GRAPH yet? It is a way to show under the equity curve and positions if and when the GRAPH conditions are met.
So if you enter GRAPH C1 (just that, nothing more) at the bottom of your code I posted above, then click on backtest, you wll see an extra display appear which shows value = 1 for all bars where c1 = (close >= indicator1[1]).