Dukascopy
 
 
Wiki JStore Search Login

how to close open position
 Post subject: how to close open position Post rating: 0   New post Posted: Wed 08 May, 2013, 16:24 
User avatar

User rating: 0
Joined: Sat 04 May, 2013, 16:08
Posts: 17
Location: ItalyItaly
hi
I tried practicing a very simple strategy based on MA crosses, I tried like crazy to find the way to close an open position once the MA cross back again. Unfortunately I can't get it to work.

I attached the strategy, please help..

thanks


Attachments:
ema6ema24cross.vfs [42.73 KiB]
Downloaded 266 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: how to close open position Post rating: 0   New post Posted: Thu 09 May, 2013, 09:25 
User avatar

User rating: 6
Joined: Fri 12 Apr, 2013, 14:08
Posts: 88
Location: FranceFrance
Your strategies looks very complicated :mrgreen: .

I will have a look at it.


 
 Post subject: Re: how to close open position Post rating: 0   New post Posted: Thu 09 May, 2013, 09:26 
Visual JForex expert at Dukascopy
User avatar

User rating: 27
Joined: Fri 03 May, 2013, 18:25
Posts: 366
Location: GermanyGermany
looks good


 
 Post subject: Re: how to close open position Post rating: 0   New post Posted: Thu 09 May, 2013, 10:40 
User avatar

User rating: 6
Joined: Fri 12 Apr, 2013, 14:08
Posts: 88
Location: FranceFrance
Could you explain step by step what your srategy is suppose to do please?

I just want to be sure that what I read in your blocks corresponds to what you where trying to do.


 
 Post subject: Re: how to close open position Post rating: 1   New post Posted: Thu 09 May, 2013, 10:59 
User avatar

User rating: 7
Joined: Wed 04 Jul, 2012, 02:40
Posts: 109
Location: Australia, Melbourne
Hi Nic,

I've fixed it up for you - some of the logic seemed to be wrong with the EMA cross - ie. when the fast ema was going above the slow ema it was selling (unless you want this as a mean reversion system - look up Howard Brandy mean reversion systems for some light reading lol - its a top book).

Also I've added in your exit on opposite cross. Some of things I would have changed is- timeframe to a global variable, I'd add in a fixed pip stoploss (define your risk), Position sizing... we'll I could do alot - but then it wouldnt be your system ;)

I've also changed the system to on bar, not on tick - and also steped the number of bars back 1 bar, as you will find with MA's a lot of false entry/exit signals due to the MA's crossing & uncrossing as the change tick by tick. I doubt you wanted this, and I guess you were looking for cleaner signals.


Attachments:
ema6ema24cross.vfs [48.4 KiB]
Downloaded 300 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: how to close open position Post rating: 0   New post Posted: Thu 09 May, 2013, 13:54 
User avatar

User rating: 6
Joined: Fri 12 Apr, 2013, 14:08
Posts: 88
Location: FranceFrance
Well done you! :idea:

That deserves a +! ;)


 
 Post subject: Re: how to close open position Post rating: 0   New post Posted: Thu 09 May, 2013, 22:13 
User avatar

User rating: 0
Joined: Sat 04 May, 2013, 16:08
Posts: 17
Location: ItalyItaly
hello, thanks very much!!!!

it works now, like I wanted. I know it's not a profitable strategy, but my goal was to try to understand how to make it work.
I just did like in the tutorial video showed, exactly the same way, but wanted to add the feature: "close the current position and open the opposite as soon as the EMAS cross back from down to up and vice-versa". I just couldn't understand how to close an open position, I tried all day in many different ways, but I noticed that your approach is totally differnt than what was showed in the tutorial video.

but there something I don't understand: in the second box, the "ema6before" whyt did you set the variable "Time period TempVar404"?

thank you very much!!!!

NIC


 
 Post subject: Re: how to close open position Post rating: 0   New post Posted: Thu 09 May, 2013, 22:25 
User avatar

User rating: 7
Joined: Wed 04 Jul, 2012, 02:40
Posts: 109
Location: Australia, Melbourne
nicbrunelli wrote:
hello, thanks very much!!!!]

but there something I don't understand: in the second box, the "ema6before" whyt did you set the variable "Time period TempVar404"?



Hi Nic,

I May have deleted that ema block and remade it. The time period temvar404 is automatically generated by VJF - you are free to change it back. It shouldnt affect the strategy.

So - just to continue the conversation - how would you make this profitable?

