Various conding requests

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #244336 quote
    Francesco
    Participant
    Veteran
    Hello everyone! How are you doing? I have some coding requests, i hope you can help me 🙂

    1- The price has increased by x percent over the last x candles.
    2- The price has remained within a certain range (moved sideways) over the last x candles 3- The price has remained over a moving average over the last x candles
    4- Set the stop loss at the low of the last x candles.

    Bonus: The price has formed higher highs over the last x candles.

    Thanks.
    #244346 quote
    robertogozzi
    Moderator
    Master
    There you go:
    // 1
    ONCE X  = 10
    ONCE PC = 5
    Gap     = ((close / close[X - 1]) - 1) * 100
    RETURN (Gap >= PC) AS "%rise"
    
    // 2
    ONCE X = 10
    HH     = highest[X](high[1])
    LL     = lowest[X](low[1])
    Signal = 0
    IF high <= HH AND low >= LL THEN
       Signal = 1
    ENDIF
    RETURN Signal AS "Signal"
    
    // 3
    ONCE X = 10
    ONCE P = 20
    Sma    = average[P,0](close)
    //Above= close > Sma
    Below  = close < Sma
    Number = BarsSince(Below)
    RETURN Number AS "Number of Bars Above"
    
    // 4
    ONCE X = 5
    SET STOP PRICE lowest[X](low)
    
    // Bonus
    ONCE X = 10
    Result = summation[X](high > high[1])
    Iván González and Francesco thanked this post
    #244354 quote
    Francesco
    Participant
    Veteran
    Thank you Roberto! Just a question: in n.3 where is “X” used? And why did you greyed out the above condition? Since the price need to stay over the moving average the below condition should be greyed out no? So it should be something like
    Above= close > Sma
    //Below  = close < Sma
    Number = BarsSince(Above)
    RETURN Number AS "Number of Bars Above"
    #244358 quote
    robertogozzi
    Moderator
    Master
    1. I forgot to remove that line that I had copied from the prior lines.
    2. Because I coded that line, but then I realized that we don’t need to know it. Since once we know what is the last bar BELOW, all the next ones will be ABOVE for sure!
    Francesco thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Various conding requests


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by robertogozzi
11 months, 3 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/25/2025
Status: Active
Attachments: No files
Logo Logo
Loading...