You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to increase the cash by 0.25 for every successful trade. I tried something like this, but it hasn't worked yet. Do you have any suggestions?
# Subclass Backtest to modify cash after each successful tradeclassCustomBacktest(Backtest):
def_on_order(self, order):
# Call the parent class's _on_order method to ensure all default behavior is preservedsuper()._on_order(order)
# Check if the order is closediforder.is_closed:
print(f"Order closed: {order}") # Debugging: Print order details# Check if the closed order was profitableiforder.pl>0:
print(f"Profitable order: {order.pl}") # Debugging: Print order profit# Increase cash by 25% of the current cash balanceoriginal_cash=self._cashself._cash+=self._cash*0.25print(f"Cash updated from {original_cash} to {self._cash}") # Debugging: Print cash update details# Create a Backtest object with the strategy and the DataFramebt=CustomBacktest(dfpl, MyStrat, cash=100, margin=1/10, commission=0.00)
The text was updated successfully, but these errors were encountered:
Hi,
I would like to increase the cash by 0.25 for every successful trade. I tried something like this, but it hasn't worked yet. Do you have any suggestions?
The text was updated successfully, but these errors were encountered: