Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

    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");
        				}

        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:


            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 jeronymite, 04-12-2024, 04:26 PM
            2 responses
            28 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by Mindset, 05-06-2023, 09:03 PM
            10 responses
            263 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by michi08, 10-05-2018, 09:31 AM
            5 responses
            742 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by The_Sec, Today, 02:29 PM
            0 responses
            2 views
            0 likes
            Last Post The_Sec
            by The_Sec
             
            Started by tsantospinto, 04-12-2024, 07:04 PM
            4 responses
            63 views
            0 likes
            Last Post aligator  
            Working...
            X