Close All at Total Equity Target Strategy

If you need an Indicator or Signal developed or translated from other language, please post all Indicator development REQUESTS to this section here.

Moderator: admin

Close All at Total Equity Target Strategy

Postby frankdrebin » Fri Jan 18, 2013 4:02 pm

Hello,

Would it be possible to create a Strategy that Closes ALL Open Positions, PLUS any pending Entry and Exit Orders, when the Account EQUITY reaches a certain target dollar amount?

I often have open positions on 8 to 10 pairs simultaneously. I also have many Entry and Exit orders pending at all times. Because of this, my Account Equity sometimes fluctuates a great deal. Often, this fluctuation results, briefly, in a good gain for the day overall, even though some positions may be losing. If I'm not sitting at my computer, in a position to close everything, I lose the opportunity to take that profit. I'd like to be able to capture that gain once my Equity hits a predescribed dollar amount.

I've looked at the Level Close Strategy
viewtopic.php?f=31&t=2901

but it does not account for losses that have resulted from Stopped out positions. It only looks at current open positions. I would like to use the Account Equity number as the trigger.

It seems like it would be pretty simple to do, but I'm not a programmer, so I don't know.

Thank you very much.
frankdrebin
 
Posts: 45
Joined: Fri Jan 18, 2013 3:10 pm

Re: Close All at Total Equity Target Strategy

Postby Apprentice » Sat Jan 19, 2013 6:24 pm

Your request is added to the development list.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36437
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Close All at Total Equity Target Strategy

Postby Gidien » Mon Jan 28, 2013 4:25 pm

Request answer:

Strategy don't think about pairs, lossers or winners.

Put the strategy to any pair, set the correct Equity Level which you want to reach and Enable "Allow Strategy to Trade".

If Equity Level is reached, then Strategy close all trades, entries at any pairs for you.

Please try first on a DEMO account, before using on a REAL Account.

file:
close_all_at_total_equity.lua
(9.24 KiB) Downloaded 591 times
Gidien
FXCodeBase: Confirmed User
 
Posts: 106
Joined: Mon Feb 08, 2010 7:39 am
Location: Hamburg

Re: Close All at Total Equity Target Strategy

Postby frankdrebin » Tue Jan 29, 2013 7:21 pm

Thanks Gidien. Much appreciated. Will give this a try.
frankdrebin
 
Posts: 45
Joined: Fri Jan 18, 2013 3:10 pm

Re: Close All at Total Equity Target Strategy

Postby frankdrebin » Tue Apr 16, 2013 7:58 pm

Gidien, I’ve given this a try and it works. It closes all positions and deletes all pending Entry Orders upon the Equity hitting the Target or better.

A few comments:

After using it, it occurred to me that it would be a good idea to use it to do the same thing to limit total Equity Lost, so I modified the code a bit (on MY copy, not the actual File above):

From:
if Equity >= EL then
To:
if Equity <= EL then

But now I must Run the Strategy twice, once for the Upper Limit, and once for the Lower. It would be nice to have both in the same Strategy, but I don’t know how to modify the code to do that.

Also, this wasn’t part of the original request, but I run other Strategies on each pair that I’m trading, and it would be very helpful if this also stopped all Strategies being run on all pairs.

So, basically, the idea is that when the Total Equity in the account reaches EITHER the Upper Limit OR the Lower Limit, then the Strategy Closes all positions, cancels all orders, AND Stops all Strategies.

Thanks again, Gidien, for your work on this so far, and I hope that you, or anyone else, can help out with these changes. I think that they would be very useful for many traders.
frankdrebin
 
Posts: 45
Joined: Fri Jan 18, 2013 3:10 pm

Re: Close All at Total Equity Target Strategy

Postby Ironbark » Sun May 12, 2013 8:58 pm

Apprentice

I'm having trouble getting this strategy to work

When it is supposed to execute I get an error message saying

"create order failed:Missed OfferID Field"

I've been onto tech support and we found out this algo is not compatible with Australian Marketscope platforms.

If time permits could yourself or Gidion please consider tweaking this to make it compatible with Australian platforms?

Thanks
Ironbark
 
Posts: 4
Joined: Thu Apr 25, 2013 9:35 pm

Re: Close All at Total Equity Target Strategy

Postby Gidien » Wed May 15, 2013 1:16 am

Hi,

AUD account problem fixed.
Add close all, if equity falling below lower Equity Level.

Unfortunately Stopping all other Strategies is a little bit complicated. You will need to add the following function to every Strategy you want to stop.

Code: Select all
function StopMe()
   core.host:execute ("stop");
end


Then you will need to add the following function to the sending Strategy.

Code: Select all
function StopAllStrategies()
   local i, n;
   for i = 0, interop:size() - 1, 1 do
      n = interop:instance(i);
      if n:name() ~= name and interop:isalive(n) and n:isIndicator() == false then
         n:invoke("StopMe");
      end
   end
end


name == the Name of the sending strategy.

If the condition in the sending strategy is matching, Lower or Upper Equity Level reched, then call the function StopAllStrategies().

file:
close_all_at_total_equity.lua
(9.63 KiB) Downloaded 542 times


best

Gidien
Gidien
FXCodeBase: Confirmed User
 
Posts: 106
Joined: Mon Feb 08, 2010 7:39 am
Location: Hamburg

Re: Close All at Total Equity Target Strategy

Postby Ironbark » Wed May 15, 2013 4:52 am

Thankyou so much for getting onto this so quickly Gidien
Ironbark
 
Posts: 4
Joined: Thu Apr 25, 2013 9:35 pm

Re: Close All at Total Equity Target Strategy

Postby Ironbark » Wed May 15, 2013 5:19 am

Gidien

The strategy now works on Australian platforms

BUT

for some reason it is instantly closing all open trades as soon as it is enabled regardless of how far away I set the equity target :cry:

Do I have something wrong with my settings?
or does the strategy need a little more work?

Thanks Again.
Ironbark
 
Posts: 4
Joined: Thu Apr 25, 2013 9:35 pm

Re: Close All at Total Equity Target Strategy

Postby Gidien » Thu May 16, 2013 4:24 am

Typing error. Fixed it. Download again.
Gidien
FXCodeBase: Confirmed User
 
Posts: 106
Joined: Mon Feb 08, 2010 7:39 am
Location: Hamburg

Next

Return to Indicator and Signal Requests

Who is online

Users browsing this forum: Majestic-12 [Bot] and 10 guests