Help with code to find previous high/low

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #40304 quote
    nickp104
    Participant
    New

    Hi,

    Forgive me, I’m sure there must be an easy solution but I can’t seem to find it anywhere.

    I am keen to open positions or, if already open, close positions if the price closes under/over a previous high/low.

    I have bene using:

    DEFPARAM CumulateOrders = FALSE
     
     
    TLow = lowest[30](low)
    THigh = highest[30](high)
     
     
    c1 = CLOSE > THigh
    C2 = CLOSE < TLow
     
    IF C1 THEN
    BUY 1 SHARES AT MARKET
    ELSIF c2 THEN
    SELLSHORT 1 SHARES AT MARKET
    ENDIF

     

     But that doesn’t generate any trades.
    I would be hugely grrateful if someone could tell me where I’m going wrong.
    Thanks in advance.
    Nick
    #40319 quote
    tob107
    Participant
    Average

    Try changing “SHARES” to “CONTRACTS” depending on what you are trading.

    The main problem is probably that you save the new values first, including the closing candle. That means that you don’t get any trades since the close is never lower than TLow or higher than the THigh, since they are included. I asssume this is the problem at least, but I can’t figure out how to fix it right now. Should be fairly easy though.

    Cheers

    #40332 quote
    Nicolas
    Keymaster
    Master

    For clarity of messages on ProRealCode’s forums, please use the “insert code PRT” button to separate the text of the code part! Thank you! <<

    If Close is superior to the highest high, Close IS THE HIGHEST HIGH! So it can’t be superior to itself obviously

    So you must compare if Close is superior to the PREVIOUS highest high instead:

    c1 = CLOSE > THigh[1]
    C2 = CLOSE < TLow[1]
    nickp104 thanked this post
    #40510 quote
    nickp104
    Participant
    New

    Nicholas, as ever, thank you.  kicking myself now!  And your point about pasting code is noted.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Help with code to find previous high/low


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
nickp104 @nickp104 Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by nickp104
8 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/11/2017
Status: Active
Attachments: No files
Logo Logo
Loading...