NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 01-09-2012, 11:30 AM   #1
ibrown
Junior Member
 
Join Date: Jan 2012
Posts: 13
Thanks: 1
Thanked 0 times in 0 posts
Default Strategy not working

Hi,

I have created a simple strategy using the Wizard.

The strategy I have is when price crosses above a 50 EMA a buy will occur and when the price crosses below the EMA is triggers a sell.

When backtesting it no trades occur, not sure if my code is correct.

Screenshots:

Code:




Uploaded with ImageShack.us







Thanks
Ivan
Last edited by ibrown; 01-09-2012 at 11:33 AM.
ibrown is offline  
Reply With Quote
Old 01-09-2012, 11:36 AM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

ibrown,

You are adding EMA's with 0 period. You will want to use something like EMA(50), etc. Currently what you have is a CrossAbove() and CrossBelow() condition for two equal EMA's.

Please let me know if I may assist further.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 01-09-2012, 12:07 PM   #3
ibrown
Junior Member
 
Join Date: Jan 2012
Posts: 13
Thanks: 1
Thanked 0 times in 0 posts
Default

I have now added the 50 but still not getting anything.

Code:
protectedoverridevoid Initialize()
{
Add(EMA(
50));
Add(EMA(
50));
Add(EMA(
50));
Add(EMA(
50));
SetProfitTarget(
"", CalculationMode.Ticks, 50);
SetStopLoss(
"", CalculationMode.Ticks, 25, false);
CalculateOnBarClose =
true;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
// Condition set 1
if (CrossAbove(EMA(50), EMA(50), 1))
{
EnterLong(
1, "");
}
// Condition set 2
if (CrossBelow(EMA(50), EMA(50), 1))
{
EnterShort(
1, "");
}
ibrown is offline  
Reply With Quote
Old 01-09-2012, 12:09 PM   #4
ibrown
Junior Member
 
Join Date: Jan 2012
Posts: 13
Thanks: 1
Thanked 0 times in 0 posts
Default

not sure if it makes any difference I trading the EUR/USD on 24/7 session templete using a tick chart.
ibrown is offline  
Reply With Quote
Old 01-09-2012, 12:09 PM   #5
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

ibrown,

CrossAbove(EMA(50),EMA(50),1) will never occur because its basically asking, if a 50 period ema crosses above a 50 period ema. I would suggest using two different periods for the EMA. What are you trying to do? Close crossing the EMA or two EMA's crossing eachother?
NinjaTrader_AdamP is offline  
Reply With Quote
Old 01-09-2012, 12:24 PM   #6
ibrown
Junior Member
 
Join Date: Jan 2012
Posts: 13
Thanks: 1
Thanked 0 times in 0 posts
Default

i am wanting to use just 1 EMA with price crossing it.
ibrown is offline  
Reply With Quote
Old 01-09-2012, 12:25 PM   #7
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

ibrown,

You probably want to use CrossAbove(Close,EMA(50),1) and CrossBelow(Close,EMA(50),1).

Please let me know if I may assist further.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 01-09-2012, 12:29 PM   #8
ibrown
Junior Member
 
Join Date: Jan 2012
Posts: 13
Thanks: 1
Thanked 0 times in 0 posts
Default

not sure what to do next. can't work out how to do it in the Wizard but I haven't compiled or clicked unlock code.
ibrown is offline  
Reply With Quote
Old 01-09-2012, 01:01 PM   #9
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

ibrown,

Please see the attached screenshot. It should show you how to implement the CrossAbove condition.

Please let me know if I may assist further.
Attached Images
File Type: png Capture.PNG (70.2 KB, 4 views)
NinjaTrader_AdamP is offline  
Reply With Quote
Old 01-09-2012, 01:10 PM   #10
ibrown
Junior Member
 
Join Date: Jan 2012
Posts: 13
Thanks: 1
Thanked 0 times in 0 posts
Default

ah yep looks like its done it!!!

Screenshot:
ibrown is offline  
Reply With Quote
Old 01-09-2012, 01:13 PM   #11
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

ibrown,

I am happy you have resolved your issue.

Here is a youtube video on automated strategy development : https://www.youtube.com/watch?v=fVFq...1&feature=plcp

Please don't hesitate to contact us should you require additional assistance.
NinjaTrader_AdamP is offline  
Reply With Quote
The following user says thank you to NinjaTrader_AdamP for this post:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strategy not working trader413 Strategy Development 15 06-27-2011 10:43 AM
Strategy not working correct L. Williams Strategy Development 3 05-11-2011 11:09 AM
Strategy not working deurich Version 7 Beta General Questions & Bug Reports 2 02-12-2010 09:23 AM
Strategy not working?? raycam Strategy Development 4 07-09-2009 05:03 AM
strategy analyser not working with my strategy junkone Strategy Analyzer 9 05-31-2009 01:37 PM


All times are GMT -6. The time now is 12:34 PM.