Announcement

Collapse
No announcement yet.

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

    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++;



        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