'pine script first trade cum. profit unreliable? BTCUSD 1 dollar initial investment
I made a pine script for tradingview that uses initial capital of 1 usd and an order size of 0.5 usd for trading BTCUSD. But for some reason the strategy tester list of trades, shows that the first trade has 88k% cum profit.
This makes absolutely no sense to me, as the specific trade entry is 10k and the exit is 11k as shown in the image enter image description here
Also, the strategy never shorts, yet one some datasets/time frames, it ends up with a portfolio of negative thousands of dollars. how can it lose more than 100% of portfolio without ever shorting? It seems to me these numbers are not trustworthy.
For strategy input, i use
strategy("BTC9%lines", overlay=false, shorttitle = "FIBBTC redist", default_qty_type = strategy.cash, default_qty_value=0.5, commission_value = 0.01, initial_capital = 1, currency=currency.USD, calc_on_order_fills=false)
Solution 1:[1]
i found out the solution to the problem. yet i dont know how to delete my post, however perhaps people can benefit from me answering my own question
The problem was that i had a
qty
in my
strategy.entry
which overwrote my strategy default values. why it was able to enter a trade with half of 1 btc at 10k usd with only 1 usd capital is still confusing.
Anyway i solved it by dividing the qty i set in strategy.entry with close
var qtyvaluelower=initialCapital*0.55
var qtyvaluehigher=initialCapital*0.45
if linecross and different and lowerthanlast
strategy.close_all(comment="lc")
strategy.entry("lower", strategy.long, qty=qtyvaluelower, comment="buy more")
if linecross and different and higherthanlast
strategy.close_all(comment="hc")
strategy.entry("higher", strategy.long, qty=qtyvaluehigher, comment="buy less")
changed to
var qtyvaluelower=initialCapital*0.55/close
var qtyvaluehigher=initialCapital*0.45/close
if linecross and different and lowerthanlast
strategy.close_all(comment="lc")
strategy.entry("lower", strategy.long, qty=qtyvaluelower, comment="buy more")
if linecross and different and higherthanlast
strategy.close_all(comment="hc")
strategy.entry("higher", strategy.long, qty=qtyvaluehigher, comment="buy less")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user17567535 |
