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.

how to code this ?? Stops related
 Post subject: how to code this ?? Stops related Post rating: 0   New post Posted: Wed 15 Dec, 2010, 04:28 

User rating: 0
Joined: Wed 15 Dec, 2010, 03:57
Posts: 14
Hi,

I'm new here and new with Java also....
I'm trying to port my strategy from MT4 and code it in Java....

I have few questions/problems that I have a hard time to figure them out...

----------------------------------------------------------------------------------------------------------
1st; in my submitOrder command I'm using stops and profit targets...
The code I have is;

tick.getAsk() +OR- instrument.getPipValue() * myvalue


My question is; how to code that to get it rounded to 0,5 pips ???

The code isn't triggering any errors in testing....however I'm aware of this specific requirement of JForex....
I found this code: https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=5&t=1661&hilit=rounding but
I don't know how to integrate into my Strategy and don't fully understand it....

-----------------------------------------------------------------------------------------------------------
2nd; My questioning is coming from the fact that my stop is set to 80 pips....and my Strategy work on daily chart....
However the StopLoss even if triggered, closes the trade with +200 or even +300pips loss.... sometimes it does after 80s...maybe 90s which I find ok...
but 200-300 is way off....

Does someone know why is this happening???.....is this related to my question above??? but then why it is triggered anyways ???

-----------------------------------------------------------------------------------------------------------
3rd; If the 2nd question behavior is normal; due to whatever reason, is it possible that I code an orderclose command or something similar,
which will instate a "new" stop just a bit "worst" that the original one and will close the order immediately when hit....

I explain:
1-let say my original stop is 80pips....but somehow sometimes it goes to 300.....
2-I will put another stop trough a function, at 100pips which triggers immediate orderclose....will this work ??
3-Will this second stop, if triggered, affect the original one in such a way that the original one will trigger anyways in 200-300 pips like it happens sometimes.....
but in this case instead of closing an opened order (which in this case was closed by 2nd stop already) it will open a opposite one ????

-----------------------------------------------------------------------------------------------------------
Thanks in advance for any help and explanations


 
 Post subject: Re: how to code this ?? Stops related Post rating: 0   New post Posted: Wed 15 Dec, 2010, 15:50 

User rating: 0
Joined: Wed 15 Dec, 2010, 03:57
Posts: 14
I think I found an answer to my 1st question:

Math.round....


but my 2nd and 3rd remain unanswered...


 
 Post subject: Re: how to code this ?? Stops related Post rating: 0   New post Posted: Wed 15 Dec, 2010, 20:31 

User rating: 0
Joined: Wed 15 Dec, 2010, 03:57
Posts: 14
I think I found the 2nd answer...
Support wrote:
Quote:
When NOT using the tick testing mode, the actual pips where the profit is taken or where the loss is taken varies greatly.

When the Historical tester runs using bars price, then the historical tester assume tick which comes on bar close/open. That's why the take profit has different results.

and the third is quite irrelevant now...


 
 Post subject: Re: how to code this ?? Stops related Post rating: 0   New post Posted: Thu 16 Dec, 2010, 16:21 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Cyps3178 wrote:
Hi,
2nd; My questioning is coming from the fact that my stop is set to 80 pips....and my Strategy work on daily chart....
However the StopLoss even if triggered, closes the trade with +200 or even +300pips loss.... sometimes it does after 80s...maybe 90s which I find ok...
but 200-300 is way off....

Does someone know why is this happening???.....is this related to my question above??? but then why it is triggered anyways ???



Hi,
Please be sure that order has stop loss after submitting.


 
 Post subject: Re: how to code this ?? Stops related Post rating: 0   New post Posted: Thu 16 Dec, 2010, 18:54 

User rating: 0
Joined: Wed 15 Dec, 2010, 03:57
Posts: 14
Support wrote:
Cyps3178 wrote:
Hi,
2nd; My questioning is coming from the fact that my stop is set to 80 pips....and my Strategy work on daily chart....
However the StopLoss even if triggered, closes the trade with +200 or even +300pips loss.... sometimes it does after 80s...maybe 90s which I find ok...
but 200-300 is way off....

Does someone know why is this happening???.....is this related to my question above??? but then why it is triggered anyways ???



Hi,
Please be sure that order has stop loss after submitting.


Thanks Support,

Yes it did...however as I said I used ''DAILY'' and ''Close Candle'' settings that's why the results were like that...
When I test with 'tick' or '10sec' the SL is never bigger than 93, or so...

In the same time,

I would like to ask how to ensure that I have only 1 trade opened in the same time ???


 
 Post subject: Re: how to code this ?? Stops related Post rating: 0   New post Posted: Fri 17 Dec, 2010, 15:19 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
To determine submitted order count, please use the following code:
int count = engine.getOrders().size()


 
 Post subject: Re: how to code this ?? Stops related Post rating: 0   New post Posted: Fri 17 Dec, 2010, 17:13 

User rating: 0
Joined: Wed 15 Dec, 2010, 03:57
Posts: 14
I actually used this as a code;

int myorders = 0;
        for (IOrder order : engine.getOrders()) {
            myorders++;
        }


It works in tester..
However....when I try on live chart in demo..
It opens 3 simultaneous orders....
I think it has to do something with the IOrder.State.....I can't find a code for an OPENED order....I've tried isLong...but have hard time to code that....

I don't know what's the purpose of the size() function ?? "in API:Returns number of the graphical objects on the chart"
Therefore I can't logically integrate it to my code....

Can someone explain it to me plz ???

Thx in advance


 
 Post subject: Re: how to code this ?? Stops related Post rating: 0   New post Posted: Tue 21 Dec, 2010, 11:15 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
engine.getOrders() returns the list of orders in IOrder.State.CREATED, IOrder.State.OPENED and IOrder.State.FILLED state.
engine.getOrders().size() returns the number of elements in this list - the number of orders in IOrder.State.CREATED, IOrder.State.OPENED and IOrder.State.FILLED state.


 
 Post subject: Re: how to code this ?? Stops related Post rating: 0   New post Posted: Wed 22 Dec, 2010, 15:59 

User rating: 0
Joined: Wed 15 Dec, 2010, 03:57
Posts: 14
Support wrote:
Hi,
engine.getOrders() returns the list of orders in IOrder.State.CREATED, IOrder.State.OPENED and IOrder.State.FILLED state.
engine.getOrders().size() returns the number of elements in this list - the number of orders in IOrder.State.CREATED, IOrder.State.OPENED and IOrder.State.FILLED state.



Thx,

That clarifies,

I would also like to know if order is closed......would the size() be equal to zero.....or it adds up every time an order is Created, Opened and Filled.....???


 
 Post subject: Re: how to code this ?? Stops related Post rating: 0   New post Posted: Mon 27 Dec, 2010, 16:38 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Cyps3178 wrote:
Support wrote:
Hi,
engine.getOrders() returns the list of orders in IOrder.State.CREATED, IOrder.State.OPENED and IOrder.State.FILLED state.
engine.getOrders().size() returns the number of elements in this list - the number of orders in IOrder.State.CREATED, IOrder.State.OPENED and IOrder.State.FILLED state.



Thx,

That clarifies,

I would also like to know if order is closed......would the size() be equal to zero.....or it adds up every time an order is Created, Opened and Filled.....???


The engine.getOrders().size() returns number of orders that is in the Created, Opened and Filled state. If all order is closed, then the size() method will return 0.


 

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