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

Cross Above/Below alternative?

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

    Cross Above/Below alternative?

    Hi! I'm wondering if there's another way to create a Cross Above/Below condition in the Strategy Builder? The issue is that the Cross Above/Below condition remains true for the entire bar once it has occurred. For example:

    IF CrossAbove(MFI (Close,(8)),10,1) then go Long.

    IF CrossBelow(Close,SMA (Close,(5),1) then Exit Long.

    So if the MFI(8) crosses above 10 we enter. In the same bar, if the current price climbs and then falls below the SMA(5) we exit. But if we're still in the same bar, then after the exit it will go in and out many times since both conditions continue to be met based on CrossAbove/Below lasting throughout the whole bar. Is there a way to create a condition for crossing that will not last the entire bar?

    Thanks!

    #2
    Hello Lance EI Camino,
    Ideally Strategy should be used OnBarClose so this problem is not there. So, the forming bar is not accounted for the strategy. Hope it helps!

    Comment


      #3
      Originally posted by Lance El Camino View Post
      Hi! I'm wondering if there's another way to create a Cross Above/Below condition in the Strategy Builder? The issue is that the Cross Above/Below condition remains true for the entire bar once it has occurred. For example:

      IF CrossAbove(MFI (Close,(8)),10,1) then go Long.
      IF CrossBelow(Close,SMA (Close,(5),1) then Exit Long.

      So if the MFI(8) crosses above 10 we enter. In the same bar, if the current price climbs and then falls below the SMA(5) we exit. But if we're still in the same bar, then after the exit it will go in and out many times since both conditions continue to be met based on CrossAbove/Below lasting throughout the whole bar. Is there a way to create a condition for crossing that will not last the entire bar?
      Hi Lance El Camino,
      Step 1: Add a bool "Cross Above/Below traded" or similar to your strategy. Per default, set it to "false".
      Step 2: Check if it is "false" in your entry conditions.
      Step 3: If yes and if your other entry conditions are met, set it to "true" immediately prior to entering the trade. This will block all further entries because trades are only allowed if the bool is "false".
      Step 4: As soon as the entry bar is over, reset the bool to "false" (if Bars Since Entry > 1, bool = false). "Bars Since Entry" can be found under "Misc".
      NT-Roland

      Comment


        #4
        Hello Lance El Camino,

        Thanks for your post.

        Based on your description it sounds like you are running the strategy with Calculate.OnPriceChange or Calculate.OnEachTick which means your strategy builder conditions are being tested many times within each bar as you have observed.

        Forum member NT-Roland has offered a solution using a bool variable.

        Here is another:

        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.

        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by FrancisMorro, Today, 03:24 AM
        0 responses
        1 view
        0 likes
        Last Post FrancisMorro  
        Started by Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,770 views
        0 likes
        Last Post Leafcutter  
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        31 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        944 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        11 views
        0 likes
        Last Post Max238
        by Max238
         
        Working...
        X