Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

„Do not trade while..."

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

    „Do not trade while..."

    Hello everyone,

    for instance: I do not want, that my strategy releases a trade during a certain period.

    To clarified, what i mean, please look at the image below.

    My idea is : If HMA (14) [0] < Close [0] && HMA (14) [0] > Open [0] { enter what ???

    ...till this period is over, and Bars ar coming who are full over / or under the HMA, so that the strategy can work further.

    Thank you for support!
    Attached Files

    #2
    Deogenes,

    You do not want your strategy to be able to trade during a certain period?

    You could use a flag for that.

    if( HMA (14) [0] < Close [0] && HMA (14) [0] > Open [0] )
    {
    flag = false;
    }
    else
    {
    flag = true;
    }

    if ( Flag && Order_Entrance_Conditions )
    {
    EnterLong();
    }
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thank you Adam,

      below i have a example. If i put my conditions in „if" and when this is done... do i have to split the orders?
      I mean, must be a part in the long condition and the other part in the sell condition or does it not depand?

      [if (longTradeOk && Close[0] > Open [1] )
      {
      EnterLong(DefaultQuantity, "buy");

      SetProfitTarget("buy", CalculationMode.Ticks,20);
      //SetStopLoss("buy", CalculationMode.Ticks, 40, false);
      longTradeOk = false;
      shortTradeOk = true;
      }

      else if (shortTradeOk && Close[0] < Open[1])
      {
      EnterShort(DefaultQuantity, "sell");

      SetProfitTarget("sell", CalculationMode.Ticks, 20);
      //SetStopLoss("sell", CalculationMode.Ticks, 40, false);
      longTradeOk = true;
      shortTradeOk = false; ]

      Comment


        #4
        Deogenes,

        You would want to put "Flag" as an additional condition in both sets of "if" statements for example.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Okay,

          i see. It ´s late in Germany, i will program it next morning, and tell you if it works.

          At first thanks a lot.

          Comment


            #6
            Originally posted by Deogenes View Post
            Okay,

            i see. It ´s late in Germany, i will program it next morning, and tell you if it works.

            At first thanks a lot.
            Need Help!

            The basis of my code below, but where to put the flag conditions in. I tried many ways... belive it depends on " Order_Entrance_Conditions" - can somebody help me ?

            [if (longTradeOk && HMA(Close, 3)[0] > Close[0]
            && Close[0] > HMA(Median, 14)[0])
            {
            EnterLong(DefaultQuantity, "Buy");
            SetProfitTarget("buy", CalculationMode.Ticks,8);
            //SetStopLoss("buy", CalculationMode.Ticks, 40, false);
            longTradeOk = false;
            shortTradeOk = true;
            }
            //Condition set 2

            else if (shortTradeOk && HMA(3)[0] < Close[0]
            && Close[0] < HMA(Median, 14)[0])

            {
            EnterShort(DefaultQuantity, "Sell");
            SetProfitTarget("sell", CalculationMode.Ticks,8);
            //SetStopLoss("sell", CalculationMode.Ticks, 40, false);
            longTradeOk = true;
            shortTradeOk = false;]

            Comment


              #7
              Deogenes,

              Try this :

              Code:
              private bool flag = true;
              
              protected override void OnBarUpdate()
              {
              
              
                if( HMA (14) [0] < Close [0] && HMA (14) [0] > Open [0] )
                {
                   flag = false;
                }
                else
                {
                   flag = true;
                }
              
                if (flag && longTradeOk && Close[0] > Open [1] )
                {
                   EnterLong(DefaultQuantity, "buy");
              
                   SetProfitTarget("buy", CalculationMode.Ticks,20);
                   //SetStopLoss("buy", CalculationMode.Ticks, 40, false);
                   longTradeOk = false;
                   shortTradeOk = true; 
                }
              
                else if (flag && shortTradeOk && Close[0] < Open[1])
                {
                   EnterShort(DefaultQuantity, "sell");
                
                   SetProfitTarget("sell", CalculationMode.Ticks, 20);
                   //SetStopLoss("sell", CalculationMode.Ticks, 40, false);
                   longTradeOk = true;
                   shortTradeOk = false;
              
                }
              
              }
              Last edited by NinjaTrader_AdamP; 06-20-2012, 08:31 AM.
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                Hello Adam,
                thanks for being back again, with me.

                I made the same just a moment befor you came in. The hole Thing looks like so: but it do not work! There are a lot of Errors.

                #region Variables
                private bool longTradeOk = true;
                private bool shortTradeOk = true;
                private bool flag = true;
                #endregion

                /// <summary>
                /// This method is used to configure the strategy and is called once before any strategy method is called.
                /// </summary>
                protected override void Initialize()
                {
                CalculateOnBarClose = true;
                }

                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                private flag = true;
                protected override void OnBarUpdate()

                {
                //Condition set 1

                if( HMA (14) [0] < Close [0] && HMA (14) [0] > Open [0] )
                {
                flag = false;
                }
                else
                {
                flag = true;
                }

                if ( Flag && longTradeOk && HMA(Close, 3)[0] > Close[0]
                && Close[0] > HMA(Median, 14)[0])
                {
                EnterLong(DefaultQuantity, "Buy");
                }
                SetProfitTarget("buy", CalculationMode.Ticks,8);
                //SetStopLoss("buy", CalculationMode.Ticks, 40, false);
                longTradeOk = false;
                shortTradeOk = true;

                }

                else if( HMA (14) [0] < Close [0] && HMA (14) [0] > Open [0] )
                {
                flag = false;
                }
                else
                {
                flag = true;
                }
                if (Flag && shortTradeOk && HMA(3)[0] < Close[0]
                && Close[0] < HMA(Median, 14)[0])

                {
                EnterShort(DefaultQuantity, "Sell");
                SetProfitTarget("sell", CalculationMode.Ticks,8);
                //SetStopLoss("sell", CalculationMode.Ticks, 40, false);
                longTradeOk = true;
                shortTradeOk = false;

                }


                }

                #region Properties
                #endregion

                Comment


                  #9
                  Deogenes,

                  if( HMA (14) [0] < Close [0] && HMA (14) [0] > Open [0] )
                  {
                  flag = false;
                  }
                  else
                  {
                  flag = true;
                  }

                  Is only needed once

                  Also, I made a mistake in the original code.

                  private flag = true; should be private bool flag = true;

                  You can attach your code as a file to your message next time and it may be easier. Code is located in My Documents / NinjaTrader 7 / bin / custom / strategy for this case.

                  Also note : HMA (14) [0] < Close [0] && HMA (14) [0] > Open [0] only tests for if the HMA is inside a "bullish" bar. You may want to add a condition for a bearish one as well.
                  Adam P.NinjaTrader Customer Service

                  Comment


                    #10
                    Adam,
                    it´s much better now / only two Errors. I know how to find the folder (bin) but how to put it in this box ?
                    Help!

                    Comment


                      #11
                      Deogenes,

                      You can hit the "Go Advanced" button when you respond. In there, there is a "Manage file attachments" that let you add the file.
                      Adam P.NinjaTrader Customer Service

                      Comment


                        #12
                        ...to know How :-)

                        Please take a look at that. And then, the second Problem is what you told with the "bullish" thing - thats true!(?)
                        Attached Files

                        Comment


                          #13
                          Deogenes,

                          Please find a modified one attached. If you check if you are above the open and close, or below the open and close, this is similar. I have added it in as well.

                          Here is a video on NinjaScript programming : http://www.youtube.com/watch?v=JZpo01eSO9c
                          Attached Files
                          Adam P.NinjaTrader Customer Service

                          Comment


                            #14
                            Wow!

                            Many, many Thanks to you. Now i can look further, and avoid things nobody likes.

                            Comment


                              #15
                              Deogenes,

                              No problem, please feel free to contact us for any educational items as you learn how to code in NinjaScript.
                              Adam P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              649 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              370 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              576 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X