Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to set automatic profit and loss limits while trading futures?

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

    How to set automatic profit and loss limits while trading futures?

    Hi,

    we are new into the development with NinjaTrader / NinjaScript. So far we've modified the example strategies that are provided in NinjaTrader 8. Sorry for our basic questions. We try to tade CL futures.

    We using Williams R for learning purposes. Our OnBarUpdate methods current looks like this:

    Code:
    protected override void OnBarUpdate()
    {
    	if (CurrentBar < BarsRequiredToTrade)
               return;
            if (this.williams.Value[0] <= 0 && this.williams.Value[0] >= -20)
            {
               EnterShort();
            }
            else if (this.williams.Value[0] <= -80 && this.williams.Value[0] >= -100)
            {
               EnterLong();
            }
    }
    We've limited our portfolio to only hold 1 contract at a time. With this code, we only seem to sell when we enter another position (e.g. we start with a EnterShort() and only sell if we are in a EnterLong() call)

    We are aiming to automatically sell within a profit and loss margin (We hope the terminology is correct). For instance, we want to enter a short contract at 50.00$ and automatically sell it at 49.92$ (so 8 ticks down) or 50.12$ (12 ticks up). So far we haven't managed to find out which NinjaScript methods should be used for this.

    We've experimented with
    Code:
    SetProfitTarget(CalculationMode.Ticks, 12);
    SetStopLoss(CalculationMode.Ticks, 8);
    but that didn't work out :-(

    How can we realize a sell with these boundaries?

    Best regards

    #2
    Hello,

    We have a sample at the link below which I believe would be helpful for this situation. The Set methods you are using would be correct to enter a protective order for an Entry. Potentially the logic being used is not allowing for the targets to be filled before executing the opposite order entry again. Without running the script it is difficult to say specifically.




    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    54 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    131 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X