Back to Community
Algo adding target to current_price instead of subtracting...

Not sure if I have this formatted correctly, but here goes.

When we take a short position, I want to set the context.target to the current_price - context.tgtval.

But the code appears to be adding the context.tgtval instead of subtracting it.

It even adds the value when I remove the variable and type the amount directly.

I put a comment with the word BUG right above where this happens.

What am I doing incorrect?

Clone Algorithm
8
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 51e0503127462806cb6338c9
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.
1 response

Chuck, that branch of code is never executed because cash is never $10k more than capital_used in your time period.

Also you should know that both cash and capital_used are calculated as the net of long and short positions (short dollars subtracted from long dollars). You may be expecting them to be calculated as the absolute sum (I posted a recent thread on the subject).

Your use of the variables may be consistent with the net calculation but I wanted to bring it to your attention nonetheless.

Clone Algorithm
2
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 51e0ba2bff5fdd06d5271f86
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.