Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

FX Trading Account Size and Dynamic lot sizing

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

    FX Trading Account Size and Dynamic lot sizing

    Hi,
    Im hoping someone can assist me with a problem I am having trouble solving, I should mention I am developing a system for forex trading, and I am trying to get the system to work on during backtesting and walk forward testing.
    I am having some difficulty achieving the desired results in coding a money management system. This basic issue that I have is that I cant access the account balance or available equity to dynamically adjust the lot size. At present I have been cycling through the trade history, to collect the result of the last trade and then either subtracting or adding the result to a running balance variable.
    Here is an example of what I am currently running.


    if(Performance.AllTrades.Count!=last_number_of_trade s)
    {
    last_number_of_trades++;


    running_balance += (Math.Round(Performance.AllTrades[last_number_of_trades-1].ProfitPoints,4)*(1/TickSize))*pip_value;

    }


    if(Performance.AllTrades.Count==0)
    {
    running_balance = account_start_balance;
    }

    I also you a File.AppendText snippet further on that allows me to print a log of each trade, the results, profit/loss, and the running balance ect...
    The problem is that I have defined the account start balance at $10,000. When the strategy is finished back testing I review the performance report and the result is something like -8000 which is fine because im working on the money management not the trade logic, but the log I have printed shows that the running balance falls from $10,00 to $8,000 a drop of only 2000. Why is this happening?
    Is there some way that I can define the account balance at the start of the back test, so that I don’t have to go through this process of cycling through the trade history after each trade to collect the results? I am aware of AccountSize, however will this result in the system discarding my dynamic lot sizing and simply allocate a lots based on the defined margin requirements for the instrument and the account size? I have tried GetAccountValue but this doesn’t work, can I ask what its purpose is if it cant be back tested?
    Also is there someway that I can get the available equity if I was to consider opening another position? It needs to work in back testing though.
    Finally, in the instrument manager, if I was define EUR/USD margin requirements as 200, given that I intend to trade with FXCM Australia who over 200:1 leverage. Would this be the correct setting? Would the backtest respect this value, so that if I already had one lot open, it would understand the available margin not simply the account value. If I adjust the point value to 1, would this be the value of 1 dollar traded which has moved one pip? For example one standard lot of 100,000 has a value of 10 dollars for each pip, whereas a mini lot of 10 000 has a value of 1 dollar for each pip. So to replicate these conditions do I need to set the point value to 0.0001, so that in back testing a mini lot of 10000 would earn 1 dollar for each pip movement?
    I have included the code im working with, its nothing fancy but it may give you a better understanding of what I have tried so far.
    Attached Files

    #2
    Hello NeuralFX,

    Thank you for your post.

    The AccountSize() will set a default value to be used for position sizing, this will overwrite your custom sizing here. With AccountSize() order contract/lot size is calculated based on AccountSize / Margin Requirement (the Margin Requirement is set for the currency or future in the Instrument Manager).

    GetAccountValue() will return 0 on historical bars, so in backtesting it will be 0 as backtesting is done on historical bars. This is because GetAccountValue() accesses the account the strategy is trading on, on historical bars this information is not available and in backtesting.

    Your idea of creating your own custom tracking values is the right way to go for your needs. I will review your code and look into the items detailed further and follow up with you here.

    I look forward to assisting you further.

    Comment


      #3
      Hello NeuralFX,

      Thank you for your patience on this matter.

      So I may investigate this matter further can you provide a screenshot of the performance report showing the account balance at -8000 and the line from your log that shows 8000?

      I look forward to your response.

      Comment


        #4
        NinjaTrader_PatrickH,

        Thanks for the reply, I have attached the two screen shots you asked for. Any chance you could answer my question the leverage setup as well.

        Thanks,
        Attached Files

        Comment


          #5
          Hello NeuralFX,

          Thank you for your response.

          You are correct to develop your own method to track these values, but somewhere in the code something is not matching the PnL of the trades based on the performance report. Your NinjaScript / C# Code will always be logically processed and evaluate according to your set logic – this can of course lead to unexpected results at times, thus we would suggest to simplify and debug your code to better understand the event sequence it would go through - unfortunately we cannot offer such debug or code modification services here, but please see the provided resources below to help you proceed productively :

          First of all you would want to use Print() statements to verify values are what you expect - Debugging your NinjaScript code.

          For strategies add TraceOrders = true to your Initialize() method and you can then view valuable output related to strategy submitted orders through Tools > Output window - TraceOrders

          It may also help to add drawing objects to your chart for signal and condition confirmation - Drawing Objects.

          If you would prefer the debug assist of a professional NinjaScript consultant, please check into the following listings - Click here for a list of certified NinjaScript Consultants

          Please let me know if you have any questions.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          671 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          379 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          111 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          575 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          582 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X