I am appling to apply in a strategy which will enter long when the close price will cross above the highest high in a variable lookback period. I tried to find the Highest high by making a double variable and also through a dataseries. However, no one is working as expected. The double variabale is compled but the dataseries not. Does anybody have an idea or any solution how can I do it?
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
R/S levels with variable lookback period
Collapse
X
-
R/S levels with variable lookback period
Hi,
I am appling to apply in a strategy which will enter long when the close price will cross above the highest high in a variable lookback period. I tried to find the Highest high by making a double variable and also through a dataseries. However, no one is working as expected. The double variabale is compled but the dataseries not. Does anybody have an idea or any solution how can I do it?Tags: None
-
I am already using the MAX() but the problem is with the CrossAbove. I code the below
As a double: double HighWeek=MAX(High,5)[0];
// As a dataseries HighWeekly.Set(MAX(High,5)[0]);
if (CrossAbove(Close[0],HighWeek[1],1))
{
Do something
}
Do you have any suggestion on this?
Comment
-
It is complite, howevere when I am running backtest doesnt make trades. Could you have at the attachedment. ThanksAttached Files
Comment
-
Your conditions are likely too restrictive to allow trades. Unfortunately we could not debug this for you. You will need to simplify and print all values to confirm they're what you expect. Since a crossing looks at two bars and two values, you need to check every bar the values for:
Close[0] and Close[1]
HighWeek[1] and HighWeek[2].
Help for debugging is here:
Ryan M.NinjaTrader Customer Service
Comment
-
If I made the condition as if (CrossAbove(Close, HighWeekly[0],1)) does not made any trades but if I change it to if (CrossAbove(Close, HighWeekly[1],1)) the strategy makes few trades. However, I am wondering if the HighWeekly[1] is correct because it is taking into account the previous highest hight not the current highest. So the idea to enter Long when the close price cross above the last month highest does not exist! What is your thoughs about it? Maybe I need to change the condition with CurrentBar ?
Thanks
Comment
-
Yes, HighWeekly[1] is the value of HighWeekly 1 bar ago. It makes sense that you would never see Close crossing above the highest high of last few bars. 100% of the time Close is <= Max(High) if it's included in Max's lookback.
In order to understand what your strategy is doing, you're going to have to dig into it with print statements. Please see my previous post for guidance on what you'll need to verify to evaluate crossing statements. If you're having trouble following it in your strategy, start simplifying and working from this good example of a crossing strategy:
Ryan M.NinjaTrader Customer Service
Comment
-
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. I want some guides if it is possible!
Comment
-
This thread has references to crossing strategy guides and guidelines for how to verify crossing conditions through Print() statements. What you're trying to do may not work until you refine the conditions a bit.
If lookback period for MAX(High, lookback)[0] includes the close value you're checking for a crossover, then your condition will never be true. See this thread that was posted today about applying indexing to a MAX expression for some ideas to change your condition.
In these examples below, you could use >= and you have a chance to enter, only if the most recent close is the highest high over the Weekly lookback. It can't/won't ever be greater.
if (Close[0]>MAX(High,Weekly)[0]) // never true
double HighWeek=MAX(High,Weekly)[0];
if (Close[0]>HighWeek) //never true
if (Close[0]>MAX(High,Weekly)[0]) //never trueLast edited by NinjaTrader_RyanM1; 09-12-2011, 08:10 AM.Ryan M.NinjaTrader Customer Service
Comment
-
Originally posted by Loukas View PostI 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. I want some guides if it is possible!
If the Close today, is higher than the highest high for the last 20 bars, as at yesterday, then go long. MAX() requires a DataSeries and an (integer) lookback period.
So that gets coded as:
Code:if (Close[0] > MAX(High, 20)[1]) { // Do stuff }
Comment
-
Thanks koganam. I done that you same but it is executing only one trade. I think something is missing.
if (CurrentBar < Weekly )
return;
if (Close[0] > MAX(High,Weekly)[1])
{
EnterLong(DefaultQuantity, "");
}
RayM
"""If lookback period for MAX(High, lookback)[0] includes the close value you're checking for a crossover, then your condition will never be true""""
A good point! Thanks for the explanation.
Comment
-
Originally posted by Loukas View PostThanks koganam. I done that you same but it is executing only one trade. I think something is missing.
if (CurrentBar < Weekly )
return;
if (Close[0] > MAX(High,Weekly)[1])
{
EnterLong(DefaultQuantity, "");
}
RayM
"""If lookback period for MAX(High, lookback)[0] includes the close value you're checking for a crossover, then your condition will never be true""""
A good point! Thanks for the explanation.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by algospoke, Yesterday, 06:40 PM
|
2 responses
19 views
0 likes
|
Last Post
by algospoke
Today, 07:04 PM
|
||
Started by ghoul, Today, 06:02 PM
|
3 responses
14 views
0 likes
|
Last Post Today, 06:43 PM | ||
Started by jeronymite, 04-12-2024, 04:26 PM
|
3 responses
44 views
0 likes
|
Last Post
by jeronymite
Yesterday, 10:10 PM
|
||
Started by Barry Milan, Yesterday, 10:35 PM
|
7 responses
20 views
0 likes
|
Last Post Today, 06:16 PM | ||
Started by AttiM, 02-14-2024, 05:20 PM
|
10 responses
180 views
0 likes
|
Last Post
by jeronymite
Today, 06:11 PM
|
Comment