Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How to create an iteration variable in a strategy action?

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

    How to create an iteration variable in a strategy action?

    I'm having a hard time with strategy not stopping after certain # of trades, especially with on bar close.
    So is it possible with a trade that gets executed if a condition is met, to create a variable called like "trades" and=1 after strategy goes long/short once, then make it =2 if it makes a second trade.
    that way I can make sure the condition for entering an order doesn't happen if it's at 2? assuming I want to limit to 2 trades total and stop.

    #2
    Hello MatthewLesko,

    You could use the existing trade performance from the strategy to see how many trades its made:



    Code:
    SystemPerformance.AllTrades.Count
    JesseNinjaTrader Customer Service

    Comment


      #3
      Yeah I tried that but it seems to not work reliably particularly when I have multiple contracts being traded. I would print that value out and it would say like 0 or 3 or 5 it was really weird.
      I can't reliably use it but I know for sure that if I could have my own variable each time I went long or short, regardless of how NT sees as a trade.

      Comment


        #4
        Hello MatthewLesko,

        A trade is an entry + exit that closes the total entry quantity. If you are using multiple contracts then you need to exit the full position before that will count up to make a trade.

        If that is not working for your specific use case you would need to use your own int variable and increment it when submitting the entries. You can increment a int variable using ++:

        myVariableName++;



        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, Yesterday, 06:40 PM
        2 responses
        19 views
        0 likes
        Last Post algospoke  
        Started by ghoul, Today, 06:02 PM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        45 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        21 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        181 views
        0 likes
        Last Post jeronymite  
        Working...
        X