NinjaTrader Support Forum  

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-29-2012, 12:18 PM   #1
bascher
Junior Member
 
Join Date: Jun 2010
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default Residual in strategy

Hallo,

I want to use my residual indicator in a strategy. I want to do something if the indicator crossbelow 2. How should I do that?
I tried somthing like:

int Variable0 =2;
...
// Condition set 1
if (CrossBelow(SpreadPlot2(10, 1, 10, "").Upper, Variable0, 10))
{
PrintWithTimeStamp("works");
}

But there occurs nothing in the output window.
Thank you in advance.
Benjamin
bascher is offline  
Reply With Quote
Old 07-29-2012, 12:59 PM   #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

bascher,

Can we see some code for the SpreadPlot2 indicator? Its possible that this would never cross below 2, for example if the tick size is small.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 07-30-2012, 11:48 AM   #3
bascher
Junior Member
 
Join Date: Jun 2010
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Thumbs up

Hallo Adam,

thank you for your reply. I have got the following code:

#region Variables
// Wizard generated variables
private int Variable0 = 1;
// 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 override void Initialize()
{

CalculateOnBarClose = true;
// Add the second instrument
Add("$USDCAD", PeriodType.Minute, 1);
// Add the indicator with the values period=10, MyInput0=1, Frequency=10
//and second instrument=$USDCAD
Add(SpreadPlot2(10, 1, 10, "$USDCAD"));
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
// If SpreadPlot indicator cross below Variable0=1 print to outputwindow="works"
if (CrossBelow(SpreadPlot2(10, 1, 10, "$USDCAD"), Variable0, 1))
{
PrintWithTimeStamp("works");
}
}

But it happens nothing.
What I have to change?
Thank you in advance.
Best regards
Benjamin
bascher is offline  
Reply With Quote
Old 07-30-2012, 11:53 AM   #4
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

Hello,

I would suggest trying this :

Variable0 = 2*TickSize;
if (CrossBelow(SpreadPlot2(10, 1, 10, "$USDCAD"), Variable0, 1))
NinjaTrader_AdamP is offline  
Reply With Quote
Old 07-30-2012, 12:25 PM   #5
bascher
Junior Member
 
Join Date: Jun 2010
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default

The condition variable is correct but I am not sure how to call the indicator and in which order this should be done.
bascher is offline  
Reply With Quote
Old 07-30-2012, 01:39 PM   #6
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

bascher,

I suspect that the following is the issue here :

CrossAbove(SpreadPlot2(10, 1, 10, "$USDCAD"), Variable0, 1)

This may never occur. The Variable0 = 2 will make the CrossAbove check to see if the spread calculation crosses above 2. Generally, spreads are Price1 - Price2 and will be something like 0.001 or something to that effect.

Does your spread indicator convert to ticks? What values does the Spread indicator output?
NinjaTrader_AdamP is offline  
Reply With Quote
Old 07-31-2012, 12:17 PM   #7
bascher
Junior Member
 
Join Date: Jun 2010
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default

Attached is the output of my SpreadPlot indicator. There occurs nothing if cross below the value 1.I tried:
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossBelow(SpreadPlot2(10, 1, 10, "").Plot0, Variable0, 1))
{
Print("funktioniert");
}
}
because .Plot0 is the property of the indicator
public DataSeries Plot0
{
get { return Values[0]; }
}

Values refered to:
if(outputStarted)
Value.Set(output);
Print(output);
???
and this is printed as:

Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));

But without any success.
Attached Images
File Type: jpg NinjaTrader_SpreadPlot.JPG (22.0 KB, 9 views)
bascher is offline  
Reply With Quote
Old 07-31-2012, 01:02 PM   #8
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

bascher,

You tried using Variable0 = 1?

In that example you showed me the value of spread doesn't seem like it ever reached 2.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 07-31-2012, 01:08 PM   #9
bascher
Junior Member
 
Join Date: Jun 2010
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default

I have changed this value to 1.
Can I send you the indicator an you will take a look?
bascher is offline  
Reply With Quote
Old 07-31-2012, 01:12 PM   #10
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

bascher,

I can take a look, but I would need the spread indicator and your strategy. We don't typically offer full debugging assistance however if its simple we don't mind taking a peek and seeing if something is immediately obvious.

You can send it to support at ninjatrader dot com with ATTN : Adam in the message.
NinjaTrader_AdamP is offline  
Reply With Quote
Reply

Tags
pairs, strategy

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
End of session BaRs problem/Residual ticks david111 Version 7 Beta General Questions & Bug Reports 3 04-15-2010 09:08 AM
Add warning to check for residual trailing stops WhoKnows Suggestions And Feedback 1 02-03-2009 03:33 AM


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