Highest function in for loop

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #240582 quote
    Carter
    Participant
    Junior

    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
    #240590 quote
    JS
    Participant
    Senior

    What is the difference between the outcome of the indicator and the trading system in the backtest…?

    #240594 quote
    Carter
    Participant
    Junior
    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
    
    #240596 quote
    JS
    Participant
    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…

    Scherm­afbeelding-2024-11-20-om-17.25.22.jpg Scherm­afbeelding-2024-11-20-om-17.25.22.jpg
    #240598 quote
    robertogozzi
    Moderator
    Master
    Try rewriting line 3 this way:
    i11 = highest[100](high[1])
    Iván González thanked this post
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Highest function in for loop


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Carter @carmac Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by robertogozzi
1 year, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/20/2024
Status: Active
Attachments: 1 files
Logo Logo
Loading...