• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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.
    Patrick H.NinjaTrader Customer Service

    Comment


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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by saeed, Today, 12:32 PM
      3 responses
      24 views
      0 likes
      Last Post NinjaTrader_PatrickG  
      Started by motog4, Today, 11:42 AM
      3 responses
      13 views
      0 likes
      Last Post NinjaTrader_PatrickG  
      Started by derivtrader, Today, 11:20 AM
      5 responses
      26 views
      0 likes
      Last Post derivtrader  
      Started by TAJTrades, Today, 10:34 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Started by timcjpfx, Today, 10:20 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X