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 11-01-2009, 07:10 AM   #1
DarthTraderson
Member
 
Join Date: May 2009
Location: Cologne
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Default SetStopLoss() in multi timeframes

Hi,

I'm asking myself if using the SetStopLoss(..) method is working, when using multi timeframes during backtesting my strategies.

First of all I had only a M10 and using CalculateOnBarClose = True. Then after placing an order a stoploss was set and during backtesting tested after every M10-Bar, thats ok ...

Now, I want to test the stop after every minute, so I add a M1 timeframe to the strategy. I'm entering the trade in M10 and then the stoploss is set. After that ten M1-bars running with the close-price through the strategy. Does NT test the stoploss for every M1-bar or only for the higher M10 timeframe?

Thx,
DT
DarthTraderson is offline  
Reply With Quote
Old 11-01-2009, 12:51 PM   #2
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,

Where is your SetStoploss located in your code?
It will work for the timeframe you have submitted it. If you did not specify, then it will be on the 0 bar in progress. This link may help:
http://www.ninjatrader-support.com/H...BarSeries.html
NinjaTrader_Ben is offline  
Reply With Quote
Old 11-01-2009, 11:31 PM   #3
DarthTraderson
Member
 
Join Date: May 2009
Location: Cologne
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Default

It is located in the Initialize-Method. So, if I understand you right, I need to move it to the

Code:
if (BarsInProgress == 1) {
   ...
   SetStopLoss (this.Name, CalculationMode.Ticks, stopLossTicks, false);
   ...
}
part of the code, if I want submit it to the M1 Timeframe when using normally a M8 Timeframe as primary Series?

The stoploss in initialize (actual code) is only checked in M8 on every close of the primary bar?

DT
Last edited by DarthTraderson; 11-02-2009 at 12:01 AM.
DarthTraderson is offline  
Reply With Quote
Old 11-02-2009, 04:25 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

Correct DT, you would need to move the code to the relevant sections in the OnBarUpdate, or work with the Exit() methods that offer a BIP paramter directly - http://www.ninjatrader-support.com/H...tLongStop.html
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 11-02-2009, 04:59 AM   #5
DarthTraderson
Member
 
Join Date: May 2009
Location: Cologne
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Default

Ok, thanks for the response ... I have to test it ...

In my yesterday evaluations I had a M8 as primary and M1 as secondary timeframe. I still set SetStopLoss(..) in the initialize-method() and the trades where entered and exit in secondary timeframe.

Entered with EnterLongLimit(1, ....) and exit worked, I thought, wit setStopLoss ... because I see the trade enter and exit time in the trade overview panel .... very strange ... that doesn't fit with you explanations ....

DT
DarthTraderson is offline  
Reply With Quote
Old 11-02-2009, 05:03 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

DT, are you linking entries and exits together with signal naming?
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 11-02-2009, 05:46 AM   #7
DarthTraderson
Member
 
Join Date: May 2009
Location: Cologne
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Default

Yes I do.

In Initialize-Method ...
Code:
SetStopLoss("MyEntry", CalcutationMode.Ticks, stopLossTicks, false);
In OnBarUpdate-Method ....
Code:
EntryLongLimit (1, false, quantity, Lows[0][0], "MyEntry");
Is it relevant?

DT
Last edited by DarthTraderson; 11-02-2009 at 06:12 AM.
DarthTraderson is offline  
Reply With Quote
Old 11-02-2009, 07:15 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

Yes, this would 'link' them together, so you stop loss is submitted as soon as the BIP 1 entry fills.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 11-02-2009, 07:47 AM   #9
DarthTraderson
Member
 
Join Date: May 2009
Location: Cologne
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Default

Sorry, Betrand ... what is the meaning of BIP ...

So, to sum it up ... my code works as expected and I did not need to move the SetStopLoss() - statement?

DT
DarthTraderson is offline  
Reply With Quote
Old 11-02-2009, 08:49 AM   #10
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

I'm sorry DT, BIP = Bars In Progess, you should be good with this code for intrabar backtesting as you already submit entries and by entry signal naming linked exits on a finer granularity than you primary chart.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 02-28-2013, 07:55 PM   #11
balancenv
Member
 
Join Date: May 2010
Posts: 40
Thanks: 8
Thanked 3 times in 2 posts
Default

Can anyone confirm if this can be done or not???

Because of the NT backtest deficiency, we have to go the extra miles to add 1min timeframe for order execution. Now you're telling me, oh by the way, set stoploss does not work and I will have to write my own stoploss code?

And this is claimed to be the best auto-trading platform??


I asked this to support:
>>>
If I have two timeframes, say 10m is primary and 2min is added.

If I do EntryLongLimit (1, false, quantity, Lows[0][0], "MyEntry"); in BIP ==0,
can do SetStopLoss(price) at the 2min (BIP is 1) to make it effective?

During backtest, the stop will be eval every 2min's cycle, or every 10min bar?

Also, how can I tell if the order is stop-out?

Thanks.
>>>

i got answer like
>>>

Hello,

Thanks for writing in.



The SetStopLoss function will only set the stop for the primary data series. For other data series you will want to place a ExitLong/ExitShort order at the proper prices.

Below is a link to the help guide on the usage of SetStopLoss.
http://www.ninjatrader.com/support/h...etstoploss.htm
>>>
balancenv is offline  
Reply With Quote
Old 03-01-2013, 03:39 AM   #12
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

balancenv, your understanding is unfortunately correct - the Set's would be evaluated on the primary series only. As they also do not expose IOrder access, checking for their states would need to be done via the approach offered in this sample - http://www.ninjatrader.com/support/f...ead.php?t=5790

We're are also looking into enhancing this area and backtest handling for our next major platform update.
NinjaTrader_Bertrand 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
How to strategy test against multi timeframes ? wcredle Strategy Analyzer 1 03-13-2009 03:37 PM
get bars of other timeframes junkone Strategy Development 1 01-20-2009 10:24 AM
dual timeframes starrynight Automated Trading 5 12-15-2008 05:18 AM
Two timeframes jriverac Strategy Development 5 05-26-2008 07:23 PM
Two timeframes jriverac Strategy Development 6 04-08-2008 03:02 PM


All times are GMT -6. The time now is 01:21 PM.