Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By namika

Thread: Stoploss Strategy

  1. #1
    namika is offline Member
    Join Date
    Aug 2015
    Posts
    2
    Rep Power
    0

    Default Stoploss Strategy

    Hello!

    I'm learning Java to create strategies in Forex and as first strategy I wanted to write a program thats puts an stoploss to all the orders that i do manually, i wrote the code but it's not working. I wonder if you could have a look and tell me what is wrong and why.

    Thank you very much for your help!


    Java Code:
    package test;
    
    import com.dukascopy.api.Configurable;
    import com.dukascopy.api.IAccount;
    import com.dukascopy.api.IBar;
    import com.dukascopy.api.IConsole;
    import com.dukascopy.api.IContext;
    import com.dukascopy.api.IEngine;
    import com.dukascopy.api.IHistory;
    import com.dukascopy.api.IIndicators;
    import com.dukascopy.api.IMessage;
    import com.dukascopy.api.IOrder;
    import com.dukascopy.api.IStrategy;
    import com.dukascopy.api.ITick;
    import com.dukascopy.api.IUserInterface;
    import com.dukascopy.api.Instrument;
    import com.dukascopy.api.JFException;
    import com.dukascopy.api.Period;
    
    public class strat implements IStrategy{
    	private IEngine engine;
        private IConsole console;
        private IHistory history;
        private IContext context;
        private IIndicators indicators;
        private IUserInterface userInterface;
        private IOrder order;
     
    
    	    @Configurable("Instrument")
    	    public Instrument instrument = Instrument.EURUSD;
    	    @Configurable("periode")
    	    public Period period = Period.TEN_SECS;
    	    @Configurable("Stop Loss In Pips")
    	    public double StopLossInPips = 5;
    	    @Override
    	    public void onAccount(IAccount arg0) throws JFException {
    		// TODO Auto-generated method stub
    		
    	}
    
    	@Override
    	public void onBar(Instrument arg0, Period arg1, IBar arg2, IBar arg3) throws JFException {
    		// TODO Auto-generated method stub
    		
    	}
    
    	@Override
    	public void onMessage(IMessage arg0) throws JFException {
    		// TODO Auto-generated method stub
    		
    	}
    
    	@Override
    	public void onStart(IContext arg0) throws JFException {
    		// TODO Auto-generated method stub
    		  boolean isLong; 
    		  isLong = order.isLong();
    		  for ( IOrder order: getOrders( instrument)){ 
    		       if (isLong) {
    		            order.setStopLossPrice(order.getOpenPrice() - StopLossInPips);
    		       }else order.setStopLossPrice(order.getOpenPrice() + StopLossInPips);
    		    }
    		
    	}
    
    	@Override
    	public void onStop() throws JFException {
    		// TODO Auto-generated method stub
    		
    	}
    
    	@Override
    	public void onTick(Instrument arg0, ITick arg1) throws JFException {
    		// TODO Auto-generated method stub
    		
    	}
    
    }
    Last edited by namika; 08-27-2015 at 10:08 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Stoploss Strategy

    Please go through BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    namika is offline Member
    Join Date
    Aug 2015
    Posts
    2
    Rep Power
    0

    Default Re: Stoploss Strategy

    i hope now is fine
    DarrylBurke likes this.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Stoploss Strategy

    You have to give a lot more detail: you're using a third party library that presumably defines how those onstop(), onTick() onStart() etc. methods should be defined; also, the 'strategy' you mentioned isn't an OO strategy; it is something defined in the stock markets to (hopefully) minimize the amount of money you're about to lose ...

    kind regarrds,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  5. #5
    Join Date
    Aug 2015
    Location
    Northern California
    Posts
    31
    Rep Power
    0

    Default Re: Stoploss Strategy

    Also you said nothing about the error you are having i.e. what is broken? Along with that description we would like to see the error
    Everything great is a challenge and all the greats were challenged at one time just like us.

Similar Threads

  1. Question about design strategy for UIs
    By Digital Larry in forum AWT / Swing
    Replies: 11
    Last Post: 12-07-2014, 04:18 PM
  2. Need advice for debugging strategy
    By Digital Larry in forum New To Java
    Replies: 9
    Last Post: 08-04-2014, 05:16 PM
  3. Is this a good solution strategy?
    By hedonist in forum New To Java
    Replies: 2
    Last Post: 07-31-2009, 08:30 PM
  4. Strategy Pattern
    By mew in forum New To Java
    Replies: 0
    Last Post: 01-25-2008, 07:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •