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