Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position Size calculation help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Position Size calculation help

    Hi,
    I've written code to perform dynamic position sizing based on the % of the total account balance I want to risk. However I'm struggling with the last step to calculate the number of UnitsToBuy when I have the amount I wish to risk in dollars and the number of points(ticks) that risk in dollars is equivalent to. Can someone please suggest what that calculation should be?

    I'm focusing on GBPUSD but ideally the sizing calculation should work with other currencies too, particularly where the point value is different (ie. GBPJPY).
    Is there a way to find the tick size of the current instrument?


    Code:
    double Risk = 3.0; //Risk in % of Account
    double backTestCash = 50000;
    
     protected override void OnBarUpdate()  {
    
      if (Historical) {
        // BACKTEST
        CASH = backTestCash + Performance.AllTrades.TradesPerformance.Currency.CumProfit;
      } else {
        // LIVE
        CASH = GetAccountValue(AccountItem.CashValue);	// returns 0 during backtest
      }
    
      TradeRiskInPoints = ( (High[0]-Close[0])+(atrfactor*ATR(14)[0]) )*1000;	
      // 1000 is for GBPUSD points, but I'd have to use a different value for GBPJPY			
      
      RiskInCash = CASH*(Risk/100);
    
      UnitsToBuy = (int)Math.Floor( ???? );
    
    
    
      // BUY SHORT ---------------------------------
      if ( GoShort==true && Position.MarketPosition == MarketPosition.Flat ) {
        entryOrder = EnterShort(UnitsToBuy,"TR_Short");	
        ShortStopLossPrice = High[0]+(atrfactor*ATR(14)[0]);
      }
    
    
    
    
      // SHORT STOP LOSS -----------------------
      if ( (High[0] >= ShortStopLossPrice) && (Position.MarketPosition == MarketPosition.Short) ) {
        ExitShort("StopLoss","TR_Short");	
      }
    
    }

    #2
    Hello,

    Thank you for the post.

    I am unsure what the exact end result equation you want would be in regard to what goes where the question marks are, but to get the tick size, you could use the property TickSize.

    An example:

    Code:
    double myPrice = Close[0] - (2 * TickSize); // Close minus 2 ticks.
    I look forward to being of further assistance.

    Comment


      #3
      Thanks Jesse.

      For position size (in units) I think this might be it...

      Number of Units to Buy = (Account size * percent exposure)/# pips risk / pip value

      Where pip value is {10 = standard, 1 = mini, 0.1 = micro, if InteractiveBroker then 0.0001}

      Comment


        #4
        Hello,

        Thank you for the reply.

        Did you need assistance forming the provided equation into syntax? I was not sure as you said you think this is the equation.

        I could not suggest the equation its self but if this is correct to what your trading logic needs, I could assist with the syntax for what you have provided.

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        576 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X