if (FirstTickOfBar) { downVol = prevVol = 0; upVol = prevVol = 0; // reset on first tick } currVol = Volume[0] - prevVol; // volume of this tick if (Volume[0] > prevVol) { if (Close[0] < prevPrice) down[B][COLOR=Red]V[/COLOR][/B]ol +=currVol; if (Close[0] > prevPrice) up[B][COLOR=Red]V[/COLOR][/B]ol += currVol; } // if (Volume[0] > prevVol) and (Close[0] < prevPrice) down[B][COLOR=Red]V[/COLOR][/B]ol +=currVol; // if (Volume[0] > prevVol) and (Close[0] > prevPrice) up[B][COLOR=Red]V[/COLOR][/B]ol += currVol; //last two lines an attempt at two lines above without begin end but still don't verify. prevVol = Volume[0]; // save value for next tick prevPrice = Close[0]; // save value for next tick if (down[COLOR=Red][B]V[/B][/COLOR][B][/B]ol - up[B][COLOR=Red]V[/COLOR][/B]ol < 0) BarColor = Color.Cyan; // bearish else BarColor = Color.Yellow; // bullish
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
Newbie coding help query; Range Bar query
Collapse
X
-
Code:Josh P.NinjaTrader Customer Service
-
Josh, thanks a lot. The code verifies but am not sure what it is doing. There is noi indicator in this one and I have given up trying to plot one in since whatever I write in doesn't verify. It's painting the bars but they are definitely not right. That massive rally into the close today had mainly bearish bars which is clearly incorrect. Oh well!
Well, I have tried, you have tried, clearly this is a very tricky thing to do in Ninja and also I have learned that if i don't first learn C+ I won't be able to code in Ninja. I went onto the linked error line and the help menu there just showed you how to make the mistake but didn't give an example of how NOT to make the mistake so I got no help there. (Messing around with if and , neither of which was in the mistake. Clearly not for beginners!
I am quite surprised. I think it might be a good idea for Ninja to supply a custom function or whatever you call it in Ninja/C+ that calculates up and down volume since clearly this is missing and I am not the only one who finds it helpful. Rather basic but surprisingly hard to code it seems.
Thanks for everything. I don't think we can keep going with this any longer because far more time for Josh and others (including me) than I ever imagined. Honestly, I thought it would take someone about 2 mins to code tops since that's what it takes in Tradestation.
That said, if Anachronist comes up with a final version I look forward to downloading it and seeing if it works better! Mine now verifies but it is totally useless.
Comment
-
Actually, looking closely at the chart and also using Anachro's versions it appears that any time the bar closes lower it is a down bar and any time higher it is an up bar. Which makes me wonder about this close[0] being equal to each tick. Looks to me like it means the close of the bar. Anyway.
Comment
-
Josh, even though we didn't get very far with this despite Anochro and your help I did learn quite a bit, albeit mainly that I am not up to Ninja Script.
However, I do have one more request, probably not to you since you are not allowed but to some other kind soul.
Although I have used TS script off and on for 15 years and can do nearly anything I want with it, I am flummoxed by NS.
I am using Ninja as a trading platform. I used a small nr. of indicators. One of which was the volume bar which was too difficult to do as we found in this thread. Ok, I can live without it.
Right now another problem which I thought I could figure out myself remains and then I am done with setting up my trading chart.
One thing I use is a moving average crossover to define trend. Simple, no? Well, I would like to be able to paint the fast MA one color when it is above the slow MA and a different color when it is below. I would also like the option to turn on and off the capability to paint the bars the same way.
So the logic is as follows:
Fast MA = an exponential moving average.
Slow MA = Simple moving average.
Both use the Median price.
So if the Fast Ma is above the slow ma then the indicator and/or bar is bullish color.
If the Fast Ma is below the slow ma then the indicator and/or bar is bearish color.
Simple as that. I have tried about 20+ times to code this myself and got nowhere. I don't know what it is that I am not understanding about Ninja script but there it is, I can't figure out this most simple of things. I have looked at the coding for MA's, the tutorials, the index etc. etc. but I just can't do it. (Believe it or not I am supposed to have a very high IQ, but this makes me feel totally stupid!)
So if someone could please code this for me I would be very, very grateful.
Comment
-
Josh wrote:
cclsys,
"It does mean the Close of the bar. The close of the bar in a real-time bar is the latest tick of the bar. On historical bars you will of course not have the intrabar tick information. You just have the OHLC."
Josh, thanks for clarifying that. We tried in this thread to do it, but it didn't work and that is that. Interesting exercise even if no definitive result. I am going to leave it now and just not have the capability.Last edited by cclsys; 10-29-2008, 12:07 PM.
Comment
-
To get multi-colored plots you will want to look at this reference sample: http://www.ninjatrader-support.com/v...ead.php?t=3227Josh P.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Josh View PostTo get multi-colored plots you will want to look at this reference sample: http://www.ninjatrader-support.com/v...ead.php?t=3227
I am trying to change color based on whether or not one MA is higher or lower than another. So having multiple plots coded on conditions to do with the same MA is too many steps removed from the problem I am trying to solve.
Comment
-
cclsys,
There is no way we can provide reference samples demonstrating the exact scenario cases for everyone. The concept to take note of is the use of multiple plots to achieve the color you want. So yes, you can change the coloring conditions however you want.Josh P.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Josh View Postcclsys,
There is no way we can provide reference samples demonstrating the exact scenario cases for everyone. The concept to take note of is the use of multiple plots to achieve the color you want. So yes, you can change the coloring conditions however you want.
I have tried this about 20 times, without success. This is my latest attempt. I cannot paste it in so I paste in a couple of the sections where the problem seems to lie:
++++++++++++++
{
//Add(new Plot(Color.LimeGreen, PlotStyle.Line, "Rising"));
Add(new Plot(Color.Yellow, PlotStyle.Line, "Bullish"));
Add(new Plot(Color.Cyan, PlotStyle.Line, "Bearish"));
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = true;
}
( The first line is from your sample 'rising'. The next two are mine for this one. I was hoping there was a simple command to change the color, but if there is I cannot find it anymore. But in theory this should work because it is what you did in your sample, i.e. have three different plots for the same indicator.)
The last part won't verify:
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.
if (EMA(period)[0] > SMA(period2)[0]) BullishPlot.Set(EMA(period)[0]);
if (EMA(period)[0] < SMA(period2)[0]) BearishPlot.Set(EMA(period)[0]);
}
The error message says that "the name BullishPlot does not exist in the current context."
In the tangentially related sample you sent, you had written:
// Connects the new falling plot segment with the rest of the line
FallingPlot.Set(1, SMA(Period)[1]);
// Adds the new falling plot line segment to the line
FallingPlot.Set(SMA(Period)[0]);
I noticed there are two lines there but don't know why exactly despite you explanation after the // and certainly don't know how to put that in with what I am trying to do here which again is simply have the color of the plot change when the fastMA is greater or less then the slowMA.
Comment
-
In another piece of coding for the volume bar thingie earlier that almost worked, we had:
if (downVol - upVol > 0) BarColor = Color.Cyan; // bearish
else BarColor = Color.Yellow; // bullish
First of all, although it verified, does that work? It seemed to work with the other indicator but with this one when I take out the PlotColor lines that are problematic and put those in it says 'statement expected'. So it doesn't work with this one.
If so, could I not say with the above example:
If EMA(period)[0] > SMA(period2)[0]
BarColor = Color.Yellow; //bullish else
BarColor = Color.Cyan;
But if I do that, do I have to get rid of the Plots on the MA indicator somehow?
Additionally, is there not simple language like this to change the plot color of an indicator so that instead of writing 'BarColor' one could write 'PlotColor' or whatever?Last edited by cclsys; 10-30-2008, 12:18 PM.
Comment
-
cclsys,
I have been doing everything shy of programming it out for you. Like I said in the beginning, we cannot custom code your scripts for you. We can show you the resources of how to do it. It is up to you to ultimately get it done though. We recommend you try contacting one of the 3rd party NinjaScript Consultants here: http://www.ninjatrader.com/webnew/pa...injaScript.htm
Your "BullishPlot" and "BearishPlot" do not exist most likely because you have not created them in the Properties region of your code. You need to expand that section and make the changes necessary. Please take a look at how it is done in the reference sample.
Just follow the example exactly how it is shown. The only thing you need to change is the condition. The sample uses the condition of Falling and Rising. Just change those conditions to your MA cross overs.Josh P.NinjaTrader Customer Service
Comment
-
cclsys,
You do not remove plots from the EMA indicators. If you wanted to change the bar color you just change the bar color. Bar color and plots are not the same thing.
The code for how to change bar and plot colors has already been provided to you. There is no other way to do it.Josh P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Skifree, Today, 03:41 AM
|
3 responses
12 views
0 likes
|
Last Post
by Skifree
Today, 12:03 PM
|
||
Started by traderqz, Yesterday, 09:06 AM
|
5 responses
32 views
0 likes
|
Last Post Today, 12:03 PM | ||
Started by guillembm, Today, 11:25 AM
|
1 response
6 views
0 likes
|
Last Post Today, 12:01 PM | ||
Started by owensd, 04-21-2024, 11:34 PM
|
9 responses
34 views
0 likes
|
Last Post Today, 11:59 AM | ||
Started by trilliantrader, 04-10-2024, 09:33 PM
|
7 responses
25 views
0 likes
|
Last Post Today, 11:56 AM |
Comment