NexusFi: Find Your Edge


Home Menu

 





Pyramiding


Discussion in EasyLanguage Programming

Updated
    1. trending_up 3,295 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 1 attachments




 
Search this Thread

Pyramiding

  #1 (permalink)
soacm
Bucharest, Romania
 
Posts: 71 since Mar 2022
Thanks Given: 38
Thanks Received: 22

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).

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Better Renko Gaps
The Elite Circle
MC PL editor upgrade
MultiCharts
Increase in trading performance by 75%
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
15 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
My NQ Trading Journal
11 thanks
  #2 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
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"

Reply With Quote
Thanked by:
  #3 (permalink)
soacm
Bucharest, Romania
 
Posts: 71 since Mar 2022
Thanks Given: 38
Thanks Received: 22



SMCJB View Post
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;

Note: I wonder if StopPrice can be the issue (?)

Attached Thumbnails
Click image for larger version

Name:	NQtest.png
Views:	83
Size:	113.3 KB
ID:	324191  
Reply With Quote




Last Updated on May 2, 2022


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts