Strategy stop trading at realized PnL - NinjaTrader Programming | futures io social day trading
futures io futures trading


Strategy stop trading at realized PnL
Updated: Views / Replies:4,539 / 4
Created: by zwentz 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
 

Strategy stop trading at realized PnL

  #1 (permalink)
 Vendor: www.ninjaterminal.com 
Austin, TX
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Optimus Futures/Rithmic
Favorite Futures: Futures [ZB]
 
Posts: 36 since Sep 2009
Thanks: 12 given, 22 received

Strategy stop trading at realized PnL

I'm trying to code a strategy that stops trading that day if it loses too much that is backtester compatible. I found this thread over at NinjaTrader's support forum, but it's still wrong. I think I saw Big Mike in that thread over there as well, so I figured this would be the best place to ask.

Here's my code, but it doesn't seem to be working. Can anyone help?

Note: I'm speaking specifically about the backtester, the problem is that it acts as if the strategy ran straight through the entire backtesting period. So your cumulated profits are always rising, hopefully, and you can't find out what it is for the day.

 
Code
protected override void OnBarUpdate()
        { 
            double currentProfits = Position.GetProfitLoss(Close[0], PerformanceUnit.Currency);
            double cumulatedProfits = Performance.AllTrades.TradesPerformance.Currency.CumProfit;
            int indicator = MyIndicator(1)[0];

	    if (ToTime(Time[0]) < 143000 && ((cumulatedProfits - realized) + currentProfits > PosiProfs || (cumulatedProfits - realized) + currentProfits < -NegiProfs))
            {
                canEnterTrade = false;
            }
	    else
            {
		canEnterTrade = true;
            }


            if (ToTime(Time[0]) >= 63300 && canEnterTrade)
            {
                    if (indicator == 1)
                    {
                        EnterLong(DefaultQuantity, "");
                    }

                    if (indicator == -1)
                    {
                         EnterShort(DefaultQuantity, "");
                    }
            }

            //if realized profits have been reached or we're at the close of the day, flatten everything
            if ((!canEnterTrade && Position.MarketPosition != MarketPosition.Flat) || (ToTime(Time[0]) >= 142700 && Position.MarketPosition != MarketPosition.Flat))
            {
                ExitLong("Close Out", "");
                ExitShort("Close Out", "");
                realized = Performance.AllTrades.TradesPerformance.Currency.CumProfit;
            }
        }


Last edited by zwentz; November 30th, 2009 at 08:21 PM. Reason: added more detail
Reply With Quote
The following user says Thank You to zwentz for this post:
 
  #2 (permalink)
Elite Member
Brisbane, Australia
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Mirus/Zen-Fire
Favorite Futures: CL
 
nanobiotech's Avatar
 
Posts: 670 since Jun 2009
Thanks: 134 given, 428 received

I know it is possible to stop a strategy when a predefined profit/loss is hit, but is it possible to have NT flatten everything when a total profit or loss target is hit when running a strategy on two or more instruments? For example, when running two strategies and net profit for the two strategies hits $1000 or loss hits $400, all strategies are stopped.

Nano

Reply With Quote
 
  #3 (permalink)
 Vendor: www.ninjaterminal.com 
Austin, TX
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Optimus Futures/Rithmic
Favorite Futures: Futures [ZB]
 
Posts: 36 since Sep 2009
Thanks: 12 given, 22 received


nano,

You have to first tackle the task of getting the strategies to speak to one another. There are a lot of solutions to this, but the most promising looks to be this. Once you get that, you'd be looking to do the same thing I am asking. As far as my question goes, I'm mainly looking at it for backtesting purposes, I can make it work realtime quite easily, but in the backtester it totals them all over all the days, so it becomes slightly more complex.

Also, anyone know when NT7 is coming out? Is it ever?

Reply With Quote
 
  #4 (permalink)
Elite Member
Brisbane, Australia
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Mirus/Zen-Fire
Favorite Futures: CL
 
nanobiotech's Avatar
 
Posts: 670 since Jun 2009
Thanks: 134 given, 428 received

Thanks zwentz.

Given that NT6.5 does keep totals of net trades across multiple instruments, hopefully NT7 may have the feature to close positions for individual instruments, groups of instruments and all instruments when specific targets for profit/loss are hit.

Anyone know if NT7 will have this facility?

Nano

Reply With Quote
 
  #5 (permalink)
Elite Member
Calgary Canada
 
Futures Experience: Intermediate
Platform: Ninja
Broker/Data: IB/Kinetic
Favorite Futures: 6E, CL
 
jackyd's Avatar
 
Posts: 47 since Jun 2009
Thanks: 44 given, 18 received

Hi zwentz,

Here is a code snippet I posted back in July that should have what you're looking for...
https://futures.io/free_downloads/ninjatrader/code_snippets/71-download.html?view

specifically this part...
 
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;}
Basically, you track the cumulative profit at the start of each session so that you can later eliminate it when you calculate the daily max profit/loss amounts.


zwentz View Post
I'm trying to code a strategy that stops trading that day if it loses too much that is backtester compatible. I found this thread over at NinjaTrader's support forum, but it's still wrong. I think I saw Big Mike in that thread over there as well, so I figured this would be the best place to ask.

Here's my code, but it doesn't seem to be working. Can anyone help?

Note: I'm speaking specifically about the backtester, the problem is that it acts as if the strategy ran straight through the entire backtesting period. So your cumulated profits are always rising, hopefully, and you can't find out what it is for the day.

 
Code
protected override void OnBarUpdate()
        { 
            double currentProfits = Position.GetProfitLoss(Close[0], PerformanceUnit.Currency);
            double cumulatedProfits = Performance.AllTrades.TradesPerformance.Currency.CumProfit;
            int indicator = MyIndicator(1)[0];

	    if (ToTime(Time[0]) < 143000 && ((cumulatedProfits - realized) + currentProfits > PosiProfs || (cumulatedProfits - realized) + currentProfits < -NegiProfs))
            {
                canEnterTrade = false;
            }
	    else
            {
		canEnterTrade = true;
            }


            if (ToTime(Time[0]) >= 63300 && canEnterTrade)
            {
                    if (indicator == 1)
                    {
                        EnterLong(DefaultQuantity, "");
                    }

                    if (indicator == -1)
                    {
                         EnterShort(DefaultQuantity, "");
                    }
            }

            //if realized profits have been reached or we're at the close of the day, flatten everything
            if ((!canEnterTrade && Position.MarketPosition != MarketPosition.Flat) || (ToTime(Time[0]) >= 142700 && Position.MarketPosition != MarketPosition.Flat))
            {
                ExitLong("Close Out", "");
                ExitShort("Close Out", "");
                realized = Performance.AllTrades.TradesPerformance.Currency.CumProfit;
            }
        }


Reply With Quote
The following 3 users say Thank You to jackyd for this post:

Reply



futures io > > > > > Strategy stop trading at realized PnL

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

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
Some coding help adding PnL display to strategy grego The Elite Circle 5 March 23rd, 2012 02:12 PM
Volume stop Strategy Possible ? isarhodes NinjaTrader Programming 5 July 12th, 2011 05:02 PM
Stop strategy disabling when position closed. phantogram NinjaTrader Programming 5 May 19th, 2011 10:29 AM
MOVE STOP LOSS AFTER STRATEGY firecan NinjaTrader Programming 2 December 13th, 2010 06:54 AM


All times are GMT -4. The time now is 01:21 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-14 in 0.09 seconds with 19 queries on phoenix via your IP 54.234.255.29