|
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.
MACDEXT difficulty with MaType, request for help |
jamesadk
|
Post subject: MACDEXT difficulty with MaType, request for help |
Post rating: 0
|
Posted: Fri 04 Apr, 2014, 16:46
|
|
User rating: 0
Joined: Fri 04 Apr, 2014, 16:35 Posts: 50 Location: Monaco, Monte-Carlo
|
Hi all, I'm quite new to JForex so this might be a blindingly easy one, but I've tried everything I can think of: I'm trying to get the MACDEXT for a renko chart, and whilst my code compiles, it always throws an error relating to the MaType when ever the feed data comes through. I keep getting the error message: com.dukascopy.api.JFException: java.lang.ClassCastException: com.dukascopy.api.IIndicators$MaType cannot be cast to java.lang.Integer Here is my code below, if anyone knows how I can fix it I'd be very grateful for a response. Many thanks in advance, J package jforex;
import java.util.*; //Dukascopy imports========================= import com.dukascopy.api.*; import com.dukascopy.api.feed.*; import com.dukascopy.api.feed.util.*; import com.dukascopy.api.IIndicators.AppliedPrice; import com.dukascopy.api.feed.IFeedDescriptor; import com.dukascopy.api.feed.IFeedListener; import com.dukascopy.api.feed.util.RenkoFeedDescriptor; import com.dukascopy.api.feed.util.TimePeriodAggregationFeedDescriptor; import com.dukascopy.api.IEngine.OrderCommand; //============================================
public class RenkoTrial2 implements IStrategy, IFeedListener { //THIS IS A TEST BED FILE //================================ private IEngine engine; private IConsole console; private IHistory history; private IContext context; private IIndicators indicators; private IUserInterface userInterface; //================================= //------FEED DESCRIPTORS--------------------- //---This is the renko data feed descriptor (2 pip bricks) public IFeedDescriptor feedDescriptor = new RenkoFeedDescriptor(Instrument.GBPUSD,PriceRange.TWO_PIPS,OfferSide.BID); //--------------------------------------------- //---------PUBLIC DECLARATIONS------------------- public Instrument selectedInstrument = Instrument.EURUSD; public int fastMaMACD = 12; public int slowMaMACD = 26; public int signalMaMACD = 9; //------------------------------------------------ public void onStart(IContext context) throws JFException { this.engine = context.getEngine(); this.console = context.getConsole(); this.history = context.getHistory(); this.context = context; this.indicators = context.getIndicators(); this.userInterface = context.getUserInterface(); //--subscribe to renko feed context.setSubscribedInstruments(java.util.Collections.singleton(feedDescriptor.getInstrument()), true); context.subscribeToFeed(feedDescriptor, this);
} //@Override public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) { Instrument myInstrument = feedDescriptor.getInstrument(); OfferSide myOfferSide = feedDescriptor.getOfferSide();
console.getOut().println("completed" + feedData); try {
//-------------RENKO MACD-------------------------------------- IIndicators.MaType fastMaType = IIndicators.MaType.EMA; IIndicators.MaType slowMaType = IIndicators.MaType.EMA; IIndicators.MaType signalMaType = IIndicators.MaType.EMA; Object[] renkoMACDEXT = indicators.calculateIndicator(feedDescriptor, new OfferSide[] { myOfferSide },"MACDEXT", new AppliedPrice[] { AppliedPrice.CLOSE }, new Object []{fastMaMACD,fastMaType,slowMaMACD,slowMaType,signalMaMACD,signalMaType},50,feedData.getTime(),0);
double MACDline = (Double) renkoMACDEXT[0]; double MACDsignal = (Double) renkoMACDEXT[1]; console.getOut().println(String.format("Renko2 MACD line currently is: %.5f, signal line is: %.5f", MACDline,MACDsignal));
} catch (JFException e) { console.getErr().println(e); e.printStackTrace(); } } public void onAccount(IAccount account) throws JFException { }
public void onMessage(IMessage message) throws JFException { }
public void onStop() throws JFException { //for (IOrder order : engine.getOrders()) { // engine.getOrder(order.getLabel()).close(); // } }
public void onTick(Instrument instrument, ITick tick) throws JFException { } public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { } }
|
|
|
|
 |
