Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Manually Pause a Strategy?

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

    How to Manually Pause a Strategy?

    Hi,

    I have a simple strategy to which I would like to add a button on the right like shown in the screen shot. The button is to pause/unpause a strategy. This will allow me to let the strategy run but only enabled when I want it to execute trades. Are there code samples you can share that I can start with?

    Please assist.

    Thanks.


    Click image for larger version

Name:	image.png
Views:	274
Size:	14.1 KB
ID:	1233369​
    ​

    #2
    Hello givemefood,

    I am not aware of anything that I could link to which shows that but really you are just asking about using a bool variable here. A button can toggle a bool variable which your strategy can use in its conditions to know if it can trade or not.

    Comment


      #3
      Can you point me to any reference material I can use to add the button? I can add a bool variable within the code based on the action taken on the button. Thanks.

      Comment


        #4
        Hello givemefood,

        You can find an example of adding buttons to charts in the following links.



        Hello All, Moving forward this will be maintained in the help guide reference samples and no longer maintained on the forum. Creating Chart WPF (UI) Modifications from an Indicator - https://ninjatrader.com/support/help...ui)-modifi.htm (https://ninjatrader.com/support/helpGuides/nt8/creating-chart-wpf-(ui)-modifi.htm) I've

        Comment


          #5
          With someone's help I got the following code built. But I get many errors. Can you please check what might be wrong with it?


          // Declare a bool variable to control the strategy
          bool strategyPaused = false;

          protected override void OnBarUpdate()
          {
          // Check if the strategy is paused, if it is, exit the method and do not execute any trades
          if (strategyPaused)
          return;

          // Strategy logic goes here
          }

          protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
          {
          // Define the button width and height
          int buttonWidth = 100;
          int buttonHeight = 30;

          // Define the button position on the chart
          int buttonX = chartControl.Bounds.Width - buttonWidth - 10;
          int buttonY = 10;

          // Draw the button on the chart
          if (GUI.Button(new Rect(buttonX, buttonY, buttonWidth, buttonHeight), strategyPaused ? "Resume" : "Pause"))
          {
          // Toggle the strategyPaused variable when the button is clicked
          strategyPaused = !strategyPaused;
          }
          }
          ​

          Comment


            #6
            Hello givemefood,

            What errors are you seeing?

            From the code you provided that is not valid so that would not compile. OnRender is also not where you would add buttons.

            Did you try the help guide sample that I previously linked which adds buttons?

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            71 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            143 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            76 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            47 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            51 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X