PDA

View Full Version : Backtest help


skat100
06-04-2009, 10:31 AM
My strategy is now ready to run. I would like to backtest it and would appreciate help with the following issues:

1-How set session begin/end times for EURUSD that starts 5:30 pm Sunday and ends 5:30 pm Friday?

2-How to specify commission? (Assume spread for EURUSD is 3 pips.)

3-How set "Exit on Close"?

4-One of my parameters is maximumLoss which has a default setting of -$150. When I enter that value it automatically changes to 1?

5-I am currently connected to both TradeStation and Gain Capital. However, although time period is set to 1/1/09 to today and 30 minute interval, I can't get the chart or the backtest to recognize those settings. Historical data doesn't show and trades don't show on chart.

NinjaTrader_Josh
06-04-2009, 10:42 AM
1. You set a start time and an end time for a day at a time. You cannot set it from Sunday to Friday. If you have some more specific needs then you should instead set it to 24 hrs sessions and program time filtering as need be.

2. You need to set this up in the Instrument Manager and be sure to select "Include commissions" when you run your strategy.

3. When you run your strategy please set it to true.

4. You need to change your code. Your code is stating minimum value for it is 1 in the Properties region for that parameter.

5. Please only connect to the data provider you wish to try and retrieve data from first. GAIN does not provide you that amount of historical data.

skat100
06-04-2009, 11:44 AM
Thanks for all the help.

In the Trades Tab in the Conrol Center, I have 7 trades. Although the Profit and Loss entries are red for losses and black for gains, all the amounts are zeros.

How do I correct this?

NinjaTrader_Josh
06-04-2009, 11:52 AM
You will need to look at the executions tab and correlate what your gains and losses actually are and try to correlate them back to what your trades are.

skat100
06-05-2009, 09:52 AM
Thanks for your reply.

I have just backtested my strategy. The performance report shows profit/loss on each trade as zero. However, it is obvious from the entry and exit prices that almost every trade is either plus or minus dollars.

Since profitability is the only reason for trading, one would expect the performance to be expressed in dollars. How can I correct this?

NinjaTrader_Josh
06-05-2009, 10:03 AM
Please ensure you are trading with enough quantity. In forex with prices being off to 4 decimal places, you can get trades that seemingly don't net anything.

Please see this article: http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?RunningFXStrategies

skat100
06-10-2009, 10:17 AM
My strategy is running simulated EURUSD 30 min.

A trade description shows S.LRx 0.1M@1.4120 (0.1M@1.4120),

1-Is 0.1M $100,000? $10,000? $1,000?

2-How can I change this? (I am using data from TradeStation. When I enter trades, I use 1 for 1 contract.)

The last trade shows as 0930 June 4. There are no entries on the chart after 1100 am June 5.

3-How can I bring the chart up to today’s date?

In a backtest, all values show as zero. Quantity is set as 100,000.

4-What am I not doing correctly?

NinjaTrader_Bertrand
06-10-2009, 10:28 AM
Skat100,

1. This is one regular lot of 100K

2. In the backtest try entering 100000 to trade a full lot as in 1

3. You would need to import a fresh set of historical data to backfill the chart to the point where you connect to realtime data.

http://www.ninjatrader-support.com/HelpGuideV6/TradeStationHistoricalDataDownloader.html

Most likely you would need to make sure all data is present before you backtest, and then enter the correct quantity to generated the trade staticstics related to the current lotsize you're looking for.

skat100
06-10-2009, 10:46 AM
Thanks for your reply.

Historical data is present back to 1/1/2009. Quantity is set to 100000. One problem is that the chart shows no data after 6/5. There is one burst of trade activity for a few days in May and on June 1. Otherwise, there are no trades showing. The performance chart shows all zeros.

How do I correct these problems?

NinjaTrader_Bertrand
06-10-2009, 10:51 AM
Please export the data and check that really all the needed historical data is present in your symbol, if not - you would then need to do a fresh data import. Have you backtested also with the SampleMACrossOver strategy?

skat100
06-10-2009, 03:43 PM
I have followed all your suggestions.

After running the Backtest Performance Report, the profit / loss figures do not make sense.

For example, trade # 51 shows entry on a short sale at 1.3387 with an exit at 1.3350 and a profit of $0.04.

In pips the profit was 37. In dollars that would be $370.00, not $0.04.

How can I troubleshoot this?

NinjaTrader_Josh
06-10-2009, 03:50 PM
What quantity did you submit at? 100,000 quantity = 1 lot. Please show us exactly what you are seeing in the Strategy Analyzer with a screenshot for a run off of the SampleMACrossOver strategy. Thank you.

NinjaTrader_Josh
06-10-2009, 04:01 PM
Please provide a screenshot of the Strategy Analyzer showing the issue. Thank you.

skat100
06-11-2009, 10:53 AM
1-When I started today, I opened a EURUSD chart. Data from 2:48 am to 11:46 am is missing. I re-imported the data but the data is still missing.

2-I tried to add my stategy to the chart but "Strategies" on the tool bar is greyed out. Control S does not work.

I have been trying for several weeks now to translate a TradeStation strategy to Ninja. This has been an agonizing experience. I would like to make a suggestion. All the controls needed to develop and operate a strategy are in different places. Why not create a dashboard which collects appropriate collections of instructions for each task? This would not be a big programming job. It would simply be a layout job plus links.

Thanks for your help. I do appreciate the rapid responses.

NinjaTrader_Bertrand
06-11-2009, 11:08 AM
skat100, just to clarify for the TradeStation connection this is expected - when you're not connected 24 hrs live collecting data, you would need to reload this historical data using the TS Data Download strategy. Please export the data from the EURUSD symbol and check if it's present as you expect. If not delete the data and export a fresh generated txt file from TradeStation.

Do you have the ChartTrader panel enabled by any chance? This will prevent the strategies button from being available.

Thanks for the suggestions!

skat100
06-11-2009, 11:17 AM
Chart Trader is not enabled. Still can't add strategy.

I did download historical data but still data missing. I'll try again but how do I delete the data as you suggested.

NinjaTrader_Bertrand
06-11-2009, 11:27 AM
Are you connected to live data? You would need this if trying to add the strategy from the chart, otherwise please use the Strategy Analyzer.

You can go to Tools > Historical Data > Delete to delete your present data. Then export a fresh txt file in TradeStation using 1min data and import it fresh.

skat100
06-11-2009, 01:29 PM
In Strategy Analyzer, profits / losses are all too small (e.g., $0.08) when it should be eighty something dollars. Contract size is set to 100000. There must be some controlling place to enter 100000 so the Analyzer shows correct P&L. I’ve checked all the obvious places but obviously something’s wrong. Please help.

NinjaTrader_Josh
06-11-2009, 01:35 PM
When you start the strategy, go down to where the order handling options are and select "By default quantity" then punch in 100000.

skat100
06-11-2009, 01:49 PM
I changed from By Strategy to 100000. This had no effect on the Analyzer results.

Also, I intend to add a order size algorithm to my strategy. At present it defines orders as: Enter Long ("n, LRx"), where n is the quantity. I set n to 100000.

None of this worked.

NinjaTrader_Josh
06-11-2009, 01:54 PM
Try 10000000 quantity then.

skat100
06-11-2009, 02:08 PM
10000000 didn't work.

Is there any possibility of getting phone support to get me over these last steps (backtest / sim trade / live trade? I've been spinning wheels for weeks to just get a simple strategy working.

I'm not a novice. I've been trading since 1968 and have developed indicators and strategies on TradeStation since its creation by Omega, long before TradeStation Securities.

I find the Ninja interface daunting and user unfriendly. I've programmed in Visual Basic, C++ and C# with less difficulty. I really appreciate the rapid response forum support but it's been one nit after another and I"m weary!!

Forgive the tirade and thanks for your help.

NinjaTrader_Josh
06-11-2009, 02:15 PM
Please send in an email with your contact information to support [at] ninjatrader [dot] com and reference this thread. Thank you.

skat100
06-16-2009, 10:03 AM
When I apply my strategy to a EURUSD 30 min chart, the next order is rejected because there is insufficient equity in the account (Sim101).

How do I change the settings to cope with this problem?

NinjaTrader_Bertrand
06-16-2009, 10:11 AM
You would either need to trade a smaller amount of lots or you would need to reset the Sim101 account with a higher cash value under Tools > Options > Simulator.

skat100
06-16-2009, 02:06 PM
I have given more thought to your suggestion about two data series.

Questions:

1-In my expression:
&& CrossAbove(LinReg(Close, 15), (LinReg(Close), 2[0] + aBuff), 1))

