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

strategy opens order on enable without signal

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

    strategy opens order on enable without signal

    Hi, when i enable strategy it opens right when its enabled without a valid signal. What else i can incldue so it doesnt open right after its enabled?

    Code:
     protected override void OnBarUpdate(). 
            {
                if (CurrentBar < FastEMAPeriod || CurrentBar < SlowEMAPeriod || BarsInProgress != 0)
                    return;
                if (CurrentBar < Math.Max(BarsRequiredToTrade, BarsBefore))
                    return;
                  if (CurrentBars[0] < 2) //Need more than 2 bars to trade
                {
                    return;
                }
                if (State == State.Historical)
                    return;
    
                if (BarsInProgress == 2) return;​
    In my entry logici have
    && (BarsSinceExitExecution(0, "", 0) > 2) || (BarsSinceExitExecution(0, "", 0) == -1)

    #2
    Hello tkaboris,

    Thank you for your post.

    The snippet you provided does not offer insight as to why the entry is occurring right when the strategy is enabled. You have only included part of your entry logic; I suggest adding a print statement that prints all of the values used in your entry condition so you may see why the condition would be evaluating to true and submitting the entry. For a guide on using prints to debug your script, please see the following page:


    If you are unsure of what to add in your print, please provide the full entry condition and I would be glad to offer an example print statement that you could test out.

    Please let me know if I may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Before i go that route. i want to mention its only opens on open when in sim trading, when in market replay its not doing it. Is there any specific code that can be used againts that? because logic seems ok.

      Comment


        #4
        Hello tkaboris,

        Thank you for your reply.

        Other than logic, the only other thing that I could think of that might result in a position being opened immediately after enabling the strategy would have to be the start behavior selected in the strategy properties. What start behavior do you have selected when trading in sim on real-time data? For more information about the different behaviors:


        I look forward to your reply.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          HI i have usualy wait until flat in my strategy
          Click image for larger version

Name:	image.png
Views:	68
Size:	36.1 KB
ID:	1242474

          Comment


            #6
            Hello tkaboris,

            Thank you for your reply.

            What is your condition that results in an entry being submitted?

            I appreciate your patience and look forward to assisting you further.
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              Than you for your patience...
              basically its these and it opens long right after strategy gets enabled Most of them are marked as true

              Code:
                if (longsOn)
                              {
                                  #region 34B
              
              
                                  if (Trade34B
              
                                      && ((Trade34B == true)
                                      && (!IsInLongTrade) && (!IsInShortTrade) && (stopOrder == null)    && (Position.Quantity == 0)
                                      && (Trade34B && AngulationOn ? (emaAngulation >= (EMAAngulation * TickSize)) : Close[0] > 0)  
                                      && (Trade34B && AngulationOn ? (emaAngulationXBarsBefore >= (EMAAngulationXBarsBefore * TickSize)) : Close[0] > 0)                        
                                      && (Trade34B && FiveBarRetracement ? ((Close[1] < Open[1]) && (Close[2] < Open[2]) && (Close[3] < Open[3])                          
                                      && (Close[4] < Open[4]) && (Close[5] < Open[5])) : Close[0] > 0)                        
                                      && (Trade34B && ThreeBarRetracement ? ((Close[1] < Open[1]) && (Close[2] < Open[2]) && (Close[3] < Open[3])) : Close[0] > 0)                          
                                      && (Low[0] < Low[1]) && (Low[0] <= slowEMA[0]) && (Close[0] > (slowEMA[0] + ABEMA34B * TickSize) && fastEMA[0] > slowEMA[0]) // standard reversal form    
                                      && (Trade34B && NoTradeAgainstWick ? (Close[0] > High[1]) : Close[0] > 0)                                                
                                      && (Trade34B && FilterEMA ? (filterEMA[0] <= slowEMA[0] && (distancefilterEMAand34 >= (6 * TickSize))) : Close[0] > 0)                              
                                      && (Trade34B && MarginToRececntSwingHL ? (marginToRecentSwingH > (MarginToSwing * TickSize)) : Close[0] > 0)                        
                                      && (Trade34B && VolumeFilter ? (VOL()[0] > VolumeReading) : Close[0] > 0)
                                      && (Trade34B && StochFilter ? ((StochasticsFast1.D[0] <= StochLongLevels) && (StochasticsFast1.D[0] >= StochShortLevels)) : Close[0] > 0)
                                      && (Trade34B && LimitWicks ? (sumUpperWicks <= CumulativeWicks) : Close[0] > 0)
                                      && (Trade34B && DistanceSettlement ? (distToSettlment >= (DistToSettlment * TickSize)) : Close[0] > 0)
              
                                      && (Trade34B && DistanceOHL ? (distToOHLH) > (DistanceToOHL * TickSize) : Close[0] > 0)                        
                                      && (BarsSinceExitExecution(0, "", 0) > 2) || (BarsSinceExitExecution(0, "", 0) == -1)
                                      && (Position.MarketPosition == MarketPosition.Flat)))​

              Comment


                #8
                Hello tkaboris,

                Thank you for your reply.

                For the items marked as true, I suggest printing the values used in the true/consequent portion of the ternary conditions. If they are false, print the values in the false/alternative portion of the conditions. In order to understand how the condition is becoming true and submitting the entry, the prints will give you additional insight. This is part of debugging the script in order to identify the unexpected behavior. In addition to the guide on adding prints, we also have the following guides regarding debugging your code:



                You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create/assist with debugging this script or any others at your request or provide one on one educational services.

                Please let us know if we may be of further assistance.
                Emily C.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by George21, Today, 10:07 AM
                0 responses
                2 views
                0 likes
                Last Post George21  
                Started by Stanfillirenfro, Today, 07:23 AM
                8 responses
                23 views
                0 likes
                Last Post Stanfillirenfro  
                Started by DayTradingDEMON, Today, 09:28 AM
                2 responses
                16 views
                0 likes
                Last Post DayTradingDEMON  
                Started by navyguy06, Today, 09:28 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by cmtjoancolmenero, Yesterday, 03:58 PM
                8 responses
                32 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X