Hi Casoni Position Sizing

#1
Dear Traderji Members,
I need position Sizing to be in this format can you help

Like i have 1 lakh capital
from initial capital i want to start trade

position sizing for initial capital is
SetPositionSize ( 100, spsPercentOfEquity );


when equity grows to 20% up
i want position size to change to
SetPositionSize ( 200, spsPercentOfEquity );

When equity Less than Initial capital Maintain the Position size of

SetPositionSize ( 100, spsPercentOfEquity );

thankyou and looking forward for your help
 
Last edited:

casoni

Well-Known Member
#2
Hello autotrade .
sorry
i have no idea how to code those , better ask / take senior members help..

and secondly never mention members name in thread / subject , this is not good practice , Now if any member know how to code this they wont come forward , because you have asked a particular person .

Thank you
 
#3
Dear Traderji Members,
I need position Sizing to be in this format can you help

Like i have 1 lakh capital
from initial capital i want to start trade

position sizing for initial capital is
SetPositionSize ( 100, spsPercentOfEquity );


when equity grows to 20% up
i want position size to change to
SetPositionSize ( 200, spsPercentOfEquity );

When equity Less than Initial capital Maintain the Position size of

SetPositionSize ( 100, spsPercentOfEquity );

thankyou and looking forward for your help
May I ask where you learned your maths?
Existing equity can not exceed 100%.
The thing that you wanna do is trading via margin -> gaining size via leverage.


Code:
// margin account example by watchinu

SetOption( "InitialEquity", 100000 );
SetOption( "FuturesMode", 1 );
SetOption( "MaxOpenPositions", 1 );
 // 50% * leverage 2 = 100% start size
SetPositionSize( 50, spsPercentOfEquity );
SetOption( "UsePrevBarEquityForPosSizing", true );

// or set contract specifications in Information window
// and remove below ones
Pointvalue    = 1;
RoundLotSize  = 1;
TickSize      = 0.01;
 
Leverage      = 2;
MarginRate    = 1 / Leverage;
// dynamic calculation of margin
MarginDeposit = -100 * MarginRate;// so -100 * 1 / 2 = -50

// 2nd Phase - custom backtest
SetOption( "UseCustomBacktestProc", True );
if ( Status( "action" ) == actionPortfolio ) {
    // retrieve the interface to portfolio backtester
    bo = GetBacktesterObject();
    bo.PreProcess();

    for ( bar = 0; bar < BarCount; bar++ ) {
        // this retrieves current value of portfolio-level equity
        Eq = bo.Equity;
        // this for loop iterates through all trade signals and adjusts pos. size  
        for ( sig = bo.GetFirstSignal( bar ); sig; sig = bo.GetNextSignal( bar ) ) {
            // when our initial equity grows by 20% set pos. size to 100%
            // since it is margin account with leverage 2 it uses 2 times the unleveraged max. pos. size
            if ( Eq > GetOption( "InitialEquity" ) * 1.2 )
                sig.PosSize = -100;
        } 
        bo.ProcessTradeSignals( bar );
    }
    bo.PostProcess();
}

// your system here
// ....
 
#4
May I ask where you learned your maths?
Existing equity can not exceed 100%.
The thing that you wanna do is trading via margin -> gaining size via leverage.


Code:
// margin account example by watchinu

SetOption( "InitialEquity", 100000 );
SetOption( "FuturesMode", 1 );
SetOption( "MaxOpenPositions", 1 );
 // 50% * leverage 2 = 100% start size
SetPositionSize( 50, spsPercentOfEquity );
SetOption( "UsePrevBarEquityForPosSizing", true );

// or set contract specifications in Information window
// and remove below ones
Pointvalue    = 1;
RoundLotSize  = 1;
TickSize      = 0.01;
 
Leverage      = 2;
MarginRate    = 1 / Leverage;
// dynamic calculation of margin
MarginDeposit = -100 * MarginRate;// so -100 * 1 / 2 = -50

