Stop strategy after a set $ amount lost from CumProfit - NinjaTrader Programming | futures io social day trading
futures io futures trading


Stop strategy after a set $ amount lost from CumProfit
Updated: Views / Replies:5,451 / 21
Created: by vast Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Stop strategy after a set $ amount lost from CumProfit

  #1 (permalink)
Elite Member
Australia
 
Futures Experience: Intermediate
Platform: Ninja
 
vast's Avatar
 
Posts: 167 since Jun 2009
Thanks: 154 given, 59 received

Stop strategy after a set $ amount lost from CumProfit

I am wondering if it is possible to stop a strategy after a certain amount of $ loss to your Cumulative profit.
I have read and used the settings for stopping if the CumProfit is > $ amount.
ie Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit - priorTradesCumProfit >= 1000
But can't get my head around how to achieve what I would like
ie. Can I store the highest daily profit achieved and then stop the strategy once a predetermined $ amount is lost from this value.
Thanks

Reply With Quote
 
  #2 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,220 received

From: https://futures.io/programmers-paradise/241-code-snippets-needed.html#post1241


jackyd View Post
Here's some code I came up with from various samples to give me some peace of mind if you were to run your strategies unattended. (in case I ever have a strategy that makes money!!!)

This is probably very simplistic and old hat for many, but hopefully it will help someone. It can be easily personalized with your own messages, input variables, etc.

 
Code
                            
// At the start of a new session calculate the prior cum profit so it won't be included in the 
// calculation. Need this for historical testing.
if (Bars.FirstBarOfSession)
    {
priorCumProfit Performance.AllTrades.TradesPerformance.Currency.CumProfit;}

// *** Calculate the toal profit (cumulative profit minus prior profit plus the current position profit 
double myMaxProfit = (double) 1000;
double myMaxLoss = (double) -1000;
double cumProfit = (double) Performance.AllTrades.TradesPerformance.Currency.CumProfit;
double curPosition = (double) Position.GetProfitLoss(Close[0], PerformanceUnit.Currency);
double totCumProfit = (double) cumProfit priorCumProfit curPosition ;
            
// *** STOP the strategy! if a total profit or loss exceeds the max
if (totCumProfit <= myMaxLoss || totCumProfit >= myMaxProfit)
    {
    if (
Position.MarketPosition == MarketPosition.Long) {ExitLong("DMA: Exit Long - max Profit/Loss exceeded""");}
    if (
Position.MarketPosition == MarketPosition.Short) {ExitShort("DMA: Exit Short - max Profit/Loss exceeded""");}
    Print(
Time[0] + ": EXIT STRATEGY - Max Profit/Loss exceeded: $" myMaxProfit "/$" myMaxLoss ", Current: $" totCumProfit);
    return;
    } 
Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following 3 users say Thank You to Big Mike for this post:
 
  #3 (permalink)
Elite Member
Australia
 
Futures Experience: Intermediate
Platform: Ninja
 
vast's Avatar
 
Posts: 167 since Jun 2009
Thanks: 154 given, 59 received


Thank you Mike. Didn't even think to look there.
I am sure that there is info in here that I could use.
Sorry for not looking

Reply With Quote
 
  #4 (permalink)
Elite Member
Australia
 
Futures Experience: Intermediate
Platform: Ninja
 
vast's Avatar
 
Posts: 167 since Jun 2009
Thanks: 154 given, 59 received

Is there a way to calculate maximum cumulative profit?
I realise that there is gross profit, but this is different to max cumulative profit.

Reply With Quote
 
  #5 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,220 received


vast View Post
Is there a way to calculate maximum cumulative profit?
I realise that there is gross profit, but this is different to max cumulative profit.

Hmm. Maybe create your own DataSeries.

 
Code
                            
#variables
private DataSeries mycumprofit;

#init
mycumprofit = new DataSeries(this);

#onbarupdate

if (Bars.FirstBarOfSession)
mycumprofit = new DataSeries(this);  // re-init each day

mycumprofit.Set(Performance.AllTrades.TradesPerformance.Currency.CumProfit);

// then to get the highest value:
double _highestcumprofit MAX(mycumprofitBars.BarsSinceSession 1)[0];

// and to find out how many bars ago that was
int _highestcumprofit_bar HighestBar(mycumprofitBars.BarsSinceSession 1)[0];

// and to find out the time stamp of that bar
Print(Time[_highestcumprofit_bar] + ": this was the time I made " _highestcumprofit.ToString()); 
Just a thought, untested code.

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following 2 users say Thank You to Big Mike for this post:
 
  #6 (permalink)