Personally - I'd throw in a stoploss (to limit downside and define the same risk every time) , the size of stoploss would be critical, so my first step would be to understand the average winner size (i.e over 100 trades what is the average winner), then I would start by chosing a stoploss 1/3 of that value.. example - if the average win was 90 pips, I would test first with a stoploss of 30 pips. What else would you do?


 
 Post subject: Re: how to close open position Post rating: 0   New post Posted: Fri 10 May, 2013, 08:36 
User avatar

User rating: 0
Joined: Sat 04 May, 2013, 16:08
Posts: 17
Location: ItalyItaly
that would be a great idea.

And there's something else I would try to do, set the strategy so that: If a position is gaining the same size as the risk (ex: stop loss =30 pips. position is filled and gaining 30 pips) close half of the position and set the SL to breakeven. Is there a way to set that..?

like every "ema cross" strategy, it works well only in trending market, but loses in sideways market. So, one way to have it work on volatile-sideways market, is to set it to open trades on the opposite direction of the cross, so: sell when slow sma crosses above the fast ema, and buy in the opposite situation. It's kinda funny, but if there's no trend it works pretty well..


 
 Post subject: Re: how to close open position Post rating: 0   New post Posted: Fri 10 May, 2013, 17:24 
User avatar

User rating: 7
Joined: Wed 04 Jul, 2012, 02:40
Posts: 109
Location: Australia, Melbourne
Hi Nic,

nicbrunelli wrote:
close half of the position and set the SL to breakeven. Is there a way to set that..?


First of all - I havent come across a way to partial close a trade , maybe SUPPORT and comment on partial closes.

I have also quickly thrown together the logic to set a breakeven stop. Now I do it a certain way on purpose. So what I mean is: The first block is to see if the trade is long or short, next block is to make sure the stop has not adjusted to breakeven already (we do this to make sure we dont accidently create a loop which would move the stop to breakeven every tick), following that we check the trade is in profit by the 30 pips, then we move the stop to breakeven.
Image

Reference my image and have a play around - see how you go! The more you experiment , the more you learn! I didnt put it in your system so you would have the opportunity to try yourself first =)

To continue our discussion - I wonder what would be more profitable - closing half the position and moving to breakeven, or just moving the stop to breakeven? (some testing for you to do =) enjoy)


Attachments:
breakeven.jpg [229.46 KiB]
Downloaded 872 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: how to close open position Post rating: 0   New post Posted: Fri 10 May, 2013, 17:50 
User avatar

User rating: 0
Joined: Sat 04 May, 2013, 16:08
Posts: 17
Location: ItalyItaly
hey Doczero, thank you very much, your help is very well appreciated..!!
usually, with my manual trading, I prefer to close half position and move the stop to breakeven, so that at least I have a partial profit. I try to use this money management on every strategy, whether is a breakout strategy, or a fibonacci strategy, or a trend-following "pin bar" strategy. Sometimes I might also divide the position i 3 parts and set 3 different targets as well, depending on the momentum and the follow-throu.

I will try to play along with the blocks as you suggested. I guess I will continue next week, because I will be flying to US all weekend. But so that you know, I appreciate your quick and wise answers, thank you very much. I will post new comments as soon as I come up with new ideas

have a great weekend!


 
 Post subject: Re: how to close open position Post rating: 0   New post Posted: Sat 11 May, 2013, 00:20 
User avatar

User rating: 7
Joined: Wed 04 Jul, 2012, 02:40
Posts: 109
Location: Australia, Melbourne
Hi Nic,

This is the beauty of coding - if we cant do something easy (i.e have a block for closed partial) we can find a way to do it. So lets say the position size you want is 2 units. Why not open 2 trades at 1 unit, then when either position goes into profit 30 pips, then close the first and leave the second one open. I have to go out with the wifey - but when I get back i'll try show you how to do this! In the meantime tho - have a go at it, and see if you can work it out =)


 
 Post subject: Re: how to close open position Post rating: 0   New post Posted: Sun 12 May, 2013, 10:22 
User avatar

User rating: 7
Joined: Wed 04 Jul, 2012, 02:40
Posts: 109
Location: Australia, Melbourne
Hi Nic,

Your system just got a whole lot bigger ;) (I was hoping you had a go a making it yourself - did you? How did you go? also you could also not download this version and have a try).

Please note - for anyone trying to learn, I have put notes into the code structure so you can learn!

Image

