Dukascopy
 
 
Wiki JStore Search Login

Dynamic TP?
 Post subject: Dynamic TP? Post rating: 0   New post Posted: Tue 15 Apr, 2014, 17:16 

User rating: 0
Joined: Fri 04 Apr, 2014, 20:32
Posts: 10
Location: FranceFrance
Hi everyone,

So I've managed to create a Visual JF strategy, and all's been working fine so far. Now however, I'd like to change its TP from a fixed value (defaultTakeProfit) to a dynamic value (price reaching a Bollinger Band).

So in this ex a sell position is being opened by the strategy, and I want that position to be closed whenever price reaches the lower band (on M5).
Here's what I've come up with, but it's obviously not good since when I run the strategy, though price reaches the lower band, the position still stays opened:
Image

Thanks in advance guys.

;)


 
 Post subject: Re: Dynamic TP? Post rating: 0   New post Posted: Wed 16 Apr, 2014, 10:41 
Visual JForex expert at Dukascopy
User avatar

User rating: 288
Joined: Thu 18 Apr, 2013, 09:26
Posts: 1496
Location: Switzerland, Geneva
Greetings,

please take a look to the attached sample that implements a dynamic TP based on the lower value of BBands.

Thanks


Attachments:
TPdynamicSample.vfs [26.08 KiB]
Downloaded 115 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: Dynamic TP? Post rating: 0   New post Posted: Wed 16 Apr, 2014, 12:04 

User rating: 0
Joined: Fri 04 Apr, 2014, 20:32
Posts: 10
Location: FranceFrance
Hi, and thanks for the answer.

That's what I had initially tried to do, but when I try to slide the lower band parameter (from the BBANDS block) to the Take Profit (of the Open at Market block), it's not accepted and I get an Alert Message: "Set variable: You can not place variable with this type in this place".
I would assume it's because Lower Band is a Double parameter while it'd seem that by default, Take Profit is an Integer parameter.

But seeing that in your block, both Stop Loss and Take Profit have been set to accept Double parameters (and not Integer ones anymore), my question would be: how do you switch in Open at Market from TP and SL accepting Integer parameters to accepting Double ones?

Thanks in advance.


 
 Post subject: Re: Dynamic TP? Post rating: 0   New post Posted: Wed 16 Apr, 2014, 12:56 
Visual JForex expert at Dukascopy
User avatar

User rating: 288
Joined: Thu 18 Apr, 2013, 09:26
Posts: 1496
Location: Switzerland, Geneva
Hi,

Excellent eye for details !
Actually I should have shown this in my previous screenshot but here is the trick:

Image


Attachments:
DoubleVsInteger PipsVsPrice.jpg [68.89 KiB]
Downloaded 427 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: Dynamic TP? Post rating: 0   New post Posted: Wed 16 Apr, 2014, 18:26 

User rating: 0
Joined: Fri 04 Apr, 2014, 20:32
Posts: 10
Location: FranceFrance
Hi again,

Thanks, now I'll know how to switch from one parameter to the other.

That unfortunately didn't solve my initial problem though (which was to get a dynamic TP equal to the ever-changing value of the lower band). However, what I'm getting here is that the moment the position is opened, the strategy takes the value of the lower band at that precise moment, and keeps that value as a fixed TP for the future.

I ran the strategy you had given me as well (in case I was missing something), but I'm getting the same problem: TP is not the dynamic value of the lower band, but the fixed value of the band at the moment the position was opened.

Thanks in advance ;)


 
 Post subject: Re: Dynamic TP? Post rating: 0   New post Posted: Tue 22 Apr, 2014, 12:58 

User rating: 0
Joined: Fri 04 Apr, 2014, 20:32
Posts: 10
Location: FranceFrance
Ok, after reflecting a bit on it, found my mistake actually, and now got it to work.

Just realized how the whole thing seems to work: on every new candle, the whole strategy's just being run entirely again, and so, the conditions to open the position not being met again on the following candles, the remainder of the strategy after the Open at Market block won't be in play on those future candles anymore.

So I just moved these conditions to the beginning of the strategy, using an If block:
- If Open Positions=0: steps to open a position,
- If Open Positions>0: steps to close the existing position (based on the value of each new, future candle, until one reaches the desired conditions).


 
 Post subject: Re: Dynamic TP? Post rating: 0   New post Posted: Tue 22 Apr, 2014, 18:08 
Visual JForex expert at Dukascopy
User avatar

