Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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
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
Can you help answer these questions from other members on NexusFi?
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.
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 .
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.
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?
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.
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.
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?
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.