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 07-11-2008, 10:06 AM   #1
giucol
Junior Member
 
Join Date: Jul 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default Josh please, help me

Hi guys, I'm an italian student adm i'm improving my thesys about trading system. I developed my code in easylanguage and now i'm trying to , translate it in C# for ninjia . I compile the code but when apply it on chart ninjia doesn't provide the signals.I think there are mistakes about ninja script...It's symple long/short limt order es long next open +(stddev(High-low)*Mul) if Ema fast > Ema slow .
Josh please can you help me?
Attached Files
File Type: zip Giu.zip (4.5 KB, 5 views)
giucol is offline  
Reply With Quote
Old 07-11-2008, 10:20 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

As you run the strategy --> Are there any error messages generated in the NinjaTrader Control Center log tab?
NinjaTrader_Ray is offline  
Reply With Quote
Old 07-11-2008, 12:22 PM   #3
giucol
Junior Member
 
Join Date: Jul 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default

Thannks Ray for the reply, i wrote the code and compile it, without problem, but when i apply it in simulation Ninjia doesn't provide the signal...This is the central of my code if you could help me...to solve the problem


private int mlt = 2; // Default setting for Mlt
private
int lenta = 50; // Default setting for Lenta
private
int veloce = 10; // Default setting for Veloce
private
int giorni = 5; // Default setting for Giorni
double
Value1;
double
Value2;
private
DataSeries HighMenoOpen;
private
DataSeries OpenMenoLow;
// 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>
protected
overridevoid Initialize()
{
SetProfitTarget(
"", CalculationMode.Price, Mlt*StdDev(High, 5)[0]);
CalculateOnBarClose =
true;
}
///
<summary>
///
Called on each bar update event (incoming tick)
///
</summary>
protected
overridevoid OnBarUpdate()
{
HighMenoOpen.Set(High[
1] - Open[1]);
OpenMenoLow.Set(Open[
1] - Low[1]);
Value1 = StdDev(HighMenoOpen , giorni)[
1];
Value2 = StdDev(OpenMenoLow , giorni)[
1];
// Condition set 1
if (EMA(Veloce)[1] > EMA(Lenta)[1] && Position.MarketPosition!=MarketPosition.Long);
{
EnterLongLimit(
1,Open[0] - (Value2 * Mlt));}
if
(Position.MarketPosition==MarketPosition.Long)
{
ExitLongLimit(Open[
0] + (Value1 * Mlt));
}
// Condition set 2
if
(EMA(Veloce)[1] < EMA(Lenta)[1] && Position.MarketPosition!=MarketPosition.Short);
{
EnterShortLimit(
1,Open[0] + (Value1 * Mlt));}
if
(Position.MarketPosition==MarketPosition.Short)
{
ExitShortLimit(Open[
0] - (Value2 * Mlt));
}
}
giucol is offline  
Reply With Quote
Old 07-11-2008, 12:42 PM   #4
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

This likely will help - http://www.ninjatrader-support.com/v...ead.php?t=3170
NinjaTrader_Ray is offline  
Reply With Quote
Old 07-12-2008, 05:17 AM   #5
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

Quote:
Originally Posted by giucol View Post
This method is used to configure the strategy and is called once before any strategy method is called.
///
</summary>
protected overridevoid Initialize()
{
SetProfitTarget("", CalculationMode.Price, Mlt*StdDev(High, 5)[0]);
CalculateOnBarClose = true;
}
Hi giucol,

you use an indicator's return value from StdDev() in SetProfitTarget() in Initialize(). Initialize() is called before your strategy starts. So, what do you expect StdDev() to return during initialization? I guess it wouldn't return a useful result anyway?

Regards
Ralph
Ralph is offline  
Reply With Quote
Old 07-12-2008, 06:14 AM   #6
giucol
Junior Member
 
Join Date: Jul 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Red face

Ralph you have reason, i have to delete Set profit target..., but i think the problem is in the code about Value1 and Value2 because i neeed to catch the standard deviation of high meno Open for value1 and standard deviation of Open meno low for value2, I used data series
HighMenoOpen and OpenMenoLow, the compile is ok, but i dont know if that's ok.
I also make an indicator to plot Value1 and Value2, the compile is ok but Ninjia doesn't plot nothing...
Please help me , safe me...
giucol is offline  
Reply With Quote
Old 07-12-2008, 07:14 AM   #7
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

Hi giucol,

