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

Re: Close All at Total Equity Target Strategy

Postby frankdrebin » Fri May 17, 2013 9:23 pm

Many Thanks Gidien. I'll give this a try.

I'm fairly clueless when it comes to coding, but I'll play with this and see what I can do.

The first part, pasting the StopMe function into the Strategy that I want to stop, seems pretty easy, as I only use one Strategy, but on many pairs.

The second part brings up a noob question:

To add the StopAllStrategies code to the "close_all_at_total_equity" Strategy (the new one you've attached below), which is the "sending" strategy, then the line:

if n:name() ~= name and interop:isalive(n) and n:isIndicator() == false then
n:invoke("StopMe");

must be changed to:

if n:close_all_at_total_equity() ~= close_all_at_total_equity and interop:isalive(n) and n:isIndicator() == false then
n:invoke("StopMe");

I just replaced "name" with "close_all_at_total_equity". Do I have that right?

Once again, Gidien, you're the man!
frankdrebin
 
Posts: 45
Joined: Fri Jan 18, 2013 3:10 pm

Re: Close All at Total Equity Target Strategy

Postby Gidien » Sun May 19, 2013 12:08 am

The name of every indicator or strategy , is coming from the prepare function.
Unfortunately we cannot read out the name of our strategy , which was set in the prepare function, directly. So have to take it from the prepare function.

from the "close_all_at_total_equity" Strategy :

Code: Select all
function prepare()
.....
 local name = profile:id() .. "(" .. instance.bid:instrument() .. ", " .. tostring(EL) .. ")";
 instance:name(name);
....
end


For the "close_all_at_total_equity" Strategy the name would be :

profile:id() .. "(" .. instance.bid:instrument() .. ", " .. tostring(EL) .. ")"

This means our function will look as followed:

Code: Select all
function StopAllStrategies()
   local i, n;
   local name = profile:id() .. "(" .. instance.bid:instrument() .. ", " .. tostring(EL) .. ")"; 
   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
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 » Mon May 20, 2013 1:25 pm

OK, I put the code into both strategies, and it didn't work, so I've done something wrong (surprise!). Here's what I did:

I'm using the Line Cross Strategy found here:
viewtopic.php?f=31&t=20142&p=41786&hilit=+line+cross#p41786

so I added the following code to that strategy:
Line Cross Strategy2.png


Then I modified the Close All at Total Equity strategy per your example to get this:
close_all_at_total_equity2.png


Both pieces of code were added at the very end, just before the "dofile" line.

Overnight, my the Upper Equity Target was hit, the open positions and orders were closed and deleted, but the Strategy still remained working, opening new orders on the several pairs that I ran it on.

Please let me know what I've done wrong.

Thanks again for your valuable help on this.
frankdrebin
 
Posts: 45
Joined: Fri Jan 18, 2013 3:10 pm

Re: Close All at Total Equity Target Strategy

Postby Gidien » Tue May 21, 2013 4:56 am

I tested and it works well. do you forget to call the StopAllStrategies() function ??

Code: Select all
function ExtUpdate(id, source, period)
    if AllowTrade then
        local Equity = core.host:findTable("accounts"):find("AccountID", Account).Equity;
        if Equity >= EL then
            -- Level Reached Close all Now
            if nexecuting > 0 then
               return ;
            end
            closeAllTrades();
            removeAllOrders();
         StopAllStrategies();
         --core.host:execute ("stop");
      elseif Equity <= ES then
         -- Level Reached Close all Now
            if nexecuting > 0 then
               return ;
            end
            closeAllTrades();
            removeAllOrders();
         StopAllStrategies();
         --core.host:execute ("stop");
        end
    end
end
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 May 21, 2013 12:31 pm

Yes, I did forget that. I have now made the changes as you've shown and will try it again. Hopefully I haven't missed anything else. Please understand that I am very new this. I certainly appreciate your patience.
frankdrebin
 
Posts: 45
Joined: Fri Jan 18, 2013 3:10 pm

Re: Close All at Total Equity Target Strategy

Postby frankdrebin » Tue May 21, 2013 10:11 pm

That's It! It works!

I initiated a Strategy on 12 different pairs, and set Total Equity Upper Limit and Lower Limit. The Strategy triggered on 5 of the pairs and eventually bumped my Equity to the Upper Limit, where it closed out all positions, cancelled all orders and stopped the Strategy on all pairs. Perfect.

Thanks again for everything Gidien!
frankdrebin
 
Posts: 45
Joined: Fri Jan 18, 2013 3:10 pm

Re: Close All at Total Equity Target Strategy

Postby Gidien » Wed May 22, 2013 6:28 am

You're welcome!
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 Mountaintrader » Tue Jun 18, 2019 7:01 pm

Hi,

Please could somebody confirm if this strategy works correctly when applied to a UK FXCM Spread Betting account ?

The reason I ask is that the "Allow Trading YES/NO" in Strategy Dashboard permanently displays "NO" even when "YES" is selected and applied in the Properties/Trading Parameters "Allow Strategy to Trade"

Thanks
User avatar
Mountaintrader
 
Posts: 63
Joined: Fri Dec 18, 2015 9:52 pm
Location: Panama

Previous

Return to Indicator and Signal Requests

Who is online

Users browsing this forum: Google [Bot] and 15 guests