NexusFi: Find Your Edge


Home Menu

 





Pyramid Scaling In and Scaling Out


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one ABCTG with 5 posts (0 thanks)
    2. looks_two tradestation18 with 5 posts (0 thanks)
    3. looks_3 Vevdeschmidt with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 4,948 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 10 posts
    2. attach_file 3 attachments




 
Search this Thread

Pyramid Scaling In and Scaling Out

  #1 (permalink)
tradestation18
Porto Portugal
 
Posts: 16 since May 2018
Thanks Given: 1
Thanks Received: 1

Hi,

I am trying to create a simple pyramid code with up to 6 cumulative entry orders and exiting with different/independent profit targets for each entry. The entries are triggered by a percentual retreat of the market. Example:
Entry1 at (High - 2%)
Entry2 at (Entry1-2%)
Entry3 at (Entry2-2%)
......

Exit1 at Entry1 + Profit Target 1
Exit1 at Entry2 + Profit Target 2
...

Developed this code which doesnt work properly namely: a) Too much orders withoud respecting the percentual retreat and
b) Sell orders not respecting the Profit Target defined ( Loss instead of profit)


I would be very much obliged if someone could help me on this. Thanks


[IntrabarOrderGeneration = false]
inputs:
PctPullBack( 1 ) , PositionBasis( False ), HD( 0 ), N(0.1), Capital (100000), Amount1 (1000), Price (Close) , // Profit target for first entry
Amount2(1000) , Amount3(1000), Amount4(1000), Amount5(1000), Amount6(1000); // Profit target for other entries


variables: HOD (0),Amt1(0),Amt2(0),Amt3(0),Amt4(0),Amt5(0),Amt6(0);

HOD = HighD( HD );



If CurrentBar> 1 then

Buy ( "ScaleIn 1" ) next bar at HOD * ( 1 - PctPullBack * .01 ) Limit ;
Amt1=Avgentryprice+Amount1*Avgentryprice/Capital ;// set profit tartet for 1st entry based on close of bar, not entryPrice end;
Buy ( "ScaleIn 2" ) next bar at HOD * ( 1 - (1+N)* PctPullBack * .01 ) Limit ;
Amt2=Avgentryprice+Amount2*Avgentryprice/Capital; // set profit tartet for 2nd entry based on close of bar, not entryPrice end;
Buy ( "ScaleIn 3" ) next bar at HOD * ( 1 - (1+2*N) * PctPullBack * .01 ) Limit ;
Amt3=Avgentryprice+Amount3*Avgentryprice/Capital;
Buy ( "ScaleIn 4" ) next bar at HOD * ( 1 - (1+3*N) * PctPullBack * .01 ) Limit ;
Amt4=Avgentryprice+Amount4*Avgentryprice/Capital;
Buy ( "ScaleIn 5" ) next bar at HOD * ( 1 - (1+4*N) * PctPullBack * .01 ) Limit ;
Amt5=Avgentryprice+Amount5*Avgentryprice/Capital;
Buy ( "ScaleIn 6" ) next bar at HOD * ( 1 - (1+5*N) * PctPullBack * .01 ) Limit ;
Amt6=Avgentryprice+Amount6*Avgentryprice/Capital;


sell ("LX1") from entry("ScaleIn 1") next bar at Amt1 limit;
sell ("LX2") from entry("ScaleIn 2") next bar at Amt2 limit; // will exit independently of 1st entry
sell ("LX3") from entry("ScaleIn 3") next bar at Amt3 limit; // will exit independently of other entries
sell ("LX4") from entry("ScaleIn 4") next bar at Amt4 limit; // will exit independently of 2nd entry
sell ("LX5") from entry("ScaleIn 5") next bar at Amt5 limit; // will exit independently of 1st entry
sell ("LX6") from entry("ScaleIn 6") next bar at Amt6 limit; // will exit independently of 2nd entry

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Deepmoney LLM
Elite Quantitative GenAI/LLM
Exit Strategy
NinjaTrader
Futures True Range Report
The Elite Circle
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
ZombieSqueeze
Platforms and Indicators
 
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623


Hi tradestation18,

can you show an example of "a) Too much orders withoud respecting the percentual retreat and
b) Sell orders not respecting the Profit Target defined ( Loss instead of profit)" on chart and clarify how it should be instead in this situation?

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #4 (permalink)
tradestation18
Porto Portugal
 
