NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM 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 04-23-2008, 07:25 AM   #1
chobotnice
Junior Member
 
Join Date: Mar 2008
Posts: 5
Thanks: 0
Thanked 0 times in 0 posts
Default Triple screen strategy development

Hi all,
I've got an issues with my stretegy based on triple screen by Alexander Elder concept.
I'm using two timeframes. Weekly for detecting the trend and daily for entering the positions.
On weekly I'm testing if current price closed above EMA(26) and if MACD is raising (if current bar is above previous one - for bull trend).
If there is a trend of weekly I'm trying to enter the position on daily by WilliamsR. In other words WilliamsR can't be overbought (above -20) for long positions and oversold (below -80) for short positions.
But as you can see from the attached screenshot I was executed into short position despite oversold WilliamsR.

I've run out of bullets already and I'd highly appreciate any hints.



Thanks in advance!


Regards,


Ondrej

entry.JPG

------------------------------------
Dump of my triple screen strategy:


protected override void OnBarUpdate()
{
if (Position.MarketPosition == MarketPosition.Flat) //no open positions at the moment
{
// 1. screen on Weekly
if (Closes[1][0] > EMA(BarsArray[1],26)[0]
&& (MACD(BarsArray[1],12, 26, 9)[0] > MACD(BarsArray[1],12, 26, 9)[1]))
{
//bull trend on weekly chart
// 2. screen on Daily
if (WilliamsR(14)[0] < -20)
{
SetStopLoss(100);
EnterLong(DefaultQuantity, "Long");
stoploss = GetCurrentAsk()-2;
Print ("Stoploss" +stoploss);
Print ("%R: " +WilliamsR(14)[0]);
}

}

// 1. screen on Weekly
if (Closes[1][0] < EMA(BarsArray[1],26)[0]
&& (MACD(BarsArray[1],12, 26, 9)[0] < MACD(BarsArray[1],12, 26, 9)[1]))
{
//bear trend on weekly
// 2. screen on Daily
if (WilliamsR(14)[0] > -80)
{
SetStopLoss(100);
EnterShort(DefaultQuantity, "Short");
stoploss = GetCurrentBid()-2;
Print ("Stoploss" +stoploss);
Print ("%R: " +WilliamsR(14)[0]);

}

}
}

Print("Open PnL: " + Position.GetProfitLoss(Close[0], PerformanceUnit.Points));

if (Position.MarketPosition == MarketPosition.Long && Position.GetProfitLoss(Close[0], PerformanceUnit.Points) > 0 && Close[0] > EMA(13)[0])
{
SetStopLoss(CalculationMode.Price, EMA(13)[0]);

}

if (Position.MarketPosition == MarketPosition.Short && Position.GetProfitLoss(Close[0], PerformanceUnit.Points) > 0 && Close[0] < EMA(13)[0])
{
SetStopLoss(CalculationMode.Price, EMA(13)[0]);

}
}
chobotnice is offline  
Reply With Quote
Old 04-23-2008, 07:41 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

You need to break your code into blocks that process OnBarUpdate() for weekly and for daily.

If you are running on Daily chart and Weekly is secondary then

Code:
if (BarsInProgress == 0)
{
    //Process daily
}
else if (BarsInProgress == 1)
{
    // Process weekly
}
Right now, this line

if (WilliamsR(14)[0] > -80)

checks for your short condition on both the daily and weekly bars.
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-24-2008, 06:39 AM   #3
chobotnice
Junior Member
 
Join Date: Mar 2008
Posts: 5
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Ray! This seems to solve the problem.


Regards,


Ondrej
chobotnice is offline  
Reply With Quote
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
A novel way for strategy development... Elliott Wave Suggestions And Feedback 1 04-20-2008 01:29 AM
Multiple data sources in strategy development Sidhartha Strategy Development 1 03-10-2008 07:19 PM
Custom optimizer development feedback Pete S Historical NinjaTrader 6.5 Beta Threads 2 02-14-2008 08:44 AM
f optimizer development - no values returned chrisdc5 Strategy Analyzer 3 01-04-2008 06:01 AM
New "Introduction to NinjaScript Strategy Development" 8 Hour Online Seminar! NinjaTrader_Ray News and Announcements 0 12-05-2007 06:35 PM


All times are GMT -6. The time now is 04:14 PM.