NexusFi: Find Your Edge


Home Menu

 





trouble adding new time frame to strategy


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one jordis with 6 posts (0 thanks)
    2. looks_two monpere with 2 posts (0 thanks)
    3. looks_3 powermoney with 1 posts (0 thanks)
    4. looks_4 tickleboy with 1 posts (0 thanks)
    1. trending_up 4,985 views
    2. thumb_up 0 thanks given
    3. group 5 followers
    1. forum 12 posts
    2. attach_file 1 attachments




 
Search this Thread

trouble adding new time frame to strategy

  #1 (permalink)
 jordis 
Mobile, Alabama
 
Experience: Beginner
Platform: NinjaTrader, TOS
Trading: Stocks
Posts: 29 since Sep 2011
Thanks Given: 6
Thanks Received: 3

I am still a beginner at coding in NT, so I apologize if this question is too basic/generic/obvious. Hopefully it has a quick solution that I am simply an idiot for overlooking!

Problem:
I'm trying to reference multiple time frames in a strategy. What I would like to do is trade in a 5 minute time frame, but I would like to check a daily chart to see if a condition is met by an indicator, and if so I want to cease trading (ie. if the market is doing something that has proven to make my 5 minute strategy ineffective, I would like to stop trading until normalcy returns).

My issue is that my code stops running the instant I add the line for the new period
 
Code
protected override void Initialize()
      {
Add(PeriodType.Day, 1);
}
Without this line, the strategy runs, but as soon as this is added it stops working. I have not even tried to call this later in the code yet. I have tried changing the period to minute, day, etc and it makes no difference.

Can someone give me any idea what I might be missing that is causing this to kill my script?

Thanks in advance,
jordis

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
REcommedations for programming help
Sierra Chart
Quant vue
Trading Reviews and Vendors
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
  #3 (permalink)
 
monpere's Avatar
 monpere 
Bala, PA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus, IB
Trading: SPY, Oil, Euro
Posts: 1,854 since Jul 2010
Thanks Given: 300
Thanks Received: 3,372



jordis View Post
I am still a beginner at coding in NT, so I apologize if this question is too basic/generic/obvious. Hopefully it has a quick solution that I am simply an idiot for overlooking!

Problem:
I'm trying to reference multiple time frames in a strategy. What I would like to do is trade in a 5 minute time frame, but I would like to check a daily chart to see if a condition is met by an indicator, and if so I want to cease trading (ie. if the market is doing something that has proven to make my 5 minute strategy ineffective, I would like to stop trading until normalcy returns).

My issue is that my code stops running the instant I add the line for the new period
 
Code
protected override void Initialize()
      {
Add(PeriodType.Day, 1);
}
Without this line, the strategy runs, but as soon as this is added it stops working. I have not even tried to call this later in the code yet. I have tried changing the period to minute, day, etc and it makes no difference.

Can someone give me any idea what I might be missing that is causing this to kill my script?

Thanks in advance,
jordis

Read about BarsInProgress and it's relation to the Add() method. Your code is now running twice on every tick, once for the main time frame, and another time for the added time frame. That tends to screw up most logic if not segregated by BarsInProgress.

if (BarsInProgress == 0) { ...Main timeframe code}
if (BarsInProgress == 1) { ...Added timeframe code}

Lacking any additional info on the strategy, that would be my guess as to what you are seeing.

Reply With Quote
  #4 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

With only this line of code, hard to sat what could be wrong.
Are you checking BarInProgress in OnBarUpdate() ?
You can take a look at the example strategy, @SampleMultiTimeFrame.cs .

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
  #5 (permalink)
 jordis 
Mobile, Alabama
 
Experience: Beginner
Platform: NinjaTrader, TOS
Trading: Stocks
Posts: 29 since Sep 2011
Thanks Given: 6
Thanks Received: 3