you declare two DataSeries variables (HighMenoOpen, OpenMenoLow) and you use it in OnBarUpdate() as class instances without instantiation. Don't think this works. For an class instantiation example look at the "Reference Samples" section. There is a packet "Synchronizing a DataSeries object to a secondary time frame". It explains how and where to generate a DataSeries class instance.

Regards
Ralph
Ralph is offline  
Reply With Quote
Old 07-14-2008, 04:44 AM   #8
giucol
Junior Member
 
Join Date: Jul 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default To Indicate Next Bar

THANKS RALPH I SOLVE THE PROBLEM TO PLOT VALUE 1 AND A VaLUE 2...NOW I NEED TO IMPLEMENT MY STRATEGY, I NEED TO INSERT AN ORDER LIMIT..IN EASY LANGUAGE CODE Buy ("LongScalp") next bar at open of next bar -
(Value2*Mlt) limit;
I wrote in C# this code for next Open
if (EMA(Veloce)[0] > EMA(Lenta)[0] && Position.MarketPosition!=MarketPosition.Long);
{
EnterLongLimit(
1,Open[-1] - (Value2 * Mlt));}

if
(Position.MarketPosition==MarketPosition.Long)
{
ExitLongLimit(Open[-1
] + (Value1 * Mlt));

I don't if i can use to indicate next bar -1
Please help me, andyou don't hate me....
giucol is offline  
Reply With Quote
Old 07-14-2008, 07:58 AM   #9
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

Never fear, no reason to hate you.

You can't access a bar in the future (would be a nice feature to return the prices of a future bar). But you can find out if a new bar has started by property "FirstTickOfBar". In the help-section of NT there is a little example how to use it.

Regards
Ralph
Ralph is offline  
Reply With Quote
Old 07-14-2008, 08:16 AM   #10
giucol
Junior Member
 
Join Date: Jul 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Ralph, i tried to aplly the code with
if (EMA(Veloce)[0] > EMA(Lenta)[0] && Position.MarketPosition!=MarketPosition.Long);
{
EnterLongLimit(
1,Open[-1] - (Value2 * Mlt));}
if(Position.MarketPosition==MarketPosition.Long)
{
ExitLongLimit(Open[-
1] + (Value1 * Mlt));
}

and now ninja gives me the signal....but do you tink that open[-1] is a mistake?
Pease can you tell me the section about "FirstTickOfBar"...Thanks Ralph
giucol is offline  
Reply With Quote
Old 07-14-2008, 08:30 AM   #11
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

Quote:
Originally Posted by giucol View Post
...and now ninja gives me the signal....but do you tink that open[-1] is a mistake?
Pease can you tell me the section about "FirstTickOfBar"...
I think first element of an open[]-array has the index number 0. If -1 works too, then you could check whether it contains the correct number. I wouldn't expect that. But, when you ever run this strategy in real time (and not only for backtesting) a reference into the future can never work.

FirstTickOfBar is described under:
NinjaScript
NinjaScript Language Reference
Shared Data Methods and Properties

Alternatively you can use the search function.

Regards
Ralph
Ralph is offline  
Reply With Quote
Old 07-14-2008, 08:40 AM   #12
giucol
Junior Member
 
Join Date: Jul 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default No Backtesting

Ralph, excuse me if i annoy you... i tried the code not in backtesting but in simulation data feed, so in real time and gives me the signal, but is possible that read -1 as 0...so don't catch next open
giucol is offline  
Reply With Quote
Old 07-14-2008, 08:45 AM   #13
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Unfortunately negative "barsAgo" indexes are not support. You'll see an error in your logs.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 07-14-2008, 09:14 AM   #14
giucol
Junior Member
 
Join Date: Jul 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default

Dierk the strategy gives me signals, also if i write O[-1], so if i can't use Open[-1] how can i say to ninja to entry in a specific level that includes the next open + (Sell limit) or - (Buy limit) something if i cant use -1?
Excuse me to all, thanks ...
giucol is offline  
Reply With Quote
Old 07-14-2008, 09:17 AM   #15
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Unfortunately you can not use/access a price value in the future. This is not supported.
NinjaTrader_Dierk 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
Josh or any advanced c# programmer please please help whitegun General Programming 12 07-05-2008 11:33 AM
Josh, I lost workspace again... funk101 Miscellaneous Support 1 04-06-2008 07:59 AM


All times are GMT -6. The time now is 03:47 PM.