tcsabina
|
Post subject: Re: MACDEXT difficulty with MaType, request for help |
Post rating: 0
|
Posted: Mon 07 Apr, 2014, 09:38
|
|
User rating: 164
Joined: Mon 08 Oct, 2012, 10:35 Posts: 676 Location: NetherlandsNetherlands
|
Hi, Probably there is a problem with the following line: new Object []{fastMaMACD,fastMaType,slowMaMACD,slowMaType,signalMaMACD,signalMaType}
Check MACDEXT's indicatorInfo: https://www.dukascopy.com/wiki/#Indicato ... icatorInfoIt should give you the proper number and type of inputs the indicator requires. But if that looks okay, wait till support replies.
|
|
|
|
 |
API Support
|
Post subject: Re: MACDEXT difficulty with MaType, request for help |
Post rating: 0
|
Posted: Mon 07 Apr, 2014, 10:05
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
jamesadk
|
Post subject: Re: MACDEXT difficulty with MaType, request for help |
Post rating: 0
|
Posted: Mon 07 Apr, 2014, 22:15
|
|
User rating: 0
Joined: Fri 04 Apr, 2014, 16:35 Posts: 50 Location: Monaco, Monte-Carlo
|
Hi, Thank you both for your replies, I applied the .ordinal() as shown in the example provided and it then compiled and appeared to run with no problem. However on closer inspection, the values it was returning for the MACD line and MACD signal line were not the same as I saw on my corresponding chart. I am not sure what the cause of this could be, I have attached the complete corrected code below, if you have any comments as to what the reason for this happening is, I'd appreciate hearing from you. (Apologies if this is now deemed as a completely separate matter, thus justifying a completely new post, but in case the problem is related to the earlier MaType problem I thought it best to keep this post open). Many thanks J package jforex;
import java.util.*; //Dukascopy imports========================= import com.dukascopy.api.*; import com.dukascopy.api.feed.*; import com.dukascopy.api.feed.util.*; import com.dukascopy.api.IIndicators.AppliedPrice; import com.dukascopy.api.feed.IFeedDescriptor; import com.dukascopy.api.feed.IFeedListener; import com.dukascopy.api.feed.util.RenkoFeedDescriptor; import com.dukascopy.api.feed.util.TimePeriodAggregationFeedDescriptor; import com.dukascopy.api.IEngine.OrderCommand; //============================================
public class RenkoTrial2 implements IStrategy, IFeedListener { //THIS IS A TEST BED FILE //================================ private IEngine engine; private IConsole console; private IHistory history; private IContext context; private IIndicators indicators; private IUserInterface userInterface; //================================= //------FEED DESCRIPTORS--------------------- //---This is the renko data feed descriptor (2 pip bricks) public IFeedDescriptor feedDescriptor = new RenkoFeedDescriptor(Instrument.GBPUSD,PriceRange.TWO_PIPS,OfferSide.BID); //--------------------------------------------- //---------PUBLIC DECLARATIONS------------------- public Instrument selectedInstrument = Instrument.EURUSD; public int fastMaMACD = 12; public int slowMaMACD = 26; public int signalMaMACD = 9; private int fastMaType = IIndicators.MaType.EMA.ordinal(); private int slowMaType = IIndicators.MaType.EMA.ordinal(); private int signalMaType = IIndicators.MaType.T3.ordinal(); //------------------------------------------------ public void onStart(IContext context) throws JFException { this.engine = context.getEngine(); this.console = context.getConsole(); this.history = context.getHistory(); this.context = context; this.indicators = context.getIndicators(); this.userInterface = context.getUserInterface(); //--subscribe to renko feed context.setSubscribedInstruments(java.util.Collections.singleton(feedDescriptor.getInstrument()), true); context.subscribeToFeed(feedDescriptor, this);
} //@Override public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) { Instrument myInstrument = feedDescriptor.getInstrument(); OfferSide myOfferSide = feedDescriptor.getOfferSide();
console.getOut().println("completed" + feedData); try { //-------------RENKO MACD--------------------------------------
Object[] renkoMACDEXT = indicators.calculateIndicator(feedDescriptor, new OfferSide[] { myOfferSide },"MACDEXT", new AppliedPrice[] { AppliedPrice.CLOSE }, new Object []{fastMaMACD,fastMaType,slowMaMACD,slowMaType,signalMaMACD,signalMaType},50,feedData.getTime(),0);
double[][] MACDFigures = {(double[]) renkoMACDEXT[0],(double[]) renkoMACDEXT[1],(double[]) renkoMACDEXT[2]};
console.getOut().println(String.format("Renko2 MACD line currently is: %.5f, signal line is: %.5f", MACDFigures[0][0] ,MACDFigures[0][1]));
} catch (JFException e) { console.getErr().println(e); e.printStackTrace(); } } public void onAccount(IAccount account) throws JFException { }
public void onMessage(IMessage message) throws JFException { }
public void onStop() throws JFException { //for (IOrder order : engine.getOrders()) { // engine.getOrder(order.getLabel()).close(); // } }
public void onTick(Instrument instrument, ITick tick) throws JFException { } public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { } }
|
|
|
|
 |
