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.

Pivot Points - JForex
 Post subject: Pivot Points - JForex Post rating: 0   New post Posted: Mon 31 Dec, 2018, 08:40 

User rating: 0
Joined: Mon 31 Dec, 2018, 08:31
Posts: 2
Location: United Kingdom,
I am unable to locate the class/function in the JForex SDK to return the PivotPoint I see on my chart called PIVOT2, so I tried to calculate the value myself based on the previous DAILY bar as below.

Two questions relating to the code segment:

Q1: Can anyone please provide me with the code to retrieve the pivot point/s using the SDK and Java?
Q2: The IBar (bars & bars2) do not exactly match the values for the previous DAILY bar on the chart. Is my code incorrect and can you suggest a better/correct way of retrieving the previous DAILY bar? prevBar is commented out as it's values are way off what I observe on the chart.

Thank you.

long prevBarTime = history.getPreviousBarStart(Period.DAILY, history.getLastTick(sInstrument).getTime());
//IBar prevBar; // = history.getBar(sInstrument, Period.DAILY, OfferSide.BID, 1);
List<IBar> bars = history.getBars(sInstrument, Period.DAILY, OfferSide.BID, Filter.WEEKENDS, 2, prevBarTime, 1);
List<IBar> bars2 = history.getBars(sInstrument, Period.DAILY, OfferSide.ASK, Filter.WEEKENDS, 2, prevBarTime, 1);

double iAvgPriceH = (bars.get(0).getHigh() + bars2.get(0).getHigh())/2;
double iAvgPriceL = (bars.get(0).getLow() + bars2.get(0).getLow())/2;
//double iAvgPriceO = (bars.get(0).getOpen() + bars2.get(0).getOpen())/2;
double iAvgPriceC = (bars.get(0).getClose() + bars2.get(0).getClose())/2;

for (int i = 1; i < bars.size(); i++) {}

oPivotPoints = new CPivotPoints();

oPivotPoints.PP = (iAvgPriceH + iAvgPriceL + iAvgPriceC)/3;
oPivotPoints.S1 = (oPivotPoints.PP * 2) - iAvgPriceH;
oPivotPoints.S2 = oPivotPoints.PP - (iAvgPriceH - iAvgPriceL);


 
 Post subject: Re: Pivot Points - JForex Post rating: 0   New post Posted: Thu 03 Jan, 2019, 17:07 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello,

Quote:
Q1: Can anyone please provide me with the code to retrieve the pivot point/s using the SDK and Java?

Indicators API have own method for calculating Pivot Points. This code should work.
        this.indicators = context.getIndicators();
        Instrument instrument = Instrument.EURUSD;
        OfferSide offerSide = OfferSide.BID;
        Period period = Period.DAILY;
        double[] pivotPoints = indicators.pivot2(instrument, period, offerSide, 0);

Quote:
Q2: The IBar (bars & bars2) do not exactly match the values for the previous DAILY bar on the chart. Is my code incorrect and can you suggest a better/correct way of retrieving the previous DAILY bar? prevBar is commented out as it's values are way off what I observe on the chart.

It is a working way. Firstly, check your chart settings, if you use Period.DAILY for retrieving bars - they will be based on GMT Timezone, therefore Day Start Time in your chart preferences(Settings - Preferences - Charts) also need be GMT. Otherwise, the values will vary.


 
 Post subject: Re: Pivot Points - JForex Post rating: 0   New post Posted: Mon 19 Aug, 2019, 20:20 
User avatar

User rating: 0
Joined: Tue 25 Oct, 2011, 19:35
Posts: 5
Location: Russian FederationRussian Federation
wheelsofsteel2 wrote:
Q2: The IBar (bars & bars2) do not exactly match the values for the previous DAILY bar on the chart. Is my code incorrect and can you suggest a better/correct way of retrieving the previous DAILY bar? prevBar is commented out as it's values are way off what I observe on the chart.


Try to create custom Daily period and filter Weekends to avoid zero periods:

Period custom_daily = Period.createCustomPeriod(Unit.Day, 1, JFTimeZone.EET);
double pivot[][] = indicators.pivot(instrument, chart_period, OfferSide.BID, custom_daily,
        Filter.WEEKENDS, 1, context.getHistory().getBar(instrument, custom_daily, OfferSide.BID, 0).getTime(),  0);


Hope it helps, because this problem is about all Daily calculations, not only pivot but ATR etc.


 

Jump to:  

cron
  © 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