Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Where to start if I want to create a strategy on a trading set-up?

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

    Originally posted by koganam View Post
    You are better off adjusting the time variables themselves so that they make sense, as the adjustment I just showed will apply to ONLY 1-minute charts.
    Hi Koganam

    Once I finish testing my strategy on 1-minute charts, plan to do more testing on different timeframes say 3-, 5- and 15-minute. How can I learn what need to be changed on the script so that it will work for these timeframes? Appreciate your tips. Thank you.

    Note: If it's too advanced for me, I'm thinking of removing the Performance codes from the strategy as it's the root issue. Am I right?

    Have a great day.

    Beth

    Comment


      Hello,

      Code:
      [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (ToTime(EndHour, EndMinute, [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]) - [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]100[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] > ToTime(Time[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]]))[/FONT] [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]return[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New];[/FONT]
      From what I've gathered, you would need to change the 100 used here to fit the desired time frame. This example above will subtract 1 minute. For a different time frame you would need to subtract that increment



      Please let me know if I can be of further assistance.
      LanceNinjaTrader Customer Service

      Comment


        Originally posted by belecona View Post
        Hi Koganam

        Once I finish testing my strategy on 1-minute charts, plan to do more testing on different timeframes say 3-, 5- and 15-minute. How can I learn what need to be changed on the script so that it will work for these timeframes? Appreciate your tips. Thank you.

        Note: If it's too advanced for me, I'm thinking of removing the Performance codes from the strategy as it's the root issue. Am I right?

        Have a great day.

        Beth
        The simplest thing to do will be to look at the logic of the code, and relate it to what you are trying to do. The issue here is how you have juxtaposed your time slot restrictions.

        However, when I read your expressed intent, per the original description that you gave at the start of this thread sequence, you are not going to take any trades before 1000 hrs anyway, so why not calculate your money management parameters at the time that you initialize the strategy for the day? i.e., in the block that is filtered by:
        Code:
        [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (startDateTime.Date != Time[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]].Date)[/FONT]
        rather than the convoluted method that tries to do it just before trading is allowed by the strategy. After all, the parameters will still be calculated only once, so there is no performance penalty.
        Last edited by koganam; 12-19-2012, 12:22 PM.

        Comment


          Thanks Koganam and Lance! Will try to digest your kind suggestion before modifying my script. It's easy for you (experienced strategy developers) .. and will take a while for me (junior learner) to get it working.

          Beth

          Comment


            Originally posted by NinjaTrader_Lance View Post
            Hello,

            Code:
            [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (ToTime(EndHour, EndMinute, [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]) - [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]100[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] > ToTime(Time[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]]))[/FONT] [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]return[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New];[/FONT]
            From what I've gathered, you would need to change the 100 used here to fit the desired time frame. This example above will subtract 1 minute. For a different time frame you would need to subtract that increment



            Please let me know if I can be of further assistance.
            That is why I said that it was not a good solution to the problem. I really just meant it as a demo of why the code was not working as written.

            Comment


              EOD Recap:

              I ran the strategy on ES and 6E 1-minute charts. The system disabled both because:

              1. ES: The strategy tried to submit a Sell Stop order (at the correct entry price I must add). Error message: Sell stop or sell stop limit orders cannot be placed above the market. OrderRejected and my strategy got disabled by the system.

              2. 6E: The strategy triggered a Buy Stop order at a price based on ?? (not according to my breakout condition). It should be a Sell Stop order and not a Buy Stop one. The trade completed and the strategy triggered another Buy Stop order (minutes later) at the same unknown price and got rejected.

              Not sure what's going on. I plan to start all over again later this week. My petite brains are not functioning. Will be back.

              Beth

              Comment


                Hello,

                Originally posted by belecona View Post
                1. ES: The strategy tried to submit a Sell Stop order (at the correct entry price I must add). Error message: Sell stop or sell stop limit orders cannot be placed above the market. OrderRejected and my strategy got disabled by the system.
                What was the current market trading at?
                What was the line of code you used to submit the order?

                2. 6E: The strategy triggered a Buy Stop order at a price based on ?? (not according to my breakout condition). It should be a Sell Stop order and not a Buy Stop one. The trade completed and the strategy triggered another Buy Stop order (minutes later) at the same unknown price and got rejected.
                Start as simple as you can and check your logic each step of the way using Print() statements to verify values are what you expect - Debugging your NinjaScript code.
                LanceNinjaTrader Customer Service

                Comment


                  Originally posted by koganam View Post
                  The simplest thing to do will be to look at the logic of the code, and relate it to what you are trying to do. The issue here is how you have juxtaposed your time slot restrictions.

                  However, when I read your expressed intent, per the original description that you gave at the start of this thread sequence, you are not going to take any trades before 1000 hrs anyway, so why not calculate your money management parameters at the time that you initialize the strategy for the day? i.e., in the block that is filtered by:
                  Code:
                  [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (startDateTime.Date != Time[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]].Date)[/FONT]
                  rather than the convoluted method that tries to do it just before trading is allowed by the strategy. After all, the parameters will still be calculated only once, so there is no performance penalty.
                  Hi Koganam and Lance

                  I will do my best to simplify my code and hopefully will have a cleaner strategy that's functional all the time. Give me some days.

                  Note to Koganam: I noticed you've added some goodies to my script. For example, it will add a horizontal line for the specified time span (I don't need an indicator now) .. haha .. Thank you!

                  Have a great day.

                  Beth

                  Comment


                    Good morning!

                    I put on my strategy on ES/6E 1-minute charts this morning. Watched them like a hawk. Got a better understanding on its performance. Actually, it did perform the way I wanted (at least this morning). That made me feel a little better. Having spent so many hours on one simple strategy .. at least I learned something new.

                    I found out what triggered RejectedOrder and why the system disabled my strategy when it happened. Upon completion of the predetermined timespan (say 9:45-10:00 am), I have the HH/LL for my breakout orders (1 tick above/below). For the current script, it will trigger a Buy/Sell stop order when price reaches or exceeds the HH/LL. Unfortunately, the stop order would only be placed on the queue upon completion of the current bar and not instantly. Considering the time lapse, the market price may trade above/below my stop order. If it does, it will cause OrderRejected and the system disables my strategy.

                    Now I need to find out how to program my strategy in a way that a pair of stop orders will be placed upon completion of the predetermined timespan. They will stay on the queue until one of them gets filled and not get cancelled within a minute or have to wait upon a bar completion.

                    I also noticed my stop order got cancelled when it's not filled within a bar. Then triggered again when price reached the breakout point (still needs to wait upon completion of the current bar).

                    A simple strategy turns out to be more complicated/advanced than I thought. Will continue working on it. Appreciate any tips to resolve the above. Thank you.

                    Beth

                    Comment


                      Hello,

                      Originally posted by belecona View Post
                      Good morning!
                      Now I need to find out how to program my strategy in a way that a pair of stop orders will be placed upon completion of the predetermined timespan. They will stay on the queue until one of them gets filled and not get cancelled within a minute or have to wait upon a bar completion.
                      This is a bit more advanced and will require to use the following overload to set liveUntilCancelled to true.
                      EnterShortStop(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double stopPrice, string signalName);


                      If you are talking about doing an OCO order this is a very advanced concept for experienced programmers only: http://www.ninjatrader.com/support/h...d_approach.htm

                      Please let me know if I can be of further assistance.
                      LanceNinjaTrader Customer Service

                      Comment


                        Thanks Lance. I will see if I can create a simple strategy that meets my expectation. Will finalize the must haves and remove nice-to-haves. It's better to have a reliable strategy than a fancy one with bugs.

                        Beth

                        Comment


                          Originally posted by belecona View Post
                          ... Note to Koganam: I noticed you've added some goodies to my script. For example, it will add a horizontal line for the specified time span (I don't need an indicator now) .. haha .. Thank you!

                          Have a great day.

                          Beth
                          Just part of the debugging: it allows me to see if the conditions are really met. It is always better not to load external scripts, unless they are critical to the processing. Just drawing a line should not require an external script.

                          Comment


                            Originally posted by belecona View Post
                            ...Not sure what's going on. I plan to start all over again later this week.
                            Beth
                            You should not have to start all over. What you have now is the first stage of any extensive program: a quick and dirty code base, used to validate the logic, assuming perfect data.

                            Welcome to the real world of programming, where the data does not behave quite so cooperatively.

                            You now need to validate your data, and to handle exceptions that are caused by a data mismatch. To do that you have to handle the market dynamics.

                            There are 3 different relevant prices of an instrument: the Last, the Bid and the Ask. The Last is the current value only, not the price. It is the current value because after all, it is the price that someone was last willing to pay for it. That may or may not be the current price. Actually there are 2 current prices:
                            1. The price that the MM will sell at, and which you must pay if you want immediate fill - the Ask, and
                            2. The price that the MM will buy at, and which you must accept if you want immediate fill - the Bid.
                            If you are using Stop Orders, then your code has to check for the real price before placing the order, and, if desired/necessary, place a Limit order instead, if the price is ahead of the intended order price. That means, you have to check the current Bid for your sells, and the current Ask for your buys.

                            Your Stop Order, even then, can still trigger an exception, due to the latency between placing your order and it arriving at the exchange. This is especially likely in a hyper instrument, that jumps around frenetically, like a cat on a hot tin roof.

                            You want to either catch the particular exception, then place a corrected order or otherwise let NT handle the exception; whether initially or by you throwing it up, if it is not an exception that you can or want to handle. It seems that NT handles the exception by disabling the strategy. You are going to have to read up on try...catch blocks. ref: http://msdn.microsoft.com/en-us/libr.../0yd65esw.aspx et al.

                            Naturally, you do not have the problem with Limit orders, as their placement is unconditional: there are conditions only on how they may be filled.
                            Last edited by koganam; 12-20-2012, 12:32 PM.

                            Comment


                              Hi Koganam

                              My trillion thanks for sharing your knowledge (incl more tips) with me. Actually, I am thinking of changing Stop orders to Limit orders.

                              First Thing First:

                              1. I will review my strategy's behavior based on today's live performance again
                              2. Identify what changes need to be made (incl removing nice-to-haves)
                              3. Explore how to make the required changes
                              4. Run the revised strategy to validate its behavior against my expectation

                              Will be back likely with more Qs ..

                              Beth

                              Comment


                                I'm back with Qs! Note: I've replaced Stop orders with Limit ones. Ran my strategy on a 60-day 6E 12-12 1-minute chart. Went through the trade log/chart.

                                1. It has trades that did not reach the breakout point yet limit orders got filled. Per enclosed chart, breakout @1.2758. Price did not reach 1.2758 and got filled. What happened? It's not an isolated incident and happened quite often.

                                2. I had Cumlosstarget and Cumprofittarget at $20 and $100 respectively. I expected the strategy would not trigger a second trade or more trades after completion of the first trade. It did not stop at one trade and continued until end trade time. Why?

                                Thanks for fixing my understanding.

                                Beth
                                Attached Files
                                Last edited by belecona; 12-20-2012, 03:32 PM.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                651 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                370 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                109 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                574 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                577 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X