Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Best way to calculate the size of the position based on stoploss in points

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

    Best way to calculate the size of the position based on stoploss in points

    I need your help to better calculate the struggle, I come from the mql language and normally use this function:

    Double CalculateLotSize(double MMRiskMoney,double sl)
    {
    double MMTickValue = Instrument.MasterInstrument.PointValue * TickSize;
    double MMTickSize = Instrument.MasterInstrument.TickSize;

    double lot = MMRiskMoney / (sl * (MMTickValue / MMTickSize));
    return lot;
    }​

    I tried it on the demo sim 101 account and on Eurusd
    I return a struggle 100000 lots
    to risk $ 100
    with 0.001 stoploss
    does not convince me much.

    Thank you​

    Best Regards

    #2
    Hello termi_80,

    From the code provided I am not sure what is wrong because I don't know what you tried in NinjaScript or what your original code looked like or what the result was. The code you provided looks pretty close to NinjaScript, the variables getting tick size and point value are correct.

    To find out what is wrong you would need to compare what you originally used against what you made for NinjaScript and make sure all the values and results are the same.

    You can use Print statements in NinjaScript to output data or variables to the output window:




    Comment


      #3
      Forgive me, maybe I did not explain the function in question well was tried on Ninja Trader, as you can see in this photo
      Click image for larger version  Name:	immagine.png Views:	0 Size:	102.1 KB ID:	1231253

      My question is,This calculation is correct?
      I tried it on the demo sim 101 account and on Eurusd
      The function return a struggle 100000 lots, but i sound me not so good....
      to risk $ 100
      with 0.001 stoploss​
      For forex in ninja trade i need to divide for 1000?

      Best Regards


      Last edited by termi_80; 01-14-2023, 05:48 AM.

      Comment


        #4
        Originally posted by termi_80 View Post
        Forgive me
        Hello, termi_80.
        in order for you to be given a competent answer you need to correctly formulate your post:
        1. Write down your end goal. i.e. what are you trying to achieve?
        2. write and describe the variables you use.
        3. write the values you use for your variables.
        4. Write and describe the sequence of your steps in your function.
        5. write why for lots you return double and not int?
        To help you, the community needs the full picture.
        but Perhaps answering these questions will close your own question.​

        Comment


          #5
          Hi Danila,
          Thanks for support.

          As I wrote I am new to the world Ninja Trader, my goal to make it simple is:

          Create a function that receives as input :

          -Risk in money
          -StopLoss in point

          And Must return:

          Lots Size (this function must be work for the forex but also for the futures and index)

          Example:

          - Risk In money 100 $
          - Stoploss Point 0.00100
          - Assett EurUsd

          Return

          LotSize example 100 MicroLots ?

          I hope to be more clear now.

          Thanks

          Davide



          Last edited by termi_80; 01-15-2023, 06:25 AM.

          Comment


            #6
            Hello termi_80,

            In regard to the code you made, I couldn't say if that's correct or not you would need to use math and see if what you are doing is what you wanted.

            You can view an instruments tick size and point value by using the instrument manager or you can use a Print in your code to output these values to the output window.

            Once you know the values for the tick and point value you can use a calculator to manually calculate the value and check if that is correct and what you wanted to do. Once you confirm that you can know if the code is right or wrong.

            A forex instrument uses lot sizes for orders so you will commonly see sizes like 100,000 which would be a full lot. When using NinjaScript you need to submit forex quantiles as the full size, for example if you wanted to submit an order with 100,000 or 1 lot its quantity needs to be 100,000 in NinjaScript to do that.






            Comment


              #7

              Hi,

              in the photo attacched you can find print of value

              Click image for larger version

Name:	immagine.png
Views:	183
Size:	5.3 KB
ID:	1231458​​

              This is my Function:

              Click image for larger version

Name:	immagine.png
Views:	189
Size:	54.6 KB
ID:	1231459


              The result is for risk 100€ with 0.0001 pips of EURUSD the function return 100 Lots


              Attached Files

              Comment


                #8
                Hello termi_80,

                Is that the math that you wanted to use? You can use the print to output the data for your own analysis to make sure that is right for what you wanted. I can't tell you if that's right or not because it would be up to you to determine if that math is correct for how you want to use the value.

                I would suggest to take a pen and paper and write out the normal math equation that you wanted and then compare it with this result, is it correct or the same? If not you would need to provide the math that you wanted to use so we can see how that may be different from what you tried.



                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                65 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                139 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                75 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                45 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                50 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X