Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
SMA crossovers
Collapse
X
-
SMA crossovers
I would like to knwo how to do a simple strategy with two identical sma's with one having a displacement and the other regular. I cannot find how to name and value the displaced one so the analyzer thinks I am comparing a 9 to a 9 as an example. If anyone can help please advise as I am very new at this. From taking the first webinar in the wizard this is a simple crossover but won't work. Thank youTags: None
-
This is exactly what I want to do but the example link does not show
how to put displacement. It shows how to offset by
percentage, price or ticks. Not how much amount of displacement.
Please advise us how to do this two identical moving average crossover,
one without displacement and one with displacement value.
Thanks.
Comment
-
badasan and traderdan68,
The way I'll do it is to create a new indicator.
Go to Tools -> New NinjaScript -> Indicator. Give a name eg SMAdisp and then Next until you reach the editor. Then, Tools -> Edit NinjaScript -> Indicator and open SMA -> Select all and copy.
Back to the SMAdisp select all delete and then paste.
Then, change public class SMA : Indicator to
public class SMAdisp : Indicator
Add the following line of code under Initialize()
Displacement = x; (x is the displacement value you wish ie 9 or -12 etc and compile.
Now you will have two SMA indicators and from the strategy wizard you select the cross above etc..
I don't know if there is a quicker way to do it but the above will work.
astra
Comment
-
In the Wiizard when using the Cross operators, you can't compare two indicator values (one with a displacement) since the internal cross methods don't support that.
You would have to create custom conditions that check for the cross yourself and on one of the indicators, set the bars ago value back 1 to get your displacement.
Something like
value 1 of 1 bar ago is less than value 2 of 2 basr ago and
valalue 1 of current abr is greater than value 2 of 1 bar agoRayNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Ray View PostIn the Wiizard when using the Cross operators, you can't compare two indicator values (one with a displacement) since the internal cross methods don't support that.
You would have to create custom conditions that check for the cross yourself and on one of the indicators, set the bars ago value back 1 to get your displacement.
Something like
value 1 of 1 bar ago is less than value 2 of 2 basr ago and
valalue 1 of current abr is greater than value 2 of 1 bar ago
Anyway, since a long time I always use custom conditions in my strategies like your example as I had some issues with cross operators. I don't remember now what was exactly the issue but I think had to do with rising / falling values + cross operators combinations and I was getting funny results. I also prefer to use custom conditions instead of rising/falling operators as I have more control of what I am doing.
astra
Comment
-
Thanks Astra for your suggestion.
I created SMAdisp and it compiles fine. When I put SMA and SMAdisp on the chart, they look good. However, when I use strategy to generate buy
or sell signal looking at crossover of SMA and SMAdisp, no order is generated.
Ray,
Would you be able to put strategy code here
that will create long and short signal
when SMA(10) and SMAdisp(10) crosses above and below? (hope this is very simple for you)
I am new to the programming and your exlplanation below is not
enough for me to create strategy.
Thanks in advance
Comment
-
Originally posted by badasan View PostThanks Astra for your suggestion.
I created SMAdisp and it compiles fine. When I put SMA and SMAdisp on the chart, they look good. However, when I use strategy to generate buy
or sell signal looking at crossover of SMA and SMAdisp, no order is generated.
Ray,
Would you be able to put strategy code here
that will create long and short signal
when SMA(10) and SMAdisp(10) crosses above and below? (hope this is very simple for you)
I am new to the programming and your exlplanation below is not
enough for me to create strategy.
Thanks in advance
What Ray says is that the cross conditions are not supported for dispaced indicators. So, instead you have to do the following:
Say, you buy when SMA crosses above SMAdisp.
Under Conditions and Actions in the Strategy wizard you click add, then indicators->select SMA. Under Parameters -> BarsAgo you place =1. Condition "<". On the right hand side select SMAdisp, BarsAgo=2, OK.
Again as above, Add, SMA -> BarsAgo=0, Condition ">", SMAdisp -> BarsAgo=1, OK.
Under Do the Following : select Enter Long
For the Short you click Set2 and you proceed as above
Hope it helps
astra
Comment
-
astra,
Just for your information, the following two resulted in same thing.
case1.
if (SMA(14)[1] < SMAdisp(14)[2]
&& SMA(14)[0] > SMAdisp(14)[1])
{
EnterLong(DefaultQuantity, "");
}
case 2.
if (SMA(14)[1] < SMA(14)[2]
&& SMA(14)[0] > SMA(14)[1])
{
EnterLong(DefaultQuantity, "");
}
Comment
-
Originally posted by badasan View Postastra,
Just for your information, the following two resulted in same thing.
case1.
if (SMA(14)[1] < SMAdisp(14)[2]
&& SMA(14)[0] > SMAdisp(14)[1])
{
EnterLong(DefaultQuantity, "");
}
case 2.
if (SMA(14)[1] < SMA(14)[2]
&& SMA(14)[0] > SMA(14)[1])
{
EnterLong(DefaultQuantity, "");
}
Comment
-
You are right basadan, even the second method will not work. "Displacement" is useless for using it in strategies. It seems it only serves the purpose to visually represent the displaced values in a chart. As there is no information about this in the help files, once again we 've learnt it the hard way...
Anyway, below I have created an SMA indicator that displaces its values (with user selectable displacement - usefull for optimization) and it should work with strategies.Attached FilesLast edited by astra; 06-07-2009, 08:38 PM.
Comment
-
Thank you so much astra,
I have one more question.
How would you change the code if strategy only trigger once
whether it is long or short whichever comes first and after that it won't
trigger any more trade even if there is a cross.
I know I can just shutdown the strategy right after first trigger but
just would like to pick your brain how to do it with programming.
Thanks a lot in advance
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by reynoldsn, Today, 02:32 PM
|
2 responses
6 views
0 likes
|
Last Post
by reynoldsn
Today, 06:06 PM
|
||
Started by reynoldsn, Today, 02:30 PM
|
2 responses
7 views
0 likes
|
Last Post
by reynoldsn
Today, 06:05 PM
|
||
Started by FishTrade, Today, 06:03 PM
|
0 responses
6 views
0 likes
|
Last Post
by FishTrade
Today, 06:03 PM
|
||
Started by Fran888, Today, 06:00 PM
|
0 responses
5 views
0 likes
|
Last Post
by Fran888
Today, 06:00 PM
|
||
Started by Playdc, Today, 05:47 PM
|
0 responses
4 views
0 likes
|
Last Post
by Playdc
Today, 05:47 PM
|
Comment