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.

Order Rejected - Invalid price format
 Post subject: Order Rejected - Invalid price format Post rating: 0   New post Posted: Thu 29 Mar, 2012, 05:45 

User rating: 0
Joined: Sun 05 Jun, 2011, 15:03
Posts: 1
Location: ItalyItaly
Hi Guys, I have some problem with this strategy...
I dont know why my orders has been rejected for price format.

Some solution?

package jforex.strategies;
 
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Queue;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.awt.Color;
import java.text.DecimalFormat;
import com.dukascopy.api.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Calendar;
import java.util.TimeZone;
 
import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IOrder.State;
 
//if we use console, we need @RequiresFullAccess for JForex-API 2.6.38 with java versions > 1.6.0_26
@RequiresFullAccess
public class PendingStrategyMATRV100 implements IStrategy {
   
   @Configurable("Instrument")
   public Instrument instrument = Instrument.EURUSD;   
   @Configurable("Period")
   public Period period = Period.FIVE_MINS;
   @Configurable("Distance Pip")
   public int Distance = 11;
   @Configurable("StopLoss")
   public int stopLossPips = 50;   
   @Configurable("TakeProfit")
   public int takeProfitPips = 15;                   
   @Configurable("Lots Size")
   public double amount = 0.1;
   @Configurable("Moving Average")
   public int Period_MA = 50;

   IOrder ordreBuy, ordreSell = null;
   
        private IContext context = null;
        private IEngine engine = null;     
        private IHistory history = null;
        private IConsole console = null;
        private IIndicators indicators = null;
        public IAccount acc = null;
   

   public double pip;   
   
   private Queue<IOrder> justFilledOrders = new ConcurrentLinkedQueue<IOrder>();
   
   //for logging
   @SuppressWarnings("serial")
   public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") {
      {
         setTimeZone(TimeZone.getTimeZone("GMT"));
      }
   };
   
   public void onStart(IContext context) throws JFException {
      this.context = context;       
      this.engine = context.getEngine();     
      this.history = context.getHistory();
      this.console = context.getConsole();
      this.indicators = context.getIndicators();     
      }
 
   public void onAccount(IAccount account) throws JFException {     
   }
 
   public void onMessage(IMessage message) throws JFException {
      //log messages to see what happens
      console.getOut().println(sdf.format(message.getCreationTime()) + " " +message);       
      //in JForex-API 2.6.38 one can't change orders in onMessage, so we enqueue order change request and process it in next onTick
      if(message.getType() == IMessage.Type.ORDER_FILL_OK){
         justFilledOrders.add(message.getOrder());
      }
   }
 
   public void onStop() throws JFException {
   }
 
   public void onTick(Instrument instrument, ITick tick) throws JFException {
   
    //----------------------------------------
       pip = instrument.getPipValue();
 
       //filter ticks
       if(instrument != this.instrument){
          return;
       }
       
       //process just filled orders
       while(!justFilledOrders.isEmpty()){
          IOrder order = justFilledOrders.poll();
          if(ordreBuy == order){
             ordreBuy.setStopLossPrice(ordreBuy.getOpenPrice()-stopLossPips*pip);
             ordreBuy.setTakeProfitPrice(ordreBuy.getOpenPrice()+takeProfitPips*pip);
          }
          if(ordreSell == order){
             ordreSell.setStopLossPrice(ordreSell.getOpenPrice()+stopLossPips*pip);
             ordreSell.setTakeProfitPrice(ordreSell.getOpenPrice()-takeProfitPips*pip);
          }
       }
   }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar)throws JFException {
   
       //filter bars
       if(period != this.period || instrument != this.instrument){
          return;
       }

       IBar prevBar = history.getBar(this.instrument, period, OfferSide.BID, 1);
       double MA = indicators.ma(instrument, period, OfferSide.BID, IIndicators.AppliedPrice.CLOSE, Period_MA, IIndicators.MaType.EMA, 0);
 
       double Max = prevBar.getHigh();
       double Min = prevBar.getLow();
       double priceBUY  = MA-Distance*pip;
       double priceSELL = MA+Distance*pip;
       
       List<IOrder> ordres = engine.getOrders();
      if(ordres.isEmpty()){
          ordreBuy = engine.submitOrder("BUYLimit", instrument, OrderCommand.BUYLIMIT, amount, priceBUY);
          ordreSell = engine.submitOrder("SELLLimit", instrument, OrderCommand.SELLLIMIT, amount, priceSELL);
      }
       if(ordreBuy.getState() != null || ordreSell.getState() != null){
          if(ordreBuy.getState() == State.OPENED){
             ordreBuy.setOpenPrice(priceBUY);
          }
          if(ordreSell.getState() == State.OPENED){
             ordreSell.setOpenPrice(priceSELL);
          }
          if(ordreBuy.getState() == State.FILLED && ordreSell.getState() == State.OPENED){
             engine.getOrder("SELLLimit").close();
          }
          if(ordreSell.getState() == State.FILLED && ordreBuy.getState() == State.OPENED){
             engine.getOrder("BUYLimit").close();
          }
       }
    }
}


Thanks a lot!


Attachments:
PendingStrategyMATRV100.java [4.97 KiB]
Downloaded 258 times
Print.PNG [27.23 KiB]
Downloaded 376 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: Order Rejected - Invalid price format Post rating: 0   New post Posted: Thu 29 Mar, 2012, 07:45 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The message already says what is the problem - you are trying to submit order with an increment less than 0.1 pip, consider roundint the prices in the following way:
//..
   private double round(double amount, int decimalPlaces) {
      return (new BigDecimal(amount)).setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP).doubleValue();
   }
        double priceBUY  = round(MA-Distance*pip,5);
        double priceSELL = round(MA+Distance*pip,5);


 

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