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 > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 08-05-2008, 04:59 PM   #1
insomniac
Member
 
Join Date: Jan 2008
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
Default How to Set() info from OnMarketData() ??

Hello,

I have a price value that I retrieve from the OnMarketData() method that is the exact price of the first tick that occurs at market open(7:30am(mst)). This price is used as an exact/true market opening price. Which amazingly can be up to around a 4-5 tick difference between the true open and the open price that occurs by simply utilizing a synchronized PC clock.

However, my problem comes in when I try to use the Set() method to keep this value for historical purposes. My indicator plots just fine as long as I am using real-time info and was connected prior to market open(7:30), but if I try to add the indicator later or look at historical charts, I cannot see view the indicator at all.

Can I use the Set() method to save values from the OnMarketData() method?

insomniac
insomniac is offline  
Reply With Quote
Old 08-05-2008, 05:04 PM   #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

I believe so.

Do you mean something like:

Code:
OnMarketData()
{
if (e.MarketDataType == MarketDataType.Last) myDataSeries.Set(e.Price);
}
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-05-2008, 05:39 PM   #3
insomniac
Member
 
Join Date: Jan 2008
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Ray View Post
I believe so.

Do you mean something like:

Code:
OnMarketData()
{
if (e.MarketDataType == MarketDataType.Last) myDataSeries.Set(e.Price);
}
Yes, except I have to throw in:

Code:
OnMarketData()
        {
            if (needOpenPrice)
            {
                if (e.MarketDataType == MarketDataType.Last)
                {
                    if (ToTime(e.Time) == 73000)
                    {
                        needOpenPrice = false;
                        myDataSeries.Set(e.Price);
                    }
                }
            }
        }
However I cannot seem to get it to show historically. I have even tried to Set() it within the OnBarUpdate()

insomniac
insomniac is offline  
Reply With Quote
Old 08-05-2008, 09:22 PM   #4
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

I forgot, you must set the value in OnBarUpdate() since when this method is called, if you don't set it, it is internally reset.

Declare a variable in the scope of the indicator, set the value of this variable in OnMarketData() then pas this variable in the .Set() method in OnBarUpdate().
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-05-2008, 10:51 PM   #5
insomniac
Member
 
Join Date: Jan 2008
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Ray View Post
I forgot, you must set the value in OnBarUpdate() since when this method is called, if you don't set it, it is internally reset.

Declare a variable in the scope of the indicator, set the value of this variable in OnMarketData() then pas this variable in the .Set() method in OnBarUpdate().
I have tried this, but I still can't seem to get it to stick.

insomniac
insomniac is offline  
Reply With Quote
Old 08-06-2008, 07:15 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

Then you will need to debug it as for sure that would work.

You can work backwards, just declare a variable and se its value at declaration time, then assign this variable to .Set() in OnBarUpdate(). You will see that it works as expected.
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-07-2008, 09:50 AM   #7
insomniac
Member
 
Join Date: Jan 2008
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Ray View Post
Then you will need to debug it as for sure that would work.

You can work backwards, just declare a variable and se its value at declaration time, then assign this variable to .Set() in OnBarUpdate(). You will see that it works as expected.
I don't know if I am just an idiot or what, but I can't get this to work. I am starting to believe it has to do with the fact that I have to throw in the following:

if (ToTime(e.Time) == 73000)
daysOpen = e.Price;

When I am running live w/real-time data feed it works just fine. But when looking back at previous days, nothing shows up at 7:30am, and if I remove the indicator at any time, even during live connections, I can reapply the indicator and it does not show. So the only way to keep the indicator showing on the chart is to stay connected to the data feed.

Essentially all I need is the same indicator as CurrentDayOHL(), but instead of grabbing and setting the Open Price using:

if (Bars.SessionBreak)
currentOpen = Open[0];

I need it to grab and set the Open Price using OnMarketData() at exactly 7:30am.

insomniac
insomniac is offline  
Reply With Quote
Old 08-07-2008, 10:08 AM   #8
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

For clarification -

OnMarketData() and OnMarketDepth() are only called in real-time NOT against historical data.
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-07-2008, 10:46 AM   #9
insomniac
Member
 
Join Date: Jan 2008
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Ray View Post
For clarification -

OnMarketData() and OnMarketDepth() are only called in real-time NOT against historical data.
Ray,

Ok, so I certainly do not want to give you sh!t, but I spoke of this very thing in my first post and my second post. So why have I been ripping my hair out for something that cannot be done, but was given suggestions on how to do it, even when I kept saying that I couldn't get it to work. As you re-read my posts, you will see that I consistently referred to Historical Charts, and in my very first post I mention that I have it working just fine in real-time.

I am disappointed.


Quote:
Originally Posted by insomniac View Post
However, my problem comes in when I try to use the Set() method to keep this value for historical purposes. My indicator plots just fine as long as I am using real-time info and was connected prior to market open(7:30), but if I try to add the indicator later or look at historical charts, I cannot see view the indicator at all.
Quote:
Originally Posted by insomniac View Post
However I cannot seem to get it to show historically. I have even tried to Set() it within the OnBarUpdate()
insomniac is offline  
Reply With Quote
Old 08-07-2008, 10:51 AM   #10
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

Sorry, I did not mean to disapoint you, it was not my intention. I overlooked that piece of information and should not have.
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-07-2008, 04:45 PM   #11
insomniac
Member
 
Join Date: Jan 2008
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
Default

Well since I don't know how to take no for an answer. Would someone be willing to help me out with coding this indicator to actually do what I am looking for it to do. I am sure that there has got to be a way to have the indicator use System.IO to Write/Read from a text file that will start to accumulate historical Opening tick prices, as I run the indicator each day, and then it can read from the file and process each past day to Set() the value of the opening price for my charts.

insomniac
insomniac is offline  
Reply With Quote
Old 08-07-2008, 04:49 PM   #12
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

You could contact a consultant.

http://www.ninjatrader.com/webnew/pa...injaScript.htm
NinjaTrader_Ray 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
OnMarketData() & CalculateOnBarClose mrlogik Strategy Development 8 07-30-2008 03:22 PM
OnMarketData Time is not accurate OnePutt General Programming 2 12-23-2007 12:52 PM
OnMarketData question Burga1 Strategy Development 8 12-20-2007 12:17 AM
OnBarUpdate and OnMarketData used in one indicator? RedDuke General Programming 9 12-14-2007 06:54 PM
OnMarketData() not working Json General Programming 4 11-08-2007 04:09 AM


All times are GMT -6. The time now is 05:01 PM.