// 2nd Phase - custom backtest
SetOption( "UseCustomBacktestProc", True );
if ( Status( "action" ) == actionPortfolio ) {
    // retrieve the interface to portfolio backtester
    bo = GetBacktesterObject();
    bo.PreProcess();

    for ( bar = 0; bar < BarCount; bar++ ) {
        // this retrieves current value of portfolio-level equity
        Eq = bo.Equity;
        // this for loop iterates through all trade signals and adjusts pos. size  
        for ( sig = bo.GetFirstSignal( bar ); sig; sig = bo.GetNextSignal( bar ) ) {
            // when our initial equity grows by 20% set pos. size to 100%
            // since it is margin account with leverage 2 it uses 2 times the unleveraged max. pos. size
            if ( Eq > GetOption( "InitialEquity" ) * 1.2 )
                sig.PosSize = -100;
        } 
        bo.ProcessTradeSignals( bar );
    }
    bo.PostProcess();
}

// your system here
// ....
Can you explain detailly please
 
#6
You can check this t00 and sure helps my issue
Thanks

https://www.bigmiketrading.com/amibroker/24507-amibroker-tiered-position-sizing.html

// -------------------------------------------------------------------------------------
Free auto trading link: http://tradingsw.blogspot.in/p/software.html
/* Global Options */
SetFormulaName("RLCO v011"); /*Name of script in backtest report */
SetOption("UseCustomBacktestProc", True ); // Use custom backtester for tiered position sizing
SetBarsRequired(100000,100000); /* ensures that the charts include all bars AND NOT just those on screen */
SetTradeDelays( 1, 0, 1, 0 ); /* DELAY one bar on entry, but not exits */
SetOption( "InitialEquity", 100000 ); /* starting capital */
//SetPositionSize( 350, spsPercentOfEquity ); // Not currently used
PositionSize = -100; /* trade size is set in the custom backtest section below. Leave at 100% (-100) here */
SetOption( "AccountMargin", 25); /* Day trading margin; 25% */
SetOption( "MaxOpenPositions", 1 ); /* Span on control = # of open positions allowed */
SetOption( "PriceBoundChecking", 1 ); /* trade only within the chart bar's price range */
SetOption( "CommissionMode", 2 ); /* set commissions AND costs as $ per trade */
SetOption( "CommissionAmount", 0.00 ); /* commissions AND cost */
SetOption( "UsePrevBarEquityForPosSizing", 1 ); /*set the use of last bar's equity for trade size*/
SetOption( "ActivateStopsImmediately", True); /* Allow immedate exit */
PositionScore = 100/C; /*Set priority order for trades when mulitple signals trigger on one bar */

// -----------------------------------------------------------------------------------------------------
/* Custom Backtest Code */
// -----------------------------------------------------------------------------------------------------

/* First we enable custom backtest procedure */
SetCustomBacktestProc("");

PctRiskPerTrade = 01; // Risk 1% of total equity per trade

/* Here's the custom backtest procedure */
if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();
// --------------------------------------------------------------------
// Testing tiered position sizing starts here
// --------------------------------------------------------------------
bo.PreProcess();

for ( bar = 0; bar < BarCount; bar++ )
{
CurrentPortfolioEquity = bo.Equity;

for ( sig = bo.GetFirstSignal( bar ); sig; sig = bo.GetNextSignal( bar ) )
{
if ( CurrentPortfolioEquity > 125000 )
sig.PosSize = -300; //1st Tier

if ( CurrentPortfolioEquity <= 125000 AND CurrentPortfolioEquity > 100000 )
sig.PosSize = -200; // 2nd Tier

if ( CurrentPortfolioEquity <= 100000 AND CurrentPortfolioEquity > 75000 )
sig.PosSize = -100; // 3rd Tier

if ( CurrentPortfolioEquity <= 75000 )
sig.PosSize = -50; // 4th Tier
}

bo.ProcessTradeSignals( bar );
}

// --------------------------------------------------------------------
// End Test tiered position sizing
// --------------------------------------------------------------------


