![]() |
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
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Jan 2008
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
I believe so.
Do you mean something like: Code:
OnMarketData()
{
if (e.MarketDataType == MarketDataType.Last) myDataSeries.Set(e.Price);
}
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Member
Join Date: Jan 2008
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
Code:
OnMarketData()
{
if (needOpenPrice)
{
if (e.MarketDataType == MarketDataType.Last)
{
if (ToTime(e.Time) == 73000)
{
needOpenPrice = false;
myDataSeries.Set(e.Price);
}
}
}
}
insomniac |
|
|
|
|
|
|
#4 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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().
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Member
Join Date: Jan 2008
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
insomniac |
|
|
|
|
|
|
#6 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#7 | |
|
Member
Join Date: Jan 2008
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
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 |
|
|
|
|
|
|
#8 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
For clarification -
OnMarketData() and OnMarketDepth() are only called in real-time NOT against historical data.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#9 | ||
|
Member
Join Date: Jan 2008
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
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:
|
||
|
|
|
|
|
#10 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Sorry, I did not mean to disapoint you, it was not my intention. I overlooked that piece of information and should not have.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Member
Join Date: Jan 2008
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#12 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Ray
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |