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

only entry in the first buy signal and the first sell signal, but not in the others

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

    only entry in the first buy signal and the first sell signal, but not in the others

    Good afternoon. I have a problem and need help.

    I have created a strategy that sometimes the entry and exit runs on the same candle. In this case, when backtesting, the signal happens multiple times and the inputs and outputs are also executed multiple times, when it should be a single input per signal.

    To fix it, I have used the condition (BarsSinceEntryExecution (1, "Largos1", 0) == -1)

    Multiple inputs per signal no longer occur. But the problem now is that input is only executed by the first long signal and the first short signal. For the other signals, the strategy draws them on the chart, but does not make the buy and sell inputs.

    I have tried, without success, to add in the conditions of entry

    BarsSinceExitExecution (the strategy stops operating)
    O well
    Position.MarketPosition == MarketPosition.Flat (only the first signal continues to run)

    But the problem is not solved.

    Thanks in advance and greetings.




    #2
    Hello mcjosejavier,

    Thanks for your post.

    Just to clarify, when you say you are backtesting, are you doing this in the Strategy Analyzer or on Market replay?

    What is the calculate setting for the strategy? (Calculate.OnBarClose, Calculate.OnPriceChange, Calculate.OnEachtick)?

    What bar type and time frame are you using?

    Can you post a screenshot that illustrates the issue you are trying to solve? (Please be sure to show the complete chart, including the time base, price scale, and instrument name/bartype)

    Can you elaborate on what you expect for the difference between your two statements:
    "...when backtesting, the signal happens multiple times and the inputs and outputs are also executed multiple times, when it should be a single input per signal." and "... the problem now is that input is only executed by the first long signal and the first short signal." Can you provide a screenshot that illustrates what you want to see?

    Are you working in the Strategy Builder or directly in Ninjascript?
    Last edited by NinjaTrader_PaulH; 08-03-2020, 01:04 PM. Reason: added question about strategy builder or ninjascript.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick reply.

      I am working on ninja script although I rely on strategy builder.

      The strategy executes OnEachTick, although I have been able to verify that the result does not vary if I set OnBarClose.

      I use three minute candle chart for signals and trades. I add a volumetric bar graph to use a specific indicator in signal formation.

      If I don't use BarsSinceEntryExecution, what can be seen in capture2 happens. Large number of inputs on a single signal when the input and output is on the same candle.

      If I use it, the problem described in the previous paragraph is solved, but now only the first long signal and the first short signal are executed. The rest of the signals have no inputs. Capture 1.

      This last problem occurs in both Strategy Analyzer and Market Repaly.

      Regards.

      Comment


        #4
        Hello mcjosejavier,

        Thanks for your reply.

        In the BarsSinceentryExection() method, it will return a -1 value when there is no previous entry so this would explain why it works once but not thereafter.

        You could try by also checking for a value >= 0 which would be the case after the first entry, for example: (BarsSinceEntryExecution (1, "Largos1", 0) == -1 || BarsSinceEntryExecution (1, "Largos1", 0) >= 0)

        If that does not work for you, another approach would be to use an int variable to save the bar number of the entry and for the entry add a check that the saved bar number is not the same as the current bar number. For example, using an int variable called entryBar:

        if (your conditions to enter && CurrentBar != entryBar) // CurrentBar is NOT equal to entryBar
        {
        // your entry orderhere
        entryBar = CurrentBar; // assign the value of the current bar as the entry bar.
        }
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Good afternoon.

          Thank you very much. The solution using (BarsSinceEntryExecution (1, "Long1", 0) == -1 || BarsSinceEntryExecution (1, "Long1", 0)> = 0) again results in a large number of executions when input and output occur on the same candle.

          I will try the other solution to see what happens.
          Last edited by mcjosejavier; 08-04-2020, 09:04 AM.

          Comment


            #6
            I'm going to leave the lines of code because I can't solve the problem.

            Thanks again.
            Attached Files

            Comment


              #7
              Hello mcjosejavier,

              Thanks for your post.

              I would suggest removing && (BarsSinceEntryExecution(0,Cortos1.ToString(),0) == -1) as well as && (BarsSinceEntryExecution(0,Largos1.ToString(),0) == -1)

              and re-testing.
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Thank you.

                We are gradually refining the strategy. It no longer gives a multitude of entries in the same candle when the exit and entry occurred in the same candle, and in each signal it executes the corresponding entry.

                But it continues with a strange behavior when the exit and entrance happens in the same candle. Capture 3.
                You should not make a new entry.

                Comment


                  #9
                  Hello mcjosejavier,

                  Thanks for your reply.

                  Looking at your code again i see that you have both an entry and an exit condition in the same code block. Please be aware that all entry methods will automatically detect when there is an opposite position and will automatically issue one order to close the position and then a second order to leave you in the desired position. If for example you are in a long position and your strategy goes to Enter short and exitlong at the same time you may end up with an additional order because the Entershort will try to close the long position as will the exitLong order. I would suggest removing the Exit long, exitshort orders and retesting.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    I have finally solved the problem. It wasn't about the ExitLong and ExitShort. I had created a bool variable to activate Shorts and another to Activate Longs. I have changed the code by removing this variables bool, and removing BarsSinceEntryExecution and using entryBar = CurrentBar, everything works perfectly.

                    Thank you very much.

                    A greeting.

                    Comment


                      #11
                      Hi mcjosejavier,

                      Did you test this strategy ?
                      Would you be able to share the zip file, I would like to do some backtesting on this strategy
                      Thanks in advance.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by funk10101, Today, 12:02 AM
                      1 response
                      11 views
                      0 likes
                      Last Post NinjaTrader_LuisH  
                      Started by GLFX005, Today, 03:23 AM
                      1 response
                      6 views
                      0 likes
                      Last Post NinjaTrader_Erick  
                      Started by nandhumca, Yesterday, 03:41 PM
                      1 response
                      13 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by The_Sec, Yesterday, 03:37 PM
                      1 response
                      11 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by vecnopus, Today, 06:15 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post vecnopus  
                      Working...
                      X