This automated trading strategy is coming from the French ProBacktest/ProOrder documentation itself. I made an article about it that you can read just here : http://www.prorealcode.com/blog/automated-breakout-trading-strategy-french-cac40/
It deals with breakout of the last high and low price levels of the first 2 15 minutes bars of the market open, french time. It’s an intraday strategy with great rewards when prices make real nice breakout. The strategy take only 2 positions maximum each every day as it tries to deals with a first false breakout and take the over side position while the price break the other price level.
I suggest you to read look at my trading journal on forum, while i am trading it myself on a small personnal account.
Here is the code with the constant trade volume (no gain is re-invest into the lot) :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
// We do not store datas until the system starts. // If it is the first day that the system is launched and if it is afternoon, // it will be waiting until the next day for defining sell and buy orders DEFPARAM PreLoadBars = 0 // Position is closed at 7h45 PM, french time (in case of CAC40 trading) DEFPARAM FlatAfter = 194500 // No new position will be initiated after the 5h00 PM candlestick LimitHour = 171500 // Market scan begin with the 15 minute candlestick that closed at 9h15 AM StartHour = 091500 // The 24th and 31th days of December will not be traded because market close before 7h45 PM IF (Month = 5 AND Day = 1) OR (Month = 12 AND (Day = 24 OR Day = 25 OR Day = 26 OR Day = 30 OR Day = 31)) THEN TradingDay = 0 ELSE TradingDay = 1 ENDIF // Variables that would be adapted to your preferences if time = 084500 then //PositionSize = max(2,2+ROUND((strategyprofit-1000)/1000)) //gain re-invest trade volume PositionSize = 2 //constant trade volume over the time endif MaxAmplitude = 32.5 MinAmplitude = 11 OrderDistance = 4 PourcentageMin = 30 // Variable initilization once at system start ONCE StartTradingDay = -1 // Variables that can change in intraday are initiliazed // at first bar on each new day IF (Time <= StartHour AND StartTradingDay <> 0) OR IntradayBarIndex = 0 THEN BuyTreshold = 0 SellTreshold = 0 BuyPosition = 0 SellPosition = 0 StartTradingDay = 0 ELSIF Time >= StartHour AND StartTradingDay = 0 AND TradingDay = 1 THEN // We store the first trading day bar index DayStartIndex = IntradayBarIndex StartTradingDay = 1 ELSIF StartTradingDay = 1 AND Time <= LimitHour THEN // For each trading day, we define each 15 minutes // the higher and lower price value of the instrument since StartHour // until the buy and sell tresholds are not defined IF BuyTreshold = 0 OR SellTreshold = 0 THEN HighLevel = Highest[IntradayBarIndex - DayStartIndex + 1](High) LowLevel = Lowest [IntradayBarIndex - DayStartIndex + 1](Low) // Spread calculation between the higher and the // lower value of the instrument since StartHour DaySpread = HighLevel - LowLevel // Minimal spread calculation allowed to consider a significant price breakout // of the higher and lower value MinSpread = DaySpread * PourcentageMin / 100 // Buy and sell tresholds for the actual if conditions are met IF DaySpread <= MaxAmplitude THEN IF SellTreshold = 0 AND (Close - LowLevel) >= MinSpread THEN SellTreshold = LowLevel + OrderDistance ENDIF IF BuyTreshold = 0 AND (HighLevel - Close) >= MinSpread THEN BuyTreshold = HighLevel - OrderDistance ENDIF ENDIF ENDIF // Creation of the buy and sell orders for the day // if the conditions are met IF SellTreshold > 0 AND BuyTreshold > 0 AND (BuyTreshold - SellTreshold) >= MinAmplitude THEN IF BuyPosition = 0 THEN IF LongOnMarket THEN BuyPosition = 1 ELSE BUY PositionSize CONTRACT AT BuyTreshold STOP ENDIF ENDIF IF SellPosition = 0 THEN IF ShortOnMarket THEN SellPosition = 1 ELSE SELLSHORT PositionSize CONTRACT AT SellTreshold STOP ENDIF ENDIF ENDIF ENDIF // Conditions definitions to exit market when a buy or sell order is already launched IF LongOnMarket AND ((Time <= LimitHour AND SellPosition = 1) OR Time > LimitHour) THEN SELL AT SellTreshold STOP ELSIF ShortOnMarket AND ((Time <= LimitHour AND BuyPosition = 1) OR Time > LimitHour) THEN EXITSHORT AT BuyTreshold STOP ENDIF // Maximal risk definition of loss per position // in case of bad evolution of the instrument price SET STOP PLOSS MaxAmplitude |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Hi @Nicolas. I am not having success. I imported the strategy, chose France 40 Cash (EUR2 Mini Contract), and changed the timeframe on the chart to 15 minutes, and the number of units to display to 100,000. The strategy does not generate any orders. Before I try to debug this, is there anything else that I should have done (or done differently)?
Thanks
Stef
Hi @Nicolas,
I see a couple of differences between the code above an the file, namely:
Code above runs until 19:45 while in the file it runs until 21:45
Code above uses PositionSize=2 by default and the file uses PositionSize=max… Not a problem.
Code above MaxAmplitude=32.5 while in the file it is 58.
Why the differences? Which values work bettter?
Regards, Stef
My bad, this is 2 different settings as the file is exported from my own Prorealtime personal account. The 2 settings work well, the one from the file is a more “risky” one with more entries, gain reinvestment on traded lot and a larger time amplitude to close trade before night. You can choose the one from the file or the other one, it all depends to your risk aversion.
Ok, so the first issue – not generating orders – is caused by how you choose to display your data WRT time zones (Platform options -> Time zones & Trading hours).
Stef
I´m new here and i didn´t quite what you mean. Is it necesarry to change the Time Zone?
@danyway
It is necessary to change the time zone, accordingly to hours of the strategy. This strategy is working on French CAC40 (time zone GMT+1).
Hello All,
I think this strategy is good and can be automated effectively with ProOrder.
I show you my own optimization of the variables.
Try it and you will see.
AmplitudeMax =58AmplitudeMin =10DistanceOrdre = 4PourcentageMin = 27
By the way, the formula with reinvested earnings is :
positionsize = 10
Capital = 10000 + strategyprofit
TaillePosition = (capital / 10000) * positionsize
(you can change the position size. I would set it to 5, less leverage, safer)
Quite effective !
Vraiment bien cette stratégie basé sur des concepts simples: trader les cassures lors de l’ouverture des marchés Européens, laisser courir ses gains et couper rapidement ses pertes. Je l’utilise sur un compte réel depuis fin juillet 2015 et les résultats sont bons: http://www.videobourse.fr/forum-forex/viewtopic.php?f=12&t=12439 .
En effet un concept simple qui fonctionne, et en intraday qui plus est! Je me suis longtemps demandé si le comportement du marché n’était pas à la base des performances plutôt que la stratégie elle-même. J’ai donc fait quelques simulations aléatoires et je suis plutôt confiant pour l’avenir : http://www.prorealcode.com/topic/proorder-breakout-on-french-cac40-my-account-performances/
EN/ Indeed a simple concept that works, and in intraday! I have long wondered if the market behavior was not based of the performance rather than the strategy itself. So I did some random simulations and I’m pretty confident for the future: http://www.prorealcode.com/topic/proorder-breakout-on-french-cac40-my-account-performances/
L’année 2015 a été exceptionnelle pour ce code !
+56,9% de capital gagné (avec mes paramètres et pour 2 euros le point / 2000 euros), sans réinvestissement des gains.
J’ai tenté de mettre au point un code de “London Open Breakout” sur le forex (avec un range de 00 à 08H), mais ça n’a pas encore abouti, je verrai bien si je peux adapter ce code pour d’autres supports : GBP/USD, EUR/USD, et l’OR (le breakout sur l’or est souvent apprécié par certains traders, je m’en suis servi auparavant).
Ciao a tutti, ho modificato il codice in modo da farlo lavorare su time frame 5 minuti su Italy cash ma mi apre in alcuni giorni più di due posizioni mentre ho letto che il codice originale dovrebbe aprire al massimo due posizioni al giorno, dov’è il mio errore? Io ho impostato il fuso orario della piattaforma su UTC/00:00
// We do not store datas until the system starts.
// If it is the first day that the system is launched and if it is afternoon,
// it will be waiting until the next day for defining sell and buy orders
DEFPARAM PreLoadBars = 0
// Position is closed at 7h45 PM, frenh time (in case of CAC40 trading)
DEFPARAM FlatAfter = 173000
// No new position will be initiated after the 5h00 PM candlestick
LimitHour = 153000
// Market scan begin with the 15 minute candlestick that closed at 9h15 AM
StartHour = 093000
// The 24th and 31th days of December will not be traded because market close before 7h45 PM
IF (month=3 and day=28) or (Month = 5 AND Day = 1) OR (Month = 12 AND (Day = 24 OR Day = 25 OR Day = 26 OR Day = 30 OR Day = 31)) THEN
TradingDay = 0
ELSE
TradingDay = 1
ENDIF
// Variables that would be adapted to your preferences
if time = 090000 then
PositionSize = max(2,2+ROUND((strategyprofit-1000)/1000)) //gain re-invest trade volume
PositionSize = 2 //constant trade volume over the time
endif
MaxAmplitude = 80
MinAmplitude = 30
OrderDistance = 4
PourcentageMin = 30
// Variable initilization once at system start
ONCE StartTradingDay = -1
// Variables that can change in intraday are initiliazed
// at first bar on each new day
IF (Time <= StartHour AND StartTradingDay <> 0) OR IntradayBarIndex = 0 THEN
BuyTreshold = 0
SellTreshold = 0
BuyPosition = 0
SellPosition = 0
StartTradingDay = 0
ELSIF Time >= StartHour AND StartTradingDay = 0 AND TradingDay = 1 THEN
// We store the first trading day bar index
DayStartIndex = IntradayBarIndex
StartTradingDay = 1
ELSIF StartTradingDay = 1 AND Time <= LimitHour THEN
// For each trading day, we define each 15 minutes
// the higher and lower price value of the instrument since StartHour
// until the buy and sell tresholds are not defined
IF BuyTreshold = 0 OR SellTreshold = 0 THEN
HighLevel = Highest[IntradayBarIndex - DayStartIndex + 1](High)
LowLevel = Lowest [IntradayBarIndex - DayStartIndex + 1](Low)
// Spread calculation between the higher and the
// lower value of the instrument since StartHour
DaySpread = HighLevel - LowLevel
// Minimal spread calculation allowed to consider a significant price breakout
// of the higher and lower value
MinSpread = DaySpread * PourcentageMin / 100
// Buy and sell tresholds for the actual if conditions are met
IF DaySpread <= MaxAmplitude THEN
IF SellTreshold = 0 AND (Close - LowLevel) >= MinSpread THEN
SellTreshold = LowLevel + OrderDistance
ENDIF
IF BuyTreshold = 0 AND (HighLevel - Close) >= MinSpread THEN
BuyTreshold = HighLevel - OrderDistance
ENDIF
ENDIF
ENDIF
// Creation of the buy and sell orders for the day
// if the conditions are met
IF SellTreshold > 0 AND BuyTreshold > 0 AND (BuyTreshold - SellTreshold) >= MinAmplitude THEN
IF BuyPosition = 0 THEN
IF LongOnMarket THEN
BuyPosition = 1
ELSE
BUY PositionSize CONTRACT AT BuyTreshold STOP
ENDIF
ENDIF
IF SellPosition = 0 THEN
IF ShortOnMarket THEN
SellPosition = 1
ELSE
SELLSHORT PositionSize CONTRACT AT SellTreshold STOP
ENDIF
ENDIF
ENDIF
ENDIF
// Conditions definitions to exit market when a buy or sell order is already launched
IF LongOnMarket AND ((Time <= LimitHour AND SellPosition = 1) OR Time > LimitHour) THEN
SELL AT SellTreshold STOP
ELSIF ShortOnMarket AND ((Time <= LimitHour AND BuyPosition = 1) OR Time > LimitHour) THEN
EXITSHORT AT BuyTreshold STOP
ENDIF
// Maximal risk definition of loss per position
// in case of bad evolution of the instrument price
SET STOP PLOSS MaxAmplitude
Ciao alfredo, si potrebbe aprire un argomento del forum qui: http://www.prorealcode.com/forum/prorealtime-forum-italiano/supporto-proorder/
Grazie!
if time = 090000 then
PositionSize = max(2,2+ROUND((strategyprofit-1000)/1000)) //gain re-invest trade volume
//PositionSize = 2 //constant trade volume over the time
endif
Ciao Alfredo, come hai scelto questi valori per il mib?
MaxAmplitude = 80
MinAmplitude = 30
OrderDistance = 4
PourcentageMin = 30
Hello,
I like this code…
But with a spread of 1 point, gains are reduced by nearly 30%, but is still profitable.With a spread of 2 points, gains are minimal !
Do you know how high is the spread with ProRealTime CFD ?
If it is more than 1 point, I think that this strategy isn’t worth the risk… unhappily
During intraday the spread is only 1 point with ProRealTime CFD, and because trades are closed automatically by 7:45PM, there are no overnight fees also.
In my code trades are closed at 9:45PM.I will backtest closing at 7:45PM, I think it is less profitable.
Yes there are 2 versions of this code with different closing time. The one you are talking about is also the same I’m trading, it’s a bit more profitable but also a more risky version because of the MaxAmplitude variable which is set differently.
For everybody,
On my code, with n = 7 and reinvested earnings :
=> 357.000 € in 8 years WITHOUT spread
=> 87.000 € in 8 years WITH 1 point spread.
Spread HURTS !
When I try the code with ProOrder (on ProRealTime CFD) with 1000€ and 1 mini-contract, no order is triggerd.Error : something like “Insufficient minimal contract”.
Do you know why ?Thanks
I believe the minimum size is 2 contracts. That’s what I’m always use with this instrument. I tried to find the information somewhere, but still don’t find by now 🙂
Hi,
I am new here. I tried the code in the backtest and it works just like shown here. However, when I start the code for real in ProOrder. Time settings are correct (Paris time etc) A yellow warning sign appears shortly after starting. I says that some command cannot be executed because DEFPARAM preload bars is set to 0. The program suggests 2000 or so. When I do this, the code worked. My question is: why is it necessary to set Preload Bars to 0 in the first place ? And second: if it is set to 0, why does it not work with me? Thank you for your answer.
Kind regards,
Glen
Hi Glen,
Preloadbars needs to be setted at 0 to avoid the system to start immediately, on the very first day of the system start. This strategy needs to be functional on the first hours of the market open. So if you launch the system in the afternoon, it will not be accurate at all for the present day (if you defined prealoadbars to anything else than 0).
Can you explain me the formula :
PositionSize = max(2,2+ROUND((strategyprofit-1000)/1000))
Thanks !
The position size is set between 2 and the max value of 2+ round number of the strategy profit divided by 1000$. But the count begin at first 1k$ profit of the strategy. Is that enough clear? 🙂
Yes, thanks !
What I find strange is that on my test, with this formula of re-invested earning, he can’t give me a result, he’s always calculating and loading… Do you have the same problem ?
The “1000” value depends of the account size and your lot size capabilities to earn 1000$ without trading a century or so 🙂
Also, the “2” parameter is the minimum size a trade would trade on market. If you change this size, be sure that your instrument can be traded with this size (minimum allowed).
Using both systems on this forum – one with maxamplitude 32.5 and the other 80, provided by Alfredo.
Result: No trades taken on CAC40 using Europe/London timezone
Tried more capital from £1k up to £10k capital — No trades taken…
Doesn’t produce any trades on 1 Hour or Daily — No trades taken…
PositionSize = max(2,2+ROUND((strategyprofit-1000)/1000))
Tried 1,2+ROUND etc —No trades taken…
Tried no commission / spread — No trades taken…
Does anyone have any idea why?
I am finding using PRT to be a real struggle as a limited coder but once very profitable discretionary spot Forex Trader would like to learn to code.
I abandoned ProOrder 5 years ago (and used Curtis Faith’s Trading Blox) because so many times systems that were supposed to be coded correctly would throw up lots of yellow warning symbols.
Why is does so much code on these forums not work first time after installation?
..and yes I tried it on 15 min bars and it lost money and only had 2 successful trades out of 18 and the other system: 6 wins out of 73 with 99% loss.
This strategy cut loss quickly and let the profit run. That’s why there are so many loss in a row. I can’t say that the strategy is actually in a good mood, but I keep on trading it since last year and so far I’m still confident. I’m used to say that automated trading needs more work than manual one.. and patience.. We all want green profit everyday, but it’s not possible. Keep on trading strategies you understand and also keep on diversification with adjusted risk on each one. (Brad= the Kase Dev Stop is on my mind, no worry.. 🙂 )
Yes, I saw your informative blog on the CAC40 Breakout Strategy and that’s why I was looking forward to trying it out (and adapting it to Forex). But it even gave errors on the very last line of the code (stop loss), that was remedied by copying that line, removing it and them re-pasting it back in and it worked? It’s that kind of nonsensical programming errors that are beyond my understanding, and it would seem, patience levels.
I had a non diversified style of trading and focused only on scalping the £/$ intraday – with hedges in other Forex pairs if things went against me. I was an average trader with strict money management rules and made 700% a year until the volatility of the ’08 Crash. After that I became a slightly better trader but more flexible on the money management and could make 1000% in 6 months until invariably tiredness or some other distraction would cause account “issues” (-:
I know that sudden volatility, trading with the trend and Dow Theory using pivot points works. I just can’t program it… If anyone has any ideas how to do that I would be interested in hearing them.The day a programmer writes a s/ware system that allows traders to express/write in normal English what they want to do, is the day that person will become an overnight millionaire.
I’m glad you haven’t forgotten, I know you’re busy. I think all the traders on here will benefit from the Kase PeakOscillator and KaseCD. Kase was using it with the confidence to be able to make million dollar trades in oil or silver — going with the main trend and getting out (in two 50% of position size exits by using different timing chart monitors and her indicators), then going with the countertrend for a limited duration and then getting back into the main trend.I have another World Class Algo Trader I’m reading about (I’m a better researcher than coder), who won the Robbins World Cup trading competition 3 years in a row with 100%+ returns. I will put the code up on a new thread to see if anyone can convert it.Did you ever post the ATR percentile rank, I couldn’t find it?
BestBrad
If the CAC40 Breakout System is not performing as well (because it would seem, looking at the chart the market is now going into sideways price action) why not incorporate – Futures Truth Magazine Top 10 Trading System designer – Randy Stuckey’s Choppiness Index used in Cat Scan IV?
p=30
//30 is the daily setting recommendation Stuckey used for every commodity he traded – this added to the robustness of his Cat Scan systems
MaxHi=Highest[p](High)
MinLo=lowest[p](low)
chop=100 * LOG( SUMMATION[p](AverageTrueRange[1](close))/log(10) / ( MaxHi – MinLo)) / (LOG(p)/log(10))
return chop as “Choppiness Index”
Also Nicolas, I don’t understand how you’re getting these performance figures here? :
http://www.prorealcode.com/topic/proorder-breakout-on-french-cac40-my-account-performances/
I’m using the same code with
MaxAmplitude = 58MinAmplitude = 11OrderDistance = 4PourcentageMin = 30
and CAC40 market and 15 timeframe and it makes losses straight away whichever month you start from this year? What Commission and Spread figures do you use live?
Thanks
Performance are not so good since the beginning of the year. But the major part of the performance of the last year, for example, were made in the last months of this one. I have posted the percentile rank indicator for your interest.
Ciao Nicolas, ho settato tutto come tu hai detto ma con timeframe 15min, ora italiana, 100000 unita, non produce nessuna transazione in proorder, puoi brevemente riassumere i parametri di funzionamento e spiegarmi perche sulla mia piattaforma prorealtime il tuo robot non funziona?
grazie
È necessario modificare il fuso orario, di conseguenza per ore di strategia. Questa strategia sta lavorando CAC 40 francese (GMT fuso orario + 1).
buonasera nicolas , grazie di nuovo per la tua risposta, sono un nuovo appassionato di trading, questo è un forum molto interessante.
avrei un paio di cose da chiederti, la prima quanto è secondo te l’importo minimo per fare funzionare questi sistemi di trading in maniera proficua, poi se si devono lasciare sempre attivi e infine come impostare stop loss un po meno devastanti.
(Non riesco ad impostarlo su super trend against trend perché mi dice che devo usare stopprice invece dei pips)
Ho lanciato alcuni trading system su Dax, cac, eurusd con risultati molto deludenti. Pur intravedendo un grosso potenziale…
Ti ringrazio se vorrai aiutarmi a crescere e ad avere meno perdite con qualche nozione di base…
grazie infinite e buona serata
Alfredo’s code tweaked to work on GBPUSD 15 min. Since 30 December the backtest shows 109.3% increase. I only changed the times, MinAmplitude, & PourcentageMin.
// Position is closed at 4h45 PM, frenh time (in case of CAC40 trading)
DEFPARAM FlatAfter = 164500
// No new position will be initiated after the 4h00 PM candlestick
LimitHour = 160000
// Market scan begin with the 15 minute candlestick that closed at 5h30 AM
StartHour = 053000
// Variables that would be adapted to your preferences
if time = 053000 then
PositionSize = max(2,2+ROUND((strategyprofit-1000)/1000)) //gain re-invest trade volume
//PositionSize = 2 //constant trade volume over the time
endif
MaxAmplitude = 80
MinAmplitude = 14
OrderDistance = 4
PourcentageMin = 41
buonasera nicolas , grazie di nuovo per la tua risposta, sono un nuovo appassionato di trading, questo è un forum molto interessante.
avrei un paio di cose da chiederti, la prima quanto è secondo te l’importo minimo per fare funzionare questi sistemi di trading in maniera proficua, poi se si devono lasciare sempre attivi e infine come impostare stop loss un po meno devastanti.
(Non riesco ad impostarlo su super trend against trend perché mi dice che devo usare stopprice invece dei pips)
Ho lanciato alcuni trading system su Dax, cac, eurusd con risultati molto deludenti. Pur intravedendo un grosso potenziale…
Ti ringrazio se vorrai aiutarmi a crescere e ad avere meno perdite con qualche nozione di base…
grazie infinite e buona serata
grazie nicolas
@nicolas
buonasera nicolas , grazie di nuovo per la tua risposta, sono un nuovo appassionato di trading, questo è un forum molto interessante.
avrei un paio di cose da chiederti, la prima quanto è secondo te l’importo minimo per fare funzionare questi sistemi di trading in maniera proficua, poi se si devono lasciare sempre attivi e infine come impostare stop loss un po meno devastanti.
(Non riesco ad impostarlo su super trend against trend perché mi dice che devo usare stopprice invece dei pips)
Ho lanciato alcuni trading system su Dax, cac, eurusd con risultati molto deludenti. Pur intravedendo un grosso potenziale…
Ti ringrazio se vorrai aiutarmi a crescere e ad avere meno perdite con qualche nozione di base…
grazie infinite e buona serata
Hey Guys,
I really like this strategy, but I would like to change the stop loss level. In the code the level is set at MaxAmplitude.
I would like it to be at at the same level as the stop buy/sell orders.
So I tried it like this
27 StopSize = Dayspread - (2*OrderDistance)
92 SET STOP PLOSS StopSize
Most of the time it seems correct, but I get a slightly different result for the backtest, because at some days the stop level is not correct.Any idea what might be the problem?
I am thankful for every help!
Cheers
Flo
Hello Nicolas,
could you please explaine, what “OrderDistance” and “MinSpread” are for? Do I get it right, that the “BuyTreshold” is 4 points below “HighLevel” and not above?
Yes you got it right. Minspread is for the minimum distance of the breakout box.
But the BUY-trigger is below the High of the first two 15min-candels?
That’s right, because what we want is to enter the market quickly and not wait for the next candle close to test if the breakout has occurred. Sometimes, the next candlestick that follow a breakout is already far away from the breakout box..
Then I don’t understand the backtest data. Yesterday (28.9.) range was from ~ 4410,5 – 4450,7 and the breakout was at 9:45 long. But the position was opened around 16 o’clock at 4457,3. Same procedure at 26. and 27.9.
The code says “buy short before breakout” but backtest shows “buy (timely and pricely) after breakout” and that’s where I can’t follow the code.
Could you write a pseudocode starting at line 50, please?