tcsabina
|
Post subject: Re: MACDEXT difficulty with MaType, request for help |
Post rating: 0
|
Posted: Tue 08 Apr, 2014, 11:59
|
|
User rating: 164
Joined: Mon 08 Oct, 2012, 10:35 Posts: 676 Location: NetherlandsNetherlands
|
|
|
|
 |
jamesadk
|
Post subject: Re: MACDEXT difficulty with MaType, request for help |
Post rating: 0
|
Posted: Tue 08 Apr, 2014, 14:44
|
|
User rating: 0
Joined: Fri 04 Apr, 2014, 16:35 Posts: 50 Location: Monaco, Monte-Carlo
|
Thanks for your reply tcsabina, I took a look at the link and tried to implement the filter as best I could from what I read and found further on the wiki, and whilst the code compiles the problem still persists. I'm clearly doing something wrong. If anyone has any suggestions I would be grateful to hear them. (Apologies again if this classifies as needing a new post). J package jforex;
import java.util.*; //Dukascopy imports========================= import com.dukascopy.api.*; import com.dukascopy.api.feed.*; import com.dukascopy.api.feed.util.*; import com.dukascopy.api.IIndicators.AppliedPrice; import com.dukascopy.api.feed.IFeedDescriptor; import com.dukascopy.api.feed.IFeedListener; import com.dukascopy.api.feed.util.RenkoFeedDescriptor; import com.dukascopy.api.feed.util.TimePeriodAggregationFeedDescriptor; import com.dukascopy.api.IEngine.OrderCommand; import com.dukascopy.api.util.DateUtils; import java.text.SimpleDateFormat; import java.util.TimeZone; //============================================
public class RenkoTrial2 implements IStrategy, IFeedListener { //THIS IS A TEST BED FILE //================================ private IEngine engine; private IConsole console; private IHistory history; private IContext context; private IIndicators indicators; private IUserInterface userInterface; //================================= //------FEED DESCRIPTORS--------------------- //---This is the renko data feed descriptor (2 pip bricks) public IFeedDescriptor feedDescriptor = new RenkoFeedDescriptor(Instrument.GBPUSD,PriceRange.TWO_PIPS,OfferSide.BID); //--------------------------------------------- //-------------SET DATE AND TIME FORMATS--------- public static SimpleDateFormat MyDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") { { setTimeZone(TimeZone.getTimeZone("GMT")); } }; //----------------------------------------------- //---------PUBLIC DECLARATIONS------------------- public Instrument selectedInstrument = Instrument.EURUSD; public int fastMaMACD = 12; public int slowMaMACD = 26; public int signalMaMACD = 9; private int fastMaType = IIndicators.MaType.EMA.ordinal(); private int slowMaType = IIndicators.MaType.EMA.ordinal(); private int signalMaType = IIndicators.MaType.EMA.ordinal();
//------------------------------------------------ public void onStart(IContext context) throws JFException { this.engine = context.getEngine(); this.console = context.getConsole(); this.history = context.getHistory(); this.context = context; this.indicators = context.getIndicators(); this.userInterface = context.getUserInterface(); //--subscribe to renko feed context.setSubscribedInstruments(java.util.Collections.singleton(feedDescriptor.getInstrument()), true); context.subscribeToFeed(feedDescriptor, this);
} //@Override public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) { Instrument myInstrument = feedDescriptor.getInstrument(); OfferSide myOfferSide = feedDescriptor.getOfferSide();
console.getOut().println("completed" + feedData); try { //-------------RENKO MACD--------------------------------------
Object[] renkoMACDEXT = indicators.calculateIndicator(feedDescriptor, new OfferSide[] { myOfferSide },"MACDEXT", new AppliedPrice[] { AppliedPrice.CLOSE }, new Object []{fastMaMACD,fastMaType,slowMaMACD,slowMaType,signalMaMACD,signalMaType},200,feedData.getTime(),0);
double[][] MACDFigures = {(double[]) renkoMACDEXT[0],(double[]) renkoMACDEXT[1],(double[]) renkoMACDEXT[2]};
console.getOut().println(String.format("Renko2 MACD line currently is: %.5f, signal line is: %.5f", MACDFigures[0][0] ,MACDFigures[0][1])); //-------------------------------------------------------
} catch (JFException e) { console.getErr().println(e); e.printStackTrace(); } } public void onAccount(IAccount account) throws JFException { }
public void onMessage(IMessage message) throws JFException { }
public void onStop() throws JFException { //for (IOrder order : engine.getOrders()) { // engine.getOrder(order.getLabel()).close(); // } }
public void onTick(Instrument instrument, ITick tick) throws JFException { } public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { } }
|
|
|
|
 |
