'Pine strategy configuration for corresponding to Forex trading
I want to simulate a trading strategy as if I was using this strategy on the Forex.
Let's say I have a 1000$ account with a leverage of 100. If I am not mistaken it would correspond to set :
initial_capital=1000
and I would be able to buy 100 000 units, which would correspond to:
default_qty_value=100000
If these two settings are correct, if I want to "risk" 20$ for each trade, should I set the default_qty_value to be equal to 2000 ? ( indeed, 20$ is 2% of my capital, then ( 2 / 100 ) * 100 000 = 2000 $ )
Solution 1:[1]
You need to set it to 20, if you trading with cash.
Check it on TSLA, 1D:
//@version=5
strategy("strategy.cash", overlay = true, default_qty_value = 20, default_qty_type = strategy.cash, initial_capital = 1000)
if bar_index == 0
// As ‘qty’ is not defined, the previously defined values for the `default_qty_type` and `default_qty_value` parameters are used to enter trades, namely 20 units of cash in the currency of `strategy.account_currency`.
// `qty` is calculated as (default_qty_value)/(close price). If current price is $5, then qty = 20/5 = 4.
strategy.entry("EN", strategy.long)
if bar_index == 100
strategy.close("EN")
Other types is strategy.fixed and strategy.percent_of_equity
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 | Starr Lucky |
