iTranslated by AI
Understanding richmanbtc's Force Entry Price: A Personal Summary
Must-read books for botters
- The Reality of a Botter Revealed by an SS-Class Trader Making 3 Million Yen a Day
This is the well-known book by richmanbtc.
It was the book that clearly led me to become a botter when I was vaguely thinking about wanting to profit from cryptocurrency trading.
I think it's good for people considering becoming a botter as you can learn about general aspects like the merits and good targets for botters.
- Techniques to Win at Kaggle
A book recommended by richmanbtc. He wrote to read it whenever you get stuck.
I sometimes thought "???" when I was doing data preprocessing or creating learning models.
I was able to clear things up by reading it then.
My journey from being a humanities major with no machine learning experience to becoming a botter by following richmanBTC's tutorial
Introduction
Please be aware that some of the information written here might be incorrect, so please read with caution.
About Force Entry Price
Force Entry Price is the actual price at which an order is filled when you follow the price with a limit order from the moment you decide to buy until it's executed. This is a custom term. The way the limit order is placed is arbitrary. Although it has "entry" in its name, the calculation for "exit" is the same, so there is no distinction between them.
What does this mean exactly?
It involves checking the price at which a limit order can be executed for an entry.
Additionally, if the order is executed, "Force Entry Time" is also calculated to determine how long it took until the execution.
I feel it's difficult to understand without knowing the difference between "Execution" and "Settlement"
I think it's easy to get confused because many people use "execution" to mean the same thing as "settlement."
-
Execution: The fulfillment of an order. In other words, orders at the time of entry are executions, and settlements (exits) such as profit-taking or stop-loss are also executions.

-
Settlement (Exit): Refers to the execution specifically for profit-taking or stop-loss.
Purpose of calculation
This is a part used to create ground truth data for machine learning.
If the order cannot be executed, you cannot enter the trade in the first place, making it impossible to determine the outcome of the trade.
How to create ground truth data (This article covers up to step ②)
- At each time step, place a buy limit order based on a limit price distance (limit_price_dist) calculated by a certain rule.
- If the buy limit order is not executed, set y to zero.
- If the buy limit order is executed, wait for a certain duration (horizon) and then exit using the Force Entry Price execution method.
- Set y to Exit Price / Entry Price - 1 - 2 * fee.
Once the execution (entry) is successful, move on to the next process.
How to Use
The idea is to explore whether an entry can be made for each bar.
If an entry is successful,
def calc_force_entry_price(entry_price=None, lo=None, pips=None):
y = entry_price.copy()
y[:] = np.nan
force_entry_time = entry_price.copy()
force_entry_time[:] = np.nan
for i in range(entry_price.size):
for j in range(i + 1, entry_price.size):
if round(lo[j] / pips) < round(entry_price[j - 1] / pips):
y[i] = entry_price[j - 1]
force_entry_time[i] = j - i
break
return y, force_entry_time
We pass entry_price into the arguments of this function.
To maintain consistency in the values assigned to entry_price, we use an indicator called ATR to create ['buy_price'] for buy limit orders and ['sell_price'] for sell limit orders.
ATR is an indicator used to measure volatility (price range).
The calculation method involves the following three formulas, and the largest one is treated as the True Range:
① High of the bar - Low of the bar = (e.g., 10 pips)
② Low of the bar - Closing price of the bar = (e.g., 15 pips)
③ High of the bar - Low of the bar = (e.g., 8 pips)
By doing this, you can find which one has the largest price range.
In the case above, ② would be used as the True Range.
Incidentally, when using ATR as an indicator, it is calculated for each bar and then the moving average is determined.
Generally, when used with daily bars, a 14-day moving average is used.
Note that since we are only using it for entry calculation this time, we will not calculate the moving average.
If it's not consistent, the data integrity will be lost.
Since this is a sample, it is mentioned that you can also create your own indicators for entry judgment.
pips = 1
limit_price_dist = df['ATR'] * 0.5 # ATR is already defined using Ta-lib
limit_price_dist = np.maximum(1, (limit_price_dist / pips).round().fillna(1)) * pips
# Place buy limit and sell limit orders at a distance of limit_price_dist on both sides from the closing price
# This is used as the consistent price for entries.
df['buy_price'] = df['cl'] - limit_price_dist
df['sell_price'] = df['cl'] + limit_price_dist
Buy Limit Price: Closing Price - ATR
Sell Limit Price: Closing Price + ATR are used as consistent entry prices.
# Whether the limit order was executed (0, 1)
df['buy_executed'] = ((df['buy_price'] / pips).round() > (df['lo'].shift(-1) / pips).round()).astype('float64')
Convert the entry status into 0 or 1.
Here, it determines whether the limit order was executed one bar later.
If executed, it's True (1); otherwise, it's False (0).
*Note: In the actual code, this part is located below the following code block.
# Force Entry Price calculation
df['buy_fep'], df['buy_fet'] = calc_force_entry_price(
entry_price=df['buy_price'].values,
lo=df['lo'].values,
pips=pips,
)
The price at which the entry was successful is returned in df['buy_fep'].
The time taken until the entry was executed is returned in df['buy_fet'].
The sell-side also exists, but since it can be implemented by making values negative, it is omitted here.
Sources
Execution Simulation: https://note.com/btcml/n/n9f730e59848c
Execution and Settlement: https://rinofx.xbiz.jp/fx-yakujou-kessai/
richmanbtc's GitHub: https://github.com/richmanbtc/mlbot_tutorial
Discussion