• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to stop a strategy after a daily profit target is reached.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to stop a strategy after a daily profit target is reached.

    Is there a way to stop a trading strategy after a daily profit target is reached. For instance after 4 ticks/$$$/%. I know there is one for each individual trade, but what about for a daily limits?

    Thanks. I will continue to search in the help section to see if its in there.

  • stphnlwlsh
    replied
    I know this is an old thread, but in case anyone else comes along...

    IncludeTradeHistoryInBacktest = true;

    That should fix the issue OP was experiencing.

    Leave a comment:


  • olingerc
    replied
    Yes I was having issues with the back testing. No changes were showing up during a back test. Assuming I change it to RealtimeTrades it would actually work live during a intraday cession. But unfortunately if I cant back test this then I am not willing to spend months of playing around with a live account only to realize that I would of made more money if I just hadn't done it to begin with.

    Leave a comment:


  • NinjaTrader_RyanM1
    replied
    Code looks OK and I don't see where you are deviating from the sample at all. just ran the sample here and it's working as expected. You have more than one session, right?

    In a backtest there are no real time trades so that won't work for you. Attach the script (exported zip file) you're using and screenshots of your backtest setup and will give it a run here.

    Leave a comment:


  • olingerc
    replied
    Ryan I am having trouble with this till. I believe I have the correct code in the correct location but during a back test it does not calculate. I can set the profit target to lets say 10,000 and during a back test it will only test up to 10,000 and nothing after. or if its 1000 it would test until a profit of 1,000 is met and nothing after. Why is this so? If I set it to RealtimeTrades would it only calculate the current day's live account information?

    How do I get my strategy to exit during the intraday after lets say a profit of 1,000 is reached.
    This is what I have so far
    // At the start of a new session
    if (Bars.FirstBarOfSession)
    {
    // Store the strategy's prior cumulated realized profit and number of trades
    priorTradesCount = Performance.AllTrades.Count;
    priorTradesCumProfit Performance.AllTrades.TradesPerformance.Currency.C umProfit;

    // NOTE: Using .AllTrades will include both historical virtual trades as well as real-time trades.
    //If you want to only count profits from real-time trades please use .RealtimeTrades.
    }

    //Prevents further trading if the current session's realized profit exceeds $1000

    if (Performance.AllTrades.TradesPerformance.Currency. CumProfit - priorTradesCumProfit >= 1000)
    {
    //TIP FOR EXPERIENCED CODERS: This only prevents trade logic in the context of the OnBarUpdate() method. If you are utilizing
    other methods like OnOrderUpdate() or OnMarketData() you will need to insert this code segment there as well.

    // Returns out of the OnBarUpdate() method. This prevents any further evaluation of trade logic in the OnBarUpdate() method.
    return;
    }
    Last edited by olingerc; 05-06-2011, 03:03 PM.

    Leave a comment:


  • NinjaTrader_RyanM1
    replied
    You should be able to import that sample in either version. It sounds like you are missing the variable declaration.

    #region Variables
    private int priorTradesCount = 0;
    private double priorTradesCumProfit = 0;
    #endregion

    You can custom code MFE if you want it calculated while you're in a trade:

    Understanding Average MFE
    Where MFE (max. favorable excursion) is defined as (best price trade reached – entry price), quantity is defined as the number of contracts traded, and point value is defined as the monetary conversion of each point (e.g. 100 for currency pairs).

    Example with long position:
    if (Position.MarketPosition == MarketPosition.Long)
    myDouble = High[BarsSinceEntry()] - Position.AvgPrice;

    Leave a comment:


  • olingerc
    replied
    I extracted the correct part of the code but when I compile I get this error "priorTradesCount" wherever priortrades" is mentioned it says "does not exist in current context" I imagine in NT 6.5 this existed? What is the equivalent for NT7?

    Thanks

    Leave a comment:


  • olingerc
    replied
    Is there anthing in the code to check for "Maximum favorable Excursion" value? that is basically the value I am looking for. I will check out the link to see if I can get what I desire. Thanks.

    Leave a comment:


  • NinjaTrader_RyanM1
    replied
    Hello olingerc,

    For this you can work with Trade Performance class and reset values for each day.

    This sample is pretty close to what you're looking for:
    http://www.ninjatrader.com/support/f...ead.php?t=4084

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by Atilla, Today, 04:05 PM
0 responses
6 views
0 likes
Last Post Atilla
by Atilla
 
Started by Displacer, Today, 02:57 PM
2 responses
13 views
0 likes
Last Post Displacer  
Started by SAILIKITY, 05-22-2019, 05:41 PM
1 response
8 views
0 likes
Last Post NinjaTrader_PaulH  
Started by rmillar, 01-09-2019, 06:02 PM
6 responses
71 views
1 like
Last Post eDanny
by eDanny
 
Started by mlarocco, Today, 11:39 AM
4 responses
23 views
0 likes
Last Post mlarocco  
Working...
X