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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    43 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    29 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    46 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Working...
    X