Buy at fixed values during price declines

Forums ProRealTime English forum ProOrder support Buy at fixed values during price declines

Viewing 10 posts - 1 through 10 (of 10 total)
  • #180221

    Buy at fixed values during price declines

    Introduction
    Starting from the all-time high of a stock, I want to buy with a StopBuy when the price has fallen below the all-time high minus 5% at the end of the day. The StopBuy should be exactly at the all-time high minus this 5%.
    The Stoploss should be when the daily close is below the all-time high minus 10%.
    The takeprofit should be at the daily close above the all-time high.
    Screenshot1

    Buy on price declines
    If the share falls further below 10% since the all-time high per daily close, I want to buy per StopBuy at all-time high minus 10%. The stoploss should be at all-time high minus 15%, the takeprofit at all-time high minus 5%.
    If the share falls below 15% from the all-time high per day close, I want to buy with StopBuy at all-time high minus 15%. Stoploss at minus 20%, takeprofit at 15%.
    screenshot2

    If the share continues to fall
    Is bought each time after a multiple of 5% (or n%) by StopBuy, SL TP are -n%. or +n%.

    The share recovers.
    Will continue to buy by stopbuy at a multiple of n%. SL and TP remain at this multiple -n% and +n% respectively.

    If the share returns to the all-time high after the close of the day, it is bought by StopBuy at the all-time high. SL TP again the corresponding -n% +n%.
    screenshot3

    If a new all-time high is created, the old all-time high is replaced by the new all-time high.

    Can someone press this into a code? I’m sorry, I completely lack the means.
    But it smells like good backtest results, especially with the ever-rising indices like Dow and S&P.

    Can you help?

    Translated with http://www.DeepL.com/Translator (free version)

    #180224

    Correction and Screensot 2

    Buy at fixed values during price declines

    Introduction
    Starting from the all-time high of a stock, I want to buy with a StopBuy when the price has fallen below the all-time high minus 5% at the end of the day. The StopBuy should be exactly at the all time high minus this 5%.
    The Stoploss should be when the daily close is below the all-time high minus 10%.
    The takeprofit should be when the daily close is above the all-time high.
    Screenshot1

    Buy on price declines
    If the share price falls further below 10% since the all-time high per daily close, I want to buy with StopBuy at all-time high minus 10%. The stoploss should be at all time high minus 15%, the takeprofit at all time high minus 5%.
    If the share falls below 15% from the all-time high at the end of the day, I want to buy with StopBuy at the all-time high minus 15%. Stoploss at minus 20%, takeprofit at 10%. (here the correkt 10 instead 15)
    screenshot2

    If the share continues to fall
    Is bought each time after a multiple of 5% (or n%) by StopBuy, SL TP are -n%. or +n%.

    The share recovers.
    Will continue to buy by stopbuy at a multiple of n%. SL and TP remain at this multiple -n% and +n% respectively.

    If the share returns to the all-time high after the close of the day, is bought by StopBuy at the all-time high. SL TP again the corresponding -n% +n%.
    screenshot3

    If a new all-time high is created, the old all-time high is replaced by the new all-time high.

    Can someone squeeze this into a code? I’m sorry, I’m completely out of resources.
    However, it smells like good backtest results especially with the ever-rising indices like Dow and S&P.

    Can you help?

    Translated with http://www.DeepL.com/Translator (free version)

    #180235

    There you go:

    I made it so that it does not accumulate positions as I am not sure you wanted this.
    Do you want to accumulate positions?

    1 user thanked author for this post.
    #180245

     

    Thank you very much for the quick help. I am glad that you help me.
    But unfortunately the code does not do exactly what I want to get.

    For a better understanding let me underlay it with numbers
    The all time high of a fictitious value is 10.000 points.
    We take n=2% of 10.000 = 200 points

    so we get
    10.000 // alltimehigh = Highest [1000](high[1])
    9.800 // alltimehigh – 2%
    9.600 // alltimehigh – 4%
    9.400 // ..
    9.200 //..

    Now it can start
    If the price falls below 9,800 at the close, we will
    StopBuy at 9,800
    SL 9.600
    TP 10,000

    If the price falls below 9,600 at the close, we will
    Stop Buy 9,600
    SL 9,400
    TP 9,800

    If the price falls below 9,400 at the close, we will
    Stop Buy 9.400
    SL 9.200
    TP 9.600

    if the price rises above 9,400 at the close, the
    StopBuy to 9.600
    SL to 9.400
    TP to 9.800

    For it as above it would have to be programmed.
    And I have made it so, where I have problems. Please can you look over it again and correct?

     

    #180246

    better again, one problem left

    DEFPARAM CumulateOrders = false
    DEFPARAM PreLoadBars = 10000

    ONCE LotSize = 1
    ONCE PerCent = 0.02

    ath = highest[10000](high[1])

    for all n = 1 to 100 do //n = 1 or 2 or 3 or 4 or 5 or …. or 100 // here ist the problem i can´t

    Entry = ath – ath*n*percent

    IF close < Entry THEN BUY AT Entry STOP ENDIF Exit = (close > ath – (ath*(n+1)*percent)) or (close < ath - (ath*(n-1)*percent)) IF OnMarket AND Exit THEN SELL AT Market ENDIF

    #180275

    If you want to accumulate positions why did you write DEFPARAM CumulateOrders = false?

    My code doesn’t accumulate positions.

    If you want to accumulate positions the code must be changed.

     

     

    1 user thanked author for this post.
    #180355

    When you place more than one pending order, all of them could be triggered as DEFPARAM CumulateOrders only works when ProOrder has the control of operations, but once the code is executed and pending orders placed, control is left to the broker until the new candle closes.

    In any case I added FOR…NEXT to place ALL pending orders (if the price has dropped 20%, 4 orders will be placed).

    But it us useless, as 5%, say on Dax, is about 800 pips and a fear it can hardly trigger one order, as I have never experienced a daily drop of more than that!

     

    1 user thanked author for this post.
    #180613

    I have only today got to look here
    You have my great and heartfelt thanks that you have taken my questions again.
    The addition of the For…Next function helps me immensely. Thank you very much.
    I’ll try to do the rest on my own. I will be back soon.

    #180770

    Hello again.

    Here you see again my question in another form.
    Can you program here that it is executed for all “n”?

     

    #180798

    There you go:

    As you can see from the attached pic, when n is reached, c2 is 0.
    It only works for the FIRST iteration. This means that iterations are useless. If you change line 12 to 1, nothing changes, because from the second iteration on, it nevcer enters. Bear in mind that 2% on DAX is now about 320 pips far!
    Anyway, you can play with it by trying to change something.

Viewing 10 posts - 1 through 10 (of 10 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login