Dukascopy Support Board http://www.dukascopy.com/swiss/english/forex/jforex/forum/ |
|
Calculate Indicator prior to candle close http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=57740 |
Page 1 of 1 |
Author: | EBMMLuke [ Sat 06 Nov, 2021, 14:50 ] |
Post subject: | Calculate Indicator prior to candle close |
Good day all! My strategy is based in daily candles, which I generate using IFeedDescriptor with custom period. Trading logic and indicator calculation is placed in the onFeedData function. When the strategy is generating an order signal on the close of Friday night, the position won't be opened until Monday, obviously. What I'd like to achieve is keeping the daily timeframe (NY open/close) as is, but check the indicators 15min prior to candle close, so the orders are properly placed. For example: candle start: 3.11. 22:00 EET candle close/start: 4.11. 22:00 EET ==> indicator check 4.11. 21:45 EET candle close: 5.11. 22:00 EET ==> indicator check 5.11. 21:45 EET What would be the best solution to keep the indicator calculation based on the candle above, but checking values earlier? I was thinking about
Thanks a lot for your help! Cheers, Luke |
Author: | EBMMLuke [ Thu 11 Nov, 2021, 22:03 ] |
Post subject: | Re: Calculate Indicator prior to candle close |
Good evening. I solved the problem with a combination of daily bars pulled from history plus a custom function for the current day, counting 15min candles. Works great with indicators with 2D input arrays in the form of double[][]. I'd like to implement it for the ATR as well, which uses a 3D input array in the form of double[][][]. Could someone please advise how to populate these arrays correctly? I didn't find anything in the support board or javadocs. Help is greatly appreciated! Cheers, Luke |
Author: | EBMMLuke [ Fri 12 Nov, 2021, 21:20 ] |
Post subject: | Re: Calculate Indicator prior to candle close |
...and here some code. Most of it is still hardcoded to fiddle around with array length and the like. Just ignore ;o) Populating price array with daily close price data: public double[][][] dataCollection3D() throws JFException { Calculating custom ATR indicator: IIndicator customATR = indicators.getIndicator("ATR"); This code calculates a result, but it's far off the values from the platform ATR. I wrote a method to calculate the ATR according to these formulas https://en.wikipedia.org/wiki/Average_true_range using the input arrays as shown above. It works perfectly and calculates the exact values as the platform ATR. Hence, there must be an issue with the input array or some settings. |
Author: | EBMMLuke [ Thu 16 Dec, 2021, 14:44 ] | ||||
Post subject: | Re: Calculate Indicator prior to candle close | ||||
Good afternoon! I was proposed a solution for my problem, see the implementation in the code attached. Everything works now as intended, but only for a single instrument. As soon as I subscribe to 2 or more instruments, something messes with my custom SSL indicator (code attached as well). Tests performed so far:
What I think it comes down to is the way I organised the subscription instruments and FeedDescriptors, or how I call the SSL indicator. Probably not the best implementation method? Interestingly, there is no issue with the platform ATR whatsoever. I'm quite new to Java, so please be kind In the screenshot below you notice the incorrect SSL values. ssl[1] is the actual, ssl[0] the previous. ssl[0] should be 0.74769, but instead the lower SMA value of 0.7436 is calculated. Therefore, a trading signal is not generated as it should have been. Feel free to play around with the instruments and settings to recreate the problem. Thanks, Luke
|
Author: | EBMMLuke [ Sun 19 Dec, 2021, 15:08 ] |
Post subject: | Re: Calculate Indicator prior to candle close |
Good afternoon After some more testing I think I've found the problem. It seems, that from the custom SSL indicator just one single instance is used for all instruments, and not one instance for every instrument. As I use a trigger variable in the SSL to determine which SMA band (high, low) to follow, and this trigger seems to be similar for all instruments. This should not be the case of course, as not for all instruments the same band is used at all times. I register the custom indi like this: String indPath = getClass().getAnnotation(CustomIndicators.class).value(); Is there a way to generate an indicator instance for every instrument/feed and call this indi-instance for the respective instru/feed? Something similar as it is done with the FeedDescriptor (see below)? Instrument/Feed subscription instSet = new HashSet<Instrument>(); select correct instrument/feed at onBar method: public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { Thanks, Luke |
Page 1 of 1 |