So this system is looking interesting - To enable it to work how you wanted, I needed to implement an order handling system (so it know if the order is the first or second trade opened). We now have a takeprofit when the trade hits 30pips, and a move to breakeven on the second position. Stoploss is working on all. I have backtested for accuracy of the logic and it looks good to me. To improve this system, I would make the following selectable Variables: Stoploss / Takeprofit / EMA 1 period / EMA 2 Period


The second thing I would do - is implement fixed fractional position sizing, it is the only way to position sizing in my opinion (to utilise the power of compounding!)

So if you want a challange , see if you can do all that yourself!

Good luck - have fun!


Attachments:
ema6ema24cross.vfs [61.35 KiB]
Downloaded 308 times
nicema.jpg [320.69 KiB]
Downloaded 829 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: how to close open position Post rating: 0   New post Posted: Tue 14 May, 2013, 16:02 
Visual JForex expert at Dukascopy
User avatar

User rating:
Joined: Mon 22 Apr, 2013, 11:30
Posts: 604
Location: UkraineUkraine
Hello Everyone.

Try a two little bit simpler solutions for SMA cross strategy in files attached.


Attachments:
SMA1.vfs [31.08 KiB]
Downloaded 276 times
SMACrossUser3.vfs [36.08 KiB]
Downloaded 267 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: how to close open position Post rating: 0   New post Posted: Tue 14 May, 2013, 21:35 
User avatar

User rating: 7
Joined: Wed 04 Jul, 2012, 02:40
Posts: 109
Location: Australia, Melbourne
Hello Vadim,

Thanks for the contribution to this thread! Can you explain why the code you attached is a better way of doing thing? (for my better understand) I have run the code and it does not act like the last version I posted (which is working correctly). I can not see partial exits (if you have a way of doing this with opening 1 order, it would be valuable to share - we have had to do this by opening 2 x 1/2 size orders) and a lot of the features seem to be missing. Not a criticism - just trying to learn more from you :P



Nic,

I have updated the attached code to be able to select via global variable the following:

SmallSMA period
LargeSMA period
Stoploss
Partial close Take Profit
and the usual defaults!

It is tested and working well =)


Attachments:
ema6ema24cross.vfs [60.98 KiB]
Downloaded 275 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: how to close open position Post rating: 0   New post Posted: Wed 15 May, 2013, 04:17 
User avatar

User rating: 0
Joined: Sat 04 May, 2013, 16:08
Posts: 17
Location: ItalyItaly
Hello everyone!

I haven't checked this thread for a couple of days but i'm happy to see it's growing more interesting. Thanks to all for contribuiting!

I was testing this strategy (not the last 2, I haven't downloaded them yet) and I made just a few changes: enter at market by tick instead of candle, so that it opens the order a little sooner, then I changed the large MA to 60 to catch larger trends.
It works very well when the market put up a nice trend, but in the ranging markets, when the 2 MAs cross each other more often, then you run into many stops, and they can eat up all the gains.

I noticed that often these ranging times are (in the eur/usd) during the asian session, when the european market is closed.
the solution to this problem could be:

- stop the strategy during the asian market and let it go during the european/American market (that's for eur/usd, but i should check some different pairs)
- have the strategy open opposite orders (buy instead of sell and sell instead of buy) during Asia session
- find a way to have the strategy recognize when the market is ranging. But how? whith a volatility indicator like ATR for example? or adding bollinger bands?

thanks guys for posting!

nic


 
 Post subject: Re: how to close open position Post rating: 0   New post Posted: Wed 15 May, 2013, 13:15 
Visual JForex expert at Dukascopy
User avatar

User rating:
Joined: Mon 22 Apr, 2013, 11:30
Posts: 604
Location: UkraineUkraine
Hello Doc.

In examples I`v shown solution for "how to close open position". I`ll describe in details.
SMA cross strategy is to close previous positions and open new one when the "cross" happens.
First example(SMA1) shows how to close ALL existing positions with one little cycle.
Image

Second example(SMACrossUser3) is more complicated. There is one trick.
When Position.State variable is created it has NULL(none) state. So it can not be used in CLOSE or IF block. It will return error.
So at the beginning of the strategy that variable has to be set "CANCELED".
Image
Now it can be used in CLOSE block with no cycles.
Image
That is how the trick works. :twisted:

We can continue development of SMA Cross strategy with other features. But lets do it in separate thread.
I think question of that thread "Re: how to close open position" is answered.


Attachments:
Untitled3.png [79.72 KiB]
Downloaded 802 times
Untitled2.png [93.13 KiB]
Downloaded 802 times
Untitled1.png [111.4 KiB]
Downloaded 838 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.
 

Jump to:  

cron
  © 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