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.

Indicator not displaying correct value
 Post subject: Indicator not displaying correct value Post rating: 0   New post Posted: Mon 16 Jan, 2012, 00:34 

User rating: 0
Joined: Sat 19 Nov, 2011, 01:24
Posts: 23
Location: United Kingdom,
I'm having a problem in my strategy when I call the value of an Indicator, it gives a different value then whats shown on the chart.

To try and find the problem I started a new strategy and its blank apart from this in ontick. (The bit of the code that was giving me trouble in my strategy and it's still giving the same problem.)

double RSI=indicators.rsi(Instrument.EURAUD, Period.FIFTEEN_MINS, OfferSide.BID, IIndicators.AppliedPrice.CLOSE, 14, 0);
       console.getOut().println(RSI);


I then go to my EURAUD chart and add a new RSI indicator with period of 14. (yes the chart is set to fifteen minutes and yes its EURAUD)

On the chart it reads 46.3 but in the output for the strategy its reading 73.2

I cant for the life of me figure out what is wrong.


 
 Post subject: Re: Indicator not displaying correct value Post rating: 0   New post Posted: Mon 16 Jan, 2012, 14:06 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See: https://www.dukascopy.com/wiki/#Indicato ... _checklist


 
 Post subject: Re: Indicator not displaying correct value Post rating: 0   New post Posted: Mon 16 Jan, 2012, 19:01 

User rating: 0
Joined: Sat 19 Nov, 2011, 01:24
Posts: 23
Location: United Kingdom,
Yes perfect...

But now I have another problem, I can't figure out how to use the correct indicator with the filter.

There are two RSI indicators that use a filter, but they both take different parameters but I can't get either to work.

Can you please post an example and explain because I don't even know which one to use.

I just want the output to match the same as the chart when filter flats on weekend is selected.

Thank you.


 
 Post subject: Re: Indicator not displaying correct value Post rating: 0   New post Posted: Wed 18 Jan, 2012, 10:35 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
For indicator calculation by shift no filter gets applied, in order to get indicator value on filtered feed, you need to use calculation method that returns indicator values on a candle interval.
package jforex.strategies.indicators;

import com.dukascopy.api.*;
import com.dukascopy.api.IIndicators.AppliedPrice;

@RequiresFullAccess
public class RSITest implements IStrategy {
   
   @Configurable("")
   public Period period = Period.FOUR_HOURS;
   @Configurable("")
   public Instrument instrument = Instrument.EURAUD;
   @Configurable("")
   public OfferSide side = OfferSide.BID;
   @Configurable("")
   public AppliedPrice appliedPrice = AppliedPrice.CLOSE;
   @Configurable("")
   public int timePeriod = 14;
   
   private IIndicators indicators;
   private IConsole console;
   private IHistory history;
   

   @Override
   public void onStart(IContext context) throws JFException {
      indicators = context.getIndicators();
      console = context.getConsole();
      history = context.getHistory();
      long time = history.getBarStart(period, history.getLastTick(instrument).getTime());
      
      double RSI=indicators.rsi(instrument, period, side, appliedPrice, 14, 0);
      double[] RSIArray =indicators.rsi(instrument, period, side, appliedPrice, 14,
            Filter.WEEKENDS, 1, time, 0);
      //in this case RSIArray[RSIArray.length - 1] = RSIArray[0] since the array length is 1,
      //we use here RSIArray.length - 1 in order to stress that the last element is the latest one
       console.getOut().println(String.format("rsi no filter: %.5f, weekend filter: %.5f", RSI, RSIArray[RSIArray.length - 1]));

       context.stop();
   }

   @Override
   public void onTick(Instrument instrument, ITick tick) throws JFException {}

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

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

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

   @Override
   public void onStop() throws JFException {}

}



Attachments:
RSITest.java [1.82 KiB]
Downloaded 277 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 

Jump to:  

  © 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