Could someone please advise me here?
I am developing a crossover type of trading system using aligning (< < or >>) HullAverage indicators for long and short triggers. The system performs well in BT, but I need to convert it for testing on the AUTO demo system. (It either triggers on every candle, or not at all)
This system is designed to trade intraday swings on the EUR/USD 1-Min bars. At each new bar, I press BT and only follow the direction of the two HullAverage indicators when they both align with each other – either up (long trigger) or down (short trigger).
I have attached a very shortened version of this system here, because it contains a few hundred lines of code due to its multiple variables. I inserted both the BT version and the corresponding AUTO format on the same page to make it easier for you to compare the two systems.
I would greatly appreciate someone having a look at this code in case you can see something wrong with it.
Thanking you!
8ficusst – One place you are going wrong is by not giving your topic a meaningful title!
- Give your topic a meaningful title. Describe your question or your subject in your title. Do not use meaningless titles such as ‘Coding Help Needed’.
I changed your title to something that describes your topic.
I posted the code as Roberto asked so then the coding wizards can readily spot any problems without having to download the .itf file.
defparam cumulateorders = false
defparam preloadbars = 1000
// a and b variables: 300-350-50
// c and d variables: 180-200-20
MA1=HullAverage[c](momentum[a](close))
MA2=HullAverage[d](momentum[a](close))
S = MA1 < MA2
MA3=HullAverage[c](momentum[b](close))
MA4=HullAverage[d](momentum[b](close))
L = MA3 > MA4
if S and NOT L then
sellshort at close stop
endif
if L and NOT S then
buy at close stop
endif
GRAPH MA1 COLOURED (255,195,77) AS "Hullone"// orange
GRAPH MA2 COLOURED (102,179,255) AS "Hulltwo"// blue
GRAPH MA3 COLOURED (255,195,77) AS "Hullthree"// orange
GRAPH MA4 COLOURED (102,179,255) AS "Hullfour"// blue
// Below is my AUTO TRADING coding attempt for the above
//////// SHORTS ///////////////////////
AnyOfTheShorts = S1 or S2 or S3 or S4
OpposingShorts = (h1 > h2) or (h3 > h4) or (h5 > h6) or (h7 > h8)
h1=HullAverage[900](momentum[300](close))
h2=HullAverage[950](momentum[300](close))
S1 = (h1 < h2)
h3=HullAverage[950](momentum[300](close))
h4=HullAverage[900](momentum[300](close))
S2 = (h3 < h4)
h5=HullAverage[900](momentum[350](close))
h6=HullAverage[950](momentum[350](close))
S3 = (h5 < h6)
h7=HullAverage[950](momentum[350](close))
h8=HullAverage[900](momentum[350](close))
S4 = (h7 < h8)
//////// LONGS ///////////////////////
AnyOfTheLongs = L1 or L2 or L3 or L4
OpposingLongs = (k1 < k2) or (k3 < k4) or (k5 < k6) or (k7 < k8)
k1=HullAverage[900](momentum[300](close))
k2=HullAverage[950](momentum[300](close))
L1 = (k1 > k2)
k3=HullAverage[950](momentum[300](close))
k4=HullAverage[900](momentum[300](close))
L2 = (k3 > k4)
k5=HullAverage[900](momentum[350](close))
k6=HullAverage[950](momentum[350](close))
L3 = (k5 > k6)
k7=HullAverage[950](momentum[350](close))
k8=HullAverage[900](momentum[350](close))
L4 = (k7 > k8)
//////// SHORTS ///////////////////////
if AnyOfTheShorts and OpposingLongs then
sellshort at close stop
endif
//////// LONGS ///////////////////////
if AnyOfTheLongs and OpposingShorts then
buy at close stop
endif
Hi Robertogozzi
Thanks for your reply – please find the code attached here.
Thanks Gra
My apologies. I was not sure.
Correction
Line 5 note should read: // c and d variables: 900-950-50
Apologies.
Does adding not onmarket as below sort your problem?
//////// SHORTS ///////////////////////
if not onmarket and AnyOfTheShorts and OpposingLongs then
sellshort at close stop
endif
//////// LONGS ///////////////////////
if not onmarket and AnyOfTheLongs and OpposingShorts then
buy at close stop
endif
GraHa – the “if NOT ONMARKET” instruction would be OK for the first trade when it is not yet onmarket, but thereafter the code itself keeps it always on market (it never exits – it just changes from shorts to longs, or vice versa), therefore the “if NOT ONMARKET” instruction would surely prevent it from being able to trigger another trade? Please correct me if my thinking is wrong about this?
Thanks, I am trying it out with NOT ONMARKET just in case it will solve the problem.
Will let you know the outcome.
Gra, no luck with NOT ONMARKET……. it only allows one trade and wont trigger after that.
Maybe someone else has an idea to get it operating like the BT does?
Did you try below …
if not shortonmarket and AnyOfTheShorts and OpposingLongs then
sellshort at close stop
endif
//////// LONGS ///////////////////////
if not longonmarket and AnyOfTheLongs and OpposingShorts then
buy at close stop
endif
Anyway, why can’t / don’t you trade your backtest version … it contains Buy and Sellshort and you say it is the same as the Auto version??
In fact why don’t you throw it all in together and get attached!? 🙂
Weird … PRT isn’t even stopping it working in ProOrder due to GRAPH in the code … I inadvertently left it in??