Position Sizing Afl

Hello

Please help with modifying this position sizing AFL. I would prefer an option to choose out of either

  1. Risk Per Trade - $ Amount
  2. % Of Capital

Thank you...!!!

_SECTION_BEGIN("Risk Management");
SetChartOptions(0,chartShowArrows|chartShowDates);
Amnt = Param("Investment $ ",1000);
perc = Param("Target %",1,1,1.5,0.1)/100 ;
share = round(Amnt/C) ;
//Vol = round(ev) ;
Vol = Ref(V, -1) ;
per = Prec(((H-L)/C)*100,4) ;
trgtup = Prec(C*(1.01+perc),4) ;
trgtdn = Prec(C*(1-perc),4) ;
Title =  Name() + ",  " + Date() + "  O: " + Open + ", H: " + High + ", L: " + Low +  ", C: " + C + ", Amnt = " + Amnt + "   
Qty  =   " + share + "\nTP = " + trgtup + "\nSL  = " + trgtdn ;

_SECTION_END();

Still a rookie here by all means but assuming you want the option to switch position sizing methods in the Parameters Dialogue and not based on some other condition, something like this should work:

// Not tested
_SECTION_BEGIN( "Risk Management" );

pSizeType = Param( "Pos Sizing (0 = $ Per Trade, 1 = % of Eq)", 0, 0, 1, 1 );

pSize = 0;

if( pSizeType == 0 )
{
    riskPerShare =  2 * ATR( 20 );
    positionRisk = 1;
    pSize =  positionRisk * BuyPrice / riskPerShare;
    SetPositionSize( pSize, spsPercentOfEquity );
    // Stop?
}

if( pSizeType == 1 )
{
    pSize =  10;
    SetPositionSize( pSize, spsPercentOfEquity );
    // Stop?
}

_SECTION_END();
1 Like

Hello larata

Thank you so much for your efforts,I really appreciate them.

For some reason I am unable to view the Qty, Tp & Sl on chart after applying your formula.

Best,
RK

I am going through amibroker knowledge base as of now to see if I can learn position sizing afl so that I don't end up asking for members help every time.

What is wrong with this afl?
Van Tharp risk based $$$ , not atr based.

No syntax error.

Entry is at current market price, Stoploss lowest low of last 5 candles.

I cant figure out coding, its not displaying anything on my chart.

Please help code Position sizing afl based on risk in $$$ only , i dont like atr approach.

Thanks.

SetOption("maxopenpositions" , 20);
SetOption("accountmargin", 100);

Entrysignal = LastValue(C);
Exitsignal = LLV(C, 5);

RiskPct = 1;
Stopsize = Entrysignal - Exitsignal;
SetPositionSize ((stopsize / RiskPct) * C, spsPercentOfEquity);

Lastvalue(C) ?

Seems incorrect if I want current running price value....

Also no section begin , end?

Can someone please help, I cant get it right....

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.