NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 04-12-2012, 07:43 PM   #1
SLASH
Member
 
Join Date: May 2010
Posts: 72
Thanks: 20
Thanked 0 times in 0 posts
Default help code

Hi please help me code my strategy
Last edited by SLASH; 04-23-2012 at 08:25 PM.
SLASH is offline  
Reply With Quote
Old 04-13-2012, 02:22 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

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?
NinjaTrader_Bertrand is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Bertrand for this post:
Old 04-16-2012, 03:00 AM   #3
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

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 -

http://www.ninjatrader.com/partners#...pt-Consultants
NinjaTrader_Bertrand is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Bertrand for this post:
Old 05-05-2012, 11:22 PM   #4
SLASH
Member
 
Join Date: May 2010
Posts: 72
Thanks: 20
Thanked 0 times in 0 posts
Default

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
    }
}
SLASH is offline  
Reply With Quote
Old 05-06-2012, 09:46 AM   #5
SLASH
Member
 
Join Date: May 2010
Posts: 72
Thanks: 20
Thanked 0 times in 0 posts
Default

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();
            }
        }
SLASH is offline  
Reply With Quote
Old 05-07-2012, 04:11 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

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'.
NinjaTrader_Bertrand is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Bertrand for this post:
Old 05-07-2012, 02:07 PM   #7
SLASH
Member
 
Join Date: May 2010
Posts: 72
Thanks: 20
Thanked 0 times in 0 posts
Default

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
SLASH is offline  
Reply With Quote
Old 05-07-2012, 02:09 PM   #8
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

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.
NinjaTrader_AdamP is offline  
Reply With Quote
The following user says thank you to NinjaTrader_AdamP for this post:
Old 05-08-2012, 01:15 PM   #9
SLASH
Member
 
Join Date: May 2010
Posts: 72
Thanks: 20
Thanked 0 times in 0 posts
Default

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 at 01:18 PM.
SLASH is offline  
Reply With Quote
Old 05-08-2012, 03:40 PM   #10
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

ninja hattori,

Sorry, I had a difficult time following your question. What is it that you're looking to accomplish in NinjaScript?
NinjaTrader_RyanM is offline  
Reply With Quote
Old 05-08-2012, 09:24 PM   #11
SLASH
Member
 
Join Date: May 2010
Posts: 72
Thanks: 20
Thanked 0 times in 0 posts
Default

Quote:
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 at 09:35 PM.
SLASH is offline  
Reply With Quote
Old 05-09-2012, 03:35 AM   #12
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

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

http://www.ninjatrader.com/support/f...ead.php?t=3751

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 -

http://www.ninjatrader.com/support/f...ead.php?t=3222
NinjaTrader_Bertrand is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A little code help? jjlamb24 Strategy Analyzer 7 02-12-2011 01:47 PM
Converting EL code to Ninja code anatop Indicator Development 1 10-18-2010 02:23 PM
NEED Help For Code Frasva General Programming 3 02-15-2009 06:43 AM
multi-time frame code and entry code Mark_486 General Programming 1 05-15-2008 11:54 AM
Code->test/debug->change code->retest ... cycle process bbarroux Strategy Development 3 10-02-2007 12:44 PM


All times are GMT -6. The time now is 08:13 AM.