Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I am trying to create a condition to enter "Long" when the current "Close" price "CrossAbove" the highest price from the previous 5 highs. I done this with two different ways, by creating a New Dataseries and also as a Double value but it seems that it is not working. Do you have any ideas why is not working? Thanks
1. double HighW=Math.Max(High[0],5);
if (CrossAbove(Close,HighWk1))
{...
2. HighWeekly.Set(Math.Max(High[0],5));
if (CrossAbove(Close,HighWeekly,1))
{...
Can you help answer these questions from other members on NexusFi?
Did you not like the solution I posted? I think it does exactly what you where asking for. Just wondering if there was some reason you didn't go with that? There are dozens of ways to do what you want, what I posted was just one possible way of doing it.
The two examples you posted above will not accomplish what you want. You are referencing a C# function when you are using "Math.Max," and that function returns the HIGHEST of two values you pass it.
So for example when you pass it the value of "High[0]" and "5", it will simply return the highest value of those two numbers. In this case, you are passing it the HIGH of the current bar, and the number 5. So if you are using an instrument like EurUsd which is commonly 1.xxxx, the statement......... Math.Max(High[0],5) will ALWAYS return 5, cause the EurUsd doesn't trade that high. If you were applying that to say the TF which is currently trading above 600s, it will always return whatever 'High[0]' is. Does that make sense?
So if say you pass "Math.Max" two numbers, say 3 and 5, it will return 5. More examples.......
If you want to reference the highest value of a few bars ago, you will want to use the Ninjatrader Function "MAX()" as opposed to "Math.Max." I made this mistake a few weeks ago myself
If you save your .cs file as it is and post it here, somebody will review and modify it. A common mistake is accessing bars with a negative index, that is looking back 5 bars from the first bar of the bar series. To avoid this problem, you would need to insert
at the beginning of OnBarUpdate. But as long as I cannot see what you have coded, this is mere speculation.
Ok, looks like you are creating an indicator, but trying to use things you would put into a strategy. This is why you couldn't compile.
What I usually do if I am wanting to do a strategy, start with an indicator first, then modify it to perform as a strategy. As most of the logic you create for your indie will work on a strategy depending on how you write it. In fact I usually just copy the entire script and paste it in my strategy and make minor changes.
When you want to create a strategy, you will want to go to Tools -> NewNinjaScript -> Strategy. Strategies are used to create an ATS(auto-trade strategy).
If you just want visual aids on your chart, you will want to go Tools -> NewNinjaScript -> Indicator. Indicators just are used to plot various visuals on your chart. So there is some difference between the two.
In either case, go through the editor, get to the last step then hit generate/unlock, and we'll start from there with the new .cs file you post in here.
In NinjaScript there is no such thing as Plot0, you just invented it. As it is a variable which is not declared, the compiler cannot read it. Try to replace Plot0[0] with Values[0][0].
""Ok, looks like you are creating an indicator, but trying to use things you would put into a strategy. This is why you couldn't compile.""
The problem is not there because I have done the same think from the beging with a simple condition EMA10 > EMA 20 and it is not make a trade because of the CrossAbove.
I change the condition with the statment below and it is working. The problem is this the CrossAbove and I cannot understad why.
if (Close[0]>=MAX(High,Weekly)[1])
{if ( EMA(5)[0]>EMA(24)[0]
enter long
I am trying something simple just to improve my skills, I have tried 3 ways but no one look to working eventhough they are compiled.
1. if (CurrentBar < Weekly )
return;
double HighWeek=MAX(High,Weekly)[0];
if (Close[0]>HighWeek)
{
EnterLong(DefaultQuantity, "");
}
2. HighWeek.Set(MAX(High,Weekly)[0]); if (CrossAbove(Close,HighWeek,1))
{
EnterLong(DefaultQuantity, "");
}
3.
if (Close[0]>MAX(High,Weekly)[0])
{
EnterLong(DefaultQuantity, "");
}
I dont thing so this is something sophisticated, I just cannot understand why is not working. Can someone guide me how to solve this .
Start with this. Simple strategy that buys the breakout if CLOSE above the highest high of the past 5 bars. Conversely, it SELLS the breakout if CLOSE below lowest low of prior 5 bars.
It has set in it an arbitrary 8 tic profit target, with a 16 tic stoploss.
--EDIT---
Initially put the wrong file up there. It is correct now though if you downloaded before I typed this.