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

On Price Change/On Each Tick Issue

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

    On Price Change/On Each Tick Issue

    I'm having an issue with custom strategies I make using Strategy Builder. Anytime I calculate using "On Price Change" or "On Each Tick"... I notice some odd behavior and I don't know how to fix it.


    For Example:
    I made a simple SMA cross strategy- When the Median price crosses above or below the SMA line, it will enter a Long or Short trade. Instead of waiting for the bar to close, I want to strategy to enter the trade immediately when the price crosses the SMA (Which is why I used "On Price Change" instead on "On Bar Close")

    So the strategy does exactly what I want but once it hits my profit target.. it will continue to submit a series of orders and won't stop until a new bar is created. At first, I thought it was because the market pulled back, and crossed the SMA line again.. But that wasn't the case. It will keep submitting orders even if the SMA line is not crossed again.


    How do I stop this from happening? Is there any way to limit how many orders are entered per bar using strategy builder? I need the strategy to enter trades only once per bar. I'm no developer... So unlocking the code isn't really an option for me.

    I've attached a photo for reference.


    Thanks in advance.
    Click image for larger version

Name:	Screenshot 2021-04-08 203710_LI.jpg
Views:	788
Size:	140.1 KB
ID:	1150700

    #2
    Hello Tartagliagroup,

    Thanks for your post.

    To limit the entries to only once per bar you would need to add another condition to your entry set(s).

    You will need to create a variable in the Variables section of the "inputs and Variables" window of the Strategy Builder. It should be an integer (int) type you can name as you wish but for this example, I will call it Savedbar.

    Create the condition Misc>Current bar, Not equal, User variables> SavedBar

    In the "do the following section of the same set, create the action: Misc>Set SavedBar In the field of SavedBar, click "set", in the value pop-up window, select Misc>Current Bar.

    The condition and action should look like the example screenshot below, again these would be in the same set as your entry conditions and order.

    What happens is that the first time your entry conditions are true the current bar will be not equal to the saved bar and this will allow the entry to occur, in the do the following section, besides your entry order, the current bar is now saved in SavedBar making them equal, so on the next price change, the entry conditions will not be true because the current bar is equal to the saved bar.

    Click image for larger version

Name:	Tartagligroup-1.PNG
Views:	1368
Size:	23.7 KB
ID:	1150758
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Good afternoon, I had this same issue and what you suggested worked. However, I have breakeven orders in my strategy and now if the breakeven trigger is met on the same bar the order is closed without staying open to attempt to hit the main target. Is there a way to stop any new long orders from happening on the same bar and make it so it stays open until it hits the main target?

      Comment


        #4
        Hello, thanks for writing in. We have an existing Breakeven/trailing stop example that is made in the builder here, this example does not have this issue and is used quite frequently:
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mongo, Today, 11:05 AM
        4 responses
        14 views
        0 likes
        Last Post Mongo
        by Mongo
         
        Started by traderqz, Today, 12:06 AM
        7 responses
        13 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by Skifree, Today, 03:41 AM
        5 responses
        13 views
        0 likes
        Last Post Skifree
        by Skifree
         
        Started by traderqz, Yesterday, 09:06 AM
        5 responses
        34 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by guillembm, Today, 11:25 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X