User rating: 288
Joined: Thu 18 Apr, 2013, 09:26
Posts: 1496
Location: Switzerland, Geneva
Greetings,

Well done !
Otherwise you can add another IF condition stating once the position created, a check of the lower value Vs the current market price are met then close the position..

Hope this helps


 
 Post subject: Re: Dynamic TP? Post rating: 0   New post Posted: Wed 23 Apr, 2014, 18:48 

User rating: 0
Joined: Fri 04 Apr, 2014, 20:32
Posts: 10
Location: FranceFrance
Hi,

Yeah, that's what I did, basically.
However, to be able to close the position at the exact moment price reaches the band (that is, for the strategy to compare current market price with the current value of the band at all times, and not just at the beginning of each new M5 candle), I had to link that part to onTick StartPoint:

Image

Or am I missing something and this can actually be done with the rest of the strategy (which relies on M5 candles and is therefore linked to onCandle StartPoint)?

Thanks ;)


 
 Post subject: Re: Dynamic TP? Post rating: 0   New post Posted: Thu 24 Apr, 2014, 01:06 
Visual JForex expert at Dukascopy
User avatar

User rating: 288
Joined: Thu 18 Apr, 2013, 09:26
Posts: 1496
Location: Switzerland, Geneva
Hi there,

Your initial idea was actually to close dynamically a given position when lower/upper band crosses the spot price, which we can call 'a dynamic exit' rather then dynamic TP. The use of the word Take Profit led me to think at the level of linking an order to your position, which is basically submitted at the level of the position creation.
Now, your latest screenshot is absolutely correct: you have to use the OnTick start point in order to make sure the price verification is made correctly and on high refreshing rate (tick prices). But working OnCandle only is also possible but as it will depend on the candle prices (either high/Low/Open/Close) the closing command will be executed in the next candle.

Attached an example of what I described.
Thanks


Attachments:
TPdynamicSample.vfs [29.05 KiB]
Downloaded 116 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: Dynamic TP? Post rating: 0   New post Posted: Thu 24 Apr, 2014, 13:02 

User rating: 0
Joined: Fri 04 Apr, 2014, 20:32
Posts: 10
Location: FranceFrance
Hi,

Yes, initially I was hoping this could be implemented within the Take Profit section of the Open at Market block, hence the title of the topic.
But then I realized doing so could only implement a fixed TP (the value of the band at the exact moment the position is opened, which is not what I was looking for).

So to have a dynamic "TP", it required, as you mentioned, to actually be a dynamic exit, which, as discussed in my last two posts, could be done by either moving the Close and Cancel Position steps at the beginning of the strategy on the onCandle StartPoint (to have a dynamic value of the band every five minutes) or to the onTick StartPoint (to have a dynamic value of the band for every tick).

But yeah, I guess that the way onCandle works, one has to use onTick too at some point to be able to exit the very second a desired dynamic value is reached.

Thanks for your input in this topic by the way ;)


 
 Post subject: Re: Dynamic TP? Post rating: 0   New post Posted: Fri 25 Apr, 2014, 17:29 
Visual JForex expert at Dukascopy
User avatar

User rating: 288
Joined: Thu 18 Apr, 2013, 09:26
Posts: 1496
Location: Switzerland, Geneva
Hi there,

You're welcome,
what you actually described could be called: trailing TP that follows the lower band.
Please have a look on the attached sample and let us know if it meet your need.

Thanks


Attachments:
TPdynamicSample.vfs [29.65 KiB]
Downloaded 128 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: Dynamic TP? Post rating: 0   New post Posted: Sat 26 Apr, 2014, 12:30 

User rating: 0
Joined: Fri 04 Apr, 2014, 20:32
Posts: 10
Location: FranceFrance
Hi,

Yeah my criteria for dynamically exiting on the M5 candles are a bit different actually (as reaching the fixed value of the lower band (taken at the beginning of the current candle) doesn't necessarily mean that price will have actually reached the dynamic value of the band), but yeah, what you did is as close as it gets for an onCandle Startpoint, and is pretty similar, in terms of reasoning, and block structure, to what I did actually.

But once again I got it to work exactly like I wanted for both cases (whether I want to dynamically exit on an M5 candle (only using onCandle StartPoint) or on a tick basis (using onTick StartPoint for the exit as shown in my last screenshot)), so it's all good ;)

Thanks again.


 

Jump to:  

  © 1998-2024 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