Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    18 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    1 view
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    6 views
    0 likes
    Last Post Javierw.ok  
    Started by timmbbo, Today, 08:59 AM
    2 responses
    10 views
    0 likes
    Last Post bltdavid  
    Started by alifarahani, Today, 09:40 AM
    6 responses
    41 views
    0 likes
    Last Post alifarahani  
    Working...
    X