Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding to a long position?

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

    Adding to a long position?

    Let say I use this strategy to enter a long position:

    Code:
    protected override void Initialize()
    {
        Add("^SP500", PeriodType.Day, 1); 	
        SetStopLoss("", CalculationMode.Percent, 10, false);
        CalculateOnBarClose = true;
    }
    
    protected override void OnBarUpdate()
     {
         if (IsIndexCloseHigherThenAverageIndexClose &&
            IsHighHigherThenAverageClose &&
            IsHighHigherThenHighestHigh)
            EnterLong();
    			
         if (IsLowLowerThenLowestLow)
    	ExitLong();
    }
    
    private bool IsIndexCloseHigherThenAverageIndexClose
    {
    	get 
    	{ 
    		return Closes[1][0] > SMA(BarsArray[1], 200).Close[0]; 
    	}
    }
    		
    private bool IsHighHigherThenAverageClose
    {
    	get 
    	{ 
    		return High[0] > SMA(High, 200)[0]; 
    	}
    }
    
    private bool IsHighHigherThenHighestHigh
    {
            get 
            { 
                     return High[0] > MAX(High, 50)[1]; 
            }
    }
    		
    private bool IsLowLowerThenLowestLow
    {
            get 
            { 
                     return Low[0] < MIN(Low, 20)[1]; 
            }
    }
    But now after I have enter a long position I wanna add more to the long position when its go up 5% of the initial long position and I wanna do this 5 times. How can I do it?

    #2
    Hello,

    You can use Position.Avg price to determine when the position has reached 5%

    if (Close[0] >= Position.AvgPrice * (1+0.05))

    Once this condition has been met, you can use EnterLong() again to scale up.
    MatthewNinjaTrader Product Management

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    646 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    367 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    107 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    569 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X