Posts: 16 since May 2018
Thanks Given: 1
Thanks Received: 1

Thanks for your reply. PLease find attache the out put for the following settings:

- PctPullBack 1.5
- PositionBasis true
- HD 15
- N 1.5
- Capital 50000
- Amount1 1000
- Price Close
- Amount2 1250
- Amount3 1500
- Amount4 2000
- Amount5 2500
- Amount6 3000

Attached Thumbnails
Click image for larger version

Name:	Ford.png
Views:	311
Size:	104.4 KB
ID:	251409  
Attached Files
Elite Membership required to download: FordList.xlsx
Elite Membership required to download: Ford.xlsx
Reply With Quote
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

tradestation18,

I would check the values for Amt1 to Amt6 using the print reserved word, as they might still be based on the previous entry during your entry bar.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #6 (permalink)
tradestation18
Porto Portugal
 
Posts: 16 since May 2018
Thanks Given: 1
Thanks Received: 1

Thanks for the tip. Thats my difficulty how to link each entry ("ScaleIn 1"), ("ScaleIn 2").. to the corresponding desired amount of profit Amt1, Amt2,....., that is what should be the correct code for Amt1, Amt2, in order that it links to the corresponding entry ("ScaleIn 1"),("ScaleIn 2"), and not to the previous or actual price Close ...

Reply With Quote
  #7 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

Hi tradestation18,

what did the print statements show? This should clarify what needs to be done to give you the desired outcome.

Regards,

ABCTG


tradestation18 View Post
Thanks for the tip. Thats my difficulty how to link each entry ("ScaleIn 1"), ("ScaleIn 2").. to the corresponding desired amount of profit Amt1, Amt2,....., that is what should be the correct code for Amt1, Amt2, in order that it links to the corresponding entry ("ScaleIn 1"),("ScaleIn 2"), and not to the previous or actual price Close ...


Follow me on Twitter Reply With Quote
  #8 (permalink)
tradestation18
Porto Portugal
 
Posts: 16 since May 2018
Thanks Given: 1
Thanks Received: 1

The output makes no sense. The sell order is coincident with the buy order, no matter the inputs are:


Type Date/Time Signal Price Roll Over Amt (USD) Shares/Ctrts/Units
Buy 07/31/14 ScaleIn 1 $36.54 $0.00 1368
Sell 07/31/14 LX1 $36.54 $0.00
Buy 08/14/14 ScaleIn 1 $35.08 $0.00 1425
Sell 08/14/14 LX1 $35.08 $0.00
Buy 09/02/14 ScaleIn 1 $34.75 $0.00 1438
Sell 09/02/14 LX1 $34.75

Reply With Quote
  #9 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

Hi tradestation18,

what code did you use to create this output? I suggested using the print statement as it might make sense to find out what values your code uses internally for the orders, to find out what you need to change to get the results you want.

What is the value within your code for "Avgentryprice" for example on the bar where you enter?

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #10 (permalink)
tradestation18
Porto Portugal
 
Posts: 16 since May 2018
Thanks Given: 1
Thanks Received: 1


The code is very simple but doesnt work properly because each entry ("ScaleIn 1" and "ScaleIn 2") are not linked with the desired Profit Tareget Price Amt1 and Amt2.

inputs:
PctPullBack( 1 ) , PositionBasis( False ), HD( 0 ), N(0.1), Capital (100000), Amount1 (1000), Price (Close) ,
Amount2(1000) ;// Amount1 and Amount2 are the Profit target

variables: HOD (0),Amt1(0),Amt2(0);
HOD = HighD( HD );

If CurrentBar> 1 then

Buy ( "ScaleIn 1" ) next bar at HOD * ( 1 - PctPullBack * .01 ) Limit ;
Amt1=Close+Amount1*Close/Capital ;// set profit tartet for 1st entry based on close of bar, not entryPrice end;
Buy ( "ScaleIn 2" ) next bar at HOD * ( 1 - (1+N)* PctPullBack * .01 ) Limit ;
Amt2=Close+Amount2*Close/Capital; // set profit tartet for 2nd entry based on close of bar, not entryPrice end;


sell ("LX1") from entry("ScaleIn 1") next bar at Amt1 limit;
sell ("LX2") from entry("ScaleIn 2") next bar at Amt2 limit; // will exit independently of 1st entry

Reply With Quote




Last Updated on July 4, 2018


© 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