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.

Complinfg the Simple Feed Strategy
 Post subject: Complinfg the Simple Feed Strategy Post rating: 0   New post Posted: Fri 14 Dec, 2012, 13:34 

User rating: 0
Joined: Mon 03 Dec, 2012, 09:55
Posts: 30
I have included code from the simple feed strategy into my onStart function (see below) and I get an error on compliation

12:27:19 Cannot refer to a non-final variable context inside an inner class defined in a different method

what does this mean?

THANKS



@Override
public void onStart(IContext context) throws JFException {

this.engine = context.getEngine();
this.console = context.getConsole();
this.history = context.getHistory();
this.context = context;
this.indicators = context.getIndicators();
this.userInterface = context.getUserInterface();

IFeedDescriptor rangeBarFeedDescriptor = new RangeBarFeedDescriptor(Instrument.EURUSD, PriceRange.TWO_PIPS, OfferSide.ASK);
context.subscribeToFeed(rangeBarFeedDescriptor, new IFeedListener() {
@Override
public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) {
context.getConsole().getOut().println("range bar completed: " + feedData + " of feed: " + feedDescriptor);
}
});


}


 
 Post subject: Re: Complinfg the Simple Feed Strategy Post rating: 0   New post Posted: Fri 14 Dec, 2012, 13:58 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You need to make both onFeedData parameters final. Consider using a java IDE in order to get instant fix suggestions in such cases, see:
https://www.dukascopy.com/wiki/#Use_in_Eclipse
https://www.dukascopy.com/wiki/#Use_in_NetBeans


 
 Post subject: Re: Complinfg the Simple Feed Strategy Post rating: 0   New post Posted: Fri 14 Dec, 2012, 14:24 

User rating: 0
Joined: Mon 03 Dec, 2012, 09:55
Posts: 30
Thanks

I'd really like to jst use the JFOREX IDe and making the parameters final does not help

public void onFeedData(final IFeedDescriptor feedDescriptor, final ITimedData feedData) {

context.getConsole().getOut().println("range bar completed: " + feedData + " of feed: " + feedDescriptor);

try { ..............................


 
 Post subject: Re: Complinfg the Simple Feed Strategy Post rating: 0   New post Posted: Fri 14 Dec, 2012, 14:38 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
murfinp wrote:
I'd really like to jst use the JFOREX IDe
It's up to you, but using ,for example, Eclipse IDE will at the very least save you time, which you need to wait on our response on this compile-time issue.
murfinp wrote:
and making the parameters final does not help
Please provide the full example strategy.


 
 Post subject: Re: Complinfg the Simple Feed Strategy Post rating: 0   New post Posted: Fri 14 Dec, 2012, 14:42 

User rating: 0
Joined: Mon 03 Dec, 2012, 09:55
Posts: 30
Hi Attached the bones of the strategy

I just need to pick ema values for last 3 bars on renko .. then place and close orders ... thanks but would also like to be able to print stuff out in console window

Thankyou


======================================

package jforex;

import java.util.*;

import com.dukascopy.api.*;
import com.dukascopy.api.feed.*;
import com.dukascopy.api.feed.util.*;
import com.dukascopy.api.IIndicators.AppliedPrice;
import com.dukascopy.api.indicators.IIndicator;
import com.dukascopy.api.indicators.IndicatorInfo;



public class RenkoStrategy implements IStrategy {
   
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
   
    @Configurable("Instrument 1")
    public Instrument currInstrument = Instrument.EURUSD;
   

    public void onStart(IContext context) throws JFException {
       
       

        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();
       
         IFeedDescriptor RenkofeedDescriptor = new RenkoFeedDescriptor(currInstrument, PriceRange.FIVE_PIPS, OfferSide.BID);
       
        context.subscribeToFeed(RenkofeedDescriptor,  new IFeedListener() {

            public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) {
               
               // context.getConsole().getOut().println("range bar completed: " + " of feed: " + feedDescriptor);
               
                try {
                                 
                Object[] emaFeed0 = indicators.calculateIndicator(feedDescriptor, new OfferSide[] { OfferSide.BID }, "EMA",new AppliedPrice[] { AppliedPrice.CLOSE }, new Object[] { 13 }, 0);             
                Object[] emaFeed1 = indicators.calculateIndicator(feedDescriptor, new OfferSide[] { OfferSide.BID }, "EMA",new AppliedPrice[] { AppliedPrice.CLOSE }, new Object[] { 13 }, 1);
                Object[] emaFeed2 = indicators.calculateIndicator(feedDescriptor, new OfferSide[] { OfferSide.BID }, "EMA",new AppliedPrice[] { AppliedPrice.CLOSE }, new Object[] { 13 }, 2);
                             
           
             } catch (JFException e) {
             }
             

            }
        });

     
    }

    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 {
    }
}


 
 Post subject: Re: Complinfg the Simple Feed Strategy Post rating: 0   New post Posted: Fri 14 Dec, 2012, 15:52 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
murfinp wrote:
I just need to pick ema values for last 3 bars on renko
https://www.dukascopy.com/wiki/#Indicator_Calculation/Calculate_on_price_feed_by_candle_interval
murfinp wrote:
then place
https://www.dukascopy.com/wiki/#Set_Market_Order
murfinp wrote:
and close orders
https://www.dukascopy.com/wiki/#Close_Orders
murfinp wrote:
but would also like to be able to print stuff out in console window
https://www.dukascopy.com/wiki/#IConsole/Logging_values


 

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