bo.Backtest(1); // run default backtest procedure

// Initialize a few variables used later.
SumProfitPerRisk =0;
NumTrades =0;
CumulativeR =0;
TotalR =0;

// Iterate through closed trades.
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{
// Risk is the maximum value we expect to lose on a trade
Risk = ( PctRiskPerTrade / 100 ) * trade.GetEntryValue();
RMultiple = trade.GetProfit()/Risk;
CumulativeR = RMultiple + CumulativeR;

// Show the initial risk and results in R on the backtest summary / trade log
trade.AddCustomMetric("Initial Risk $", Risk );
trade.AddCustomMetric("R-Multiple", RMultiple );
trade.AddCustomMetric("Cumulative R", CumulativeR );

SumProfitPerRisk = SumProfitPerRisk + RMultiple;
NumTrades++;
}

// expectancy = SumProfitPerRisk / NumTrades;
AverageR = CumulativeR / NumTrades;
// bo.AddCustomMetric( "Expectancy Per $ Risked", expectancy );
bo.AddCustomMetric( "Total R", CumulativeR );
bo.AddCustomMetric( "Average R", AverageR );
bo.ListTrades();

}
 
Last edited:
#7
Re: Position Sizing

Please Refer this

https://groups.yahoo.com/neo/groups/amibroker/conversations/topics/155383

about

SetPositionSize( 200, spsPercentOfEquity );
SetPositionSize( 300, spsPercentOfEquity * ( Buy == sigScaleIn) );
The code in post #3 will do what you are after. You don't seem to understand that you can't exceed 100% equity. As long as you don't understand that it makes no sense to talk any further. Not sure in what kind of world are you living in? Even in your posted link you can read that Tomasz Janeczko has pointed out the same thing. You can only raise position size via margin account to exceed maximum possible position size of 100% equity. So you have to pay interest if you want go higher than that. No broker will make a gift to you and won't give you additional 100% or 200 % of your existing deposit in a way like "You are such a nice guy.That's why we felt that it would just be appropriate to make you even richer than you currently are and make us less richer as we don't deserve anything. We are so in awe of your excellence and we bow to you, our financial god. You deserve any imaginable praise from us poor souls. This small gift is just the least imaginable so please accept our apology. We can assure you that you can accept much more from us but please forgive us if it is not enough of it yet.".
 
#8
Re: Position Sizing

The code in post #3 will do what you are after. You don't seem to understand that you can't exceed 100% equity. As long as you don't understand that it makes no sense to talk any further. Not sure in what kind of world are you living in? Even in your posted link you can read that Tomasz Janeczko has pointed out the same thing. You can only raise position size via margin account to exceed maximum possible position size of 100% equity. So you have to pay interest if you want go higher than that. No broker will make a gift to you and won't give you additional 100% or 200 % of your existing deposit in a way like "You are such a nice guy.That's why we felt that it would just be appropriate to make you even richer than you currently are and make us less richer as we don't deserve anything. We are so in awe of your excellence and we bow to you, our financial god. You deserve any imaginable praise from us poor souls. This small gift is just the least imaginable so please accept our apology. We can assure you that you can accept much more from us but please forgive us if it is not enough of it yet.".

Thankyou for your understanding about that we can exceed 100% of equity And it the below one is we can use according to you

Initial Capital:100000;
PositionSize = -100; // which mean No margin( uses 100000)
PositionSize = -200; // which means double leverage of Initial Capital ( uses 200000)
PositionSize = -300; // which means triple leverage of Initial Capital ( uses 300000)

I thought the above one can be used
 
#9
Re: Position Sizing

Thankyou for your understanding about that we can exceed 100% of equity
You got it all wrong! You can NOT exceed equity beyond 100% but can raise positions size by trading on margin.

T
PositionSize = -200; // which means double leverage of Initial Capital ( uses 200000)
PositionSize = -300; // which means triple leverage of Initial Capital ( uses 300000)
This is all wrong
 

Similar threads