Dukascopy
 
 
Wiki JStore Search Login

APICLIENT-192 MACD-Histogram indicator in Renko Strategy
 Post subject: APICLIENT-192 MACD-Histogram indicator in Renko Strategy Post rating: 0   New post Posted: Thu 12 Jul, 2012, 07:26 
User avatar

User rating: 2
Joined: Tue 16 Aug, 2011, 19:01
Posts: 70
Location: ItalyItaly
Hi Support,
this is a piece of renko strategy


    private IEngine engine;
    private IConsole console;
    private IHistory history;
   
    private IAccount account;
   
    private IIndicators indicators;
    private int counter = 0;
    private IFeedDescriptor feedDescriptor;
    private IOrder order = null;
    public int brickSize = 1;           
    public int fastMaPeriod = 50;         
    public MaType fastMaType = MaType.EMA;
    public int slowMaPeriod = 100;       
    public MaType slowMaType = MaType.EMA;
   
    @Configurable("Instrument")
    public Instrument instrument = Instrument.EURUSD;
    @Configurable("Offer side")
    public OfferSide offerSide = OfferSide.BID;
    @Configurable("Slippage")
    public double slippage = 0.7;               
    public double amount = 0.01;               
    public int takeProfitPips = 40;
    public int stopLossPips = 40;               






    @Override
    public void onStart(IContext context) throws JFException {
        this.console = context.getConsole();
        this.indicators = context.getIndicators();
        this.history = context.getHistory();
        this.engine = context.getEngine();
       
       
        // range bar feed
        feedDescriptor = new FeedDescriptor();
        feedDescriptor.setDataType(DataType.RENKO);
        feedDescriptor.setOfferSide(offerSide);
        feedDescriptor.setInstrument(instrument);
        feedDescriptor.setPriceRange(PriceRange.valueOf(brickSize));
    }





    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        if (instrument != this.instrument) {
            return;
        }


        tickBid = tick.getBid();


                               
        if (!isActive(order)) {
            order = null;
        }

                               
                                                                                               
        IRenkoBar brick = history.getRenkoBar(instrument, offerSide, PriceRange.valueOf(brickSize), 0);
        IRenkoBar brickMeno1 = history.getRenkoBar(instrument, offerSide, PriceRange.valueOf(brickSize), 1);
       
        // calculate indicator
        double[] slowMAfeed = (double[]) indicators.calculateIndicator(
                feedDescriptor,
                new OfferSide[]{OfferSide.BID},
                "MA",
                new AppliedPrice[]{AppliedPrice.CLOSE},
                new Object[]{slowMaPeriod, slowMaType.ordinal()},
                2, brick.getTime(), 0)[0];

.....



Please, could you show how to obtain MACD-Histogram and Awesome with indicators.calculateIndicator(), like the previous example with MA ?


Best regards,
Frank


 
 Post subject: Re: MACD-Histogram and Awesome indicator in Renko Strategy Post rating: 0   New post Posted: Thu 12 Jul, 2012, 07:35 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
for MACD see:
https://www.dukascopy.com/wiki/#Indicator_Calculation/Calculate_on_price_feed_by_candle_interval
for awesome see (just see the approach how the calcualateIndicator call is made and how the results are parsed):
https://www.dukascopy.com/wiki/#Use_custom_indicator_in_strategies/Handle_multiple_outputs_and_plot_on_chart

In general case, if you wish to find out what optional inputs to pass and what outputs to expect, use the following example with an arbitrary indicator:
https://www.dukascopy.com/wiki/#Calculate_arbitrary_indicator/Calculate_on_a_feed


 
 Post subject: Re: MACD-Histogram and Awesome indicator in Renko Strategy Post rating: 0   New post Posted: Thu 12 Jul, 2012, 16:16 
User avatar

User rating: 2
Joined: Tue 16 Aug, 2011, 19:01
Posts: 70
Location: ItalyItaly
API Support wrote:
for MACD see:
https://www.dukascopy.com/wiki/#Indicator_Calculation/Calculate_on_price_feed_by_candle_interval
for awesome see (just see the approach how the calcualateIndicator call is made and how the results are parsed):
https://www.dukascopy.com/wiki/#Use_custom_indicator_in_strategies/Handle_multiple_outputs_and_plot_on_chart

In general case, if you wish to find out what optional inputs to pass and what outputs to expect, use the following example with an arbitrary indicator:
https://www.dukascopy.com/wiki/#Calculate_arbitrary_indicator/Calculate_on_a_feed




Hi Support,
I would like to obtain the MACD value for last closed renko bar but I obtain always the bar minus 1 (that is the bar previous the last closed bar)


//-----------------------------------------------------------------------------------------------------------------        
        //Doesn't consider the last closed renko bar but the previous closed renko bar. Why?
        Object[] MACD_Feed =  indicators.calculateIndicator(
                feedDescriptor,
                new OfferSide[]{OfferSide.BID},
                "MACD",
                new AppliedPrice[]{AppliedPrice.OPEN},
                new Object[]{12,26,9 },
                 0);

        double[] macdArray = {(Double)  MACD_Feed[0], (Double)  MACD_Feed[1]};



       double macd      = macdArray[0];
       double signal    = macdArray[1];
       double histogram =   macd - signal;

               
       Print("macd:      " + macd);
       Print("signal:    " + signal);
       Print("Histogram: " + histogram);


//-----------------------------------------------------------------------------------------------------------------


Could you explain why?

Best regards,
Frank


 

Jump to:  

  © 1998-2024 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