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.

MIN indicator works badly after weekends
 Post subject: MIN indicator works badly after weekends Post rating: 0   New post Posted: Sun 03 Jul, 2011, 01:34 

User rating: 0
Joined: Thu 30 Jun, 2011, 20:11
Posts: 41
Location: Spain,
Hi,

I'm using the min indicator and after weekends it doesn´t work.

When I try to call it using the method which includes the filter option, it does require a double [][] value. I don´t understand why.

My whole code is using this data and storing it on an array in order to store min values from different time periods.

I mean:
gs[0]=this.indicators.min(instrument, Period.ONE_HOUR, OfferSide.BID, IIndicators.AppliedPrice.LOW, 45,0);
gs[1]=this.indicators.min(instrument, Period.ONE_MINUTE, OfferSide.BID, IIndicators.AppliedPrice.LOW, 45,0);

I don´t know why should I use a variable called gs [0][0] and my whole code is builded with gs [0]. It is not only that I should change the whole code to write gs [0][0] instead of g[0], it is that anyway it doesn´t works.

Please, help.


 
 Post subject: Re: MIN indicator works badly after weekends Post rating: 0   New post Posted: Sun 03 Jul, 2011, 14:47 

User rating: 0
Joined: Wed 18 May, 2011, 23:26
Posts: 40
Location: Switzerland,
Try filtering out weekends:

double[] min(Instrument instrument,
Period period,
OfferSide side,
IIndicators.AppliedPrice appliedPrice,
int timePeriod,
Filter filter,
int numberOfCandlesBefore,
long time,
int numberOfCandlesAfter)
throws JFException

filter documentation:
https://www.dukascopy.com/client/javadoc ... ilter.html


 
 Post subject: Re: MIN indicator works badly after weekends Post rating: 0   New post Posted: Mon 04 Jul, 2011, 10:04 

User rating: 0
Joined: Thu 30 Jun, 2011, 20:11
Posts: 41
Location: Spain,
Thanks, buyandhold.

That's what I tried. The problem is that I'm not very good managing arrays. My experience with java and jforex is only 2 weeks. I use an array to store the min value for every time frame.

When I use the method MIN whithout filters it gives me back a double value.

min

double min(Instrument instrument,
Period period,
OfferSide side,
IIndicators.AppliedPrice appliedPrice,
int timePeriod,
int shift)
throws JFException

So I store it in my array. But to use the method that you suggest I need to store it in an array, since it gives back the MIN values for a period of time, not just for a candle. I only need the value for one candle but anyway the method gives back double[] value. There is where the problems arise. I dont know how to work with those data. I would like to use the filter but getting back a double value instead of a double [] value.

Any idea?


 
 Post subject: Re: MIN indicator works badly after weekends Post rating: 0   New post Posted: Wed 06 Jul, 2011, 07:57 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
carlosfx wrote:
So I store it in my array. But to use the method that you suggest I need to store it in an array, since it gives back the MIN values for a period of time, not just for a candle. I only need the value for one candle but anyway the method gives back double[] value. There is where the problems arise. I dont know how to work with those data. I would like to use the filter but getting back a double value instead of a double [] value.

Any idea?
Please check the following sample strategy if it gives you a better idea how to work with indicator return values:
package jforex.strategies.indicators;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.TimeZone;

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

public class MinWithFilter implements IStrategy {

   //Strategy params
   private Instrument instrument = Instrument.EURUSD;
   private Period period = Period.ONE_MIN;
   
   //MIN indicator params
   private AppliedPrice appliedPrice = AppliedPrice.HIGH;
   private int timePeriod = 40;
   
   private IConsole console;
   private IIndicators indicators;
   private IHistory history;
   
   @SuppressWarnings("serial")
   private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") {{setTimeZone(TimeZone.getTimeZone("GMT"));}};
   private DecimalFormat df = new DecimalFormat("0.00000");
   
   @Override
   public void onStart(IContext context) throws JFException {
      this.console = context.getConsole();
      this.indicators = context.getIndicators();
      this.history = context.getHistory();
      
      print("start strategy " + this.getClass().getSimpleName());
      
   }


   @Override
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
      if(period != this.period || instrument != this.instrument)
         return;
      
      IBar prevBar = history.getBar(instrument, this.period, OfferSide.BID, 1);
      
      //the last three params - we take 10 bars back, starting from previous bar
      int candlesBefore = 10;
      long time = prevBar.getTime();
      int candlesAfter = 0;
      
      double[] minArray = this.indicators.min(instrument, period, OfferSide.ASK, appliedPrice, timePeriod, Filter.WEEKENDS,
            candlesBefore, time , candlesAfter);
      
      //should equal last element of minArray i.e. minArray[minArray.length - 1]
      double minValue = this.indicators.min(instrument, period, OfferSide.ASK, appliedPrice, timePeriod, Filter.WEEKENDS,
            1, time , 0)[0];

      //the most recent min value is the last one in array
      print ( sdf.format(askBar.getTime())  + " minValue = " + minValue  + " whole array:"+ arrayToString(minArray));
   }
   

   public String arrayToString(double [] arr){
      String str = "";
      for (int r=0; r<arr.length; r++) {
          str += " [" + r + "]" + df.format(arr[r]) + "; ";
      }
      return str;
   }
   
   private void print(Object o){
      console.getOut().println(o);
   }

   public void onTick(Instrument instrument, ITick tick) throws JFException {}
   public void onMessage(IMessage message) throws JFException {}
   public void onAccount(IAccount account) throws JFException {}
   public void onStop() throws JFException {}

}


 

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