Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Loss and profit target

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

    Stop Loss and profit target

    I'm developed a strategy builder. Once my entry signal enters an order, I have a exitlongstopmarket and exitlonglimit for a stop loss and profit target. These are executed on the following bar. How can I make them execute on the same bar as the entry signal?

    #2
    Hello Zinger357,

    Thank you for your inquiry.

    To execute orders intrabar you would need to change the Calculate setting to OnPriceChange or OnEachTick.



    Please let us know if you have any further questions.

    Comment


      #3
      Gaby, I tried that last night and need more time to try it out. There still seems to be a delay between the original entry and then the stop loss and profit target. Ultimately, I like these placed right after the entry signal. I only tested it a few minutes and will try more later. I'm just wondering what's the best combination after the entry signal. Right now 1: conditions flat conditions to enter long/short 2nd condition: strategy long/short exit stop limit exit limit. The quicker the exit orders are entered would be more beneficial. I hope this makes sense.

      Comment


        #4
        Hello Zinger357,

        When the orders are executed depends entirely on your strategy's logic.

        If the orders aren't executing when expected, I would recommend debugging using prints and TraceOrders.

        To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

        In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that places an order.

        The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

        The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.

        Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

        Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

        After enabling TraceOrders remove the instance of the strategy from the Configured list in the Strategies window and add a new instance of the strategy from the Available list.

        I am happy to assist you with analyzing the output from the output window.

        Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

        Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.

        https://support.ninjatrader.com/s/ar...nd-TraceOrders

        Comment


          #5
          NinjaScript Output 11_6_2024 7_44 PM.txt I went to "on each tick" but now during the backtest it just fills orders constantly. I did put the stoploss and target 1 bar ago (did this cause that). I'll change that and retry. Looking at the output the stoploss is always 0 so that's not working.

          Comment


            #6
            NinjaScript Output 11_6_2024 8_07 PM.zip I set the stop and profit back to 0 bars ago. Now the profit is pegged to the current price and is always the profit target away from it.

            Comment


              #7
              Hello Zinger357,

              Changing the Calculate setting to OnEachTick will make the strategy process each and every tick per bar, so your conditions will be evaulated many times per bar and if they are true you may get many orders filling per bar. You may need to consider adjusting your logic to prevent further entries if you don't want orders happening many times per bar.

              It's not clear to me what the conditions or information being presented in the output are - based on the below it's not clear what any of these values are, or how they are being compared / used in your conditions. Additionally, there are no timestamps.

              Code:
              5862.5 5862.25 5860.43974432119 5862.68829366345 5872.75 0
              5862.5 5862.5 5860.47307765452 5862.73412699678 5872.75 0
              5862.5 5862.25 5860.43974432119 5862.68829366345 5872.75 0
              5862.5 5862 5860.40641098786 5862.64246033012 5872.75 0

              Add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that places an order.

              The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

              If you need assistance creating a print, provide an example of a condition in your strategy and I can provide an example print for that condition.

              "I set the stop and profit back to 0 bars ago. Now the profit is pegged to the current price and is always the profit target away from it"

              Can you provide more details as to what you mean by this? Exit methods do not allow you to specify 1 bar ago or 0 bars ago. They will always be submitted on the CurrentBar. Additionally, is the strategy now working as expected or are you still having issues? ​

              Comment


                #8
                Gaby, the 1st condition of the strategy is >current market position equals >market position flat. However, the condition to enable the stop and profit target is market condition long. I'll work on the prints today and see it I can do better. The strategy works great if I allow the stop/profit to be the next bar but goes crazy when it's every tick. Thanks for all your help

                Comment


                  #9
                  NinjaScript Output 11_9_2024 2_25 PM.zip I switched the >exitlonglimit to the close of 1 bar ago for this one

                  Comment


                    #10
                    Hello Zinger357,

                    The prints still don't have any descriptive text or timestamps.

                    Code:
                    5868.25 03:45:00 5863.26395517977 5862.02894740543 5862 03:45:00 2.5 03:45:00
                    5868 03:45:00 5863.26116188368 5861.99947372122 5862 03:45:00 2.5 03:45:00
                    5868 03:45:00 5863.26116188368 5861.99947372122 5862 03:45:00 2.5 03:45:00
                    5868 03:45:00 5863.26116188368 5861.99947372122 5862 03:45:00 2.5 03:45:00
                    If you need assistance creating a print, please provide a screenshot of a condition used in your script and I can provide an example print.

                    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.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Today, 05:17 AM
                    0 responses
                    38 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    124 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    64 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    41 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    46 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X