I need an afl code that is used in the trading software amibroker. This file should help me backtest my trade idea. The buy and sell signals are simple moving average crossovers. Buy the security when 5 EMA crosses 13 EMA and goes above it and sell the security when the 5 EMA crosses below the 13 EMA. This is quite simple.
But the complex part comes next. I want to check if the previous trade was profitable or not. If the previous trade made a loss, then I want to get the highest highs and lowest lows of
1. All the candles between the open and close of the previous trade.
2. 10 candles before previous trade's entry.
3. 8 candles after previous trade's close.
The program should find the highest high and lowest low values among all candles from the 3 groups described above.
A new trade will be opened only if
1. the previous trade made a profit
Or,
2. the previous trade made a loss but the new trade's entry price is above the highest high or below the lowest low of the candles from the 3 groups described above.
The above rule ensures that we are not taking a trade in a sideways market. A trade will be taken only if price has moved away from the previous losing trade's range.
I would appreciate if you can write a simple code to carry out this task. I may have to edit this program myself from time to time. So I would appreciate if you use simple formulas to get this done. Adequate commenting along the use of functions necessary so that I can understand what is going on. The deliverable will be a complete .afl file that can be run on any futures database in amibroker.
Please do not use functions/processes that significantly slows down the software. For example, Amibroker suggests the following:
There are following areas of AFL programming that require some attention if you want to write multithreading-friendly AFL formulas:
1. Avoiding the use of OLE / CreateObject
2. Reducing use of AddToComposite / Foreign to minimum
3. Efficient and correct use of static variables
4. Implementing pre-processing / initialisation in the Analysis window
5. Accessing ---Equity symbol
If you think the price I offered is too low, please feel free to ask for a higher price.
About the recuiterMember since Nov 11, 2022 Sophia Noreen Syed
from Uttar Pradesh, India