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 charlesugo_1, 05-26-2026, 05:03 PM
            0 responses
            61 views
            0 likes
            Last Post charlesugo_1  
            Started by DannyP96, 05-18-2026, 02:38 PM
            1 response
            149 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            162 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 05-10-2026, 08:12 PM
            0 responses
            99 views
            0 likes
            Last Post CarlTrading  
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            286 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Working...
            X