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

excute order entry just once

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

    excute order entry just once

    Hi,

    How should I write a code to excute order entry just once although
    strategy may generate many signals? For example, if I have two moving
    average cross strategy, it will generate long or short signal whenever
    fast moving average crosses over or below slow moving average. I just
    want to take first signal and ignore any signal after first. How should I
    code this situation?

    Thanks in advance.

    #2
    Hello,

    I suggest creating a bool flag that is set to true or false, then have that flag as a condition to trading.

    Let me know if you have questions.
    DenNinjaTrader Customer Service

    Comment


      #3

      Comment


        #4
        Hi m3power222,

        No. I just shut down the strategy as soon as I take the first signal.

        Comment


          #5
          Badasan,
          Here's a simple way to do what Ben is suggesting. I don't use the boolean, but a simple variable. I'm not going to write it in code, but it will give you the idea:

          First, Add this to your variables section in the Ninjascript strat you are writing:
          private int firstcross = 0:

          Then, for the first entry condition:

          If (firstcross <= 0
          && SMA7 crosses SMA 20
          {
          Enter Long (or Short);
          firstcross = 1
          }

          From that point on, as long as firstcross is not reset to zero, it won't take any more trades.
          Hope that helps,
          Joe

          ** This variable thing is REALLY handy to do all kinds of things with a script!

          Comment


            #6
            Thank you very much Trade1953. I appreciate your help.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by thaboushca, Today, 09:39 AM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by JakeOfSpades, Today, 09:34 AM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by lorem, 04-25-2024, 09:18 AM
            12 responses
            54 views
            0 likes
            Last Post lorem
            by lorem
             
            Started by ETFVoyageur, Today, 05:50 AM
            6 responses
            41 views
            0 likes
            Last Post ETFVoyageur  
            Started by thumper57, 05-11-2024, 04:30 PM
            14 responses
            41 views
            0 likes
            Last Post thumper57  
            Working...
            X