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,5);
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" 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,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' 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 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.
The following user says Thank You to Fat Tails for this post:
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.
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 )
2. HighWeek.Set(MAX(High,Weekly)); if (CrossAbove(Close,HighWeek,1))
I dont thing so this is something sophisticated, I just cannot understand why is not working. Can someone guide me how to solve this .