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

Automated trading

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

    Automated trading

    Good morning all,

    Live working strategy will open positions whenever conditions are met. How it’s possible in NT 8 to make strategy STOP working after opening and closing only one position, so I will put it back on manually after some time. Or just take a break for like 3 minutes and continue work normally after that?
    Thank you
    Michael

    #2
    Hello 2014Michael,

    Thank you for your post.

    It is in fact possible to stop the strategy from trading. Below is a basic example:
    Code:
    		private bool IsTrading = false;
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Name										= "ExampleStopStrategyAfterOneTrade";
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			// Only trade on realtime data
    			// This means no historical trading (backtests) will occur
    			if (State <= State.Historical) return;
    			
    			// check if we have already submitted an entry and if that entry was filled
    			// You can include any exit conditions here
    			if (IsTrading && Position.MarketPosition == MarketPosition.Long)
    			{
    				ExitLong();
    				// We don't set IsTrading back to false here as we want the strategy to stop trading
    				// If you want the strategy to pick up trades later you can use a condition and then set the IsTrading bool to false
    			}
    			// If we are not in a trade and have not taken a trade then place an entry
    			if (!IsTrading)
    			{
    				EnterLong();
    				// Now we set the bool to true to indicate we have placed an entry
    				IsTrading = true;
    			}
    		}
    If you would like to take a look a time filter condition please visit the following links:
    Please let me know if you have any questions.

    Comment


      #3
      Thank you Patrick H. Let my see how it works.
      Sincerely,
      Michael

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by helpwanted, Today, 03:06 AM
      1 response
      11 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      9 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      5 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      242 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      387 views
      1 like
      Last Post Gavini
      by Gavini
       
      Working...
      X