Dukascopy
 
 
Wiki JStore Search Login

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.

hline on ema value
 Post subject: hline on ema value Post rating: 0   Post Posted: Mon 03 Dec, 2012, 10:40 

User rating: 0
Joined: Fri 30 Nov, 2012, 09:18
Posts: 2
How do I draw a horizontal line on the ema value of 2 candles back? It seems easy to draw based on high, low close etc, but I cannot get it working using the value of an ema of 2 candles back as the price level?
Thanks


 
 Post subject: Re: hline on ema value Post rating: 0   Post Posted: Mon 03 Dec, 2012, 11:38 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See:
https://www.dukascopy.com/wiki/#Indicator_Calculation/Calculate_indicator_by_shift
and:
https://www.dukascopy.com/wiki/#Chart_object_catalog
Should you encounter any problems, please provide us your example strategy.


 
 Post subject: Re: hline on ema value Post rating: 0   Post Posted: Mon 10 Dec, 2012, 01:10 

User rating: 0
Joined: Fri 30 Nov, 2012, 09:18
Posts: 2
Here is the code I have so far. It does appear to draw the line on EMA3 for period 5min, BUT the line only flashes extremely briefly and also not on the actual forming of the new 5min bar.

package charts.test;

import com.dukascopy.api.*;
import com.dukascopy.api.drawings.IHorizontalLineChartObject;
import com.dukascopy.api.indicators.IIndicator;
import com.dukascopy.api.indicators.OutputParameterInfo.DrawingStyle;
import java.awt.Color;
import com.dukascopy.api.IIndicators.AppliedPrice;

@RequiresFullAccess
public class HLineKeyRemove implements IStrategy {
// public double EMA3 = 3;
    private IChart chart;
    private IHistory history;
    private IConsole console;
        private IIndicators indicators;
    public Filter indicatorFilter = Filter.NO_FILTER;   
    public int SMA3 = 3;   
   
    @Override
    public void onStart(IContext context) throws JFException {
        this.chart = context.getChart(Instrument.EURUSD);
        this.history = context.getHistory();
        console = context.getConsole();
        this.indicators = context.getIndicators();
    }
   
    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {}

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {

IBar bar = history.getBar(Instrument.EURUSD, Period.FIVE_MINS, OfferSide.BID, 1) ;
double[] EMA3 = indicators.ema(instrument, Period.FIVE_MINS, OfferSide.BID, AppliedPrice.CLOSE, 3,indicatorFilter, 2, bar.getTime(), 0);
     
                                                 
        String key = "EMALine";
 
 //              IHorizontalLineChartObject hLine = chart.getChartObjectFactory().createHorizontalLine(key, tick.getBid());     
              IHorizontalLineChartObject Line = chart.getChartObjectFactory().createHorizontalLine(key, EMA3[1]);   
           
        Line.setColor(Color.WHITE);   
        chart.addToMainChartUnlocked(Line);
       
        }

    @Override
    public void onMessage(IMessage message) throws JFException {}

    @Override
    public void onAccount(IAccount account) throws JFException {}

    @Override
    public void onStop() throws JFException {}

}


 
 Post subject: Re: hline on ema value Post rating: 0   Post Posted: Mon 10 Dec, 2012, 09:44 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See IStrategy.onBar description:
https://www.dukascopy.com/wiki/#Strategy_API
See:
https://www.dukascopy.com/wiki/#Filter_Ticks_Bars


 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com