Elite Member
Australia
 
Futures Experience: Intermediate
Platform: Ninja
 
vast's Avatar
 
Posts: 167 since Jun 2009
Thanks: 154 given, 59 received

Thank you once again. Will have a look.
I am wanting to stop the risk of losing all the profits of the day . So I was thinking of this method. I think that it makes good money management. ie. If I get up to $500 cumulative profit and then get on a string of losers or low trades, I don't want to whittle it down to zero. I am willing to keep trading until I lose a set amount form this highest total. So if I am willing to risk a loss of $300 from my highest point then the strat stops at that point.

Reply With Quote
 
  #7 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,220 received


vast View Post
Thank you once again. Will have a look.
I am wanting to stop the risk of losing all the profits of the day . So I was thinking of this method. I think that it makes good money management. ie. If I get up to $500 cumulative profit and then get on a string of losers or low trades, I don't want to whittle it down to zero. I am willing to keep trading until I lose a set amount form this highest total. So if I am willing to risk a loss of $300 from my highest point then the strat stops at that point.

Yup good job.

Gary and I have similar thoughts and MM plan, think of it like a trailing stop for your daily profit target/loss.

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #8 (permalink)
Elite Member
Australia
 
Futures Experience: Intermediate
Platform: Ninja
 
vast's Avatar
 
Posts: 167 since Jun 2009
Thanks: 154 given, 59 received

Hi Mike
I tried the code and had a few errors. come up.
It didn't like the [0] is this:
int _highestcumprofit_bar = HighestBar(mycumprofit, Bars.BarsSinceSession - 1)[0];

Also had to add (double) after the = signs.
double _highestcumprofit = (double) MAX(mycumprofit, Bars.BarsSinceSession - 1)[0];
But now when I apply the strat it just freezes up.
Thanks forth ehelp so far though.
Regards

Reply With Quote
 
  #9 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,220 received

Sorry can't test right now. You may need to do a check first:

if (Performance.AllTrades.Count > 1)

If it's zero it may screw up the rest. Check the log for any obvious errors.

Sorry about the type-o on HighestBar, I don't use it very often and forgot you can't index it.

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #10 (permalink)
Member
Chicago
 
Futures Experience: Advanced
Platform: X_Trader, Ninja
Broker/Data: Advantage/TT and Mirus/ZenFire
Favorite Futures: ES
 
Posts: 60 since Jun 2009
Thanks: 0 given, 16 received


Here's some code ive used in a production robot.... works well and does pretty much what i think you're trying to do

 
Code
////////////////////////
/// TRACK LAST TRADE //
/// //////////////////

if (Performance.RealtimeTrades.Count > 0) 
{
    lastTrade = Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 1]; 
}

////////////////////
// STRATEGY HALT //
//////////////////
/// 
// Strategy is halted if Net P&L is <= -$450.00
if (strategyhalt)
    return;

if (Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit <= -450)
{
    strategyhalt = true;
    Print ("Strategy Halted" + "    " + "P&L is:" + " " + Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit + "    " + "Number of trades is:" + " " + Performance.RealtimeTrades.Count);
}



////////////////////////
/// PROFIT PROTECTION //
/// ///////////////////
 
if (Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit >= 500)
{
    ceiling = true;
}

if (ceiling == true
    && lastTrade !=null
    && lastTrade.ProfitCurrency < 0)
{
    strategyhalt = true;
    Print ("Strategy Halted" + "    " + "P&L is:" + " " + Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit + "    " + "Number of trades is:" + " " + Performance.RealtimeTrades.Count);
}

Reply With Quote

Reply



futures io > > > > > Stop strategy after a set $ amount lost from CumProfit

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using SuperTrend for trailing stop in a strategy - help needed DarrenH NinjaTrader Programming 16 September 29th, 2017 11:03 PM
Volume stop Strategy Possible ? isarhodes NinjaTrader Programming 5 July 12th, 2011 05:02 PM
How to set up a Stop (Limit) Loss order - Ninja Trader jdumanic NinjaTrader 2 June 7th, 2011 06:40 PM
MOVE STOP LOSS AFTER STRATEGY firecan NinjaTrader Programming 2 December 13th, 2010 06:54 AM
Drawdowns, when has a strategy lost its 'edge' fluxsmith Psychology and Money Management 6 October 16th, 2010 07:24 PM


All times are GMT -4. The time now is 05:57 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-12 in 0.12 seconds with 19 queries on phoenix via your IP 54.167.44.32