Highest function in for loop
- This topic has 4 replies, 3 voices, and was last updated 11 months ago by .
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
Similar topics:
Forums › ProRealTime English forum › ProOrder support › Highest function in for loop
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
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
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 |
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
|
1 2 3 4 5 6 7 8 9 |
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 |
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:
|
1 |
i11 = highest[100](high[1]) |
Find exclusive trading pro-tools on 