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

gap filling strategy

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

    gap filling strategy

    Hello, I am trying to create a strategy that will buy when there is a gap at the open and the price is at the low of the previous day's close and sell when there is a gap and the price is above the previous day's close. . above the gap, with the stoploss at the minimum or maximum of the entry candle respectively, I tried it with the strategy builder but it makes me too many trades, when I only need to do one per day, but I can't get the stop to be on the minimum or maximum of the entry candle, and that the target is at the last price of the previous day, I appreciate it if anyone knows a similar strategy, or if you can guide me to develop it, I would appreciate it.

    #2
    Hello Miguelcuello16,

    Thanks for your post.

    You could use the Prior Day OHLC indicator to detect if the current Open price (Open[0]) is greater or less than the prior day close price.

    An offset could be applied to the Open price, such as Open[0] - 10 * TickSize, to check if the current Open price minus 10 ticks are say less than the PriorClose plot of the Prior Day OHLC indicator.

    See the help guide documentation linked below for more information.

    Open: https://ninjatrader.com/support/help.../nt8//open.htm
    Prior Day OHLC: https://ninjatrader.com/support/help...r_day_ohlc.htm
    Managed Approach Order Methods: https://ninjatrader.com/support/help...d_approach.htm
    TickSize: https://ninjatrader.com/support/help...//ticksize.htm

    A bool could be used to control when trades are made by the strategy. You could create a bool named something like OkToTrade (initially set to false). You would create your order entry condition and set the bool to true. Then you would check if the bool is true and call your entry order method and set the bool to false.

    By doing this, the order entry method will only be called to place an order when the bool is true. When the bool is false, the order entry condition will not be called so the strategy will stop placing trades until the bool becomes true.

    See the attached example script demonstrating using a bool to control trades made by a strategy.​

    Let me know if I may assist further.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hello Brandon H. Thanks for answering and for your help, I am attaching the file that I tried to modify but I still can't get it to perform the operations, can you please review it to know what I'm doing wrong, the idea is that in the opening if it opens a gap a purchase is made below the previous close, with a stoploss below the entry bar, and two targets, 1 target anchored to the 20-period exponential moving average and the other target at the previous day's closing price, and if it opens a gap above the previous close, a sale is made, with a stoploss above the entry bar, and two targets, 1 target anchored to the 20-period moving average and the other target at the closing price of the day previous,

      I really appreciate your help​
      Attached Files

      Comment


        #4
        Update
        I already got the entries, but I can't get the stoploss to be in the buy order below the candle, and in the sell order above the candle,

        I can't add another target to the exponential moving average of 20 periods either, I appreciate it if you can review the strategy to see what I'm programming wrong, please

        attached update of the strategy that I have achieved so far​
        Attached Files

        Comment


          #5
          Hello Miguelcuello16,

          Thanks for your notes.

          I have reviewed the apert.zip strategy you shared and do not see anything specific that stands out that might cause an issue. When enabling the strategy on a chart, I am seeing the entry order submitted and the stop loss order (ExitLongStopMarket()/ExitShortStopMarket()) also submits.

          If the strategy places a short entry order, the stop loss order is placed at the previous bar's High price (High[1]) from when the entry is placed as expected when testing it on my end.

          I did not see the strategy place a long entry order when testing because the conditions did not become true. However, I see that the ExitLongStopMarket() order is programmed to submit to the previous bar's Low price from when the entry is placed (Low[1]).

          "I can't add another target to the exponential moving average of 20 periods either,"

          I do not see anywhere in your strategy where a second stop loss order is called to be placed, only a single stop loss order for the long or short position. I also do not see were an EMA indicator is being referenced in the script. To place another stop loss order, you would need to call ExitLongStopMarket() or ExitShortStopMarket() again in the script.

          Please view the simple example script attached in my previous post (ExitMethodsSampleSB) demonstrating submitting multiple profit target orders and one stop loss order for an entry position. Similar logic would need to be used in your script to place multiple stop-loss orders. Note that the example places multiple profit target orders, you would need to create multiple stop-loss orders in your strategy instead or profit target orders.

          Ultimately, if the strategy is not behaving as you expect it to then you would need to debug the strategy by adding prints.

          Below is a link to a forum post that demonstrates how to use prints to understand behavior.

          https://ninjatrader.com/support/foru...121#post791121

          Let us know if we may assist further.​
          Brandon H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Jonafare, 12-06-2012, 03:48 PM
          5 responses
          3,985 views
          0 likes
          Last Post rene69851  
          Started by Fitspressorest, Today, 01:38 PM
          0 responses
          2 views
          0 likes
          Last Post Fitspressorest  
          Started by Jonker, Today, 01:19 PM
          0 responses
          2 views
          0 likes
          Last Post Jonker
          by Jonker
           
          Started by futtrader, Today, 01:16 PM
          0 responses
          8 views
          0 likes
          Last Post futtrader  
          Started by Segwin, 05-07-2018, 02:15 PM
          14 responses
          1,792 views
          0 likes
          Last Post aligator  
          Working...
          X