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.

Strategy works on History Test but no trades on Demo Run
 Post subject: Strategy works on History Test but no trades on Demo Run Post rating: 0   New post Posted: Fri 25 Mar, 2011, 01:36 

User rating: -
Please help!!!......the historical backtest gives me trades...but the demo local run no trades at all.....help with this code would be appreciated!!!.



package pinto ;
import java.util.*;
import com.dukascopy.api.*;
public class pinto  implements IStrategy { 
    private IEngine engine;
    private IConsole console;
    private IUserInterface userInterface;
    private IAccount account;       
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    public int    SL = 30;
    public int    TP =17;   
    public Instrument instrument = Instrument.GBPUSD;
   public Period period = Period.FIFTEEN_MINS;
   public double SLIPPAGE = 5;
   public int counter = 0;
   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();       
    }



    public void onStop() throws JFException {   
               
    }

   
           
    public void onAccount(IAccount account) throws JFException {
        this.account = account;
    }


    public void onMessage(IMessage message) 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 != this.instrument) return;
        if (period != this.period) return;
             double Lot = .50;
        double PIP = instrument.getPipValue();       
        int pos=0;
        for (IOrder order : engine.getOrders(instrument)) {
            if (order.getState() == IOrder.State.FILLED) {
                if (order.isLong())  pos=1;                                 
                      else                 pos=-1;                                                                               
                if (SL>0 && order.getStopLossPrice()==0) order.setStopLossPrice(order.getOpenPrice() - pos*PIP*SL);               
                if (TP>0 && order.getTakeProfitPrice()==0) order.setTakeProfitPrice(order.getOpenPrice() + pos*PIP*TP);
            }   
        }               
                     
                     
                     
        if (pos==0) {
               double macd0 = indicators.macd(Instrument.GBPUSD, Period.TWENTY_MINS,
                OfferSide.BID, IIndicators.AppliedPrice.CLOSE, 2,3,3, 0)[0];
        double signal0 = indicators.macd(Instrument.GBPUSD,
                Period.TWENTY_MINS, OfferSide.BID,
                IIndicators.AppliedPrice.CLOSE, 2,3,3, 0)[1];
        double macd1 = indicators.macd(Instrument.GBPUSD, Period.TWENTY_MINS,
                OfferSide.BID, IIndicators.AppliedPrice.CLOSE, 2,3, 3, 1)[0];
        double signal1 = indicators.macd(Instrument.GBPUSD,
                Period.TWENTY_MINS, OfferSide.BID,
                IIndicators.AppliedPrice.CLOSE, 2, 3,3, 1)[1];
           
                         Date datetime = new Date(askBar.getTime());
           int day  = datetime.getDate();
        if   ((macd0 > signal0 && macd1 < signal1))
                 engine.submitOrder("S"+(day*100+counter++), instrument, IEngine.OrderCommand.SELL, Lot, 0, SLIPPAGE);       
           
             
                    if   ((macd0 < signal0 && macd1 > signal1))         
                  engine.submitOrder("B"+(day*100+counter++), instrument, IEngine.OrderCommand.BUY, Lot, 0, SLIPPAGE);
        }

    }
   
}


 
 Post subject: Re: Strategy works on History Test but no trades on Demo Run Post rating: 0   New post Posted: Thu 31 Mar, 2011, 02:30 

User rating: 1
Joined: Fri 26 Mar, 2010, 19:19
Posts: 116
Location: Canada
try adding a few println() functions to verify your states


 

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