Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to edit Order Entry Button strategy to calculate correct position size

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

    How to edit Order Entry Button strategy to calculate correct position size

    Hi everyone,

    First post here on the forums. I have a coding question about a free Order Entry Buttons strategy that I came across on the Trade Saber channel on Youtube. The strategy creates a set of order entry buttons under the default Ninja chart trader order buttons that you can use to make entering trades easier with the correct position size instead of having to do the position sizing math in real-time and possibly miss entries, among other things. I use it with a defined $ risk per trade, and the strategy calculates position size so that I don't risk more than that $ amount per trade.

    I emailed Trade Saber about if it was okay to edit his code, and he gave me the thumbs up as it's a free strategy he offers on his website. I have the entire code document attached to this post. It should be able to be opened in Notepad for viewing and any other coding application that can read NinjaTrader code. I would paste the entire code here, but it makes this post too long.

    Currently, with entering trades with a user-defined $ risk per trade, the code will base the position size off of the price range between the prior candle high (for long trades) or low (for short trades), and a user-defined stop loss (In the strategy inputs I have the strategy set the stop loss at the lowest price of the previous four candles for long trades, or highest price of the previous four candles for short trades). The only issue I have with that position sizing calculation is that sometimes the strategy will get you into a trade with less than the correct amount of contracts due to candle wicks, when really I would like it to base the contract size off of the range between that same stop loss level and current price, while still maintaining a certain user-defined $ risk per trade. That way you should have the correct position sizing for every trade. I understand that making that change would probably use up more computer resources since it would have to constantly be calculating the position sizing as price moves, but I am wondering if it is possible to change that in the code.

    I believe the piece of the code that deals with this calculation is the "CandleLookBackEntry" term. By default it's set to 1 to indicate it uses the prior candle to start the position sizing caculation with. I've tried setting it to zero to see if that would work, but it doesn't work. It's in several places in the code, but I'm not sure which instances of it would need to be changed to be able to make the new position sizing calculations like I detailed above. I apologize for being unable to be more specific as to where exactly in the code to look where it deals with calculating the position size.

    Hopefully all of that made sense, and I can try to answer questions the best I can, but my coding knowledge is pretty limited. Trade Saber does have a Youtube link on the strategy's page on his website on how the strategy buttons work that might help explain things better than I can. Does anyone know what I would need to change or add to the code to change how it calculates position size to what I mentioned above? I've also attached a screenshot of what the buttons look like when the strategy is enabled on chart trading. Thank you for any assistance!


    Attached Files

    #2
    Hello navyguy06,

    Welcome to the forums!

    We recommend you use prints to identify the code that calculates the value you are investigating. The page below guides you through debugging using prints to understand behavior.



    This thread will remain open for any community members that would like to debug and correct this code on your behalf.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services.

    Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.​

    We are happy to answer any direct questions you have and/or help guide you through the debugging process if you decide to create this yourself.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    52 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    43 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    47 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X