Need help with Positionsize problem

Hi guys,
I face with this problem that i used both PowerPlay condition and "Account Margin" to decide Open 100% position or 50% of position when the condition is not met.
When i used spsPercentOfEquity in SetPositionSize, PowerPlay is still working but Account Margin is not working.
While i used "spsPercentOfPosition" in SetPositionSize, Account Margin is working but PowerPlay Condition is not working.
Can SomeOne know to solve this problem or other way to use both PowerPlay Condition and Account Margin in Position Size like below Code?
Thanks for reading!

RSICrossup = Cross(RSI(),30);
RSICrossDn = Cross( 70,RSI());

PowerPlay_Short = ShortCond1 AND RSICrossDn;
PowerPlay_Long = BuyCond1 AND RSICrossUp;

PowerPlay = IIf( PowerPlay_Short OR PowerPlay_Long,1,2);
Pos_powerplay = 100/PowerPlay;
Buy = Buy_Cond1;
Sell = Sell_cond1;
Short = Short_cond1;
Cover = Cover_cond1;
SetOption("FuturesMode", True);
SetOption("InitialEquity", 10000);
SetOption("AccountMargin", 10  );
//SetOption("MaxOpenPositions", Pos_powerplay );
PositionSize = -Pos_powerplay ;
//SetPositionSize( -100, spsPercentOfPosition  ); 
//SetPositionSize(100/PowerPlay, spsPercentOfEquity );

Account Margin is for using leverage. Is that your intent?

See Set Options.
See Set Position Size.

Hi @TrendSurfer,
Your right, its for leverage. I use my system for futures trading. Therefore, i need setup leverage to backtest and optimize the system

Is this what you are after?

If not please post full code and give more specifics.

maxPositions = 10;

PowerPlay = IIf(PowerPlay_Short OR PowerPlay_Long, True, False);
PositionSizer = 100 / maxPositions;

SetOption("MaxOpenPositions", maxPositions);
SetPositionSize(IIf(PowerPlay, PositionSizer, PositionSizer / 2), spsPercentOfEquity);

Account margin is for trading stocks (borrowing money from your broker to buy stocks). It is not Futures trading setttings.

As for Futures, CFD, FX trading

etc.

3 Likes

Thank you so much @fxshrat
You solved my problem