Preston James
Preston James

Reputation: 11

Configuring Strategy Settings and Qty To Use Variable Calculated Lots With Leverage

Any help on this would be GREATLY appreciated. It's stumped me for way too long.

I'm trying to set up my strategy for deep backtesting. I currently use my own custom backtesting table calcs, and I'm having a lot of trouble getting the built-in strategy settings to return the same result.

I'm trading EURUSD on 1-min timeframe with 500:1 leverage. Trades will auto-close if margin level reaches 0.7 or below. Commission is $8 per lot (100,000 units).

I calculate position size in lots by using volatility to set a stop then setting the max loss (loss if stop is hit) to 2% of account balance. Thus, "strategy.percent_of_equity" won't work because it varies on each trade. Instead, I'm trying to use "strategy.fixed" and pass in my lots calc.

My current attempt at the strategy settings:

    default_qty_type=strategy.fixed,
    default_qty_value=(1*100000.0)*500,

    initial_capital=10000,
    currency=currency.USD,

    commission_type=strategy.commission.cash_per_contract,
    commission_value=(8.0/100000.0),

    margin_long=(1.0/500)*70,
    margin_short=(1.0/500)*70,

My current attempt at "qty" during trade execution:

    var float x_unitsPerLot = 100000.0
    strategy.entry(id="Long",  direction=strategy.long,  qty=(x_lots*x_unitsPerLot)*500)
    strategy.entry(id="Short", direction=strategy.short, qty=(x_lots*x_unitsPerLot)*500)

Thanks!

Upvotes: 0

Views: 937

Answers (1)

G.Lebret
G.Lebret

Reputation: 3108

"default_qty_type = strategy.percent_of_equity" will work for you.

If you use it in the strategy setting, it just tell pinescript that the qty value (in your strategy.entry) will represent the percent of equity (and not a quantity of shares).

So you can change it in your strategy.entry by using a variable.

Upvotes: 0

Related Questions