Announcement

Collapse
No announcement yet.

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 cmoran13, Yesterday, 01:02 PM
            0 responses
            29 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            21 views
            0 likes
            Last Post PaulMohn  
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            160 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            95 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            148 views
            2 likes
            Last Post CaptainJack  
            Working...
            X