|
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.
EMA code |
brspma
|
Post subject: EMA code |
Post rating: 0
|
Posted: Sun 29 Sep, 2013, 14:05
|
|
User rating: 0
Joined: Sun 29 Sep, 2013, 13:46 Posts: 9 Location: United Kingdom, London
|
hi there! I am a kind of newbie. New with Java and Jforex environment. I have some very basic questions. AND believe me I've tried my best to find my answers by now. 1- Can you kindly post here the CODE for the EMA indicator source file. It might be very small, so if you do that, I ll really appreciate. I've tried to get it from https://www.dukascopy.com/wiki/#Platform ... urce_files, but I couldn't. 2- I have done quite a lot with MT4. the MQL Editor have a very nice navigator on the right side of the editor and a very nice help for the syntax of the MQL language. Is there anything similar for jForex? thank you very much,
|
|
|
|
 |
API Support
|
Post subject: Re: EMA code |
Post rating: 1
|
Posted: Mon 30 Sep, 2013, 07:38
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
brspma wrote: 1- Can you kindly post here the CODE for the EMA indicator source file. It might be very small, so if you do that, I ll really appreciate. I've tried to get it from https://www.dukascopy.com/wiki/#Platform ... urce_files, but I couldn't. See the last sentence of the article. brspma wrote: 2- I have done quite a lot with MT4. the MQL Editor have a very nice navigator on the right side of the editor and a very nice help for the syntax of the MQL language. Is there anything similar for jForex? Use a Java IDE, for instance Eclipse or NetBeans. Write your strategies there and then open them by full path in the JForex platform.
|
|
|
|
 |
brspma
|
Post subject: Re: EMA code |
Post rating: 0
|
Posted: Mon 14 Oct, 2013, 18:00
|
|
User rating: 0
Joined: Sun 29 Sep, 2013, 13:46 Posts: 9 Location: United Kingdom, London
|
Great! I have done all that is required so far. I have Netbeans and JKD installed in my computer... so now, where exactly I can find the code of the a specific indicator, as instance EMA!?
Thanks again,
|
|
|
|
 |
tcsabina
|
Post subject: Re: EMA code |
Post rating: 1
|
Posted: Mon 14 Oct, 2013, 18:40
|
|
User rating: 164
Joined: Mon 08 Oct, 2012, 10:35 Posts: 676 Location: NetherlandsNetherlands
|
javadoc: https://www.dukascopy.com/client/javadoc/examples can also be found in the wiki: https://www.dukascopy.com/wiki/#But to be a bit more constructive  : There are 4 ways to calculate EMA indicator, based on different things. These are: ema(Instrument, Period, OfferSide, IIndicators.AppliedPrice, int, int) ema(Instrument, Period, OfferSide, IIndicators.AppliedPrice, int, long, long) ema(Instrument, Period, OfferSide, IIndicators.AppliedPrice, int, Filter, int, long, int) ema(Instrument, Period, OfferSide, IIndicators.AppliedPrice, int, Filter, long, long) This wiki example uses STOCH indicator. Just replace it with EMA, and you should be good. Facing any problems? Don't hesitate to fire them right away. Good luck!
|
|
|
|
 |
brspma
|
Post subject: Re: EMA code |
Post rating: 0
|
Posted: Mon 14 Oct, 2013, 19:16
|
|
User rating: 0
Joined: Sun 29 Sep, 2013, 13:46 Posts: 9 Location: United Kingdom, London
|
Thank you, tcsabina! I've checked out the links you gave me, but they are not exactly what I am looking for...
After Netbeans was installed, it downloaded so much stuff in my computer. I just think that there is a place within Netbeans where I can find all source Codes of the indicators used in JForex. As instance I want to open in Netbeans the source Code of the EMA indicator. In my mind this should be a very simple task. Nevertheless, it is the first time I am using the Netbeans as my editor so I am finding some barriers on my way...
I'll really appreciate any help...
thank you again,
|
|
|
|
 |
brspma
|
Post subject: Re: EMA code |
Post rating: 0
|
Posted: Mon 14 Oct, 2013, 20:52
|
|
User rating: 0
Joined: Sun 29 Sep, 2013, 13:46 Posts: 9 Location: United Kingdom, London
|
I've found! you just have to Locate in the project hierarchy this: Dependencies/JForex-API-2.9.3.1-sources.jar/com/dukascopy/indicators/MAIndicator.javathank you again all! 
|
|
|
|
 |
