Hi Guys,
I need a little help with some code that I cant seem to get to work probably. I’m trying to detect if a cross of the highest function has occurred within the last 20 bars. Can you use the highest function in a for loop. I am heading towards a breakout system with a pullback.
I have tried the code as an indicator and I seem to get the right output but not in trading system.
Thanks Carter
defparam cumulateOrders = false
defparam PRELOADBARS =2000
b1 = 0
for i = 2 to 20 DO
i11 = highest[50](high)
if close[i] crosses over i11[i+1] then
b1 = 1
break
ENDIF
NEXT
//i1 = highest[2](high)
i1 = ExponentialAverage[4](close)
c2 = close crosses over i1
if b1 and c2 then
buy .2 contracts at market
ENDIF
set target pprofit 10
set stop ploss 10
T
JSParticipant
Senior
What is the difference between the outcome of the indicator and the trading system in the backtest…?
With the indicator I get the expected histogram when triggered but in the back test I don’t seem to get any triggers. I used the graph function to try and see what was happening in the back test but it came out blank. I have simplified the code to find the issue because when included there were no trades taken. So when I started to investigate it seems as though a never get a positive result from the loop. maybe I’m missing something. Please find indicator code below I was using.
Thanks Carter
b1 = 0
for i = 2 to 20 DO
i11 = highest[100](high)
if close[i] crosses over i11[i+1] then
b1 = 1
break
ENDIF
NEXT
return b1
JSParticipant
Senior
When I use your original trading system, it does generate positions…
I have set the number of contracts from 0.2 to 1…
The signals are a bit “treacherous” for example the signal “b1” can remain valid for 20 bars so within 20 bars after the actual “trigger” more buy signals can follow…
Try rewriting line 3 this way:
i11 = highest[100](high[1])