tosin2013 commited on
Commit
e66a30a
·
1 Parent(s): 066c173

updating backtest wording

Browse files
Files changed (1) hide show
  1. app.py +32 -6
app.py CHANGED
@@ -254,14 +254,41 @@ def run_backtest(api_key, from_symbol, to_symbol, interval):
254
  win_percentage = (total_wins / total_trades) * 100
255
  loss_percentage = (total_losses / total_trades) * 100
256
 
257
- # Determine if it's a buy or sell based on percentages
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  if win_percentage > loss_percentage:
259
- signal = "Backtest Agrees"
260
  color = "green"
261
  else:
262
- signal = "Backtest Disagress"
263
  color = "red"
264
 
 
265
  # Get trade decision information
266
  trade_decision, trade_type, trade_timeframe, reason = should_trade(strategy_instance, api_endpoint, api_key, from_symbol, to_symbol)
267
 
@@ -278,12 +305,11 @@ def run_backtest(api_key, from_symbol, to_symbol, interval):
278
  <p><strong>Trade Log:</strong></p>
279
  <ul>
280
  """
281
- # Get trade log from the strategy
282
- trade_log = strategy_instance.get_trade_log()
283
-
284
  for trade in trade_log:
285
  html_message += f"<li>Trade {trade['trade_num']}: {trade['trade_type']} - {trade['outcome']}</li>"
286
 
 
287
  html_message += "</ul>"
288
 
289
  # Include trade decision information
 
254
  win_percentage = (total_wins / total_trades) * 100
255
  loss_percentage = (total_losses / total_trades) * 100
256
 
257
+ # Get trade log from the strategy
258
+ trade_log = strategy_instance.get_trade_log()
259
+
260
+ # Iterate through the trade log and count valid trades
261
+ valid_buy_trades = 0
262
+ valid_sell_trades = 0
263
+
264
+ # Initialize a variable to store the last trade line
265
+ last_trade_line = ""
266
+
267
+ # Iterate through the trade log and count valid trades
268
+ for trade in trade_log:
269
+ if trade['trade_type'] == 'CALL':
270
+ valid_buy_trades += 1
271
+ elif trade['trade_type'] == 'PUT':
272
+ valid_sell_trades += 1
273
+
274
+ # Store the last trade line
275
+ last_trade_line = f"Trade {trade['trade_num']}: {trade['trade_type']} - {trade['outcome']}"
276
+
277
+ for trade in trade_log:
278
+ if trade['trade_type'] == 'CALL':
279
+ valid_buy_trades += 1
280
+ elif trade['trade_type'] == 'PUT':
281
+ valid_sell_trades += 1
282
+
283
+ # Determine if the backtest agrees (valid Buy trades > valid Sell trades)
284
  if win_percentage > loss_percentage:
285
+ signal = last_trade_line
286
  color = "green"
287
  else:
288
+ signal = last_trade_line
289
  color = "red"
290
 
291
+
292
  # Get trade decision information
293
  trade_decision, trade_type, trade_timeframe, reason = should_trade(strategy_instance, api_endpoint, api_key, from_symbol, to_symbol)
294
 
 
305
  <p><strong>Trade Log:</strong></p>
306
  <ul>
307
  """
308
+
 
 
309
  for trade in trade_log:
310
  html_message += f"<li>Trade {trade['trade_num']}: {trade['trade_type']} - {trade['outcome']}</li>"
311
 
312
+
313
  html_message += "</ul>"
314
 
315
  # Include trade decision information