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
Moving Average Price Crossover
Collapse
X
-
Moving Average Price Crossover
There are many indicators out there where a signal is generated when two moving averages cross. Does anyone have an indicator that would generate a signal (arrow, dot etc.) when price crosses a user defined, single, moving average? How difficult would it be to create it on the platform's "new indicator" function?Tags: None
-
Hello edleal,
I'm not aware of one but should be easy enough to create. You can create through New Indicator if you are comfortable working with code. If you want to create this without code, you can use the strategy wizard to define the crossing condition as well as the draw action. Help for working with the strategy wizard is available here:
Ryan M.NinjaTrader Customer Service
-
Moving Average Price Crossover
Thanks for your help Ryan. I used the Strategy Wizard and have not been successful in gettng the strategy to work. When activated nothing appears on my charts. I smply tried to program an up arrow to appear for price closing above the moving average and a down arrow for price closing below the moving average. A copy of the generated code is in the attached file. Not sure where I messed up.
Comment
-
Rya here's the code
///</summary>
[Description("A buy or sell signal is generated when price crosses the moving average.")]
publicclass MAPriceCrossover : Strategy
{
#region Variables
// Wizard generated variables
privateint mAPeriod = 1; // Default setting for MAPeriod
// User defined variables (add any user defined variables below)
#endregion
///<summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
///</summary>
protectedoverridevoid Initialize()
{
CalculateOnBarClose = true;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
// Condition set 1
if (CrossAbove(Close, EMA(14), 1))
{
DrawArrowUp("My up arrow" + CurrentBar, false, 0, 0, Color.Lime);
}
// Condition set 2
if (CrossBelow(Close, EMA(14), 1))
{
DrawArrowDown("My down arrow" + CurrentBar, false, 0, 0, Color.Red);
}
}
#region Properties
[Description("Moving Average Period")]
[GridCategory("Parameters")]
publicint MAPeriod
{
get { return mAPeriod; }
set { mAPeriod = Math.Max(1, value); }
}
#endregion
}
}
Comment
-
Moving Average Price Crossover
Ryan thanks again for your help but may I offer a suggestion. I think your company's time would be well spent putting effort into making your help guides more comprehensive and user friendly. Maybe also consider adding a weekly webinar for indicator/strategy creation like you do for ATMs. Ninja's wizard help guide is simply not helpful enough, things could be made a lot easier if there were more examples provided for each step. It's very frustrating to have the option to use all these powerful trading tools but yet not be able to make them work with a reasonable investment of time and effort.
I got the arrow/Y access issue squared away but there are many other variables that I have not programmed properly. Even though I've selected a different moving average the program invariably uses the default setting of 14 periods. It is also generating an excessive number of arrows. Not only does it generate an arrow for the appropriate "crossing bar"but then does the same for every successive bar on the same side of the moving average as the trigger bar.
Comment
-
Thank you for the feedback. You may be interested in attending this webinar on automated strategy development.Ryan M.NinjaTrader Customer Service
Comment
-
my ema/price cross doesnt compile
I copied your code into a new indicator and tried to compile but it says 'the type or namespace name "publicint" could not be found.
I'm using it as an indicator not strategy since I want signals but dont want Ninja making entries for me. I want a signal when 1 bar ago price was less than the 5 EMA and now >= 5 EMA. I wanted to get yours to work then adjust it for my needs but I can't get yours working.Attached Files
Comment
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by andrewtrades, Today, 04:57 PM
|
1 response
5 views
0 likes
|
Last Post Today, 05:02 PM | ||
Started by chbruno, Today, 04:10 PM
|
0 responses
3 views
0 likes
|
Last Post
by chbruno
Today, 04:10 PM
|
||
Started by josh18955, 03-25-2023, 11:16 AM
|
6 responses
436 views
0 likes
|
Last Post
by Delerium
Today, 03:42 PM
|
||
Started by FAQtrader, Today, 03:35 PM
|
0 responses
7 views
0 likes
|
Last Post
by FAQtrader
Today, 03:35 PM
|
||
Started by rocketman7, Today, 09:41 AM
|
5 responses
19 views
0 likes
|
Last Post Today, 03:33 PM |
Comment