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

Scalping Strategy

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

    Scalping Strategy

    Hey everyone! I've been working on this strategy but I get errors every once in a while when the code is executing when backtesting. The program will execute three or four trades before it automatically shuts off when an execution error occurs. Can someone look at my code and tell me what 'm doing wrong? Thank you!
    Attached Files

    #2
    Hello Cubanaso24, thanks for writing in.

    Please look in the Log tab of the Control Center, what is the exact error you are getting from this strategy?

    I look forward to hearing from you.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Order='3f1c65b2b3bb44d79c7767cac5f63057/Playback101' Name='Sell' New state='Rejected' Instrument='NQ 06-21' Action='Sell' Limit price=0 Stop price=12763.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='Order rejected' Native error='Sell stop or sell stop limit orders can't be placed above the market.'

      Comment


        #4
        I don't understand why this only happens after a couple of trades have been executed

        Comment


          #5
          Hello Cubanaso24, thanks for your reply.

          The strategy is submitting a sell order on the wrong side of the market. Add Print methods throughout the strategy to print the data the strategy is using and the prices it is submitting orders at. The incorrect price should show up in the prints before the error is hit, that will help to solve the bug.

          https://ninjatrader.com/support/help...nt8/?print.htm - Print()

          Please let me know if I can assist any further.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by Cubanaso24 View Post
            Hey everyone! I've been working on this strategy but I get errors every once in a while when the code is executing when backtesting. The program will execute three or four trades before it automatically shuts off when an execution error occurs. Can someone look at my code and tell me what 'm doing wrong? Thank you!
            Interesting strategy, I have a similar one using MACDBBLines but use MACD crossing BBUpper instead of BBLower which when changing your condition for long does much better. I always add a separate bool TradeLong == true and TradeShort to be able to see how the strategy does long or short and yours does much better Long. I don't ever see it stoploss which is strange
            Your ExitLongStopMarket(Convert.ToInt32(ScalpContracts) , (Position.AveragePrice + (ScalpSL * TickSize)) , @"SM", @"ScalpLong"); has a plus sign which is not a stop, it does capture profit. When backtesting using Strategy analyzer the trade only exits on a positive win. Some of trades go on 2000 bars before closing. I mainly use NQ also, this on a minute chart does quite well in backtest but would have to see in Live Sim trading to see if it is real. You can also add RealtimeErrorHandling.StopCancelCloseIgnoreRejects to see if this helps on rejected orders. NQ moves so fast that the order you are trying to place gets rejected. I'll play with this some more and will report any improvements.

            Comment


              #7
              Hi Cubanaso24, yes after backtesting in Playback mode you are getting errors just as I suspected due to trying to enter a stoploss that is a positive number. Put a minus sign on each of those ExitLongStopMarket conditions and it will fix your problem. So far trading last week in Playback it seems to do quite well. Remember to give your Long and short conditions an extra condition to tradeLong or tradeshort boolean to see how it does each direction.

              Comment


                #8
                Originally posted by Cubanaso24 View Post
                I don't understand why this only happens after a couple of trades have been executed
                Hi Cubanaso,

                I agree with everything that Chris and set2win wrote.

                "I don't understand why this .. happens.. "

                The answer is it is either 1) a logic problem or 2)..

                So what is the fix? 1) a logic problem .. If we are innovating fast enough we all make logic mistakes and the print suggestion from Chris is great to help sort that out.


                So what is the fix? 2) .. If your logic is correct then price has moved and the error message is correct.

                Personally, Prilnt()s or correcting my logic mistakes were never enough to solve the problem. The fix has been to better account for market data delays.

                The real current Price is really not what your system thinks it is. Pragmatically, to gain more reliability expect your "real-time" market data is often 1-3 seconds behind.



                Scalping implies a fast market.. set2win offers good suggestions to try "I suspected due to trying to enter a stoploss that is a positive number. Put a minus sign on each of those ExitLongStopMarket conditions and it will fix your problem"

                I will add to his..

                If you are scalping tight entries and stops on a fast moving market

                1) Add a 1 tick series and while you might signal entries off your primary chart or data series execute entries and exits against that 1 tick data series. NT has a great example strategy code here to copy from.. Ask Chris for a link to that example.

                2) "If you are scalping tight entries and stops on a fast moving market.. " Then lean less on "Position.AveragePrice" (the market could not care less what we paid and has now moved on) and trust your Entries, Exits and CHANGE Order price inputs to GetCurrentBid()/Ask() against that I tick BarsArray[x] (again see the example Chris can provide).

                As well as..

                https://ninjatrader.com/support/help...currentbid.htm
                https://ninjatrader.com/support/help...currentask.htm


                3) If your scalping a fast moving market expect your "real-time" market data is 1-3 seconds behind so for new Entries, Exits and Change order submissions place all Limit and Stop prices at least X ticks away/further/past the current prices reported by GetCurrentBid()/Ask().

                Test sim executions on each instrument to find out how many ticks "X" needs to be for that instrument.




                Best of Luck!
                HedgePlay
                Last edited by hedgeplay; 04-11-2021, 01:08 PM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by snoussi, Today, 12:26 PM
                3 responses
                9 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by reynoldsn, Today, 12:42 PM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by f.saeidi, Today, 12:35 PM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by Italohispanico, Today, 12:39 PM
                0 responses
                4 views
                0 likes
                Last Post Italohispanico  
                Started by SnailHorn, 05-02-2024, 10:49 PM
                3 responses
                30 views
                0 likes
                Last Post SnailHorn  
                Working...
                X