Are “LinReg(Close, 15)” and “LinReg(Close), 2[0 ]” not two data series?
(Is not a 15 period data series different from a 2 period data series?)

2-In your example:
CrossAbove(IDataSeries1, IDataSeries2, int lookBackPeriod)
The “int lookBackPeriod” does not enable the two different look backs

3-I changed the explicit 15 and 2 lookBackPeriods to the input variables “fast” and “slow”.
I also added these in the Properties region.
Repeating my question above in these terms, are LinReg(Close, fast) and LinReg(Close, slow)
two data series?

4-When you say “double value (where double has no history)”, what does that mean and to which
value are you referring? If you are referring to aBuff, which is a double value, aBuff is a
declared input variable

NinjaTrader_Josh
06-16-2009, 02:39 PM
1. The first is a data series the second is an actual value from within a data series.

2. You can change the 1 to some other value if you want to lookback further.

3. What determines a DataSeries is if you are using the [] index or not. The index grabs individual data points from within the DataSeries that is the LinReg indicator.

4. A double value is just any variable or value that is of the object type "double". I suggest you try googling some C# resources. They can explain this concept a lot more indepth.

skat100
06-17-2009, 09:59 AM
I have lost track of questions and answers.

I asked how I could identify trailing stop orders since I don't know how to designate the trade label as in trades other than trailing stops. The code I am using shows SetTrailStop ("SS.LRx", Calculation.Price, STS, true). To me this means the stop applies to a trade marked SS.LRx. How can I designate a name for the trailing stop order so I can identify the stop orders in the strategy performance reports. (All my orders, other than trailing stops, are market orders)

I asked about designating the quantity (#lots). My strategy calls for lot size this way: EnterLong(n, "B.LRx") where n is an input
variable currently set as 100000. However, the strategy does not seem to be responding to that designation. Apparently, lot size is set somewhere outside the strategy. My data is coming from TradeStation. I assume the lot size designation is the same as for TradeStation, where the lot size is pre-set and can only be changed by TS personnel. At present my Sim101 account is set for 100000. I'd appreciate a full explanation of how to set lot size for backtesting, for optimizing and for live trading. Thanks for help on this.

You asked for a screen shot of the Performance Report. How do I create a screen shot in NinjaTrading?

I was grateful for the opportunity to discuss my problems with Bertrand on the phone. I sent him my TS code and my Ninja code and would like to be able to tackle the above problems with him. Is this possible?

Thanks again for all the help I'm getting.

Stan

NinjaTrader_Bertrand
06-17-2009, 10:01 AM
Stan,
Thanks for the post - I got your mail and will follow up with you this way shortly, thanks for your patience.

skat100
06-18-2009, 09:47 AM
I wonder if Bertrand could possibly call me before the end of the day?
860/434-9609.
Thanks.

NinjaTrader_Bertrand
06-18-2009, 10:57 AM
skat100, I'll contact you via email to schedule a call.

skat100
06-23-2009, 11:27 AM
What steps do I have to take to get my strategy running in simulated mode?

NinjaTrader_Bertrand
06-23-2009, 11:35 AM
Ensure you're connected to your live TradeStation feed for the needed symbols and start the strategy on the Sim101 account either from the Chart or Strategies tab -

http://www.ninjatrader-support.com/HelpGuideV6/RunningANinjaScriptStrategyFromAChart.html

http://www.ninjatrader-support.com/HelpGuideV6/RunningANinjaScriptStrategyFromStrategiesTab.html

I would recommend using the chart, as visual checks are much easier then.