backtest stocks ath
Forums › ProRealTime English forum › ProOrder support › backtest stocks ath
- This topic has 12 replies, 3 voices, and was last updated 8 months ago by Iván.
-
-
03/28/2024 at 11:32 AM #230642
I want to write a code for backtesting that buys the highest of the previous bar over a given period (1 week, 1 month, 1 year or more). with a target of 10%. for the stock of my choice. for example, it’s march 2024. i buy the highest reached in april 2024. thanks you
03/28/2024 at 12:31 PM #230651Hi
here you have an example (please,consider to use a stop loss or another way to exit than just the profit 10%)123456789defparam cumulateorders=falsen=20 //lookback periodhhv = highest[n](high)if not longonmarket and high>hhv[1] thenbuy 1 contract at market//set stop %loss 10set target %profit 10endif03/28/2024 at 3:31 PM #23066303/29/2024 at 11:30 AM #23069603/29/2024 at 11:56 AM #23070104/01/2024 at 3:16 PM #230850Thank you very much IVAN, but that’s not exactly it. Here are normally the orders that must be taken. I will take example since 2017 ON APPLE. IVAN if you can start from this example to make the code.
ATH IN 2017: 44. 30
I TAKE A POSITION IN 2018 IF I REACH 44.3
THEN 10% TARGET OR 10% STOP LOSSSAME IN 2018: 58.36
I POSITION MYSELF FOR 2019 AT THIS PRICE AT 58.36IN 2019 : HIGH REACHED 73.49
I’M POSITIONED AT THIS PRICE IN 20202020 : HIGH REACHES 138.78
ENTER THE 2021 MARKET AT THIS PRICEAND FOR ALL 10% TARGET AND 10% STOP LOSS FROM THIS PRICE.
THANK YOU MR
04/01/2024 at 6:12 PM #23085504/02/2024 at 11:12 PM #23094704/03/2024 at 8:46 AM #230953First point: about working for any timeframe, just in case, if you’re after an all time high, keep in mind you need to make sure your timeframe is big enough to show all history (yearly or monthly is surely big enough, at the extreme opposite 1mn or (x) seconds might not be for older stocks)
2nd point: keeping in mind first point’s limitation for smaller timeframe, if you have maximum history wanted in your backtest, and considering first bar is barindex=0 then you can try to define your ath with:
1highest[barindex+1](high)and check it has been reached in the signal candle with:
123if high = highest[barindex](high) thenbuy etc...3rd point is a moderation point: you asked your question in this topic first, the rule about double post applies so your same question posted later on french forum is considered double post and will be deleted (please have a look at yellow box at bottom of this page the “do not double post” rule). To answer your other question there, anyone can reply if they want and when they want, there isn’t on one hand those who only ask and on the other hand those who only answer, it would only lead to those who ask remaining alone in the end, please feel free to help others too when you see questions you know the answer to. Moderators just have extra tools in their hands to keep the forum tidy within their own availability. If the points above didn’t help enough or didn’t help at all, please feel free to carry on the conversation with anyone, moderator or not, but in this topic, not in a duplicate topic, thanks.
04/03/2024 at 9:22 AM #230962Hi
Here you have an example (to be runned in monthly, weekly, daily, …, but not annualy)123456789101112131415defparam cumulateorders=falseif year = year[1] thenn=n+1elsehhv = highest[n](high)n=0endifif not longonmarket and high crosses over hhv thenbuy 1 contract at hhv stopset stop %loss 10set target %profit 10endifgraphonprice hhv coloured("red")04/03/2024 at 9:25 AM #23096404/03/2024 at 9:56 AM #230970thank you IVAN but i’m probably explaining myself badly but that’s not it. Like janury 2020 time 6 months. Ath 93.095. code entry in july 91.28. or it must be 93.095 .
And if you take a period spanning 1 year, nothing appears.
04/03/2024 at 10:22 AM #230977Yes, in annualy nothing happens because there is not cross over. As I wrote, this system is to be runned in monthly, weekly, daily, timeframe, but not annualy.
I have coded a cross over the last year high.
Sorry but I don’t know what you want… maybe another one can help you. -
AuthorPosts
Find exclusive trading pro-tools on