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)
Protecting the cumulative profit target in an automated strategy
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):
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:
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.
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.