Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Builder

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

    #16
    Hello Kate,

    I am still struggling to understand and figure out how to implement the stop loss, breakeven and trail. I reviewed the example you sent, but I couldn't make sense of it. I do have a different question that I am hoping you can help me with. Right now, my strategy is painting an arrow every time a candle meets the conditions. So in a long trend, I can have 10 signal arrows in a row. Currently, the strategy is set to, "only one trade per direction." Can you explain how I can enter a trade on each of these signal arrows as long as I am not currently in a trade? I also don't want to keep entering trades on the same candle if I am stopped out on it. Thank you for your help.

    Comment


      #17
      Hello gregorious13,

      Thank you for your reply.

      If you place your entry at the same time you're drawing the arrow, Entries per direction set to 1 will allow 1 trade in that direction for each arrow as long as you're not already in that position.

      If you are running the strategy OnPriceChange or OnEachTick it is possible that you could see a reentry on the same bar if your conditions for entry are still true after being stopped out on that bar. You can avoid having the strategy enter again on the same bar by creating a condition group using the group option in the condition builder and creating conditions within this that check that Misc > Bars Since Exit is either equal to -1 (meaning no exits have occurred yet) OR that Misc > Bars Since Exit is greater than 0:

      Click image for larger version

Name:	2022-02-03_13-30-21.png
Views:	196
Size:	21.1 KB
ID:	1190454
      Adding this to your conditions for entry will keep the strategy from entering again on the same bar it exits.

      Please let us know if we may be of further assistance to you.

      Comment


        #18
        Ahhh, that makes sense!!! The signal paints and entry is on bar close. However, not every signal is generating an entry. It seems that the first signal of a direction triggers an entry, and then I have to wait until the opposite direction signal generates before the next entry. All the trade opportunities are missed that are in the same direction as the latest entry. Hopefully that makes sense.

        Comment


          #19
          Hello gregorious13,

          Thank you for your reply.

          That's correct, we would expect that further entries would not be seen after you have met the number of entries per direction until you return to a flat position. If another signal in the same direction is seen after returning to a flat position, then that entry would be submitted.

          Please let us know if we may be of further assistance to you.

          Comment


            #20
            So if I changed the entries per direction to say 50 then theoretically I could enter 50 trades in one direction until flat?

            Comment


              #21
              Hello gregorious13,

              Thank you for your reply.

              That's essentially correct, however, there can be more than that in a row if one is closed, it's simply a limit on how many simultaneous orders in that direction you can have before you're flat. So if you have this set to 2 entries, and you enter twice, but then close out of one of the entries, you could enter again once that first one closes and that would be allowed.

              Please let us know if we may be of further assistance to you.

              Comment


                #22
                Originally posted by NinjaTrader_Kate View Post
                Hello U0000999,

                Thank you for your inquiry.

                A simple trailing stop (which will trail by 1 tick for each tick in profit starting from a defined offset from the entry price) may be set on the Stops and Targets screen, as may a profit target. I'm attaching a simple example below.

                For more complex trailing behaviors, you can use exit orders to create a trailing stop. Going this route would require you to use a ExitLong or ExitShort to mimic a profit target as if you try to use a limit order for this you'll run afoul of order handling rules for managed strategies and either the profit target or the trail stop order would be ignored. I'm also attaching an example below that demonstrates using exit orders to set up the trailing behavior.

                Please let us know if we may be of further assistance to you.
                Hi Kate,

                I'd like to tag in here if I may to address the trail behavior you created in Strategy Builder. I've implemented it into one of my strategies, but as it is a short entry, it doesn't seem to be working properly and giving me an error that it can't put in a stop market order. I recognize that the logic you created is for a long position with integers put together for a long trail. I've tried to flip the logic to positive numbers, but that doesn't seem to be working. The "SimpleTrailStopProfitTargetExample" works well for a short, but I'm using OnEachTick, and a bit more complex conditions in the strategy builder that's already making use of Position.MarketPosition = MarketPosition.Short. I feel like the CurrentTriggerPrice and CurrentStopPrice should be Default input[0] (minus) TrailFrequency and TrailStopDistance, but can't figure out how to do that in StrategyBuilder. Could you provide a similar example of the trail if it was built for a short?

                Thanks kindly,
                Last edited by wisdomspoon; 02-18-2022, 11:22 AM.

                Comment


                  #23
                  Hello wisdomspoon,

                  Thank you for your reply.

                  I've attached a newer example that shows creating trailing functionality in the Strategy Builder for both long and short positions.

                  Please let us know if we may be of further assistance to you.
                  Attached Files

                  Comment


                    #24
                    Hi Kate,

                    Thanks so much for the quick response. It looks like I may be able to run these Sets for different positions, i.e., have one short position enter on specific conditions with a profit target in mind, and then run your examples on separate sets for a second position on the same bar with the trail stop. Is that an accurate assessment, and if so, does it typically work better to build a strategy for just one position and then build a second strategy that uses a different entry, or does it make sense to build it all together?

                    Thanks,

                    Comment


                      #25
                      Hello wisdomspoon,

                      Thank you for your reply.

                      Yes, you could submit separate orders and connect them to the specific stops/targets with Signal Names so the trailing would only be applied to exits for a specific entry. We generally don't recommend running separate strategies on the same account and instrument combination simulataneously as this can affect syncing between the strategies and the account, so we would recommend combining all logic into a single strategy that can then manage the entire position.

                      Please let us know if we may be of further assistance to you.

                      Comment


                        #26
                        Hello Kate,
                        it seems that some trades do not the exits expected when applying the sample strategy LongOrShortTrailBuilderExample.zip posted above.
                        Please could you show why this is happening and how to fix it ?

                        Click image for larger version  Name:	one of the trades not respecting stop loss.png Views:	0 Size:	136.8 KB ID:	1190661
                        Thank you.

                        Click image for larger version  Name:	some trade do not respect stops loss.png Views:	0 Size:	175.5 KB ID:	1190660
                        Last edited by guidoisot; 02-18-2022, 04:09 PM.

                        Comment


                          #27
                          Hello guidoisot,

                          Thank you for your reply.

                          The example strategy relies on being run in real time. I would not expect it to function as it would in real time in a backtest if you've removed the conditions that check that the State is Realtime before entering. I would suggest restoring those conditions and testing with Market Replay data in the Playback connection to get a better idea of its performance as strategies in the Strategy Analyzer are only able to run OnBarClose, as all that is known is the OHLC of the bar.

                          Please let us know if we may be of further assistance to you.

                          Comment


                            #28
                            Click image for larger version

