Custom AmiBroker Code for Trading Optimizations

Job ID: 38678512

Budget: $250 – $750 USD

I want to create code that's an AmiBroker exploration, backtest, and optimization. There are two components, including Simple Moving Average State and Opening Location.

Simple Moving Average Component:
The SMAs are based on daily bars.

Four SMA States:
SMA State 1: Close > SMA20 AND Close > SMA300
SMA State 2: Close > SMA20 AND Close < SMA300
SMA State 3. Close < SMA20 AND Close > SMA300
SMA State 4: Close < SMA20 AND Close < SMA300

Opening Location Component:

The Opening Location is the difference between the prior daily bar's close versus the current daily bar's open.

Opening Locations:
// Calculate the previous day's range and adjustments for open positions
PrevRange = PrevHigh - PrevLow;
PrevRangeAdjusted = IIf(PrevRange == 0, 1, PrevRange); // Adjust for zero range to avoid division by zero
OpenPositionPercentage = ((Open - PrevLow) / PrevRangeAdjusted) * 100;

// Define opening position classifications within the range
WithinRange = Open >= PrevLow AND Open <= PrevHigh;
Opening Location 1: Top10 = WithinRange AND OpenPositionPercentage >= 90;
Opening Location 2: Top25 = WithinRange AND OpenPositionPercentage >= 75 AND OpenPositionPercentage < 90;
Opening Location 3: TopHalf = WithinRange AND OpenPositionPercentage >= 50 AND OpenPositionPercentage < 75;
Opening Location 4: BottomHalf = WithinRange AND OpenPositionPercentage < 50 AND OpenPositionPercentage >= 25;
Opening Location 5: BottomQuarter = WithinRange AND OpenPositionPercentage < 25 AND OpenPositionPercentage >= 10;
Opening Location 6: Bottom10 = WithinRange AND OpenPositionPercentage < 10;

// Define classifications for opening above previous day's range
AboveRange = Open > PrevHigh;
ATRAboveRange = (Open - PrevHigh) / ATRValue;
Opening Location 7: OpenATR0to25 = AboveRange AND ATRAboveRange <= 0.25;
Opening Location 8: OpenATR25to50 = AboveRange AND ATRAboveRange > 0.25 AND ATRAboveRange <= 0.5;
Opening Location 9: OpenATR50to75 = AboveRange AND ATRAboveRange > 0.5 AND ATRAboveRange <= 0.75;
Opening Location 10: OpenATR75to1 = AboveRange AND ATRAboveRange > 0.75 AND ATRAboveRange <= 1;
Opening Location 11: OpenATRGreater1 = AboveRange AND ATRAboveRange > 1;

// Define classifications for opening below previous day's range
BelowRange = Open < PrevLow;
ATRBelowRange = (PrevLow - Open) / ATRValue;
Opening Location 12: OpenBelowATR0to25 = BelowRange AND ATRBelowRange <= 0.25;
Opening Location 13: OpenBelowATR25to50 = BelowRange AND ATRBelowRange > 0.25 AND ATRBelowRange <= 0.5;
Opening Location 14: OpenBelowATR50to75 = BelowRange AND ATRBelowRange > 0.5 AND ATRBelowRange <= 0.75;
Opening Location 15: OpenBelowATR75to1 = BelowRange AND ATRBelowRange > 0.75 AND ATRBelowRange <= 1;
Opening Location 16: OpenBelowATRGreater1 = BelowRange AND ATRBelowRange > 1;

Everything is based on a 10 day ATR.

I want to combine each Opening Location with each Simple Moving Average in order to create individual Indicators.

Example of an Indicator: Simple Moving Average 1 + Opening Location 1 = SMA State 1_Opening Location 1. Because there are four Simple Moving Average States and 16 Opening Locations, there are 64 individual Indicators.

Parameters:
Make a parameter that allows me to choose:
- Entry Time (HH:MM:SS) based on five minute bars
- Exit Time (HH:MM:SS) based on five minute bars
- Minimum number of trades taken previously over the range of dates (Example: this particular strategy which is valid for today yielded 100 trades from 2011-present)
- Minimum CAR/Maximum Draw Down
- Profit target in 10 day ATR
- Stop loss in 10 day ATR

If neither a profit target or stop loss are hit, the trade is exited by time specified in Exit Time. This is an intraday system only. This is a long strategy only.

Exploration Report:
All tickers that are included in the filter will come up in the exploration. In the exploration report, I don't want to see all 64 individual Indicators. I simply want to see:
1. Win %
2. Average Profit
3. Average Profit %
4. Average Loser
5. Average Loser %
6. CAR/Maximum Draw Down
7. RAR/Maximum Draw Down
8. Number of previous trades trades taken with today's conditions (gap size + moving average)

Make each column sortable.

Backtest:
Ensure I can create a backtest based on all of these requirements.

Optimization:
Create the code without loops so my machine isn't single threaded in order to avoid prolonging optimization time. I should be able to discover the optimal fast moving average, slow moving average, opening gap location, entry time, and exit time.
Related categories: Algorithm Amibroker Formula Language