Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Save backtest results

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

    #31
    Thanks Patrick,

    Could I still get some help? I am quite new in NT ATM programming.
    How would you program this rule: after a long tentry the next one must be short, and vice versa?

    Thanks.

    Comment


      #32
      Hello Borsz,

      Thank you for your post.

      The condition would need to know the previous position and then determine if a new position would take place. We would need an initial order placement though, and then we can set this new variable to long or short for the previous position:
      Code:
              #region Variables		
              private string prevPosition = "";
              #endregion
      
              
              protected override void Initialize()
              {
                 	
              }
      		
      		protected override void OnBarUpdate()
      		{	
      			// Ensure we are flat to avoid reversals caused by the prevPosition string.
      			if(Position.MarketPosition == MarketPosition.Flat)
      			{
      				// Place initial trade.
      				if(prevPosition == null) // prevPosition will initially be null.
      				{
      					// Calculate long or short trade.
      				}
      				
      				// Place trade based on previous position.
      				if(prevPosition == "long")
      				{
      					// Go short.
      				}
      				if(prevPosition == "short")
      				{
      					// Go long.
      				}
      			}
      		}
      	
      		protected override void OnPositionUpdate(IPosition position)
      		{
      			// Calculate previous position.
      			if(Position.MarketPosition == MarketPosition.Long)
      				prevPosition = "long";
      			else if(Position.MarketPosition == MarketPosition.Short)
      				prevPosition = "short";
      		}
      For information on the OnPositionUpdate() method please visit the following link: http://www.ninjatrader.com/support/h...tionupdate.htm

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      88 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      48 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      30 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      34 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      68 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X