Name:	2022-02-22_12-38-48.png
Views:	223
Size:	25.3 KB
ID:	1191106 Ok, I am still having issues with entry. 1) entries are not triggering on some arrows even though they are part of the same "actions" group. 2) Once triggered I am getting entries on every signal candle even if I am currently in a trade. For instance, if I am in a strong trend with 20 signals, it will enter me on every signal. I do want it to take a trade on all signals, but only if I am not already in a trade. Can you please advise? Thank you!
                            Last edited by gregorious13; 02-22-2022, 12:39 PM.

                            Comment


                              #29
                              Hello gregorious13,

                              Thank you for your reply.

                              What is your entries per direction set to? If it is set to 1, it will only take trades on a signal if it is not already in a trade in that direction. If you only want it to take trades if the current position is flat, you can compare Strategy > Current Market Position to Strategy > Market Position > Flat in your conditions for entry and it will only take a trade if you are flat.

                              If you aren't seeing entries when you expect, the first thing I would recommend would be to turn on the Order Trace function:

                              Strategy Builder > Default Properties > More Properties > Trace Orders

                              Once you then recompile the strategy, you can open a new NinjaScript Output window under New > NinjaScript Output. This will print a log of any orders submitted by the strategy during while it's running, along with any ignored orders. You can then look through and see what may be occurring - it's likely some orders are being ignored and this will tell you why.

                              Here is a link to our help guide that goes into more detail on tracing orders:

                              https://ninjatrader.com/support/help...aceorders2.htm

                              Trace orders alone may not give you the full picture of whether or not a trade should have been entered on a given bar, so adding prints to your strategy that will show in the NinjaScript Output window, with information on what the variables you're using for your conditions are on a particular bar, can be helpful.

                              This forum post goes into great detail on how to use prints to help figure out where issues may stem from — this should get you going in the correct direction. You can even add these using the Strategy Builder.

                              https://ninjatrader.com/support/foru...ns-not-working

                              If you run into issues like we saw here, the above information will allow you to print out all values used in the condition in question that may be evaluating differently. With the printout information you can assess what is different between the two.

                              Please let us know if we may be of further assistance to you.

                              Comment


                                #30
                                Originally posted by NinjaTrader_Kate View Post
                                Hello gregorious13,

                                Thank you for your reply.

                                If you place your entry at the same time you're drawing the arrow, Entries per direction set to 1 will allow 1 trade in that direction for each arrow as long as you're not already in that position.

                                If you are running the strategy OnPriceChange or OnEachTick it is possible that you could see a reentry on the same bar if your conditions for entry are still true after being stopped out on that bar. You can avoid having the strategy enter again on the same bar by creating a condition group using the group option in the condition builder and creating conditions within this that check that Misc > Bars Since Exit is either equal to -1 (meaning no exits have occurred yet) OR that Misc > Bars Since Exit is greater than 0:

                                Click image for larger version

Name:	2022-02-03_13-30-21.png
Views:	196
Size:	21.1 KB
ID:	1190454
                                Adding this to your conditions for entry will keep the strategy from entering again on the same bar it exits.

                                Please let us know if we may be of further assistance to you.
                                Hi Kate,

                                Thanks so much for your help last week on the trailing short/long stop. Much appreciated.

                                Wanted to follow up on the attached quote, as I have added this to one of my strats but it does not seem to stop it from buying more than once on the entry bar after an exit by way of profit target. Could you expand on this condition a bit more? Presumably, you would enter the signal name into both conditions - should it be the same entry signal on both? And should these go into the same set as the conditions for the entry, or the actions for same, or an entirely different set? Also, as a follow-up, is it possible to enter more than once, but less than (x) amount of times - would this require a different condition group or can it be done from the same condition group?

                                Thanks kindly,

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                88 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                48 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                30 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                34 views
                                0 likes
                                Last Post TheRealMorford  
                                Started by Mindset, 02-28-2026, 06:16 AM
                                0 responses
                                68 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Working...
                                X