NexusFi: Find Your Edge


Home Menu

 





Protecting the cumulative profit target in an automated strategy


Discussion in NinjaTrader

Updated
    1. trending_up 5,925 views
    2. thumb_up 1 thanks given
    3. group 1 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

Protecting the cumulative profit target in an automated strategy

  #1 (permalink)
 
nanobiotech's Avatar
 nanobiotech 
Brisbane, Australia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus/Zen-Fire
Trading: CL
Posts: 670 since Jun 2009
Thanks Given: 134
Thanks Received: 430

Hi everyone

As most of you know I am very active in developing the Hurley strategy that Big Mike initiated.

The latest version of Hurley is working well. It can use up to 5 contracts per trade with each contract having a different profit target. I use an initial setstoploss for all contracts which moves to BE + half the ticks of the first target when the first target is hit. I use a variable "cumprofittarget" to define the total cumulative profit for the strategy for that session (presently $1000) and another variable, cumlosstarget, for a loss target. I use CalculateOnBarClose=true.

Have a look at the latest version: Hurley6_7a_NT or Hurley6_7a_6_5. The profit targets in ticks for Target1, Target2, Target3, Target4, and Target 5 are 20, 20, 20, 20, and 150. Therefore using Big Mikes method the actual profit targets on the CL are 20, 40, 60, 80, and $1500. The reason I like the very big last target is to extend staying in the trade to avoid re-entries with retracements.

However, I want to improve the strategy so that when cumprofittarget is exceeded when one or more contracts are still in play in a trade, the cumprofittarget is protected. For example in a long if cumprofittarget is exceeded by 20 ticks, I could reset the setstoploss to a number of ticks below the current price (eg close of the last bar). The reason for this as frequently the cumprofittarget is exceeded by a large margin after the 3rd contract is hit

This part of my code that exits when the cumulative profit or loss target is hit works OK:

if (Position.MarketPosition != MarketPosition.Flat) return;

/* Prevents further trading if the current session's cumulative profit or loss targets are realised. */
if (Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit >= cumprofittarget || Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit <= -cumlosstarget)
{
return;
}


I am trying to add the code after the above to protect the cumprofittarget and have tried the following but it doesn't appear to work (beyond my current expertise):

if ((Position.MarketPosition == MarketPosition.Long)
&& ((Position.GetProfitLoss(Close[0], PerformanceUnit.Currency)) - cumprofittarget) >= 200)
{
SetStopLoss("target1", CalculationMode.Price, Math.Min(GetCurrentBid(), - (20 * TickSize)), false);
SetStopLoss("target2", CalculationMode.Price, Math.Min(GetCurrentBid(), - (20 * TickSize)), false);
SetStopLoss("target3", CalculationMode.Price, Math.Min(GetCurrentBid(), - (20 * TickSize)), false);
SetStopLoss("target4", CalculationMode.Price, Math.Min(GetCurrentBid(), - (20 * TickSize)), false);
SetStopLoss("target5", CalculationMode.Price, Math.Min(GetCurrentBid(), - (20 * TickSize)), false);
}

if ((Position.MarketPosition == MarketPosition.Short)
&& ((Position.GetProfitLoss(Close[0], PerformanceUnit.Currency)) - cumprofittarget) >= 200)
{
SetStopLoss("target1", CalculationMode.Price, Math.Min(GetCurrentBid(), + (20 * TickSize)), false);
SetStopLoss("target2", CalculationMode.Price, Math.Min(GetCurrentBid(), + (20 * TickSize)), false);
SetStopLoss("target3", CalculationMode.Price, Math.Min(GetCurrentBid(), + (20 * TickSize)), false);
SetStopLoss("target4", CalculationMode.Price, Math.Min(GetCurrentBid(), + (20 * TickSize)), false);
SetStopLoss("target5", CalculationMode.Price, Math.Min(GetCurrentBid(), + (20 * TickSize)), false);
}

Does anyone have any ideas?

Thanks in advance,
Nano

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Cheap historycal L1 data for stocks
Stocks and ETFs
Trade idea based off three indicators.
Traders Hideout
Better Renko Gaps
The Elite Circle
ZombieSqueeze
Platforms and Indicators
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,465 since Jun 2009
Thanks Given: 33,243
Thanks Received: 101,665


Nano,

 
Code
                            
 Math.Min(GetCurrentBid(), - (20 TickSize)) 

That is saying whatever is the lesser of GetCurrentBid or - 20 ticks. It's not valid. The command in Math.Min separates two values, like GetCurrentBid() and Close[0]. Here if bid is 82.00 you are saying, "what is less? 82.00, or - 20*ticks" the answer is always -20 ticks, the value is always -20 ticks you aren't subtracting it from anything.

If you meant to say currentbid minus 20 ticks, it would be:

 
Code
                            
SetStopLoss("target1"CalculationMode.Price, (GetCurrentBid() - (20 TickSize)), false); 

Also, if you use GetCurrentBid() on one side, you should use GetCurrentAsk() on the other side probably, to balance.

As for the Position.GetProfitLoss, I don't use that method but I believe that it is evaluated for the entire trade, not just 1 contract. So make sure that is what you were intending.

The best thing to do when running into trouble is use Print() statements. Print out the values so you can see what it is doing.

Mike



Join the free Markets Chat beta: one platform, all the trade rooms!

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,465 since Jun 2009
Thanks Given: 33,243
Thanks Received: 101,665

I moved the thread to NinjaTrader programming from Elite Group Trading methods. So long as you don't post Elite code (Hurley) I think it would be best here. Your example is really non-specific to Hurley.

If you don't want it here I can move it to the general Elite area, but it shouldn't be in the group trading area.

Mike



Join the free Markets Chat beta: one platform, all the trade rooms!

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 
nanobiotech's Avatar
 nanobiotech 
Brisbane, Australia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus/Zen-Fire
Trading: CL
Posts: 670 since Jun 2009
Thanks Given: 134
Thanks Received: 430


Big Mike View Post
I moved the thread to NinjaTrader programming from Elite Group Trading methods. So long as you don't post Elite code (Hurley) I think it would be best here. Your example is really non-specific to Hurley.

If you don't want it here I can move it to the general Elite area, but it shouldn't be in the group trading area.

Mike

No problem Mike.
Thanks
Nano

Started this thread Reply With Quote




Last Updated on April 1, 2010


© 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