• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SMA crossover with Strategy builder

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

    SMA crossover with Strategy builder

    hi,
    I'm trying to create a simple automated strategy.
    The entry is based on a usual moving average system and works as following: you enter
    the market long on the bar where a fast moving average crosses above a slow moving
    average and in the same way you go short if the fast moving average crosses below the
    slower moving average. And till here, no problem with the strategy builder.
    now I would like to add a breakout filter. At the bar when the fast moving average
    crosses above the slow moving average the trade is not directly initiated. I would take the
    high of this bar (“crossover bar”) and keep it as the entry stop point as long as the fast moving average stays above the slow moving average.
    Now If I set the function "enterlongstopmarket" and I set High as the Stop price, the system enters only if the next bar has a High > the crossover bar, but doesn't enter if the new High is produced, for example, at the third or fourth bar after the signal.
    What can I do for keep the crossover High as the entry stop point as long as the fast moving average stays above the slow moving average and not only for the next bar?

    #2
    Hello d_ceres,

    Thanks for your post and welcome to the NinjaTrader forums!

    The strategy builder creates strategies that follow the "managed approach" rules (link: https://ninjatrader.com/support/help...d_approach.htm). In the managed approach, orders that are placed but not filled are automatically canceled at the end of the bar. This is what you would see with your approach of submitting a stopmarket order on the crossover.

    What you would need to do is to continue resubmitting the order on each bar after the crossover (assuming the order is appropriate to the stop price). To accomplish this what you can do is at the crossover is to set a bool variable to be true and save the High (or Low) price of the crossover bar in a double variable. In another set, you can check the state of the bool and if it is true and if the ask/bid price is above/below the High/Low price to then place the StopMarket order using the High or low price that was saved from the crossover bar. This action will resubmit the order on each bar (as long as the bid/ask are relative to the stop price). Once the order is filled, you can use another set to then reset the trigger bool to false to prevent further orders in that direction.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you Paul for your reply.
      I'm novice in programming Ninjatrader and I don't know how "to set a bool variable to be true and save the High (or Low) price of the crossover bar in a double variable".

      Comment


        #4
        Hello d_ceres,

        Thanks for your reply.

        I highly recommend that you attend the free live webinar training that we offer on the strategy builder (every other week On Thursdays at 4:00 PM EST (alternates weeks with Ninjascript editor)), here is a link to platform training: https://ninjatrader.com/PlatformTraining

        If you want to get started sooner, you can review a previously recorded session here: https://www.youtube.com/watch?v=HCyt...We0Nf&index=11

        In addition, if you haven't already, please review the helpguide materials on the strategy builder, here is a link: https://ninjatrader.com/support/help...gy_builder.htm The condition builder page is helpful with a number of how to examples.

        You can create variables in the Input and variables page of the strategy builder. On that page, below the window "Variables" click the "add" to add a variable, enter a name that make sense to you (such as entryUpTrigger), change the type to bool (a bool is a variable that is either true or false only) and set the "default to "False" and click OK. To create a variable for holding a price value, once again click add, provide a name that makes sense (such as EntryUpPrice), change the type to "Double" (which means it can handle decimal values) and leave the default value as is and click OK.

        In the set where you have your crossabove condition, remove any entry orders in the action section and then click add, then Misc folder and you will find Set EntryUpTrigger and Set EntryUpPrice (assuming you used those names or whatever names you provided when you created them). For the EntryUpTrigger you will see an empty check box, if you left click on the check box then it will set that bool to be true, if you leave it unchecked it will set it false. In the case of the crossover you would want to set it true. Also you can "set' the EntryUpPrice variable, when selected, left click in the blank field (on the word "set") and a "value" window opens where you can select the price folder and in the case of the cross above select the "high" price. This is how you save the price for the stop market order.

        You can then create a new set where the "conditions are" that the bool EntryUpTrigger = true and that the EntryUpPrice is greater than the Ask price (this is needed to ensure you don't enter a longstopmarket order when price is already above that level). In the "actions" section of the set, you can place your EnterLongStopMarket and you would use the variable EntryUpPrice as the stop price.

        The above set will continue submitting the longstopmarket order until such time as the condition EntryUpTrigger = true becomes false. As a suggestion, you can use another set where you check the market position and if the market position is long (which means the entry order filled) you can then in the actions section set the bool EntryUpTrigger false, to prevent further long orders until the next crossabove occurs.

        You would add the same type sets and variables for going short.

        Note it is important, in general, that you think out the variable names and settings (type and default values) before using them in the sets, once a variable is used in a set you cannot go back and change it (by this I mean if you wanted to change the name or change from an int to a bool) as the strategy builder will not permit it and in that case you either start over with your strategy or use a different variable.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          thank you Paul for the valuable suggestions. now the strategy works perfectly
          by

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by TazoTodua, Today, 12:21 AM
          0 responses
          7 views
          0 likes
          Last Post TazoTodua  
          Started by U0000999, Today, 12:20 AM
          0 responses
          7 views
          0 likes
          Last Post U0000999  
          Started by sidviciousX, Yesterday, 06:47 AM
          1 response
          21 views
          0 likes
          Last Post bltdavid  
          Started by Mykro, Yesterday, 10:22 PM
          0 responses
          7 views
          0 likes
          Last Post Mykro
          by Mykro
           
          Started by rudccv, Yesterday, 08:42 PM
          0 responses
          6 views
          0 likes
          Last Post rudccv
          by rudccv
           
          Working...
          X