Upload e.g. position sizing via stoploss distance requirement.py
Browse files
e.g. position sizing via stoploss distance requirement.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pxyq
|
| 2 |
+
|
| 3 |
+
ASSET = 'AUDCADc'
|
| 4 |
+
digits = int(pxyq.true_decimal_digits(ASSET)) # 5 decimal digits
|
| 5 |
+
ticksize = float(pxyq.true_tick_size(ASSET)) # 0.00001
|
| 6 |
+
risk_in_cash = 1.03 # cash to risk
|
| 7 |
+
SL_Spread_Mul = 10 # multiplier of spread
|
| 8 |
+
entry_price = 0.98434 # buy the ask
|
| 9 |
+
|
| 10 |
+
# --- compute spread and stoploss distance ---
|
| 11 |
+
proxy_spread = int(pxyq.proxy_spread_in_pips(ASSET)) # 28 pips
|
| 12 |
+
spread_in_price = proxy_spread * ticksize
|
| 13 |
+
sl_distance = spread_in_price * SL_Spread_Mul
|
| 14 |
+
|
| 15 |
+
# stoploss price: for a buy, stoploss is below entry
|
| 16 |
+
stoploss_price = entry_price - sl_distance
|
| 17 |
+
print(f"Stoploss price: {stoploss_price:.{digits}f}")
|
| 18 |
+
|
| 19 |
+
# --- compute proxy-based values ---
|
| 20 |
+
proxy_sl_distance = float(pxyq.proxy_stoploss_distance_covering_1_cash(ASSET))
|
| 21 |
+
print(f"With a SL distance of {proxy_sl_distance:.{digits}f} which overs 1 cash")
|
| 22 |
+
|
| 23 |
+
sl_ratio = sl_distance / proxy_sl_distance
|
| 24 |
+
print(f"SL ratio: {sl_ratio:.2f}")
|
| 25 |
+
|
| 26 |
+
supposed_risk_cash = sl_ratio # because proxy_sl_distance = 1 cash
|
| 27 |
+
print(f"Supposed risk cash: {supposed_risk_cash:.2f}")
|
| 28 |
+
|
| 29 |
+
proxy_lotsize = float(pxyq.proxy_lotsize_covering_1_cash(ASSET)) # 0.02
|
| 30 |
+
proxy_betsize = 1 # always 1 cash
|
| 31 |
+
|
| 32 |
+
# --- conditional logic for minimum lotsize ---
|
| 33 |
+
# Define the broker's minimum lot size (constant)
|
| 34 |
+
min_lotzie = 0.01
|
| 35 |
+
|
| 36 |
+
if supposed_risk_cash > risk_in_cash:
|
| 37 |
+
# Use minimum lotsize
|
| 38 |
+
lowest_lotsize = min_lotzie
|
| 39 |
+
lowest_position = (lowest_lotsize / proxy_lotsize) * proxy_betsize
|
| 40 |
+
position_in_trade = lowest_position * sl_ratio
|
| 41 |
+
print(f"If risk is smaller than what it was supposed to (i.e. {supposed_risk_cash:.2f} > {risk_in_cash:.2f}) –> use minimum lot {lowest_lotsize}")
|
| 42 |
+
else:
|
| 43 |
+
# Otherwise, use the original (calculated) position size
|
| 44 |
+
# For example, position is directly proportional to sl_ratio
|
| 45 |
+
position_in_trade = sl_ratio # or any other logic you prefer
|
| 46 |
+
|
| 47 |
+
print(f"Then that makes our final position in trade: {position_in_trade:.2f} cash")
|
| 48 |
+
|
| 49 |
+
"""
|
| 50 |
+
# CLI output example
|
| 51 |
+
|
| 52 |
+
Stoploss price: 0.98154
|
| 53 |
+
With a SL distance of 0.00071 which overs 1 cash
|
| 54 |
+
SL ratio: 3.94
|
| 55 |
+
Supposed risk cash: 3.94
|
| 56 |
+
If risk is smaller than what it was supposed to (i.e. 3.94 > 1.03) –> use minimum lot 0.01
|
| 57 |
+
Then that makes our final position in trade: 1.97 cash
|
| 58 |
+
"""
|