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.

Getting ALL pivot levels
 Post subject: Getting ALL pivot levels Post rating: 0   New post Posted: Mon 13 Jun, 2011, 18:21 

User rating: -
Dear Support,

Could you tell me please how to get the daily pivot levels (R3, R2, R1, P, S1, S2, S3 ), the daily median pivot levels and the weekly pivot levels from within a strategy for a given instrument? I don't need to plot them only to get their values when my strategy is running. I ask because I found it impossible to get the right values for them without the weekend candles (thus with filtering). I tried to use the "pivot" jforex indicator but that one is buggy.

Is there any other alternative in JFOREX?

Please help here....

Thanks in advance
Christian


 
 Post subject: Re: Getting ALL pivot levels Post rating: 0   New post Posted: Wed 15 Jun, 2011, 09:44 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
For daily and weekly pivot levels consider the following example strategy:
package jforex.strategies.indicators;

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

import com.dukascopy.api.*;

/**
 * The startegy prints out daily and weekly pivot levels
 *
 */
public class Pivot implements IStrategy {
   private IConsole console;
   private IIndicators indicators;
   private SimpleDateFormat sdf;

   private Instrument instrument = Instrument.EURUSD;
   private Period selectedPeriod = Period.DAILY;
   
   private static String[] pivotLevelNames = { "P", "R1", "S1", "R2", "S2", "R3", "S3" };

   public void onStart(IContext context) throws JFException {
      this.console = context.getConsole();
      this.indicators = context.getIndicators();
      
      String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
      sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
      sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
      
      print("start");
      
   }

   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 {

      if (!instrument.equals(this.instrument) || !period.equals(selectedPeriod))
         return;      
      
      
      boolean showHistoricalLevels = true;
      int shift = 0;
      double [] pivotDaily = indicators.pivot(instrument, selectedPeriod, OfferSide.BID, 7, showHistoricalLevels, shift);
      double [] pivotWeekly = indicators.pivot(instrument, selectedPeriod, OfferSide.BID, 8, showHistoricalLevels, shift);

      print(sdf.format(bidBar.getTime())
            + " ## "+  " pivotWeekly " +arrayToString(pivotWeekly)
            + " ## "+  " pivotDaily " +arrayToString(pivotDaily)
      );

   }
   
   private void print(Object message) {
      console.getOut().println(message);
   }
   
   public static String arrayToString(double [] arr){
      String str = "";
      for (int r=0; r<arr.length; r++) {
          str += " " + pivotLevelNames[r] + ": "+ (new DecimalFormat("#.#######")).format(arr[r]) + "; ";
      }
      return str;
   }

}
Currently JForex does not have an indicator for daily median pivot levels, however you might obtain such indicator by a slight PivotIndicator (find it in the API's library com.dukascopy.indicators) modification:
by changing
double p = (previousBar.getClose() + previousBar.getHigh() + previousBar.getLow())/3; 
to
double p = ( previousBar.getHigh() + previousBar.getLow())/2; 
at line 151.


 
 Post subject: Re: Getting ALL pivot levels Post rating: 0   New post Posted: Fri 03 Feb, 2012, 22:23 

User rating: 0
Joined: Fri 03 Feb, 2012, 22:13
Posts: 3
hi,

sorry for asking my question in this thread, but i need a median pivot indicator for jforex, like the one mentioned above.
i'm no programmer.

i tried to create a "new indicator" in jforex, and pasted the content of the mentioned indicator from the api download package.
then i changed the line 151 like mentioned in the last post.

when i try to compile the indicator in jforex, i get many errors:

21:11:52 ^^^^^^^^^^^
21:11:52 int x = indicatorDrawingSupport.getXForTime(innerOutputs[i].getTime());
21:11:52 5. ERROR in /tmp/jfxide/tmp/PivotIndicator.java (at line 624)
21:11:52 ----------
21:11:52 The method getXForTime(long) is undefined for the type IIndicatorDrawingSupport
21:11:52 ^^^^^^^^^^^
21:11:52 int x = indicatorDrawingSupport.getXForTime(innerOutputs[i].getTime());
21:11:52 4. ERROR in /tmp/jfxide/tmp/PivotIndicator.java (at line 589)
21:11:52 ----------
21:11:52 The method getXForTime(long) is undefined for the type IIndicatorDrawingSupport
21:11:52 ^^^^^^^^^^^
21:11:52 int x = indicatorDrawingSupport.getXForTime(innerOutputs[i].getTime());
21:11:52 3. ERROR in /tmp/jfxide/tmp/PivotIndicator.java (at line 538)
21:11:52 ----------
21:11:52 The method getFeedDescriptor() is undefined for the type IIndicatorContext
21:11:52 ^^^^^^^^^^^^^^^^^
21:11:52 dailyInput.setFilter(context.getFeedDescriptor().getFilter());
21:11:52 2. ERROR in /tmp/jfxide/tmp/PivotIndicator.java (at line 154)
21:11:52 ----------
21:11:52 The method setSparseIndicator(boolean) is undefined for the type IndicatorInfo
21:11:52 ^^^^^^^^^^^^^^^^^^
21:11:52 indicatorInfo.setSparseIndicator(true);
21:11:52 1. ERROR in /tmp/jfxide/tmp/PivotIndicator.java (at line 94)
21:11:52 ----------
21:11:50 Compiling PivotIndicator.java


can someone please provide me a compiled version with the correct change and provide it to me..

many thanks and best regards
costal


 
 Post subject: Re: Getting ALL pivot levels Post rating: 0   New post Posted: Mon 06 Feb, 2012, 10:13 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
This is because the latest indicator version uses JForex-API features that are not yet supported by the JForex-API version that is used by JForex client.
We attached the PivotIndicator version corresponding to JForex-API 2.6.38 - the version of JForex client. Consider doing adjustments in this indicator.


Attachments:
PivotIndicator.java [17.76 KiB]
Downloaded 311 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.
 
 Post subject: Re: Getting ALL pivot levels Post rating: 0   New post Posted: Mon 06 Feb, 2012, 12:44 

User rating: 0
Joined: Fri 03 Feb, 2012, 22:13
Posts: 3
thank you for your fast response,

i tried it again, but still without success.

error when compiling:
2012-02-06 11:42:13   ----------
2012-02-06 11:42:13   The public type PivotIndicator must be defined in its own file
2012-02-06 11:42:13   ^^^^^^^^^^^^^^
2012-02-06 11:42:13   public class PivotIndicator implements IIndicator, IDrawingIndicator {
2012-02-06 11:42:13   1. ERROR in /tmp/jfxide/tmp/myPivot.java (at line 38)
2012-02-06 11:42:13   ----------
2012-02-06 11:42:01   Compiling myPivot.java


any hints?

best regards
costal


 
 Post subject: Re: Getting ALL pivot levels Post rating: 0   New post Posted: Mon 06 Feb, 2012, 12:45 

User rating: 0
Joined: Fri 03 Feb, 2012, 22:13
Posts: 3
please forget my last message, everything is fine..
the problem was the rename of the indicator...

thanks and best regards
costal


 

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