Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help building a strategy

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

    Help building a strategy

    Hi,

    how do i create a simple strategy, for testing purposes, that is always in the Mkt and reverses position after a trailing stop is hit? Would like to set discretionary entry, say at some point in time (ToTime = 0830 => Enter long), and does not exit at a close. Can this be done by using the Wizard only?

    #2
    Hi Bagzi,

    Thank you for posting.

    You can use the Strategy Wizard to generate a simple strategy using your parameters that you have listed. You will need to create your conditions for reversing the position first then your main entry.

    I have attached a sample code that will get pointed in the right direction of what you are wanting to accomplish. This can all be done in the wizard. once downloaded you will need to import it into NinjaTrader. Click here for info on how to import NinjaScript

    I set the trail stop in the set stop loss and profit target section of the wizard.

    In Condition set 3 is the discretionary entry at the time frame and will only do this once. This will set the variable0 to 1.

    In Condition set 2, it will check when the trail stop puts the market to flat and that we had already entered long (variable0 = 1) and set the variable = 2. This will then enter a short position.

    In Condition set 1, it will check when the position is flat and that we came out of a short position (Variable = 2) and enter a long position thus resetting the variable0 back to 1.

    Please note this is just sample code.

    Please let me know if I can be of further assistance.
    Attached Files
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thanks a lot, this looks exactly like what i wanted!!

      Comment


        #4
        Hi again,

        i am playing a little bit with this Sample strategy, but now it seems to me that it does not work as i initialy thought. Namely, i run it on 1 min IWM, RTH only (this year only - 2013) and adjusted quantities to be 100 shares, and 50 tick trailing stop. However, i see 2 problems. In my backtest i get only 8 long trades and 133 short trades? I think the number of trades should be the same for long and short +/-1.

        Second problem i see is the first entry. It happens on a first day of backtest, but not on a first bar like i thought it will, but instead it gives me an entry on 8:52, some 22 mins after the open.

        I was wondering if you got any idea on why these two problems are occuring?

        Igor

        Comment


          #5
          Hi Bagzi,

          Can you attach a screenshot, to your response, of your backtest setup?

          To send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

          For detailed instructions please visit the following link

          http://take-a-screenshot.org/

          I look forward to assisting you
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            Thanks, is this what u think?







            Comment


              #7
              Hi Bagzi,

              I just wanted to check and see how you had the back test setup with the strategy.

              The strategy I sent is just a sample. You will need modify the strategy and back test settings to get the results you are looking for.

              Please note that the back test results can differ from live trading. Please see the link below from the online help guide on discrepancies between real-time and back test results.
              http://www.ninjatrader.com/support/h...ime_vs_bac.htm

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

              Comment


                #8
                Hi,
                once I've created my strategy, I ran a backtest and no trades occur. I then tried using the Sample MAcrossover strategy, and once again no trade happens. My results are 0 across the board, even though I followed the example provided online. Does anyone know what the problem is?
                Thank you

                Comment


                  #9
                  Hi,

                  in regards to this strategy im testing, i noticed that possible problem could be the Set3 condition. Can u help me figure out how do i set this condition in Set3 to be executed only once? It seems that it is executing every time the position is swithching from long to short.

                  Comment


                    #10
                    Bagzi,

                    Set 3 is designed to enter a trade between the time frame that you specified and if you are flat in your position, once those conditions are met then it will place a long trade and then set the variable to 1 that we setup earlier. Thus allowing the short condition to take place as well as the long. Since C# works logically it will hit the first, then second, then third condition when calculating.

                    What are you seeing with the strategy that seems wrong?

                    Can you give you an example of the issue you are seeing?
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      Right now, i deleted all entry conditions in Set3 and only left "Do the following part", to set valiable to 1 and enter long 100.

                      What is happening is pretty strange to me. The strategy enters the position long, when trail stop is hit it enteres short on the open of next bar. However, now it seems it does not resec trail stop rule anymore, but exits the trade on the next bar open, and reverse the position to long again. When its long the trailing stop seems to work, but as the position switches short it immediately exits on the next bar openinig.

                      Any idea on how to make it respect the trail stop when the trade is short?

                      Comment


                        #12
                        Here is the code i have, it maybe helps understand:

                        protected override void Initialize()
                        {
                        SetTrailStop("", CalculationMode.Ticks, 50, false);

                        CalculateOnBarClose = false;
                        }


                        protected override void OnBarUpdate()
                        {
                        // Condition set 1
                        if (Variable0 == 2
                        && Position.MarketPosition == MarketPosition.Flat)
                        {
                        EnterLong(100, "Long");
                        Variable0 = 1;
                        }

                        // Condition set 2
                        if (Variable0 == 1
                        && Position.MarketPosition == MarketPosition.Flat)
                        {
                        EnterShort(100, "");
                        Variable0 = 2;
                        }

                        EnterLong(100, "");
                        Variable0 = 1;
                        }

                        Comment


                          #13
                          Bagzi,

                          Thank you for your code.

                          Here is how the logic of your code works and why you are seeing this.

                          When the OnBarUpdate is called, it will run through the method top to bottom. Since both your conditions are not met the next step is to place a long order and then set the variable.

                          However, the two conditions have it set to only trade when market is flat, but this would never become true since you are to first enter a position before the conditions become true.

                          When your trail stop is hit, it exits your position and then your condition to go short becomes true allowing it to place the trade, however on the next bar update, your logic goes back to entering a long trade thus cancelling your short and entering a long position.

                          You need to have the conditions set differently on how you want to reverse the positions and when you first enter a position.
                          Cal H.NinjaTrader Customer Service

                          Comment


                            #14
                            Ok, thanks for the explanation, i understand not what it does. Will try to work on it and will post more if i have a question..

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by bortz, 11-06-2023, 08:04 AM
                            47 responses
                            1,603 views
                            0 likes
                            Last Post aligator  
                            Started by jaybedreamin, Today, 05:56 PM
                            0 responses
                            8 views
                            0 likes
                            Last Post jaybedreamin  
                            Started by DJ888, 04-16-2024, 06:09 PM
                            6 responses
                            18 views
                            0 likes
                            Last Post DJ888
                            by DJ888
                             
                            Started by Jon17, Today, 04:33 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post Jon17
                            by Jon17
                             
                            Started by Javierw.ok, Today, 04:12 PM
                            0 responses
                            12 views
                            0 likes
                            Last Post Javierw.ok  
                            Working...
                            X