Responding here such that the posts remain structured to the original query, instead of haphazard responses and discussions spread randomly over the Forum. It will concisely help future users going through the same learning curve.
In lieu of the same, if possible, requesting Moderator to please split the following three posts from another thread and merge those here (Thank You):
https://forum.amibroker.com/t/easiest-way-to-lock-buyprice/12496/7
/12496/8
/12496/9
You're Welcome!
Sure take your time! Not so long back, I had also failed to take care, as basic a thing as, Magic Numbers in my AFLs, although I was aware of those concepts but still a kindhearted Expert had to correct me. Call it my negligence or lack of focus or lack of ability, whatever! It's okay, as long as you scale-up!
I am quite sure, if you implement the examples (as shown in the KB Article or from here) you will be able to easily Plot a TSL for your strategy. However, the reason I am writing this post is to highlight few other things that can be observed from your shared code.
- AFL is not a Low-Level Assembly Programming Language but when it comes to Speed, it is nothing less either. AFL is highly efficient Polymorphed (more here) Humane High-level Languange with unmatched Vector Processing power. When you write Codes as below, it is a bit of disrespect to the Person who has spent more than two decades of his life perfecting it. I know you did not mean it, but that's what it implies.
Still not sure what you really want to attain from the above, aren't these functions available to meet your needs:
Lowest/Highest
- HHV - highest high value
- HHVBars - bars since highest high
- Highest - highest value
- HighestBars - bars since highest value
- HighestSince - highest value since condition met (AFL 1.4)
- HighestSinceBars - bars since highest value since condition met (AFL 1.4)
- LLV - lowest low value
- LLVBars - bars since lowest low
- Lowest - lowest value
- LowestBars - bars since lowest
- LowestSince - lowest value since condition met (AFL 1.4)
- LowestSinceBars - barssince lowest value since condition met (AFL 1.4)
(Source: Categorized list of functions)
Kindly do not judge AFL from the perspective of your problem, it will be hard to find the solution, often, you will get stuck with the problem only. Rather understand AFL as it is, and you will automatically find a way to solve the problem.
- This other section of your code:
Hope you are going to run that many Optimizers
responsibly, and have already done research for the same.
Because:
(Source: How to optimize trading system guide)
Also aware of:
Math 101: Over-fitting
Optimization and exploration together ? - #2 by Tomasz