API Support
|
Post subject: Re: MACDEXT difficulty with MaType, request for help |
Post rating: 0
|
Posted: Tue 08 Apr, 2014, 16:23
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
you are using the wrong indicies, this should work as one would expect: console.getOut().println(String.format("Renko2 MACD line currently is: %.5f, signal line is: %.5f", MACDFigures[0][MACDFigures[0].length-1], MACDFigures[1][MACDFigures[1].length-1]));
|
|
|
|
 |
jamesadk
|
Post subject: Re: MACDEXT difficulty with MaType, request for help |
Post rating: 0
|
Posted: Tue 08 Apr, 2014, 21:55
|
|
User rating: 0
Joined: Fri 04 Apr, 2014, 16:35 Posts: 50 Location: Monaco, Monte-Carlo
|
Hi, Thanks for your reply but this still doesn't solve the problem, the figures returned for the MACD are still not matching what is shown on the chart. Perhaps I did not set up the date format and time zone correctly? I'm sure the renko feed itself is working since I have tested it with moving averages and they match what I see on my charts, is there another issue with the MACD that I have overlooked? Any help would be appreciated. Thanks J
|
|
|
|
 |
jamesadk
|
Post subject: Re: MACDEXT difficulty with MaType, request for help |
Post rating: 0
|
Posted: Wed 09 Apr, 2014, 10:48
|
|
User rating: 0
Joined: Fri 04 Apr, 2014, 16:35 Posts: 50 Location: Monaco, Monte-Carlo
|
Hi, On further investigation this morning, it seems that the data fed out by the MACD is correct but not for the most recent bar. I am using shift = 0 for the MACD, yet the MACD is returning the levels for the second brick in from the right, (i.e. what I consider to be shift = 1). There is another post raising a similar issue: viewtopic.php?f=85&t=50994It seems that the Renko feed has been programmed incorrectly (as the API team have now acknowledged in the form thread listed above). Do you know when this will be rectified? Thanks J
|
|
|
|
 |
API Support
|
Post subject: Re: MACDEXT difficulty with MaType, request for help |
Post rating: 0
|
Posted: Fri 11 Apr, 2014, 09:50
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
jamesadk wrote: It seems that the Renko feed has been programmed incorrectly (as the API team have now acknowledged in the form thread listed above). Do you know when this will be rectified? Please ask this in the Trading Platforms section.
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|