Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

help code

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

    help code

    Hi please help me code my strategy
    Last edited by SLASH; 04-23-2012, 08:25 PM.

    #2
    Looks correct ninja hattori, but you have actually 2 bars of rising volume in those setup. What issues do you see? Do they work as you would expect or not?

    Comment


      #3
      ninja hattori, unfortunately we would not offer coding or code modification services here, for those the certified NinjaScript consultants listed on my link below could be tasked -

      Comment


        #4
        deleted previous codes ,as they were causing confusion
        I want to set my stop below current day open - 10 ticks ,Why am I not getting desired result
        HTML Code:
        {
                #region Variables	
        	
        	  	private int		stoplossticks		= 10;
        		private int		profittargetticks	= 20;
        		
        		#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()
                {
                    /* There are several ways you can use SetStopLoss and SetProfitTarget. You can have them set to a currency value
        			or some sort of calculation mode. Calculation modes available are by percent, price, and ticks. SetStopLoss and
        			SetProfitTarget will submit real working orders unless you decide to simulate the orders. */
        			SetStopLoss(CalculationMode.Ticks, stoplossticks);
        			SetProfitTarget(CalculationMode.Ticks, profittargetticks);
                    CalculateOnBarClose = false;
        			Add(CurrentDayOHL());					
        		           			
                }
        		
        		
        
                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                protected override void OnBarUpdate()
               {
        		// Resets the stop loss to the original value when all positions are closed
        			if (Position.MarketPosition == MarketPosition.Flat)
        			{
        				SetStopLoss(CalculationMode.Ticks, stoplossticks);
        			}
        	    // If a long position is open, set stoploss below  current day open - 10 ticks
        				else if (Position.MarketPosition == MarketPosition.Long)
        			{
        				// Once the price is greater than entry price set stoploss below current day open 
        				if (High[0] > (Position.AvgPrice-CurrentDayOHL().CurrentOpen[0] )+ 10 * TickSize)
        				{
        					SetStopLoss(CalculationMode.Ticks, (Position.AvgPrice-CurrentDayOHL().CurrentOpen[0] )+ 10 * TickSize);
        				}
        			}
        		
                    // Condition set 1
                    if (Close[0] > CurrentDayOHL().CurrentOpen[0]
                        && High[0] > High[1])
                    {
                       
                        EnterLong();
                    }
        
                    // Condition set 2
                    if (Close[0] < CurrentDayOHL().CurrentOpen[0]
                        && Low[0] < Low[1])
                    {
                        
                        EnterShort();
                    }
                }
               #region Properties
        		
        		
        		
                #endregion
            }
        }

        Comment


          #5
          Hi as per condition i am getting Dots at the correct bars why am i getting long signal on the next bar
          http://i.imgur.com/39blV.jpg
          HTML Code:
            protected override void OnBarUpdate()
                 {
          // Condition set 1
                      if (Close[1] > CurrentDayOHL().CurrentOpen[0]
          				&& Close[1]>Open[1]
          				&& High[0]>Open[0]
                          && High[0] > High[1])
                      {
                         Print("");
          				DrawDot("My Dot"+ CurrentBar,false,0,High[0],Color.Blue);
                         EnterLong();
                      }
          
                      // Condition set 2
                     if (Close[1] < CurrentDayOHL().CurrentOpen[0]
          				&& Close[1]<Open[1]
          				&& Low[0]<Open[0]
                         && Low[0] < Low[1])
                      {
                          Print("");
          				DrawDot("My Dot"+ CurrentBar,false,0,Low[0],Color.Red);
                          EnterShort();
                      }
                  }

          Comment


            #6
            Sorry, perhaps I'm not following you, however after the blue dot you show with your arrow you see a long entry to reverse the position. The trade will be entered on the next bar after your condition to enter evaluated to 'true'.

            Comment


              #7
              plz see pic below marked with arrow ,why am I getting lot size everywhere as 100@,when I have not given this in my strategy, how can I change it ? I want target 1=50,target2=25 and target3=25
              http://i.imgur.com/lJD7v.png

              Comment


                #8
                Ninja,

                This is a plot of some execution that occurred in the past. If you want to see the live orders with stop loss and take profits, I would suggest opening a new chart, and then enabling chart trader on this chart. You cannot have chart trader on a chart that has a strategy active on it.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks for helping me
                  I want to break even by partially booking some lots for that my calculation is this
                  private int target1 = 4; ( I am considering for commission etc)

                  private int stop =2; ( the stop value ,below current day open for long and above current day open for short)

                  so if current day open is at 5000 and my Position.AvgPrice is 5005

                  my risk in this trade is : 5005-5000= 5
                  so total points 4+2+5 =11 points

                  if lot size is 50 and I buy 10 lots so risk is (50*10)=500*11= 5500 INR

                  To cover this risk I have sell 60% out of total 500 lots so 5500/300=18.33 points

                  Now how can I SetProfitTarget to cover these 18.33 points

                  HTML Code:
                  SetProfitTarget("target1", CalculationMode.Price, (Position.AvgPrice+(Position.AvgPrice-current day open+stop) + (Target1*TickSize));
                  how do I book these 18.33 points with 6 lots ?what changes should I make in above Target1 profit booking ?

                  plz look at the codes below
                  HTML Code:
                   public class test3 : Strategy
                      {
                          #region Variables
                       		
                  		private int		target1			= 4;
                  		private int		target2			= 10;
                  		private int		target3			= 10;
                  		
                  		private int		stop			=2;
                  		
                  		
                  		#endregion
                  
                          protected override void Initialize()
                          {
                              Add(CurrentDayOHL());	
                              CalculateOnBarClose = true;
                  			EntryHandling		= EntryHandling.UniqueEntries;
                  					
                  		           			
                          }
                  		
                  		private void GoLong()
                  		{
                  			SetStopLoss("target1", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] - (Stop*TickSize), false);
                  			SetStopLoss("target2", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] - (Stop*TickSize), false);
                  			SetStopLoss("target3", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] - (Stop*TickSize), false);
                  			
                  			SetProfitTarget("target1", CalculationMode.Price, (Position.AvgPrice+(Position.AvgPrice-stop)) + (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, CurrentDayOHL().CurrentOpen[0] + (Stop*TickSize), false);
                  			SetStopLoss("target2", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] + (Stop*TickSize), false);
                  			SetStopLoss("target3", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] + (Stop*TickSize), false);
                  			
                  			SetProfitTarget("target1", CalculationMode.Price, (Position.AvgPrice-(stop-Position.AvgPrice)) - (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");
                  			
                  			
                  		}
                  			
                  			
                  		
                  		
                          protected override void OnBarUpdate()
                          {
                              EntryHandling		= EntryHandling.UniqueEntries;
                  		
                  			if (Position.MarketPosition != MarketPosition.Flat) return;
                  			
                  			 // Condition set 1
                           if (  (Close[1] > CurrentDayOHL().CurrentOpen[0]
                  				&& Close[1]>Open[1]
                  				&& High[0]>Open[0]
                                  && High[0] > High[1])
                  				||
                  			// Condition set 2
                  				 (CrossAbove(High, CurrentDayOHL().CurrentOpen, 1))
                  			     && Close[1]>Open[1]
                  				 && High[0]>Open[0]
                                   && High[0] > High[1]
                  	    	)
                  				
                              {
                                 
                                 GoLong();
                  				{
                                  PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\OrderFilled.wav");
                              }
                              }
                  
                              // Condition set 3
                            else if ((Close[1] < CurrentDayOHL().CurrentOpen[0]
                  				&& Close[1]<Open[1]
                  				&& Low[0]<Open[0]
                                  && Low[0] < Low[1])
                  			||
                  			// Condition set 4
                  				 (CrossBelow(Low, CurrentDayOHL().CurrentOpen, 1))
                  			     && Close[1]<Open[1]
                  				&& Low[0]<Open[0]
                                  && Low[0] < Low[1]
                  			)
                             {
                                  
                                  GoShort();
                  			{
                                  PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\OrderFilled.wav");
                              }
                              }
                  			
                          }
                  Last edited by SLASH; 05-08-2012, 01:18 PM.

                  Comment


                    #10
                    ninja hattori,

                    Sorry, I had a difficult time following your question. What is it that you're looking to accomplish in NinjaScript?
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_RyanM View Post
                      ninja hattori,

                      Sorry, I had a difficult time following your question. What is it that you're looking to accomplish in NinjaScript?
                      scaling out ,by partially booking some lots to get risk free
                      Last edited by SLASH; 05-08-2012, 09:35 PM.

                      Comment


                        #12
                        ninja hattori, the scale out of a position you would need to scale in first it the desired quantities -



                        For the target value needed to get 'risk free' you can dynamically calculate either a price or tick value in your OnBarUpdate and adjust the SetProfitTarget to it -

                        Comment


                          #13
                          Vol alert

                          Hi please help me with indicator,editing this post because I am not able to post new thread
                          Check the following code ,i want to edit this indicator I want to Draw a rectangle ,Whenever specific high volume occur.
                          HTML Code:
                          // This namespace holds all indicators and is required. Do not change it.
                          namespace NinjaTrader.Indicator
                          {
                              /// <summary>
                              /// Enter the description of your new custom indicator here
                              /// </summary>
                              [Description("Enter the description of your new custom indicator here")]
                              public class aa : Indicator
                              {
                                  #region Variables
                                  // Wizard generated variables
                                     private int highVolume = 1000; // Default setting for HighVolume
                          		  private int rectWidth	= 0;
                          		private Color highAlert = Color.Black;
                          		
                                  // User defined variables (add any user defined variables below)
                                  #endregion
                          
                                  /// <summary>
                                  /// This method is used to configure the indicator and is called once before any bar data is loaded.
                                  /// </summary>
                                  protected override void Initialize()
                                  {
                                     
                                     // Add(new Plot(new Pen(Color.Blue, 2), PlotStyle.Bar, "Volume"));
                          			//Add(new Line(Color.DarkGray, 0, "Zero line"));
                          			{
                                      CalculateOnBarClose	= true;
                                      Overlay				= true;
                                  }
                                  }
                          
                                  /// <summary>
                                  /// Called on each bar update event (incoming tick)
                                  /// </summary>
                                  protected override void OnBarUpdate()
                                  {
                                      Value.Set(Volume[0]);
                          		
                                      if (Volume[0] >= HighVolume)
                          			{
                          			
                          			
                          				DrawRectangle("Rectangle", false, rectWidth+ CurrentBar,true, 0, High[0] + 20*TickSize, highAlert, Color.Blue, Color.BlueViolet, 5);
                          			}
                          			
                                  }
                          
                                 #region Properties
                          		[Description("Enter volume threshold")]
                                  [Category("Parameters")]
                                  public int HighVolume
                                  {
                                      get { return highVolume; }
                                      set { highVolume = Math.Max(1, value); }
                                  }
                          		
                          		/// <summary>
                          		/// </summary>
                                 	
                          		[Description("Select Color")]
                          		[Category("Colors")]
                          		[Gui.Design.DisplayName("highAlert")]
                          		public Color HighAlert
                          		{
                          			get { return highAlert; }
                          			set { highAlert = value; }
                          		}
                          		
                          		// Serialize Color object
                          		[Browsable(false)]
                          		public string highAlertSerialize
                          		{
                          			get { return NinjaTrader.Gui.Design.SerializableColor.ToString(highAlert); }
                          			set { highAlert = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
                          		}
                                  #endregion
                              }
                          }
                          
                          #region NinjaScript generated code. Neither change nor remove.
                          // This namespace holds all indicators and is required. Do not change it.
                          namespace NinjaTrader.Indicator
                          {
                              public partial class Indicator : IndicatorBase
                              {
                                  private aa[] cacheaa = null;
                          
                                  private static aa checkaa = new aa();
                          
                                  /// <summary>
                                  /// Enter the description of your new custom indicator here
                                  /// </summary>
                                  /// <returns></returns>
                                  public aa aa(int highVolume)
                                  {
                                      return aa(Input, highVolume);
                                  }
                          
                                  /// <summary>
                                  /// Enter the description of your new custom indicator here
                                  /// </summary>
                                  /// <returns></returns>
                                  public aa aa(Data.IDataSeries input, int highVolume)
                                  {
                                      if (cacheaa != null)
                                          for (int idx = 0; idx < cacheaa.Length; idx++)
                                              if (cacheaa[idx].HighVolume == highVolume && cacheaa[idx].EqualsInput(input))
                                                  return cacheaa[idx];
                          
                                      lock (checkaa)
                                      {
                                          checkaa.HighVolume = highVolume;
                                          highVolume = checkaa.HighVolume;
                          
                                          if (cacheaa != null)
                                              for (int idx = 0; idx < cacheaa.Length; idx++)
                                                  if (cacheaa[idx].HighVolume == highVolume && cacheaa[idx].EqualsInput(input))
                                                      return cacheaa[idx];
                          
                                          aa indicator = new aa();
                                          indicator.BarsRequired = BarsRequired;
                                          indicator.CalculateOnBarClose = CalculateOnBarClose;
                          #if NT7
                                          indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                                          indicator.MaximumBarsLookBack = MaximumBarsLookBack;
                          #endif
                                          indicator.Input = input;
                                          indicator.HighVolume = highVolume;
                                          Indicators.Add(indicator);
                                          indicator.SetUp();
                          
                                          aa[] tmp = new aa[cacheaa == null ? 1 : cacheaa.Length + 1];
                                          if (cacheaa != null)
                                              cacheaa.CopyTo(tmp, 0);
                                          tmp[tmp.Length - 1] = indicator;
                                          cacheaa = tmp;
                                          return indicator;
                                      }
                                  }
                              }
                          }
                          
                          // This namespace holds all market analyzer column definitions and is required. Do not change it.
                          namespace NinjaTrader.MarketAnalyzer
                          {
                              public partial class Column : ColumnBase
                              {
                                  /// <summary>
                                  /// Enter the description of your new custom indicator here
                                  /// </summary>
                                  /// <returns></returns>
                                  [Gui.Design.WizardCondition("Indicator")]
                                  public Indicator.aa aa(int highVolume)
                                  {
                                      return _indicator.aa(Input, highVolume);
                                  }
                          
                                  /// <summary>
                                  /// Enter the description of your new custom indicator here
                                  /// </summary>
                                  /// <returns></returns>
                                  public Indicator.aa aa(Data.IDataSeries input, int highVolume)
                                  {
                                      return _indicator.aa(input, highVolume);
                                  }
                              }
                          }
                          
                          // This namespace holds all strategies and is required. Do not change it.
                          namespace NinjaTrader.Strategy
                          {
                              public partial class Strategy : StrategyBase
                              {
                                  /// <summary>
                                  /// Enter the description of your new custom indicator here
                                  /// </summary>
                                  /// <returns></returns>
                                  [Gui.Design.WizardCondition("Indicator")]
                                  public Indicator.aa aa(int highVolume)
                                  {
                                      return _indicator.aa(Input, highVolume);
                                  }
                          
                                  /// <summary>
                                  /// Enter the description of your new custom indicator here
                                  /// </summary>
                                  /// <returns></returns>
                                  public Indicator.aa aa(Data.IDataSeries input, int highVolume)
                                  {
                                      if (InInitialize && input == null)
                                          throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
                          
                                      return _indicator.aa(input, highVolume);
                                  }
                              }
                          }
                          #endregion

                          Comment


                            #14
                            SLASH, on which price panel and which bars do you then want to draw the rectangle object?

                            To draw on the non main price panel please work with the DrawOnPricePanel property -

                            Comment


                              #15
                              I couldn't get a new thread to start for some reason, so will jump onto this thread..... a quick and easy question.....what's the easiest way to code "if a condition happened within the last 5 bars, and something else happens now, go long or short?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              671 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              379 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              111 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              582 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X