Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
How to build a ( Bid+Ask)/2 indicator
Collapse
X
-
Originally posted by pstrusi View PostI'd like to have a simple (Bid+ask)/2 indicator to plot in a chart, for several time-frames..since I'm not a programmer I'm struggling to construct it...any help would be appreciated
this should get you started. the above is for the primary series. if you had added additional data series then simply modify the above code to
(GetCurrentBid(1) + GetCurrentAsk(1)) / 2; //1 representing the 2nd data series.
-
Thanks Bukkan, studying the manual I built this code but I can see it isn't ok...can you please check it and tell me what to correct?
Code:
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Mpoint"));
CalculateOnBarClose = false;
Overlay = true;
myDataSeries = new DataSeries(this); // this refers to the indicator/strategy itself
// and syncs the DataSeries object to historical
// data bars
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
// Calculate the range of the current bar and set the value
myDataSeries.Set((GetCurrentBid(0) + GetCurrentAsk(0))/2);
Mpoint.Set(myDataSeries[0]);
}
Comment
-
Originally posted by pstrusi View PostA little example of what I found:
For any bar, we had Bid 1243.50 Ask 1243.75; then the midpoint should be 1243.625 but the indicator shows either 1243.5 or 1243.75.
The formula is ok, variables...etc but still not ok
Print("Bid: " + GetCurrentBid().ToString() + " Ask: " + GetCurrentAsk().ToString() + " Avg: " + ((GetCurrentBid() + GetCurrentAsk()) / 2).ToString());
Comment
-
Originally posted by pstrusi View PostI've checked well in my database and all Bid/ask are ok, but somehow the functions getcurrentbid and ask are having problem,
edit, aslo make sure you put
if (Historical) return;
the GetCurrentBid GetCurrentAsk is for RT quotes only.Last edited by bukkan; 12-02-2011, 10:01 PM.
Comment
-
Since I need to exhaust several historical analysis with other indicators, it's very important to me that I can get the whole historical calculation bar by bar; I'll try "if (Historical) return;" maybe with it it coud have the right output.
Thanks for your good attention
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by pmachiraju, 11-01-2023, 04:46 AM
|
8 responses
147 views
0 likes
|
Last Post
by rehmans
Today, 06:44 PM
|
||
Started by mattbsea, Today, 05:44 PM
|
0 responses
5 views
0 likes
|
Last Post
by mattbsea
Today, 05:44 PM
|
||
Started by RideMe, 04-07-2024, 04:54 PM
|
6 responses
33 views
0 likes
|
Last Post
by RideMe
Today, 05:31 PM
|
||
Started by tkaboris, Today, 05:13 PM
|
0 responses
5 views
0 likes
|
Last Post
by tkaboris
Today, 05:13 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
16 responses
3,282 views
0 likes
|
Last Post
by Leafcutter
Today, 04:14 PM
|
Comment