Buy at fixed values during price declines
Forums › ProRealTime English forum › ProOrder support › Buy at fixed values during price declines
- This topic has 9 replies, 2 voices, and was last updated 2 years ago by robertogozzi.
-
-
10/23/2021 at 10:54 AM #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.
Screenshot1Buy 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%.
screenshot2If 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%.
screenshot3If 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)
10/23/2021 at 10:57 AM #180224Correction 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.
Screenshot1Buy 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)
screenshot2If 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%.
screenshot3If 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)
10/23/2021 at 12:28 PM #180235There you go:
123456789101112131415161718DEFPARAM CumulateOrders = falseDEFPARAM PreLoadBars = 10000ONCE LotSize = 1ONCE PerCent5 = 0.05 //5%HIGHESTprice = highest[10000](high[1]) //get the highest price as far as can beCurDistance = HIGHESTprice - closeChunkSize = HIGHESTprice * PerCent5Chunks = round((CurDistance / ChunkSize) - 0.5)Entry = HIGHESTprice - (HIGHESTprice * (Chunks * PerCent5))c1 = Chunks > 0c2 = Not OnMarketIF c1 AND c2 THENBUY LotSize Contracts AT Entry STOPSET STOP LOSS ChunkSizeENDIFIF OnMarket AND close > HIGHESTprice THENSELL AT MarketENDIFI 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.
10/23/2021 at 4:25 PM #180245Thank 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 pointsso 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,000If the price falls below 9,600 at the close, we will
Stop Buy 9,600
SL 9,400
TP 9,800If the price falls below 9,400 at the close, we will
Stop Buy 9.400
SL 9.200
TP 9.600if the price rises above 9,400 at the close, the
StopBuy to 9.600
SL to 9.400
TP to 9.800For 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?buy at price declines12345678910111213141516171819202122DEFPARAM CumulateOrders = falseDEFPARAM PreLoadBars = 10000ONCE LotSize = 1ONCE PerCent = 0.02ath = highest[10000](high[1])for all n = 1 to 100 do // every n and again and again // how can i program this?Entry = close < ath - (ath*percent*n)IF close < ath or Entry THENBUY AT Entry STOP<span style="vertical-align: inherit;"><span style="vertical-align: inherit;">ENDIF</span></span>Exit = (close > ath - (ath*percent*n+1)) or (close < ath - (ath*percent*n-1))IF OnMarket AND Exit THENSELL AT Market<span style="vertical-align: inherit;"><span style="vertical-align: inherit;">ENDIF</span></span>10/23/2021 at 4:51 PM #180246better again, one problem left
DEFPARAM CumulateOrders = false
DEFPARAM PreLoadBars = 10000ONCE LotSize = 1
ONCE PerCent = 0.02ath = 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
10/24/2021 at 5:09 PM #180275If 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.
10/26/2021 at 7:51 AM #180355When 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!
12345678910111213141516171819202122DEFPARAM CumulateOrders = falseDEFPARAM PreLoadBars = 10000ONCE LotSize = 1ONCE PerCent5 = 0.05 //5%HIGHESTprice = highest[10000](high[1]) //get the highest price as far as can beCurDistance = HIGHESTprice - closeChunkSize = HIGHESTprice * PerCent5Chunks = round((CurDistance / ChunkSize) - 0.5)Entry = HIGHESTprice - (HIGHESTprice * (Chunks * PerCent5))c1 = Chunks > 0c2 = Not OnMarketIF c1 AND c2 THENEntryPrice = EntryFor i = 1 to ChunksBUY LotSize Contracts AT EntryPrice STOPEntryPrice = EntryPrice + ChunkSizeNextSET STOP LOSS ChunkSizeENDIFIF OnMarket AND close > HIGHESTprice THENSELL AT MarketENDIF1 user thanked author for this post.
10/30/2021 at 5:34 PM #180613I 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.11/01/2021 at 7:33 PM #180770Hello again.
Here you see again my question in another form.
Can you program here that it is executed for all “n”?123456789101112131415161718192021222324defparam cumulateorders = falseonce percent = 0.02 //2%a = 100*percentb = 100/an = b// follow must be done for all n from 1 to ntimeframe (daily)ath = highest [1000] (high [1]) //100%c1 = ath - (ath * (n+1) * percent)c2 = ath - (ath * n * percent)c3 = ath - (ath * (n-1) * percent)timeframe (default) // timeframe 1HIf close < c2 thenbuy at c2 stopendifIf close < c3 or close > c1 thensell at marketendif11/02/2021 at 5:58 PM #180798There you go:
12345678910111213141516171819202122232425262728293031323334defparam cumulateorders = falseonce percent = 0.02 //2%a = 100*percentb = 100/an = b// follow must be done for all n from 1 to ntimeframe (daily)ath = highest [1000] (high [1]) //100%FOR i = 1 TO n//1c1 = ath - (ath * (i+1) * percent)c2 = ath - (ath * i * percent)c3 = ath - (ath * (i-1) * percent)If close < c2 thenbuy at c2 stopendifNEXTtimeframe (default) // timeframe 1HIf close < c3 or close > c1 thensell at marketendifgraph agraph bgraph ngraph igraphonprice c1 coloured(255,0,0,255)graphonprice c2 coloured(0,128,0,155)graphonprice c3 coloured(9,0,255,255)graphonprice athAs 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. -
AuthorPosts
Find exclusive trading pro-tools on