Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy development

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

    strategy development

    Hi friends I have created this strategy after seeing big mike video.
    Please help me fix its errors,Targets and stoploss not working properly
    I want to enter 10 lots
    target 1 : book 6 lots
    target 2 : book 2 lots
    target 3 ; book 2 lots

    want to keep initial stoploss below low or high of entry bar
    then after target 1 ,moved below low or high of target 1 bar then to target 2 bar .
    cheers
    nh
    HTML Code:
           //#region Variables
            private int        smalength        = 200;
            private int        emalength        = 100;
            private int        hmalength        = 40;
            
            private int        target1            = 100;
            private int        target2            = 200;
            private int        target3            = 300;
            
            private int        stop            = 500;
            
            private bool    be2                = true;
            private bool    be3                = true;
            
            
            //#endregion
    
            /// <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;
                
                Add(SMA(Close,HMAlength));
                Add(EMA(Close,HMAlength));
                Add(HMA(Close,HMAlength));
                
            }
            
            private void GoLong()
            {
                SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
                SetStopLoss("target2", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
                SetStopLoss("target3", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
                
                SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));
                SetProfitTarget("target2", CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize));
                SetProfitTarget("target3", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
                
                EnterLong("target1");
                EnterLong("target2");
                EnterLong("target3");
                
                
            }
            private void GoShort()
            {
                SetStopLoss("target1", CalculationMode.Price, Close[0] + (Stop*TickSize), false);
                SetStopLoss("target2", CalculationMode.Price, Close[0] + (Stop*TickSize), false);
                SetStopLoss("target3", CalculationMode.Price, Close[0] + (Stop*TickSize), false);
                
                SetProfitTarget("target1", CalculationMode.Price, Close[0] - (Target1*TickSize));
                SetProfitTarget("target2", CalculationMode.Price, Close[0] - ((Target1+Target2)*TickSize));
                SetProfitTarget("target3", CalculationMode.Price, Close[0] - ((Target1+Target2+Target3)*TickSize));
                
                EnterShort("target1");
                EnterShort("target2");
                EnterShort("target3");
                
                
            }
            
            private void ManageOrders()
            {
                if (Position.MarketPosition == MarketPosition.Long)
                {
                    if (BE2 && High[0] > Position.AvgPrice + (Target1*TickSize))
                        SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice, false);
                    
                    if (BE3 && High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
                        SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice, false);
                
                }
                if (Position.MarketPosition == MarketPosition.Short)
                {
                    if (BE2 && Low[0] < Position.AvgPrice - (Target1*TickSize))
                        SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice, false);
                    
                    if (BE3 && Low[0] < Position.AvgPrice - ((Target1+Target2)*TickSize))
                        SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice, false);
                
                }
                
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                EntryHandling        = EntryHandling.UniqueEntries;
                
                SMA        smav        = SMA(SMAlength);
                EMA        emav        = EMA(EMAlength);
                HMA        hmav        = HMA(HMAlength);
                
                ManageOrders();
                
                if (Position.MarketPosition != MarketPosition.Flat) return;
                
                if (Rising(smav) && Rising(emav) && Rising(hmav))
                    GoLong();
                else
                if (Falling(smav) && Falling(emav) && Falling(hmav))
                    GoShort();
                
            }
    
            //#region Properties
            [Description("")]
            [Category("Parameters")]
            public int SMAlength
            {
                get { return smalength; }
                set { smalength = Math.Max(1, value); }
            }
            [Description("")]
            [Category("Parameters")]
            public int EMAlength
            {
                get { return emalength; }
                set { emalength = Math.Max(1, value); }
            }
            [Description("")]
            [Category("Parameters")]
            public int HMAlength
            {
                get { return hmalength; }
                set { hmalength = Math.Max(1, value); }
            }
            [Description("")]
            [Category("Parameters")]
            public int Target1
            {
                get { return target1; }
                set { target1 = Math.Max(1, value); }
            }
            [Description("")]
            [Category("Parameters")]
            public int Target2
            {
                get { return target2; }
                set { target2 = Math.Max(1, value); }
            }
            [Description("")]
            [Category("Parameters")]
            public int Target3
            {
                get { return target3; }
                set { target3 = Math.Max(1, value); }
            }
            [Description("")]
            [Category("Parameters")]
            public int Stop
            {
                get { return stop; }
                set { stop = Math.Max(1, value); }
            }
            [Description("")]
            [Category("Parameters")]
            public bool BE2
            {
                get { return be2; }
                set { be2 = value; }
            }
            [Description("")]
            [Category("Parameters")]
            public bool BE3
            {
                get { return be3; }
                set { be3 = value; }
            }
            
            
            //#endregion
        }
    }
    Last edited by SLASH; 09-02-2010, 01:48 AM.

    #2
    ninja hattori, can you please clarify what you see not working? For the specific qty's please use an overload for the EnterLong / EnterShort that would allow to enter them - http://www.ninjatrader-support.com/H...EnterLong.html

    To debug strategy's, the TraceOrders feature is very helpful - http://www.ninjatrader.com/support/f...ead.php?t=3627
    BertrandNinjaTrader Customer Service

    Comment


      #3
      trailing stop

      Hi Bert my trailing stop not working I want to place it below my entry bar and then below profit target 1 bar and then below profit target 2 bar when long same for short above the entry ,profit target 1,profit target 2,bars.

      HTML Code:
      //#region Variables
              private int        target1            = 70;
              private int        target2            = 110;
              private int        target3            = 120;
              private bool    be2                = true;
              private bool    be3                = true;
              private int        trailstop       = 50;
              private double highestHigh    = 0;
              private double lowestLow    = 0;
              //#endregion
              /// This method is used to configure the strategy and is called once before any strategy method is called.
              protected override void Initialize()
              {
                  CalculateOnBarClose = true;
                  ExitOnClose        = true; 
                  ExitOnCloseSeconds = 30; 
                  EntriesPerDirection = 3; 
                  SetTrailStop(CalculationMode.Price, 50);
                  EntryHandling        = EntryHandling.AllEntries; 
                  
                              
              }
              private void GoLong()
              {
                  SetTrailStop("target1", CalculationMode.Price, Position.AvgPrice - (TrailStop *TickSize), false);
                  SetTrailStop("target2", CalculationMode.Price, Position.AvgPrice - (TrailStop *TickSize), false);
                  SetTrailStop("target3", CalculationMode.Price, Position.AvgPrice - (TrailStop *TickSize), false);
                  
                  SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize));
                  SetProfitTarget("target2", CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize));
                  SetProfitTarget("target3", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
                  
                  EnterLong("target1");
                  EnterLong("target2");
                  EnterLong("target3");            
              }
              private void GoShort()
              {
                  SetTrailStop("target1", CalculationMode.Price, Position.AvgPrice + (TrailStop*TickSize), false);
                  SetTrailStop("target2", CalculationMode.Price, Position.AvgPrice + (TrailStop*TickSize), false);
                  SetTrailStop("target3", CalculationMode.Price, Position.AvgPrice + (TrailStop*TickSize), false);
                  
                  SetProfitTarget("target1", CalculationMode.Price, Close[0] - (Target1*TickSize));
                  SetProfitTarget("target2", CalculationMode.Price, Close[0] - ((Target1+Target2)*TickSize));
                  SetProfitTarget("target3", CalculationMode.Price, Close[0] - ((Target1+Target2+Target3)*TickSize));
                  
                  EnterShort("target1");
                  EnterShort("target2");
                  EnterShort("target3");
              }
              
              private void ManageOrders()
              {
                  if (Position.MarketPosition == MarketPosition.Long)
                  {
                      if (BE2 && High[0] > Position.AvgPrice + (Target1*TickSize))
                          SetTrailStop("target2", CalculationMode.Price, (Position.AvgPrice-TrailStop), false);
                      
                      if (BE3 && High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
                          SetTrailStop("target3", CalculationMode.Price, (Position.AvgPrice-TrailStop), false);
                  
                  }
                  if (Position.MarketPosition == MarketPosition.Short)
                  {
                      if (BE2 && Low[0] < Position.AvgPrice - (Target1*TickSize))
                          SetTrailStop("target2",CalculationMode.Price,(Position.AvgPrice+TrailStop), false);
                      
                      if (BE3 && Low[0] < Position.AvgPrice - ((Target1+Target2)*TickSize))
                          SetTrailStop("target3", CalculationMode.Price, (Position.AvgPrice+TrailStop), false);
                  }
              }
      
             
              /// Called on each bar update event (incoming tick)
            
               protected override void OnBarUpdate()
              {
                  // Resets the highest high and lowest low at the start of every new session
                  if (Bars.FirstBarOfSession)
                  {
                      highestHigh = High[0];
                      lowestLow = Low[0];
                  }
                  
                  // Stores the highest high and lowest low from the first 1 bars
                  if (Bars.BarsSinceSession < 1)
                  {
                      // If current high is greater than current highest high, set highest high to current high
                      if (High[0] > highestHigh)
                          highestHigh = High[0];
                      
                      // If current low is lower than current lowest low, set lowest low to current low
                      if (Low[0] < lowestLow)
                          lowestLow = Low[0];
                  }
                  
                  /* Entry Condition: After the first 1 bars, submit an entry order when price crosses either the highest high or the lowest low
                  if you have no market positions open */
                  if (Bars.BarsSinceSession > 1 && Position.MarketPosition == MarketPosition.Flat)
                  {
                      // If price crosses above the highest high, enter long
                      if (CrossAbove(Close, highestHigh, 1))
                          GoLong(); 
                      
                      // If price crosses below the lowest low, enter short
                      else if (CrossBelow(Close, lowestLow, 1))
                          GoShort(); 
                      }
              }
      
              //#region Properties
              [Description("")]
              [Category("Parameters")]
              public int Target1
              {
                  get { return target1; }
                  set { target1 = Math.Max(1, value); }
              }
              [Description("")]
              [Category("Parameters")]
              public int Target2
              {
                  get { return target2; }
                  set { target2 = Math.Max(1, value); }
              }
              [Description("")]
              [Category("Parameters")]
              public int Target3
              {
                  get { return target3; }
                  set { target3 = Math.Max(1, value); }
              }
              [Description("")]
              [Category("Parameters")]
              public int TrailStop
              {
                  get { return trailstop; }
                  set { trailstop = Math.Max(1, value); }
              }
              [Description("")]
              [Category("Parameters")]
              public bool BE2
              {
                  get { return be2; }
                  set { be2 = value; }
              }
              [Description("")]
              [Category("Parameters")]
              public bool BE3
              {
                  get { return be3; }
                  set { be3 = value; }
              }
              //#endregion
          }
      }
      Last edited by SLASH; 09-05-2010, 10:49 AM.

      Comment


        #4
        also how can I enter as below
        entry 1 : 6 lots
        entry 2 : 2 lots
        entry 3 : 2 lots

        Comment


          #5
          ninja hattori, you would need to custom code this trailstop behavior, you can for example save the low of your entry bar and then start trailing from this point on - a reference sample to get started can be found here -



          You can directly enter the qty you wish to trade in the EnterLong / EnterShort overloads -

          BertrandNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Bertrand View Post
            ninja hattori, you would need to custom code this trailstop behavior, you can for example save the low of your entry bar and then start trailing from this point on - a reference sample to get started can be found here -



            You can directly enter the qty you wish to trade in the EnterLong / EnterShort overloads -

            http://www.ninjatrader-support.com/H...EnterLong.html
            Thanks Bert
            qty problem solved but I am not able to solve trailstop behavior.when profit target given in private void is working why manage orders not working?
            how can I custom code it ?

            Comment


              #7
              Great you got the qty's entered successfully - if you want to move your stops, you would just call the SetStopLoss again as needed, we have dedicated sample posted here - http://www.ninjatrader.com/support/f...ead.php?t=3222
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Bertrand View Post
                Great you got the qty's entered successfully - if you want to move your stops, you would just call the SetStopLoss again as needed, we have dedicated sample posted here - http://www.ninjatrader.com/support/f...ead.php?t=3222
                Bert tried everything according to link but no success.

                Comment


                  #9
                  ninja hattori, unfortunately we would not offer scripting / debugging services, however a NinjaScript could code this professionally for you as alternative - http://www.ninjatrader.com/webnew/pa...injaScript.htm
                  BertrandNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Impeesa, Today, 11:53 AM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by Brian.T, Today, 11:02 AM
                  4 responses
                  10 views
                  0 likes
                  Last Post Brian.T
                  by Brian.T
                   
                  Started by jmrbtrader08, Today, 11:50 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post jmrbtrader08  
                  Started by juanfer, 02-11-2025, 07:29 AM
                  2 responses
                  10 views
                  0 likes
                  Last Post juanfer
                  by juanfer
                   
                  Started by hoppy222, Today, 09:27 AM
                  1 response
                  13 views
                  0 likes
                  Last Post NinjaTrader_ChristopherJ  
                  Working...
                  X