Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Create Strategy

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

    Create Strategy

    Hi
    I am trying to setup a simple strategy based on the change of colour of the HMA. I d/l an indicator for NT called HMAColourChange. It basically chages colour depending on whether it is trending up or down.,

    I now want to create a strategy that enters a long position on RisingPlot and enters a short position on FallingPlot. I would also like the strategy to exit the short position when entering long and vice versa for short. Seems simple, but have not been able to crack it.

    I started by naming the strategy and selecting int under Type. I put 40 as Default, as I have chosen 40 as the HMA parameter I want to test.I left Min. set to 1.

    Under conditions I selected the indicator and the condition looks like this HMAColourChange(40).RisingPlot(0) == HMAColourChange(40).RisingPlot(0) I left bars to look back as 0 as it seems I can override this in the strategy tester by selecting Calculate on bar close. I have changed it to (1) but it made no difference.

    I select EnterLong as the action, calling the signal RisingPlot and select a stop loss. When I test the strategy, I get 0 in everything

    Can anybody spot what I am doing wrong? I am sure it is very much the nut holding the wheel, but it is my first attempt at setting a strategy

    Cheers

    #2
    honkin, for your strategy I would suggest working directly with comparing the HMA indicator values, not the rising / falling plot segments used for the visual display.
    Attached Files
    BertrandNinjaTrader Customer Service

    Comment


      #3
      cheers Bertrand. I have now decided to write my own strategy but am just struggling slightly with the script. I wonder if you might assist if possible.

      protected override void OnBarUpdate()
      {
      EntryHandling = EntryHandling=UniqueEntries;

      HMA hmav = HMA(HMAlength);

      ManageOrders();

      if (Position.MarketPosition != MarketPosition.Flat) return;
      if (Position.MarketPosition == MarketPosition.Long) && Falling(hmav); ExitLong()&& GoShort();
      else if (Position.MarketPosition == MarketPosition.Short) && Rising(hmav); ExitShort()&& GoLong();

      }

      The aim is just to have the script enter a position long, closing any pre-existing short position if the HMA is rising and the opposite for a falling HMA. There appears to be an error in the syntax somewhere but I cannot find it.

      cheers

      honkin

      Comment


        #4
        Thank you for persevering. I am VERY eager to jin you in backtesting the Hull MOving Average. I am very interested in learning how to construct a basic backtest as well as the bility to manipulate the setting in the back test if possible. The HMA holds up to visal inspection but this is laborious and not quite as rigorus and quantitivative as NinjaTraders excellent ability in this area. Once we settle on a clear methodology to back test (needs to be clear for a newbie like me), it will be an excellent addition to our community!

        Comment


          #5
          honkin, please try as example the below, the Enter methods would automatically reverse for you if needed -

          Code:
          protected override void OnBarUpdate()
                  {
                     
          	EntryHandling = EntryHandling.UniqueEntries;
          
          	HMA hmav = HMA(Period);
          
          	//ManageOrders();
          
          	if (Position.MarketPosition != MarketPosition.Flat) return;
          			
          	if ((Position.MarketPosition == MarketPosition.Long) && Falling(hmav))
          		EnterShort();
          			
          	if ((Position.MarketPosition == MarketPosition.Short) && Rising(hmav))
          		EnterLong();
          
          
                  }
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Bertrand View Post
            honkin, please try as example the below, the Enter methods would automatically reverse for you if needed -

            Code:
            protected override void OnBarUpdate()
                    {
                       
            	EntryHandling = EntryHandling.UniqueEntries;
            
            	HMA hmav = HMA(Period);
            
            	//ManageOrders();
            
            	if (Position.MarketPosition != MarketPosition.Flat) return;
            			
            	if ((Position.MarketPosition == MarketPosition.Long) && Falling(hmav))
            		EnterShort();
            			
            	if ((Position.MarketPosition == MarketPosition.Short) && Rising(hmav))
            		EnterLong();
            
            
                    }
            Hi Bertrand

            Thanks very much for your reply. There still appears to be some problems with the code supplied. Errors are generate. I will give you them 1 by 1.

            HMA hmav = HMA(Period);
            This brings up an error CS0118 saying 'NinjaTrader.Data.Period' is a 'type' but is used like a 'variable'


            if ((Position.MarketPosition == MarketPosition.Long) && Falling(hmav))
            EnterShort();
            This brings up 2 errors - CS0201 only assignment, call, increment etc and CS0019 operator '&&' cannot be applied to operands etc

            The same with the next line in your code.

            What I am after is really just having the position reverse when the HMA changes, but was not sure if I needed to have ExitLong and EnterShort in the same line to achieve that.

            Would some of the earlier code below be causing the problem?

            cheers Bertrand

            public class NewHMA : Strategy
            {
            private int hmalength =40;

            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
            CalculateOnBarClose = true;
            EntryHandling = EntryHandling.UniqueEntries;
            }

            private void GoLong()
            {
            }
            private void GoShort()
            {
            }
            protected override void OnBarUpdate()
            {
            EntryHandling = EntryHandling.UniqueEntries;

            HMA hmav = HMA(Period);

            Comment


              #7
              honkin, please see the explanation I posted in your other thread on the compile issues - the ones you see do not have to be confined to the currently open script - you would need to click on the ones listed at the bottom to be taken to the offending code lines in the scripts present.

              Also: if you EnterLong on a signal and a short position is open, NT would do the reverse for you, there's no ExitShort needed here then prior to reversing.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Bertrand View Post
                honkin, please try as example the below, the Enter methods would automatically reverse for you if needed -

                Code:
                protected override void OnBarUpdate()
                        {
                           
                	EntryHandling = EntryHandling.UniqueEntries;
                
                	HMA hmav = HMA(Period);
                
                	//ManageOrders();
                
                	if (Position.MarketPosition != MarketPosition.Flat) return;
                			
                	if ((Position.MarketPosition == MarketPosition.Long) && Falling(hmav))
                		EnterShort();
                			
                	if ((Position.MarketPosition == MarketPosition.Short) && Rising(hmav))
                		EnterLong();
                
                
                        }
                Cheers Bertrand

                I am getting information from Bike Mike's site that this will not reverse my trade, but will instead flatten it. Can you confirm that the code you indicated will actually reverse my trade and not just flatten?

                1. if ((Position.MarketPosition == MarketPosition.Long) && Falling(hmav))
                EnterShort();

                2. if ((Position.MarketPosition == MarketPosition.Short) && Rising(hmav))
                EnterLong();
                So, the net result of 1. would be to be left with a short position, not just closing my long and the opposite for 2. Is that correct?

                cheers

                honkin

                Comment


                  #9
                  honkin, sorry - please remove your MarketPosition checks in the entry conditions then you should see it trigger trades -

                  if (Falling(hmav))
                  EnterShort();

                  if (Rising(hmav))
                  EnterLong();

                  The Enter() method do reverse for you if needed - it would be important to be in proper sync account / strategy position wise though - http://www.ninjatrader.com/support/h..._account_p.htm
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Bertrand View Post
                    honkin, sorry - please remove your MarketPosition checks in the entry conditions then you should see it trigger trades -

                    if (Falling(hmav))
                    EnterShort();

                    if (Rising(hmav))
                    EnterLong();

                    The Enter() method do reverse for you if needed - it would be important to be in proper sync account / strategy position wise though - http://www.ninjatrader.com/support/h..._account_p.htm
                    Hi Bertrand

                    Thanks again for your reply.

                    OK, so if I remove the Market.Position check, the trades will now reverse instead of flattening.

                    Thanks for the information re account syncing

                    Can you also tell me how I can run NT6.5 and NT7 on the same machine correctly? I do not mean at the same time, but unfortunately I have some proprietary indicators that only work in NT6.5, so I need to keep it installed.

                    My broker is PFG Best and as you know there is an API that is needed. What I find happens is that I have to reinstall the API of whichever version I need to use at a given time. This is painful.

                    Is there any way to have them both installed and operational, with only one being able to be run at a time?

                    Thanks again

                    Comment


                      #11
                      You're welcom honkin - unfortunately not when using PFG as broker as you correctly noted the needed API version would differ for 6.5 and 7.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Your help appreciated

                        Honkin,

                        I came across your post after seaching the forum for Hull color change strategy.

                        It looks like it has been over year ago and I hope you will see this post.

                        Did you ever complete the strategy and if so could you post your code, I am not a programmer and it would be greatly appreciated.

                        Thanks, Al

                        Comment


                          #13
                          Strategy Code

                          Bertrand,

                          Would it be possible for you to copy and paste the complete working code for this HMA color change strategy. I see bits & pieces above and not sure what is working and what will not.

                          It would be nice to see more working strategies posted in the Strategy section of the forum, seems it would save you all a lot of work.

                          Thanks for your help, it is greatly appreciated.

                          Al

                          Comment


                            #14
                            Here's an example you could start working with for educational purposes - it will :

                            a) trade the reversal of the user chosen HMA

                            b) have a profit target scaleout and will exit if the stop is taken out, price recrossing the HMA or reversal signal is generated

                            c) it can only take a long and then a short or vice versa.

                            Enjoy,
                            Attached Files
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              Bertrand,

                              Thank you very much for your help with this.

                              Al

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by usazencort, Today, 01:16 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post usazencort  
                              Started by kaywai, 09-01-2023, 08:44 PM
                              5 responses
                              603 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              6 responses
                              22 views
                              0 likes
                              Last Post xiinteractive  
                              Started by Pattontje, Yesterday, 02:10 PM
                              2 responses
                              21 views
                              0 likes
                              Last Post Pattontje  
                              Started by flybuzz, 04-21-2024, 04:07 PM
                              17 responses
                              230 views
                              0 likes
                              Last Post TradingLoss  
                              Working...
                              X