|
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.
TestStopLoss |
[carlos]
|
Post subject: TestStopLoss |
Post rating: 0
|
Posted: Fri 06 Nov, 2009, 12:38
|
|
User rating: 0
Joined: Fri 09 Oct, 2009, 11:09 Posts: 4
|
Hi, I modified an strategy for setting a stop loss that you gave me.
The modification is not working, I still don´t know why. I don´t manage to run it on demo to find the mistake, and doing it on real account is risking money. Could you tell me why it doesn´t run on demo?
The strategy is supposed to set a stop loss n pips away of the entry price. I attach the code.
Thanks
Attachments: |
StopLoss.java [1.04 KiB]
Downloaded 615 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.
|
|
|
|
|
 |
API Support
|
Post subject: Re: Problems running strategy on demo. |
Post rating: 0
|
Posted: Fri 06 Nov, 2009, 15:27
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Hi, you should submit an order manually, after the strategy is started. Also you could submit an order when the strategy starts in your code. It could be done like this: package jforex;
import com.dukascopy.api.*; import com.dukascopy.api.IEngine.OrderCommand;
public class TestStopLoss implements IStrategy{ private IContext context; private IOrder order; @Configurable("Stop Loss price") public double slPrice; double entrada; boolean compra; public void onAccount(IAccount account) throws JFException { }
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar)throws JFException { }
public void onMessage(IMessage message) throws JFException { if (message.getType() == IMessage.Type.ORDER_FILL_OK) { entrada = message.getOrder().getOpenPrice(); compra = message.getOrder().isLong(); if (compra == true) { message.getOrder().setStopLossPrice(entrada-(slPrice)/10000); }else { message.getOrder().setStopLossPrice(entrada+(slPrice)/10000); } } }
public void onStart(IContext context) throws JFException { this.context = context; //submit order when strategy starts order = context.getEngine().submitOrder("MyOrder", Instrument.EURUSD, OrderCommand.BUY, 0.1); }
public void onStop() throws JFException { //close order if (order.getState() == IOrder.State.FILLED || order.getState() == IOrder.State.OPENED) { order.close(); } }
public void onTick(Instrument arg0, ITick arg1) throws JFException { } }
Attachments: |
TestStopLoss.jfx [2.6 KiB]
Downloaded 623 times
|
TestStopLoss.java [1.59 KiB]
Downloaded 599 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.
|
|
|
|
|
 |
[carlos]
|
Post subject: Re: Problems running strategy on demo. |
Post rating: 0
|
Posted: Fri 06 Nov, 2009, 16:00
|
|
User rating: 0
Joined: Fri 09 Oct, 2009, 11:09 Posts: 4
|
Hi, I know that I should open manually a position. Actually the program works asking how many pips away should it set the stop.
On real platform it does it. Then I still don´t know that, it doesn´t do what it is supposed to do.
But on demo platform, it doesn´t even ask me the distance. And when I open a position it doesn´t sets any stop. No message is coming,... so I think it doesnt work.
Thanks
|
|
|
|
 |
API Support
|
Post subject: Re: Problems running strategy on demo. |
Post rating: 0
|
Posted: Mon 09 Nov, 2009, 10:48
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Hi, please consider a step by step manual to be sure, that we are on the same page. - Open a JForex Demo platform https://www.dukascopy.com/client/demo/jclient/jforex.jnlp
- Use your login name and password to log in to a platform.
- With right mouse click on a Strategies tree choose the label New Strategy (Step1.png)
- Copy, paste a strategy code from website https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=7&t=1604 and to the JForex platform and then save it from the JForex (Step2.png)
- Press a button "F5" or the special "Compile" button in strategy editor to compile the strategy (Step3.png)
- Check an output message in console, to verify that the strategy is compiled successfully (Step4.png)
- In workspace from a Strategies tree choose the saved strategy. Press right mouse button to open a strategies menu and press Run (Step5.png).
- When a strategy is running, then in the Strategies tree it showed with the green label. Verify that a strategy in the Strategies tree is with the correct label (Step6.png). Also verify that a console, had been outputted, the message, that a particular strategy had been started (Step7.png).
- After a this particular strategy is launched, the message console will show all done changes (Step8.png). From a picture we see, that the console shows us three messages:
- Order FILLED at 1.4959 USD (#15917436 BUY 0.1 mil. EUR/USD @ MKT MAX SLIPPAGE 0.0005) - Position #6146159 - a particular position is filled;
- Order ACCEPTED: #15917437 STOP LOSS SELL 0.0000000000 mil. EUR/USD @ MKT IF BID <= 1.4958 - Position #6146159 - a new stop loss price for the particular position is accepted;
- Order FILLED at 1.4958 USD (#15917437 STOP LOSS SELL 0.1 mil. EUR/USD @ MKT IF BID <= 1.4958) - Position #6146159 - a particular position with the particular stop loss price is filled;
Attachments: |
Step1.PNG [39.23 KiB]
Downloaded 877 times
|
Step2.PNG [54.16 KiB]
Downloaded 780 times
|
Step3.PNG [56.97 KiB]
Downloaded 798 times
|
Step4.PNG [5.45 KiB]
Downloaded 786 times
|
Step5.PNG [60.54 KiB]
Downloaded 800 times
|
Step6.PNG [4.74 KiB]
Downloaded 776 times
|
Step7.PNG [1.96 KiB]
Downloaded 744 times
|
Step8.PNG [11.47 KiB]
Downloaded 757 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.
|
|
|
|
|
 |
[carlos]
|
Post subject: Re: Problems running strategy on demo. |
Post rating: 0
|
Posted: Mon 09 Nov, 2009, 15:55
|
|
User rating: 0
Joined: Fri 09 Oct, 2009, 11:09 Posts: 4
|
Thanks a lot. I don´t know why but suddenly it works, on demo and on real account. And, moreover, is working properly  Anyway thank you very much for all the work of posting everything step by step even with screenshots. It was very nice from you.
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|