EA - Close Positions by incurred swap value

 

Greetings,

I'm looking for a function to close any positions which incurred a Swap - the first swap incurred on a currency pair would trigger a close order in the indexed positions. 

Any ideas how to construct such function? 


All the best!

K

 
you can simply set a time filter? forex charges swap fees on wednesday 
 
Pak Hong Poon: you can simply set a time filter? forex charges swap fees on wednesday 

That's incorrect. Swap fees are charged every weekday and triple on Wednesday to Thursday roll over to account for the swap fees over the weekend.

 
Kierunkowskaz:

Greetings,

I'm looking for a function to close any positions which incurred a Swap - the first swap incurred on a currency pair would trigger a close order in the indexed positions. 

Any ideas how to construct such function? 


All the best!

K

There are brokers that work without swap. You can work with them. Spreads are high.

 

Apologies Gents, I should have clarified. I'm running an EA strategy and I'm getting regular drawdawns on my acc. I'm seeing trades which meet my MM criteria, whereby positions which cause the drawdawn can be closed by checking the position swap amount - the ones which incurred the first swap are destined for an axe. 

Those positions can in fact be opened up until the very first swap - I don't mind the fee. However, because SL in almost non-existent in this strategy - I'm using this Swap analogy to control my trades, and so I'm hoping to create an EA which will scan for such positions and kill them. 

 
Kierunkowskaz:

Apologies Gents, I should have clarified. I'm running an EA strategy and I'm getting regular drawdawns on my acc. I'm seeing trades which meet my MM criteria, whereby positions which cause the drawdawn can be closed by checking the position swap amount - the ones which incurred the first swap are destined for an axe. 

Those positions can in fact be opened up until the very first swap - I don't mind the fee. However, because SL in almost non-existent in this strategy - I'm using this Swap analogy to control my trades, and so I'm hoping to create an EA which will scan for such positions and kill them. 

I'm afraid, that your clarifications is no more clear than before (at least for me).

Any and all open trades, that remain open during the end-of-day roll over, will incur a swap expense (on non Islamic/Sharia accounts). That is just a fact that is predetermined and you don't need to check after the fact.

So, with that in mind, it does not make any sense to check for that, and then only close the trades after it has happened. In fact, you can close them BEFORE the end of the day. Not only will you prevent having to pay the swap expense, but you will be carrying out your "rule" of axing any trades that would have had a swap cost.

EDIT: Forgot to mention, that the are also positive swaps, that are gains and not losses, but you also know about that before the fact too. So, you can also use that information to decide whether to close or not, the trade before the end-of-day.

 

Thanks Fernando, but what you're saying takes me no closer to a solution than I was before (although I get your point as whoever I ask always says why "why wait for the swap?!" - that's not the point tho...). As in my previous post - I can see that the trades which go in to a substantial drawdawn - apart from loosing money, have most of the time incurred negative swaps - those swaps are usually a couple of pence, while the position itself is few dollars on the negative, as such I'm not concerned with the swap cost at this point.

I'm basically trying to prevent my self from using a static SL and close the trades on other criteria - either "date by expiry" or by using the swaps as a flag which means the position is no good. This approach allows for the price to return to profit in changing market conditions (I think) rather than risk the position being closed on static SL if there's an unexpected price deviation. 

In terms of the strategy - unfortunately the EA I'm using is licenced, cannot be therefore changed, but I identified the trades which can be closed before they lead to the drawdawn - those trades are as I describe above hence some independent position management is needed, which is again why I'm looking for some alternatives to manage those loosing trades. 

 
How to start with MQL5
How to start with MQL5
  • 2021.06.15
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
 
Kierunkowskaz:

Thanks Fernando, but what you're saying takes me no closer to a solution than I was before (although I get your point as whoever I ask always says why "why wait for the swap?!" - that's not the point tho...). As in my previous post - I can see that the trades which go in to a substantial drawdawn - apart from loosing money, have most of the time incurred negative swaps - those swaps are usually a couple of pence, while the position itself is few dollars on the negative, as such I'm not concerned with the swap cost at this point.

I'm basically trying to prevent my self from using a static SL and close the trades on other criteria - either "date by expiry" or by using the swaps as a flag which means the position is no good. This approach allows for the price to return to profit in changing market conditions (I think) rather than risk the position being closed on static SL if there's an unexpected price deviation. 

In terms of the strategy - unfortunately the EA I'm using is licenced, cannot be therefore changed, but I identified the trades which can be closed before they lead to the drawdawn - those trades are as I describe above hence some independent position management is needed, which is again why I'm looking for some alternatives to manage those loosing trades. 

But that is exactly my point! You are complicating your own strategy when the cleanest solution is so simple.

If your "filter" is "close all trades that incurred a swap cost" (because they are the ones most likely to incur greater losses and increase the drawdown), then simply close ALL trades at the end of the day, because surely those will meet the filter's criteria. ALL trades that roll-over at the end of the day will incur a swap. Why wait to cull them later when you already have clear knowledge beforehand of which trades will be culled anyway.

The only condition I would add, is if you want all trades closed or just those that would incur negative swaps.

Since, you can't change your current EA, just add another one that monitors trades and just before the end of the trading session for the day, checks all open positions (for that EA's magic number and symbol) and closes them (optionally filtered by if swaps will be negative or not).

Reason: