Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Hi everyone, I am trying to implement pyramiding in a strategy but every time my last position's stop gets touched, all the previous positions are liquidated at the same level.
I tried the reserved word Total but still it did not fix it, below I will paste the entry code, please let me know.
vars: StopPrice(0),
MP(0),
CC(0);
MP = Marketposition;
CC = Currentcontracts;
// LE1
If MP = 0 and CC = 0 and
{type of entry} then
begin
Buy ("LE1") next bar 1 Contract at Open;
StopPrice = Low[1]; // Stop below previous candle
end;
Sell ("LE1Loss") 1 Contract Total next bar at StopPrice on Stop;
// LE2
If MP = 1 and CC = 1 and
{type of entry} then
begin
Buy ("LE2") next bar 1 Contract at Open;
StopPrice = Low[1]; // Stop below previous candle
end;
Sell ("LE2Loss") 1 Contract Total next bar at StopPrice on Stop;
Note: every time the stop of LE2 gets touched, LE1 is automatically closed at that same level (the same happens for LE3 or LE4 which I did not include in the code).
Can you help answer these questions from other members on NexusFi?
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,049 since Dec 2013
Thanks Given: 4,384
Thanks Received: 10,206
I worked on a pyramiding system about 5 years ago and couldn't get it to work. I reached out to somebody my knowledgeable than me and they sent me this...
Tying an Exit to an Entry
It is possible to tie an exit instruction to a specific entry. This can be achieved only if you named the long entry, and the long entry is in the same strategy as the exit order. Consider the following strategy:
Buy ("MyBuy") 10 Shares Next Bar at Market;
Buy 20 Shares Next Bar at High + 1 Point Stop ;
Sell From Entry ("MyBuy") Next Bar at High + 3 Points Stop;
In the above example, the strategy may buy 30 shares total; your long position is 30 shares. However, the Sell instruction only closes out the 10 shares bought using the MyBuy entry order. It ignores any other order, and does not close out the other 20 shares. Therefore, this strategy leaves you long 20 shares.
You can also close part of an entry order. For example, if your entry, which you named "MyBuy" buys 10 shares, you can specify that you want to exit from entry "MyBuy" but only close out 5 shares, not the entire 10:
Sell From Entry ("MyBuy") 5 Shares Next Bar at High + 3 Points Stop;
Important The entry name is case sensitive. Be sure to use consistent capitalization. Also, it is important to remember that exit orders do not pyramid; therefore, if an exit does not close out an entire position, you will need another exit order (or reversal order) in order to close out the position.
Number of Shares/Contracts
To specify how many shares/contracts to close out, use a numeric expression followed by the word shares or contracts after the trading verb Sell. Some Examples:
Sell 100 Shares This Bar on Close;
Sell From Entry ("MovAvg") 10 Shares Next Bar at High + 1 Point Stop ;
The words shares and contracts are synonymous.
If you do not specify the number of shares or contracts in the Sell instruction, the exit order closes out the entire long position, rendering your position flat.
When you specify the number of shares/contracts, the Sell instruction exits the specified number of shares/contracts from every open entry.
Therefore, if the Strategy allows for pyramiding, and has bought 500 shares twice (for a total of 1,000 shares), and an order to Sell 100 Shares is placed by the Strategy, the instruction will exit a total of 200 shares: 100 shares from each of the two entries.
However, if you want to exit a total of 100 shares, you can use the word Total in the Sell instruction. Using the word Total instructs the Strategy to exit 100 shares from the first open entry (first in, first out). For Examples:
Sell 100 Shares Total This Bar on Close;
Sell From Entry ("MovAvg") 10 Shares Total Next Bar at High + 1 Point Stop ;
Looking at the email chain, I was using multiple entries and multiple exits that were not tied to each other. The important part to get this to work for me was the part highlighted in red part. Specifically the use of the word "TOTAL"
Thank you for your reply,
I tried to implement both Total and from entry but nothing changes. Below I will upload an example with 3 consecutive entries (LE1, LE2,LE3). As you can see when LE3's stop loss gets touched, the code sells all of the previous entries at that same level. In the image I also outlined the previous stop losses levels, let me know if it's not clear. Changes applied to the code:
vars: StopPrice(0),
MP(0),
CC(0);
MP = Marketposition;
CC = Currentcontracts;
// LE1
If MP = 0 and CC = 0 and
{type of entry} then
begin
Buy ("LE1") next bar 1 Contract at Open;
StopPrice = Low[1]; // Stop below previous candle
end;
Sell from entry ("LE1") 1 Contract Total next bar at StopPrice on Stop;
// LE2
If MP = 1 and CC = 1 and
{type of entry} then
begin
Buy ("LE2") next bar 1 Contract at Open;
StopPrice = Low[1]; // Stop below previous candle
end;
Sell from entry ("LE2") 1 Contract Total next bar at StopPrice on Stop;
// LE3
If MP = 1 and CC = 2 and
{type of entry} then
begin
Buy ("LE3") next bar 1 Contract at Open;
StopPrice = Low[1]; // Stop below previous candle
end;
Sell from entry ("LE3") 1 Contract Total next bar at StopPrice on Stop;