Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

Dynamic TP?
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=146&t=51083
Page 1 of 1

Author:  maurice5220 [ Tue 15 Apr, 2014, 17:16 ]
Post subject:  Dynamic TP?

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.

;)

Author:  amine_chourou [ Wed 16 Apr, 2014, 10:41 ]
Post subject:  Re: Dynamic TP?

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

Author:  maurice5220 [ Wed 16 Apr, 2014, 12:04 ]
Post subject:  Re: Dynamic TP?

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.

Author:  amine_chourou [ Wed 16 Apr, 2014, 12:56 ]
Post subject:  Re: Dynamic TP?

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

Author:  maurice5220 [ Wed 16 Apr, 2014, 18:26 ]
Post subject:  Re: Dynamic TP?

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 ;)

Author:  maurice5220 [ Tue 22 Apr, 2014, 12:58 ]
Post subject:  Re: Dynamic TP?

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).

Author:  amine_chourou [ Tue 22 Apr, 2014, 18:08 ]
Post subject:  Re: Dynamic TP?

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

Author:  maurice5220 [ Wed 23 Apr, 2014, 18:48 ]
Post subject:  Re: Dynamic TP?

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 ;)

Author:  amine_chourou [ Thu 24 Apr, 2014, 01:06 ]
Post subject:  Re: Dynamic TP?

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 117 times

Author:  maurice5220 [ Thu 24 Apr, 2014, 13:02 ]
Post subject:  Re: Dynamic TP?

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 ;)

Author:  amine_chourou [ Fri 25 Apr, 2014, 17:29 ]
Post subject:  Re: Dynamic TP?

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 129 times

Author:  maurice5220 [ Sat 26 Apr, 2014, 12:30 ]
Post subject:  Re: Dynamic TP?

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.

  Page 1 of 1