tcsabina
|
Post subject: Re: EMA code |
Post rating: 1
|
Posted: Tue 15 Oct, 2013, 10:04
|
|
User rating: 164
Joined: Mon 08 Oct, 2012, 10:35 Posts: 676 Location: NetherlandsNetherlands
|
|
|
|
 |
brspma
|
Post subject: Re: EMA code |
Post rating: 0
|
Posted: Sun 20 Oct, 2013, 12:08
|
|
User rating: 0
Joined: Sun 29 Sep, 2013, 13:46 Posts: 9 Location: United Kingdom, London
|
Hi there! Sorry guys... After a closer look at it. I found out that it is not exactly what I am looking for. I just want to see the most simple example using EMA as an indicator. I don't want the calculation of EMA. I just want to use one of these "indicator call" from my code: ema(Instrument, Period, OfferSide, IIndicators.AppliedPrice, int, int) ema(Instrument, Period, OfferSide, IIndicators.AppliedPrice, int, long, long) ema(Instrument, Period, OfferSide, IIndicators.AppliedPrice, int, Filter, int, long, int) ema(Instrument, Period, OfferSide, IIndicators.AppliedPrice, int, Filter, long, long) In MQL4 it would look like something like that: #property indicator_buffers 1 #property indicator_chart_window
double b0[]; // ---------------------- int init() { SetIndexBuffer(0,b0); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3,Blue); SetIndexLabel(0,"m1"); return(0); } // ---------------------- int start(){
if (Period() > PERIOD_M1) return(0);
int limit; int counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; if (limit>30000) limit = 30000; //---------------------------------------- main loop for(int i=limit; i>=0; i--){
b0[i]= iMA(NULL,PERIOD_M1,200,0,MODE_EMA,PRICE_CLOSE, i);
} // ---------------------- return(0);}
I think the support here is great, but much more could be done to help the beginners. As a matter of fact, in the Jforex wiki I could not find a simple example of indicator at all. So please, if anyone ( tcsabina ~:) would care for helping me out with my humble endeavor, I would appreciate! thank you!!!
|
|
|
|
 |
API Support
|
Post subject: Re: EMA code |
Post rating: 0
|
Posted: Mon 21 Oct, 2013, 08:45
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
brspma
|
Post subject: Re: EMA code |
Post rating: 0
|
Posted: Mon 21 Oct, 2013, 09:47
|
|
User rating: 0
Joined: Sun 29 Sep, 2013, 13:46 Posts: 9 Location: United Kingdom, London
|
Thank you for your reply... Actually I am not looking for the calculation of the indicator. What I am looking for is a simple code where you use this ema(Instrument, Period, OfferSide, IIndicators.AppliedPrice, int, int). Suggestions: 1. it would be nice to create an area here in the forum for the beginners! 2. as I've stated above. I couldn't find any simple indicator as the example in MQL4 I shared above. It would be very helpful to have that code in javaFX. In my understanding it would look like something like this: package jforex;
import com.dukascopy.api.indicators.*;
public class Indicator implements IIndicator { /** * * some code here * * */ public void onStart(IIndicatorContext context) { /** * * some code here * * */ }
public IndicatorResult calculate(int startIndex, int endIndex) { /** * * some code here which would use this as return value ema(Instrument, Period, OfferSide, IIndicators.AppliedPrice, int, int) * * */ }
public IndicatorInfo getIndicatorInfo() { return indicatorInfo; }
public InputParameterInfo getInputParameterInfo(int index) { if (index <= inputParameterInfos.length) { return inputParameterInfos[index]; } return null; }
public int getLookback() { return timePeriod; }
public int getLookforward() { return 0; }
public OptInputParameterInfo getOptInputParameterInfo(int index) { if (index <= optInputParameterInfos.length) { return optInputParameterInfos[index]; } return null; }
public OutputParameterInfo getOutputParameterInfo(int index) { if (index <= outputParameterInfos.length) { return outputParameterInfos[index]; } return null; }
public void setInputParameter(int index, Object array) { inputs[index] = (double[]) array; }
public void setOptInputParameter(int index, Object value) { timePeriod = (Integer) value; }
public void setOutputParameter(int index, Object array) { outputs[index] = (double[]) array; } }
|
|
|
|
 |
API Support
|
Post subject: Re: EMA code |
Post rating: 1
|
Posted: Mon 21 Oct, 2013, 10:02
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
You are now confusing Strategy API with the Indicator API - the methods you referred to in your previous post are to be used only from strategies. Here is an example how you calculate EMA from an indicator: https://www.dukascopy.com/wiki/#Indicator_calls_other_indicatorAlso there are various examples in the aforementioned JForex-API sources which use MA indicators, like - AwesomeOscillator
- APOscillator
- BollingerBands
- StochasticIndicator
All of those indicators use EMA when you select it in the optional inputs. Select an indicator which you find closest to your desired logic and modify it according to your needs. Mind to change the indicator's name, as it needs to be unique.
|
|
|
|
 |
tcsabina
|
Post subject: Re: EMA code |
Post rating: 1
|
Posted: Mon 21 Oct, 2013, 20:27
|
|
User rating: 164
Joined: Mon 08 Oct, 2012, 10:35 Posts: 676 Location: NetherlandsNetherlands
|
Here is an example strategy, that uses all 4 ema calculations. I don't know if this really helps, as Support provided plenty of links, but as you asked for it, here it comes. I haven't put too much explanation in the code, as it is pretty straight forward. Hope this helps... package jforex;
import java.util.*; import java.text.SimpleDateFormat;
import com.dukascopy.api.*; import com.dukascopy.api.IIndicators.AppliedPrice;
public class EMAs implements IStrategy { private IEngine engine; private IConsole console; private IHistory history; private IContext context; private IIndicators indicators; private IUserInterface userInterface; private SimpleDateFormat sdf;
@Configurable("Instrument") public Instrument selectedInstrument = Instrument.EURUSD; @Configurable("Period") public Period selectedPeriod = Period.ONE_MIN; @Configurable("Indicator Filter") public Filter indicatorFilter = Filter.WEEKENDS; @Configurable("Applied Price") public AppliedPrice appliedPrice = AppliedPrice.CLOSE;
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(); sdf = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss.SSS"); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); }
public void onAccount(IAccount account) throws JFException { }
public void onMessage(IMessage message) throws JFException { }
public void onStop() throws JFException { }
public void onTick(Instrument instrument, ITick tick) throws JFException { } public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { double EMA1; double EMA2[] , EMA3[] , EMA4[]; IBar prevBar , aBar;
if ( (instrument.equals(selectedInstrument)) && (period.equals(selectedPeriod))) { prevBar = history.getBar(instrument, selectedPeriod, OfferSide.BID, 1); aBar = history.getBar(instrument, selectedPeriod, OfferSide.BID, 10); EMA1 = indicators.ema(instrument, period, OfferSide.BID, appliedPrice, 21, 1); EMA2 = indicators.ema(instrument, period, OfferSide.BID, appliedPrice, 21, aBar.getTime(), prevBar.getTime()); EMA3 = indicators.ema(instrument, period, OfferSide.BID, appliedPrice, 21, indicatorFilter, 1, prevBar.getTime(), 0); EMA4 = indicators.ema(instrument, period, OfferSide.BID, appliedPrice, 21, indicatorFilter, aBar.getTime(), prevBar.getTime());
print("%s - Last bar's EMA (without filter)=%.5f", sdf.format(bidBar.getTime()), EMA1); print("%s - Last 10 bar's EMA (without filter): 10th=%.5f; 9th=%.5f; 8th=%.5f; 7th=%.5f; 6th=%.5f; 5th=%.5f; 4th=%.5f; 3rd=%.5f; 2nd=%.5f; 1st=%.5f;" , sdf.format(bidBar.getTime()), EMA2[0], EMA2[1], EMA2[2], EMA2[3], EMA2[4], EMA2[5], EMA2[6], EMA2[7], EMA2[8], EMA2[9]); print("%s - Last bar's EMA (with filter)=%.5f", sdf.format(bidBar.getTime()), EMA3[0]); print("%s - Last 10 bar's EMA (with filter): 10th=%.5f; 9th=%.5f; 8th=%.5f; 7th=%.5f; 6th=%.5f; 5th=%.5f; 4th=%.5f; 3rd=%.5f; 2nd=%.5f; 1st=%.5f;" , sdf.format(bidBar.getTime()), EMA4[0], EMA4[1], EMA4[2], EMA4[3], EMA4[4], EMA4[5], EMA4[6], EMA4[7], EMA4[8], EMA4[9]); } }
public void print(String message) { console.getOut().println(message); }
private void print(Object o) { console.getOut().println(o); }
private void print(String format, Object...args) { print(String.format(format,args)); } }
|
|
|
|
 |
brspma
|
Post subject: Re: EMA code |
Post rating: 0
|
Posted: Tue 22 Oct, 2013, 00:45
|
|
User rating: 0
Joined: Sun 29 Sep, 2013, 13:46 Posts: 9 Location: United Kingdom, London
|
Thank you so very much!!! the links Support provided and your code, tcsabina, are all what I was looking for. Plenty of information to have fun with... I am very pleased. Cheers! 
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|