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.

How to get value of 1HR period indicators every say 15M or 30M bar?
 Post subject: How to get value of 1HR period indicators every say 15M or 30M bar? Post rating: 0   New post Posted: Fri 14 Dec, 2012, 03:30 
User avatar

User rating: 8
Joined: Tue 25 Oct, 2011, 23:02
Posts: 74
Location: Australia, Melbourne
Dear Community/Support

What is the recommended method for getting indicator values based on 1HR period, at a smaller period, say 15 minute or 30 minute?

For example if we have an onBar implementation like below, it will calculate the value of linear regression every 1HR bar.
But I would like to get the value of the 1HR period linear regression halfway through the 1HR - at the 30M mark - how can I calculate the value of the 1HR period linear regression every time onBar receives a Period.THIRTY_MINS bar?

public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException 
{     
      if (period == Period.ONE_HOUR)
      {
            try
            {       
                   IBar currentBidBar = _history.getBar(instrument, _period, OfferSide.BID, 0);
              IBar closedBar = _history.getBar(instrument, _period, OfferSide.BID, 1);
                      
              long closedBarTime = _history.getBarStart(_period, closedBar.getTime());
              long openedBarTime = currentBidBar.getTime();
                      
              // linear regression
              Object[] values;
                      
              values = indicators.calculateIndicator(instrument,
                                      _period,
                                      new  OfferSide[] {OfferSide.BID },
                                      "LINEARREG",
                                      new IIndicators.AppliedPrice[] { IIndicators.AppliedPrice.CLOSE },
                                      new Object[] { _lrPeriod },
                                      Filter.WEEKENDS,
                                      2,
                                      closedBarTime,
                                      0);       
                      
                double[] lrValues = (double[]) values[0];
                double lr =  lrValues[1];
                double lr1 =  lrValues[0];
   
            }
            catch (JFException e)
            {
                e.printStackTrace();
            }

         }
    }



 
 Post subject: Re: How to get value of 1HR period indicators every say 15M or 30M bar? Post rating: 0   New post Posted: Fri 14 Dec, 2012, 14:06 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Try something like this:
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
      if (period == Period.THIRTY_MINS) {
         try {
            long curr1HBarStartTime = _history.getBar(instrument, Period.ONE_HOUR, OfferSide.BID, 0).getTime();
            // linear regression
            Object[] values = indicators.calculateIndicator(instrument, Period.ONE_HOUR, new OfferSide[] { OfferSide.BID }, "LINEARREG",
                  new IIndicators.AppliedPrice[] { IIndicators.AppliedPrice.CLOSE }, new Object[] { _lrPeriod }, Filter.WEEKENDS, 2,
                  curr1HBarStartTime, 0);

            double[] lrValues = (double[]) values[0];
            double lr = lrValues[1];
            double lr1 = lrValues[0];

         } catch (JFException e) {
            e.printStackTrace();
         }
      }
   }


 
 Post subject: Re: How to get value of 1HR period indicators every say 15M or 30M bar? Post rating: 0   New post Posted: Fri 19 Apr, 2013, 00:14 
User avatar

User rating: 8
Joined: Tue 25 Oct, 2011, 23:02
Posts: 74
Location: Australia, Melbourne
I'd just like to point out that your suggestion does not actually get you the mid-1HR-bar values. The solution for this (getting a 1HR indicator value every 15M or 30M bar) is actually much, much more complex.


 

Jump to:  

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