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 > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 04-17-2008, 09:33 AM   #1
justmake
Junior Member
 
Join Date: Dec 2007
Posts: 17
Thanks: 0
Thanked 0 times in 0 posts
Default how to refer to the price of previous entry?

Hello,masters,

Is there any way I can refer to "the price of previous entry buy point" by using Ninja Script Wizard?

For example:
I want to buy another 100 shares once the current price drop 5% "below the previous buy entry point. So I want to add a condition in the wizard which says:
when current price< previous entry price*(1-5%)
then buy 100 shares more

Since I am not sure "how many bars ago" I entered the previous buy point. Is there any other way refer to the "previous entry price"?

thanks,
Justmake
justmake is offline  
Reply With Quote
Old 04-17-2008, 09:48 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Unfortunately not, you can only referece the open positions' average entry price.
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-17-2008, 09:32 PM   #3
justmake
Junior Member
 
Join Date: Dec 2007
Posts: 17
Thanks: 0
Thanked 0 times in 0 posts
Default

Hello,Ray,

Thanks for reply. Is there any way for me to refer to the previous entry price in
Ninja Script language?

thanks,
Justmake
justmake is offline  
Reply With Quote
Old 04-18-2008, 12:43 AM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

You can save the current position's avg entry price into a temporary variable. That will grant you access to it in the future. Definitely doable with custom programming in NinjaScript.
NinjaTrader_Josh is offline  
Reply With Quote
Old 04-18-2008, 07:44 AM   #5
justmake
Junior Member
 
Join Date: Dec 2007
Posts: 17
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks for the answer,Josh.
Do you offer the service of writing customized ninja script ?
how would you charge it?
Justmake
justmake is offline  
Reply With Quote
Old 04-18-2008, 07:51 AM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

No.

Here is a current list of available NinjaScript consultants available for contract work.

http://www.ninjatrader.com/webnew/pa...injaScript.htm
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-27-2010, 07:18 AM   #7
no111
Member
 
Join Date: May 2010
Posts: 66
Thanks: 6
Thanked 1 time in 1 post
Default

Let say the strategy isfilled with quantity of 2.

When i'm trying this, see attachment..

it doesnt work?
Attached Images
File Type: jpg 1.JPG (37.8 KB, 7 views)
no111 is offline  
Reply With Quote
Old 05-27-2010, 07:32 AM   #8
NinjaTrader_Tim
NinjaTrader Customer Service
 
NinjaTrader_Tim's Avatar
 
Join Date: Nov 2009
Location: Denver, CO
Posts: 1,424
Thanks: 0
Thanked 3 times in 3 posts
Default

Hi no111,

Can you clarify a little on what you are intending to do?

Position.AvgPrice will return the average price of a strategy's position.

More info at - http://www.ninjatrader-support.com/H....html?AvgPrice
NinjaTrader_Tim is offline  
Reply With Quote
Old 05-27-2010, 07:44 AM   #9
no111
Member
 
Join Date: May 2010
Posts: 66
Thanks: 6
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by NinjaTrader_Tim View Post
Hi no111,

Can you clarify a little on what you are intending to do?

Position.AvgPrice will return the average price of a strategy's position.

More info at - http://www.ninjatrader-support.com/H....html?AvgPrice
I want to add on the position if close[1] > close[0]
no111 is offline  
Reply With Quote
Old 05-27-2010, 07:57 AM   #10
NinjaTrader_Tim
NinjaTrader Customer Service
 
NinjaTrader_Tim's Avatar
 
Join Date: Nov 2009
Location: Denver, CO
Posts: 1,424
Thanks: 0
Thanked 3 times in 3 posts
Default

Hi no111,

This can be done using the wizard as well, and the logic descrsibes....

"if the close of the previous bar is greater than the close of the current bar"
Attached Images
File Type: png SW1.png (43.5 KB, 9 views)
NinjaTrader_Tim is offline  
Reply With Quote
Old 05-27-2010, 08:02 AM   #11
no111
Member
 
Join Date: May 2010
Posts: 66
Thanks: 6
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by NinjaTrader_Tim View Post
Hi no111,

This can be done using the wizard as well, and the logic descrsibes....

"if the close of the previous bar is greater than the close of the current bar"
I know, thanks.
But I want that only if there is already a position of 2.
How do I set that.

My purpose is to average in..
no111 is offline  
Reply With Quote
Old 05-27-2010, 08:49 AM   #12
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

Hello no111,

This is controlled through EntriesPerDirection and EntryHandling properties. These properties can be hard coded or set when you run the strategy.

If you want to access the current position, you can access this in the wizard under Strategy > Current Position size.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 05-27-2010, 09:30 AM   #13
no111
Member
 
Join Date: May 2010
Posts: 66
Thanks: 6
Thanked 1 time in 1 post
Default

Max. entries: 66.

When RSI is below 25; 2 long.

So the nextbar should be added by 3 because of: if (Position.Quantity == 2)
{
EnterLong(3, "long3");
}

But it doesn't.. what is wrong?


PHP Code:
protected override void Initialize()
        {
             
EntriesPerDirection 66
            
EntryHandling EntryHandling.AllEntries
            
Add(SMA(200));
            
Add(RSI(23));

            
CalculateOnBarClose true;
        }

        
/// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        
protected override void OnBarUpdate()
        {

            
// Condition set 2
            
if (Close[0] > SMA(200)[0]
                && 
RSI(23).Avg[0] < 25
                
&& RSI(23).Avg[1] < 25)
            {
                
EnterLong(2"long2");
            }
            

            
// Condition set 3
            
if (Position.Quantity == 2)
            {
                
EnterLong(3"long3");
            }

            
// Condition set 4
            
if (RSI(23).Avg[0] > 70
                
&& Position.MarketPosition == MarketPosition.Long)
            {
                
ExitLong("exit""");
            }
        }

        
#region Properties
        
[Description("")]
        [
Category("Parameters")]
        public 
bool MyInput0
        
{
            
get { return myInput0; }
            
set myInput0 value; }
        }
        
#endregion
    
}

no111 is offline  
Reply With Quote
Old 05-28-2010, 01:37 AM   #14
no111
Member
 
Join Date: May 2010
Posts: 66
Thanks: 6
Thanked 1 time in 1 post
Default

Does anyone know how to fix this?
no111 is offline  
Reply With Quote
Old 05-28-2010, 06:21 AM   #15
NinjaTrader_Tim
NinjaTrader Customer Service
 
NinjaTrader_Tim's Avatar
 
Join Date: Nov 2009
Location: Denver, CO
Posts: 1,424
Thanks: 0
Thanked 3 times in 3 posts
Default

Hi no111,

If the only condition is Quantitiy==2, you could simply enter with 5 contracts initially.

If you're looking to add more conditions to that, start by adding Print()s to ensure your condition is being met and entered.
More info at - http://www.ninjatrader.com/support/f...ead.php?t=3418

Also, it may take another bar for it to recognize the initial contracts.

Check for any errors in the Log tab while running the script.
NinjaTrader_Tim 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
Avg Entry Price in a Strategy Sartis23 SuperDOM and other Order Entry Windows 1 03-28-2008 08:17 AM
Price Entry and EMA Close gygraham Strategy Development 6 03-21-2008 10:06 AM
Price Entry and EMA Close gygraham Strategy Development 0 03-19-2008 12:38 PM
Best way to get priorclose from days previous to the previous scriabinop23 General Programming 3 02-02-2008 12:41 AM
Incorrect entry price displayed in SuperDOM EuroFX Miscellaneous Support 2 09-24-2006 01:34 PM


All times are GMT -6. The time now is 03:55 PM.