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

Need Help Implementing Different Stop and Target Parameters for Multiple Contracts

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

    Need Help Implementing Different Stop and Target Parameters for Multiple Contracts

    I'm trying to create a strategy with three contracts, each with different stop and target parameters. However, I'm having trouble including and calling these parameters properly in the NinjaScript code. Could you please help me with this? I appreciate any guidance you can provide. Thank you!

    #2
    Hello leotraderc,

    Thank you for your post.

    Are you using Set() methods or Exit methods for your stops and targets?

    In either case, you can specify the fromEntrySignal parameter to tie the stop or target to a specific entry.

    SetStopLoss(string fromEntrySignal, CalculationMode mode, double value, bool isSimulatedStop)




    ExitLongStopMarket(double stopPrice, string fromEntrySignal)



    For example:

    Code:
    private double stopPrice = 0;
     
    protected override void OnBarUpdate()
    {
        if (CurrentBar < 20)
            return;
     
        // Only enter if at least 10 bars has passed since our last entry
        if ((BarsSinceEntryExecution() > 10 || BarsSinceEntryExecution() == -1) && CrossAbove(SMA(10), SMA(20), 1))
        {
            EnterLong([B]"SMA Cross Entry"[/B]);
            stopPrice = Low[0];
        }
     
        // Exits position
        ExitLongStopMarket(stopPrice, [B]"SMA Cross Entry"[/B]);
    }​

    Please let me know if you have any further questions.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      The truth is I don't know, I'm not a programmer, with Chat GPT I developed a system, but I haven't been able to make the entries with two contracts and that each Stop and Target of each contract can be parameterized separately, it's the only thing I'm missing, but I don't know how to give it the indications

      Comment


        #4
        Hello leotraderc,

        What specifically are you having trouble with when trying to tie the stops and targets to the entries? Are the expected trades not appearing when you test your strategy out?

        You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services.

        Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.​
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          When I was setting up my trading strategy for three different contracts, the first thing I did was decide on the stop loss and target profit levels for each one. It's like setting up safety nets and goals for each trade. I used variables to keep track of these numbers so I could easily change them if needed.
          Then, I made sure I knew exactly when I wanted to jump into a trade. This is super important because it's the starting point for everything else. It's like deciding when to start running in a race – you need to know the right moment to go.
          For each contract, I had to set up its own stop loss and target profit. NinjaTrader has these tools called SetStopLoss and SetProfitTarget that let you do just that. It's a bit like setting up different rules for each player in a game, making sure each one knows when to stop and when they've reached their goal. I made sure to apply these rules to each contract individually, so each one had its own plan to follow.​

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by halgo_boulder, 04-20-2024, 08:44 AM
          2 responses
          21 views
          0 likes
          Last Post halgo_boulder  
          Started by mishhh, 05-25-2010, 08:54 AM
          19 responses
          6,189 views
          0 likes
          Last Post rene69851  
          Started by gwenael, Today, 09:29 AM
          0 responses
          5 views
          0 likes
          Last Post gwenael
          by gwenael
           
          Started by Karado58, 11-26-2012, 02:57 PM
          8 responses
          14,830 views
          0 likes
          Last Post Option Whisperer  
          Started by Option Whisperer, Today, 09:05 AM
          0 responses
          2 views
          0 likes
          Last Post Option Whisperer  
          Working...
          X