Hi,
Thanks for the replies. I have tried using barsinprogress on my strategy, but with no luck. I have also sent my code to ninjatrader support, but have not heard back (i guess maybe they don't work weekends?)

Just to see what mtf is supposed to do, I ran the @SampleMultiTimeFrame.cs strategy on 1, 5, 10, and 60 minute charts... and that didn't even work. The averages plot on the chart, but no trades are ever entered. I have not altered the sample code at all.

Also, I've tried on 2 different computers with the same results. This leads me to believe I am missing some obvious setting somewhere.

Any ideas on why nothing ever happens in these strategies?

ps. I am using imported minute data to backtest, and without the mtf code my strategies work, so I don't think it could be caused by "bad data" or anything like that.

thanks again for the help

Started this thread Reply With Quote
  #6 (permalink)
 powermoney 
North Carolina
 
Experience: Advanced
Platform: Ninjatrader
Broker: IQ Feed
Trading: GC, 6E, CL
Posts: 4 since Jan 2010
Thanks Given: 0
Thanks Received: 0


jordis View Post
Hi,
Thanks for the replies. I have tried using barsinprogress on my strategy, but with no luck. I have also sent my code to ninjatrader support, but have not heard back (i guess maybe they don't work weekends?)

Just to see what mtf is supposed to do, I ran the @SampleMultiTimeFrame.cs strategy on 1, 5, 10, and 60 minute charts... and that didn't even work. The averages plot on the chart, but no trades are ever entered. I have not altered the sample code at all.

Also, I've tried on 2 different computers with the same results. This leads me to believe I am missing some obvious setting somewhere.

Any ideas on why nothing ever happens in these strategies?

ps. I am using imported minute data to backtest, and without the mtf code my strategies work, so I don't think it could be caused by "bad data" or anything like that.

thanks again for the help

1) What datafeed/broker are you connected to in the Control Center ?

2) What account are you running the strategy in (SIM101, etc) ?

3) What error messages (yellow background text) do you see in the LOG tab of the Control Center?

Reply With Quote
  #7 (permalink)
 jordis 
Mobile, Alabama
 
Experience: Beginner
Platform: NinjaTrader, TOS
Trading: Stocks
Posts: 29 since Sep 2011
Thanks Given: 6
Thanks Received: 3

thanks for the reply.

answers:
1. im not currently connected to a datafeed or broker. all of my backtesting is done on imported data
2. the account is listed as "Backtest." the other options are "Sim101" and "Replay101"
3. under the Log tab, here is everything that I see is in the attached image.



thanks again for the help

Started this thread Reply With Quote
  #8 (permalink)
 jordis 
Mobile, Alabama
 
Experience: Beginner
Platform: NinjaTrader, TOS
Trading: Stocks
Posts: 29 since Sep 2011
Thanks Given: 6
Thanks Received: 3

also, I've tried enabling order tracking in my code, which i can see in the output window when i run single time frame strategies, but when i try to run an mtf strategy the output window is blank as if nothing is being attempted.

don't know if that's helpful or not, but just wanted to put that out there.

Started this thread Reply With Quote
  #9 (permalink)
 jordis 
Mobile, Alabama
 
Experience: Beginner
Platform: NinjaTrader, TOS
Trading: Stocks
Posts: 29 since Sep 2011
Thanks Given: 6
Thanks Received: 3

ok, another wrinkle in the problem.

I tried running the sample multiple time frame strategy on a different set of data (daily data, last price, downloaded from Yahoo for a random stock) and it works. However, when I try to use my Forex data it doesnt work.

I could understand this being an issue if the data was bad and didnt work for the single time frame strategies, but all of my strategies work perfectly on this Forex data in a single time frame. Why would adding another time frame cause this data suddenly to stop working?

Started this thread Reply With Quote
  #10 (permalink)
 
monpere's Avatar
 monpere 
Bala, PA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus, IB
Trading: SPY, Oil, Euro
Posts: 1,854 since Jul 2010
Thanks Given: 300
Thanks Received: 3,372


I would suggest experimenting by starting with a simple strategy with a simple print statement for each BarsInProgress to get a better idea of what is happening, and what is suppose to happen. Then incrementally add your other code to pinpoint where the problem might be.

Reply With Quote




Last Updated on September 18, 2014


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts