|
Attention! Read the forum rules carefully before posting a topic.
Try to find an answer in Wiki before asking a question. Submit programming questions in this forum only. Off topics are strictly forbidden.
Any topics which do not satisfy these rules will be deleted.
Mismatching: Strategy - Historical Tester Chart |
JackTheDog
|
Post subject: Mismatching: Strategy - Historical Tester Chart |
Post rating: 0
|
Posted: Wed 26 Dec, 2012, 19:45
|
|
User rating: 0
Joined: Mon 14 May, 2012, 06:56 Posts: 6 Location: Italy, Rome
|
Hi Everybody,
I am trying to figure out why when I run the historical tester there is a slight difference between the parameters of my strategy and the graphical plot of it.
In my case, I have setted a buy/sell order when the 1H bar cross the SMA(200). As you can see in the attached file the order, according to my strategy, should have been filled on the red-circled candle but it is filled some candles afterwards instead...
Can't understand where the problem is...
These are my parameters:
instrument = Instrument.EURUSD; selectedPeriod = Period.ONE_HOUR; smaTimePeriod = 200; indicatorFilter = Filter.WEEKENDS; ( I have tried to change this one but it doesn't change anything at all) candlesBefore = 200; candlesAfter = 0;
double sma = indicators.sma(instrument,selectedPeriod,OfferSide.BID,AppliedPrice.CLOSE,smaTimePeriod,indicatorFilter,candlesBefore,prevBar.getTime(),candlesAfter)[0];
Thank You for your Help!
Attachments: |
FAQ.JPG [141.3 KiB]
Downloaded 449 times
|
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on
this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control
on their content. Anyone accessing this webpage and downloading or otherwise making use of any document,
data or information found on this webpage shall do it on his/her own risks without any recourse against
Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from
the use and/or reliance on any document, data or information found on this webpage.
|
|
|
|
|
 |
API Support
|
Post subject: Re: Mismatching: Strategy - Historical Tester Chart |
Post rating: 0
|
Posted: Thu 27 Dec, 2012, 08:14
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
For appropriate comparsion, you should use the same filter both on chart and strategy. Consider logging the relevant values from your strategy (i.e. indicator outputs, bar times, prices, etc.) to see what execution paths get taken and why, see: https://www.dukascopy.com/wiki/#IConsole/Logging_values
|
|
|
|
 |
JackTheDog
|
Post subject: Re: Mismatching: Strategy - Historical Tester Chart |
Post rating: 0
|
Posted: Thu 27 Dec, 2012, 21:55
|
|
User rating: 0
Joined: Mon 14 May, 2012, 06:56 Posts: 6 Location: Italy, Rome
|
Thanks, I added this:
console.getOut().println("Instrument:" + instrument + "sma:" + df.format(sma));
but I can't find out where I should see it, it doesn't appear in the final report, and no exception has been thrown therefore there shouldn't be any error.
|
|
|
|
 |
CriticalSection
|
Post subject: Re: Mismatching: Strategy - Historical Tester Chart |
Post rating: 1
|
Posted: Fri 28 Dec, 2012, 00:02
|
|
User rating: 70
Joined: Sat 22 Sep, 2012, 17:43 Posts: 118 Location: Brazil, Fortaleza, Ceará
|
"slight difference" - this bit made me laugh - the space there is big enough to park two cars  ok so here's the thing. either: a) your filtering is off such that what you think your strategy is seeing in terms of price or SMA at time t isn't what you think it is b) the piece of code you are using to determine the cross is broken c) the essential elements are not written to deal with the testing scheme (1H, 4OHLC ticks) you've selected d) two but not three of the above are true e) three of the first three are true the question is, are you just telling us your woes just so we know, or are you telling us so we can really try to help you?  No instrument subscription / feed descriptor logic you might use  No look at the crossover logic  No indication what you are doing with that 'double sma' you pulled with [0] which is for the *'previous candle' (edit: *not true - see below)  No indication as to whether your observation is one-off or noticed on every entry - and further if the observation follows any pattern e.g. does the 'parking space' between expected entry and actual entry candles increase after a potentially filtered period (e.g. weekend).  Does 'price cross SMA' mean current 1H candle opened below SMA and passes or closes above SMA or does it mean previous 1H candle close was below SMA and now the candle has passed the SMA or closed above the SMA. Support has suggested introducing logging in order to determine what your code is actually doing - the line you've provided above doesn't exactly scream 'judicious use of logging' does it? At the very least you can try to output the price, the time/bar, where your code is in its execution flow, values when a trade is made, etc? o.O If you can output the price and sma you use in your comparison at least you have something you can use to trace both the price and sma on the chart. Support and the rest of the community are here for you but you have to help us help you...
|
|
|
|
 |
JackTheDog
|
Post subject: Re: Mismatching: Strategy - Historical Tester Chart |
Post rating: 0
|
Posted: Fri 28 Dec, 2012, 18:41
|
|
User rating: 0
Joined: Mon 14 May, 2012, 06:56 Posts: 6 Location: Italy, Rome
|
Thanks CriticalSection for your answer  . Yes I am trying to get some help because I have done VBA previously but Java it is completely new to me and I am getting familiar with it and OOP but I still have some issues...(I have done finance at the university). But let's proceed with order: a) I have setted filter to: Filter.ALL_FLATS; b) smaTimePeriod = 200; numberOfCandlesBefore = 200; sma = indicators.sma(Instrument.EURUSD, Period.ONE_HOUR, OfferSide.BID, IIndicators.AppliedPrice.CLOSE, smaTimePeriod,indicatorFilter,numberOfCandlesBefore ,prevBar.getTime(),0)[0]; c) For the testing it is setted to 1H - Bid - 4 Ticks at OHLC; I have noticed that changing the numberOfCandlesBefore variable yields some results. Infact putting it to 250 I get the first position opened properly but not the others (as you may see form the attached printscreen). I can't picture why since the smaTimePeriodi is the same: 200. Yes I have to admit I don't really know what "logging in" means and what I have to do in order to fulfill Support's request. I have tried to figure it out by myself but...bad times  how can I do it? Should I post my code?If there is anything else that I can do just tell me Thank you for your help!
Attachments: |
PrintScreen2.JPG [151.29 KiB]
Downloaded 434 times
|
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on
this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control
on their content. Anyone accessing this webpage and downloading or otherwise making use of any document,
data or information found on this webpage shall do it on his/her own risks without any recourse against
Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from
the use and/or reliance on any document, data or information found on this webpage.
|
|
|
|
|
 |
CriticalSection
|
Post subject: Re: Mismatching: Strategy - Historical Tester Chart |
Post rating: 0
|
Posted: Fri 28 Dec, 2012, 19:40
|
|
User rating: 70
Joined: Sat 22 Sep, 2012, 17:43 Posts: 118 Location: Brazil, Fortaleza, Ceará
|
A quick check reveals one issue. You and I both assume that the array coming out of that SMA is in reverse order. i.e sma[0] holds the most recent and sma[199] the most distant. But it appears that the array you're getting out is actually in the traditional left to right ascending order. sma[0] is the most distant candle you requested. sma[199] is the most recent. So that [0] you have sitting on the end there should be pulling the oldest value not the most recent. If you use (we don't know) that to determine the cross to the right of the graph that's the culprit. I implement all my indicators at the strategy level so I've not played around with Jforex functions to for example pull the 10 period filtered SMA between time t0 and time t1 so this is new to me. The prevBar.getTime() might be a different issue because it doesn't give you the SMA on current forming candle, only up to the previous one (if indeed prevBar represents the last bar coming in to onBar). The appropriateness of this depends on your actual strategy anyway. Logging just means where you have code written that has a problem and really can't tell by looking where it's going wrong, using Printout or Logging functions to output various variables (like the contents of that sma array) or useful messages like "P was true so entering if", "Pi * D was greater than 60", etc. This small example here told me about the organisation issue. double [] test = null; try{ test = i.sma(Instrument.EURUSD, Period.FIVE_MINS, OfferSide.BID, IIndicators.AppliedPrice.CLOSE,40, Filter.WEEKENDS, 5, teh.tick.getTime(),0); }catch(Exception e){}
// jforex arrays should match mine if they are also reversed System.out.println("SMA40[0]: " + test[0]); System.out.println("SMA40[1]: " + test[1]); System.out.println("SMA40[2]: " + test[2]); System.out.println("SMA40[3]: " + test[3]); System.out.println("SMA40[4]: " + test[4]);
// my arrays are all reverse (0 is most recent) ordered System.out.println("mySMA40[0]: " + mysma[0]); System.out.println("mySMA40[1]: " + mysma[1]); System.out.println("mySMA40[2]: " + mysma[2]); System.out.println("mySMA40[3]: " + mysma[3]); System.out.println("mySMA40[4]: " + mysma[4]); output was SMA40[0]: 1.29587975 SMA40[1]: 1.2958990000000001 SMA40[2]: 1.2959155000000002 SMA40[3]: 1.2959377500000002 SMA40[4]: 1.2959590000000003
mySMA40[0]: 1.2959590000000003 mySMA40[1]: 1.2959377500000002 mySMA40[2]: 1.2959155000000002 mySMA40[3]: 1.2958990000000001 mySMA40[4]: 1.29587975
|
|
|
|
 |
JackTheDog
|
Post subject: Re: Mismatching: Strategy - Historical Tester Chart |
Post rating: 0
|
Posted: Sat 29 Dec, 2012, 14:24
|
|
User rating: 0
Joined: Mon 14 May, 2012, 06:56 Posts: 6 Location: Italy, Rome
|
Yes your hypotesis does make sense. I am going to check that out. Excuse me for the dummy question but where should I get the output from? I mean in Eclipse/NetBeans environment the output will appear in the Console tab but since I am editing the code directly in the Dukascopy Workspace I can't find it anywhere...
|
|
|
|
 |
JackTheDog
|
Post subject: Re: Mismatching: Strategy - Historical Tester Chart |
Post rating: 0
|
Posted: Wed 09 Jan, 2013, 20:29
|
|
User rating: 0
Joined: Mon 14 May, 2012, 06:56 Posts: 6 Location: Italy, Rome
|
|
|
|
 |
API Support
|
Post subject: Re: Mismatching: Strategy - Historical Tester Chart |
Post rating: 0
|
Posted: Thu 10 Jan, 2013, 08:23
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
JackTheDog wrote: Excuse me for the dummy question but where should I get the output from? From java console, see: viewtopic.php?f=81&t=39073
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|