• 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

Multi-Timeframe & Profit Calculation

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

    Multi-Timeframe & Profit Calculation

    Hi,

    I have a couple questions after practicing some programming.

    I'm trying to understand how to get multiple timeframes for a strategy. I'm looking at this simple strategy using a day primary bar series and tried adding an additional bar series to get a quicker signal for trading. but when I add the bar series (a 30 minute series) and the BarsInProgress == 0, it does not work. If I remove the BarsSinceEntry or BarsSinceExit, then it works, but then that changes the logic. What is wrong here? I simply want to be able to get a signal the same day it is triggered instead of waiting for the next day because I don't have a shorter bar series.

    Also, I have a general question regarding the cumulative profit calculation. Specifically, when this particular strategy enters two positions at the same time, I'm unable to follow the logic in the profit calculation. If for example, the first position produces 6.88% profit and the second position produces 4.91% profit, the total it calculates for the cumulative is 12.13%. Why is this,and more importantly, is this correct for this logic?? I understand how the cumulative profit is calculated, but I guess I don't believe that this is correct for this since they are parallel trades. I do not claim to be an expert, so I'm looking for some insight here. If these trades were entered at the same time, with the same quantity, why would the cumulative profit be 12.13% instead of 11.79% ?

    Thanks for the help,

    Regards,

    Lee
    Attached Files

    #2
    Hello Lee,

    Thank you for your post.

    Your logic prevents an initial trade from occurring on the secondary series when OrigEntryLogic is set to false.
    Code:
    else if (Position.MarketPosition == MarketPosition.Flat && (BarsSinceExit("") == -1 || BarsSinceEntry("Long1") > IdleBars || BarsSinceExit("Long2") > IdleBars))
    This will never return true because there was not first an entry that did not require a previous entry or exit. You will need to create a condition that allows for the first trade to go through without the restrictions of BarsSinceEntry or BarsSinceExit.

    You can use a bool that is true and when the first entry is submitted is then false, check for this bool as true before submitting the first entry.

    For the Cumulative Profit question, the two entries are considered two trades based on their entry and exit signal names and times.

    Please let me know if I may be of further assistance.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Hi Patrick,

      Thanks for the response. I will try to add a bool to it. Do you have a suggestion on what this would look like?

      Regarding the profit calculation, I see that they are considered two trades, but is the summing of the profits correct? This small difference adds up quickly and if I am to look at the cumulative profit over a longer period, can I believe the total number? If its correct, then great, but I'm concerned about its accuracy (for this strategy). The two trades are parallel, so can the profit be calculated this way?

      Thanks for all the support,

      Regards,

      Lee

      Comment


        #4
        Hello Lee,

        Thank you for your response.

        For the profits, you would have to enter the 2 quantity together in one order and exit them together.

        For the BarsSinceEntry and Exit, please refer to the example below:
        Code:
        		private bool initialTrade = true;
                #endregion
        
                protected override void Initialize()
                {
                    CalculateOnBarClose = true;
        			SetStopLoss(CalculationMode.Percent, PctLoss);
        			EntryHandling = EntryHandling.UniqueEntries;
        			Add(PeriodType.Minute, 30);
        		}
        		
        		protected override void OnBarUpdate()
                {
        		if (BarsInProgress == 0)
        		  {
        			if (CrossBelow(StochasticsFast(1, StochPer).K, Threshold, 1))
        			{
        				if (OrigEntryLogic)
        					EnterLong(0, DefaultQuantity, "Long1");
        				
        				else if(initialTrade && Position.MarketPosition == MarketPosition.Flat)
        				{
        					EnterLong(1, DefaultQuantity, "Long1");
        					EnterLong(1, DefaultQuantity, "Long2");
        				}
        				else if (!initialTrade && Position.MarketPosition == MarketPosition.Flat && (BarsSinceExit("") == -1 || BarsSinceEntry("Long1") > IdleBars || BarsSinceExit("Long2") > IdleBars))
        				{
        					EnterLong(1, DefaultQuantity, "Long1");
        					EnterLong(1, DefaultQuantity, "Long2");
        				}
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          I will like to learn how to develop and automate a multiple timeframe strategy, I know NinjaTrader 7 have that capability. Please refer me to any training videos available. Thanks

          Comment


            #6
            Hello,
            Thank you for writing to the forum.
            There is a sample strategy for multiple timeframes called SampleMultiTimeFrame. You may look at as an example of how to do this. Open this in NinjaTrader 7 by clicking Tools>Edit NinjaScript>SampleMultiTimeFrame. To access it in NinjaTrader 8, select New>NinjaScript editor, and SampleMultiTimeFrame will be in the 'Strategies' folder.

            Here are some tips on using multi-time frame. It explains how you can add additional data and reference it and use for calculations. See the 'add additional bars' section:
            https://ninjatrader.com/support/help...nstruments.htm

            This also includes documentation for the components that need to be used in multi-time frame strategy development.

            Please let me know if I may be of any further assistance.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Revan, Yesterday, 11:53 PM
            4 responses
            23 views
            0 likes
            Last Post NinjaTrader_Jim  
            Started by Vincere, Today, 03:32 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_ChrisSch  
            Started by hir04068, Today, 04:26 AM
            0 responses
            5 views
            0 likes
            Last Post hir04068  
            Started by Thomas79, Today, 03:22 AM
            0 responses
            3 views
            0 likes
            Last Post Thomas79  
            Started by pjsmith, Today, 12:50 AM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_ChrisSch  
            Working...
            X