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

How to write an accurate code for my scalping strategy

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

    How to write an accurate code for my scalping strategy

    Hi,

    I have a scalping strategy that needs to enter the trade as soon as condition is meet, not after the bar closes. I used the granularity sample code and ran it in the back-tester and it didn't work as had thought that it would. While it wasn't always entering at the exact close of the bar, it was like always a minute after the primary bar and the chances that the moving averages crossing always one minute past the primary bar is pretty much 0%.

    So what is an easy way to program a code that would allow me to enter a trade intrabar?
    Also, I can't have spreads greater than one. My broker spread FXCM would average about 1 pip including the commission that they charge. How can I get around the 3-pips spreads that I been seeing when I run it in the simulator? I'm not 100% sure how they do it in the backtester, but I'm assuming that the spreads are handled the same way as the simulator.

    #2
    Hello,

    Thank you for the question.

    You are on the correct path, you would either need to use a multi timeframe script, or add a tick series to execute orders on, another option would be to use the OnMarketData override but this would only be for realtime.

    In either case logic can be executed on a tick by tick basis, in backtesting a Tick series would be needed. In realtime either option could be used.

    I would like to ask, have you tried the strategy in realtime yet to see if it actually is doing what it should? Depending on how the script is programmed, the granularity will allow for more accurate backtesting but can still differ from realtime so it is best to check if this works in realtime as well.

    Regarding your spread question, can I clarify, by "Simulator" are you referring to the sim101 account or the Simulated Data feed?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      I had a discussing with Mike with this matter. The thread is located here:



      He goes to explain that the sample code provided in the forum isn't going to help me reach my goal because of what was explained in that thread. What I'm trying to do is create a strategy that can place trades within the 5 min bars--anytime in that 5 min bar that my condition is satisfied. He went ahead explain how NJ8 fixed that problem, but I later determined that problem is going to be implemented in NJ8, but it is currently being worked on.

      And for the simulator, it is sim101. When I look at the bid/ask prices, the spread is bigger than my broker spread. The difference is so significant that I might can run this strategy profitably with my broker, but I would love to test it out.

      As far as running it live, I just test it on the simulator. I don't have a VMS to run it just yet on a demo account.

      Thanks

      Comment


        #4
        Hello,

        Thank you for the reply.

        Because you already have another thread open with another support member for the first question, I will let him address that in the other thread to avoid any confusion.

        Regarding the spread, If by Simulator you mean the Simulated data feed, there is no way to modify the values this connection uses as this connection is random fake data that is irrelevant to an actual market.

        To have the actual price values from the broker you would either need to use a Live data connection from the brokerage or a demo connection. In either case these would match correctly to the broker where the simulated data feed is fake data.

        The sim101 can be used with any connection, this is just a local trading account so it could be used with a live data source with the strategy.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi,

          That thread is pretty old and I went on to work on building this scalping strategy on NJ8, then I realized that the Tick Replay features is currently not working. So because of that, I decided to write in another thread trying to find a way to accurately write my scalping strategy that would allow me to trade intrabar. This thread is completely different from others that I wrote. The one with Mike was me trying to figure out why I couldn't get the sample code to work as I thought that it should. Being that the sample code wasn't designed to fix the problem that I'm having, I decided to write a thread to see if anyone has any suggestions or for that matter, a sample somewhere that would trade intrabar.

          Also, I meant to say the account was Playback101 instead of sim101. My fault. The spreads is about 3 pips which is about 2 more than what I will be paying on a EUR/USD. I'm not trying to be difficult to deal with, but obviously that is a big dilemma that I would have to solve in order to write profitable scalping strategies. They is nothing I can do programmatically that can fix this issue. Correct? Knowing that answer would allow me to stop allocating time and resources into trying to do something that might not be possible.

          Thanks so much

          Comment


            #6
            Hello BernWillChris,

            You need to have added a 1 tick series to the script.

            Then only process the logic when BarsInProgress == 1 which is the secondary tick series.

            When calling any indicator provide BarsArray[0] which is the primary series do to calculations.

            Then when your condition is true it will not wait until the bar closes to place the order, it will be placed immediately.

            May I confirm that your script processes when BarsInProgress is 1 and you are supplying BarsArray[0] to any indicator calls?

            BarsInProgress - http://ninjatrader.com/support/helpG...inprogress.htm

            BarsArray- http://ninjatrader.com/support/helpG.../barsarray.htm
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Trader146, 03-29-2024, 01:22 PM
            4 responses
            24 views
            0 likes
            Last Post Trader146  
            Started by elirion, Today, 09:48 PM
            0 responses
            2 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by set2win, 08-04-2021, 09:23 AM
            39 responses
            1,001 views
            0 likes
            Last Post WaleeTheRobot  
            Started by md4866, Today, 08:15 PM
            0 responses
            8 views
            0 likes
            Last Post md4866
            by md4866
             
            Started by mjbatts91, Yesterday, 04:48 PM
            2 responses
            23 views
            0 likes
            Last Post mjbatts91  
            Working...
            X