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

First Strategy Help

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

    First Strategy Help

    Hi,

    I am trying to build a simple first strategy. Bit lost about how to define the required condition for the simple actions I want.

    Basically....

    1) If price goes above the high of the previous bar, then buy at market,
    2) if price goes below the low of the previous bar, short at market.

    LOL. It´s pretty simple, but I can´t do it. I thought this was as simple as it got really, i´m guessing it is but I am just not doing it right.

    Can someone tell me the amount of conditions this would need, and maybe give me an example of how to do this in the condition builder?

    What I did was set two conditions:

    Set 1 - Bid > High (1) then go long
    Set 2 - Ask < Low (1) then go short

    Thanks.

    #2
    ScottieDog.

    Thank you for your post.

    You have the right setup. These will check if the Bid price is greater than the High[1] and if the Ask is less than the Low[1].

    If you wanted to check the close price you would want to use the Close from the Price Data drop down.

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      For instance, see attached.

      Why is it ignoring the first bars in the blue box?

      And why is it entering at the close of bar, and not the break of the high bar where the green arrow is?
      Attached Files

      Comment


        #4
        ScottieDog,

        Are these historical trades taken place?

        If so can you tell me who you are connected to? This is displayed in the lower left hand corner of the control center
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          I am connected to CQG.

          The attachment was a screenshot of the chart in the backtest utility.

          (Not sure what you mean by historical).

          Comment


            #6
            Another attachment here. Let´s ignore the fact that it missed the first 24 candles. I guess there´s an explanation for that?

            If that is the first entry, on the BUY candle at 97.15, then the entry should have been at the green arrow, break of the high of the previous candle, it entered on the close of previous candle, for some reason?

            And the exit, that should have been on the second red candle down, as that candle took out the low of the previous candle. It exited one candle late, on the green candle - It should have been doing nothing on this green candle, it should however of been getting long on the next candle (Doji) as that Doji took out the high of the green candle.

            LOL. It doesn´t get much simpler does it, yet im struggling to get it to work. Sorry for my noobness.
            Attached Files

            Comment


              #7
              ScottieDog,

              Strategies by default require a minimum of 20 bars before they start calculating.

              This can be adjusted in the strategy parameters, when running a back test, called Min. Bars Required under 'General'.

              Additionally, there are some items for the back test that you would want to read about to understand the results you may see. Such as the CalculateOnBarClose always set to true in a Back Test and the price of filled orders
              Please read the link below from the help guide on the Discrepancies between Real-Time vs Back Test -
              http://www.ninjatrader.com/support/h...ime_vs_bac.htm

              Let me know if I can be of further assistance.
              Cal H.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Cal View Post
                ScottieDog,

                Strategies by default require a minimum of 20 bars before they start calculating.

                This can be adjusted in the strategy parameters, when running a back test, called Min. Bars Required under 'General'.

                Additionally, there are some items for the back test that you would want to read about to understand the results you may see. Such as the CalculateOnBarClose always set to true in a Back Test and the price of filled orders
                Please read the link below from the help guide on the Discrepancies between Real-Time vs Back Test -
                http://www.ninjatrader.com/support/h...ime_vs_bac.htm

                Let me know if I can be of further assistance.
                OK, fully understand about the 20 bars minimum, thats fine, can live with that.

                I can also understand discrepancies when using realtime vs backtest, but its clearly not even trading on the correct bar, something must be wrong with my setup. The exit for that first trade should have been on the candle prior to the green candle (when there was a lower low candle triggering a short), and the doji after the green candle should have been getting long as the doji had a higher high - It´s not a discrepancy, its completely wrong.

                Comment


                  #9
                  Another attachment of where the actual entries/exits should be. Arrow on the bar which breaks the low/high of previous candle, dotted line at the entry point.

                  Is that not possible to replicate? I would have thought it was as easy as it gets.

                  I was only doing it as a test for my first strategy now its got to be a bit of a mission. lol.

                  Buy when price takes out previous candle high.. stay in buy until candle takes out previous bar low. Reverse for short. Rinse repeat.

                  If I have coded the strategy correctly then I don´t understand, because the result is totally different and not one entry or exit lines up as it should. That can´t be the way it has to be surely?
                  Attached Files

                  Comment


                    #10
                    ScottieDog,

                    This is because in a back test the CalculateOnBarClose is always set to true.

                    Your strategies calculations are happening on the bar before the trade, however because we are waiting on the bar close, the execution will show on the next bar at the open price since they are market orders. This would account for why the trades appear a bar late.

                    A bar, when it closes, the last tick of that bar is the first tick of the next bar.

                    Let me know if this is the answer you are looking for.
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      Are you saying then that the entries on the screenshot here are "impossible" to replicate with a backtest?

                      Regardless of what settings / configuration / conditions etc, that I set? There is no way around it?
                      Attached Files
                      Last edited by ScottieDog; 10-25-2013, 09:59 AM.

                      Comment


                        #12
                        What about having it run in market replay at 500x speed? Would that resolve it so entries/exits are correct?

                        There´s no other way of making it work properly in backtest mode?

                        Comment


                          #13
                          Originally posted by ScottieDog View Post
                          If that is the first entry, on the BUY candle at 97.15, then the entry should have been at the green arrow, break of the high of the previous candle, it entered on the close of previous candle, for some reason?

                          And the exit, that should have been on the second red candle down, as that candle took out the low of the previous candle. It exited one candle late, on the green candle - It should have been doing nothing on this green candle, it should however of been getting long on the next candle (Doji) as that Doji took out the high of the green candle.

                          LOL. It doesn´t get much simpler does it, yet im struggling to get it to work. Sorry for my noobness.
                          It is in the nature of how the specific data is processed. You only have access to the OHLC data in this case, so it requires 2 candles to satisfy the condition, after which the order is placed on the open of the next candle. As you are entering using Market Orders, what you are seeing is orders placed on the open of the next candle (the first candle after the condition is satisfied): which is identically the close of the candle on which the condition was satisfied.

                          Comment


                            #14
                            Originally posted by ScottieDog View Post
                            What about having it run in market replay at 500x speed? Would that resolve it so entries/exits are correct?

                            There´s no other way of making it work properly in backtest mode?
                            Not without finagling a simulation of the correct entry by adding and using a finer time series for processing.

                            Comment


                              #15
                              So it runs with COBC, even in market replay, not just in backtest mode?

                              Thanks for your help.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rhyminkevin, Today, 04:58 PM
                              4 responses
                              52 views
                              0 likes
                              Last Post dp8282
                              by dp8282
                               
                              Started by iceman2018, Today, 05:07 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post iceman2018  
                              Started by lightsun47, Today, 03:51 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post lightsun47  
                              Started by 00nevest, Today, 02:27 PM
                              1 response
                              14 views
                              0 likes
                              Last Post 00nevest  
                              Started by futtrader, 04-21-2024, 01:50 AM
                              4 responses
                              50 views
                              0 likes
                              Last Post futtrader  
                              Working...
                              X