• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Not trading within the desired timeframe>> executing a trade on every single candle.

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

    #16
    Code:
    SetProfitTarget("0", CalculationMode.Ticks, Variable0);
    SetProfitTarget("", CalculationMode.Ticks, Variable1);
    SetTrailStop("", CalculationMode.Ticks, Variable2, false);
    SetTrailStop("", CalculationMode.Ticks, Variable3, false);
    First the SetProfitTargets. In the script currently there is no signal name 0 so this profit target would not be called, the second would be used instead.
    Sorry my coding is very weak.


    so would I have to use a signal name at all?


    I will just remove the 0.






    With the Trail Stops, these are both the same blank signal name so the first would be over taken by the second so in reality we are left with the following:
    Code:
    SetProfitTarget("", CalculationMode.Ticks, Variable1);
    SetTrailStop("", CalculationMode.Ticks, Variable3, false);

    and I would have to have a signal name?







    Next the way you are calculating the variables, you specify Ticks but the output from the variables is a price.
    Code:
    Variable3 = Low[0] + -2 * TickSize;
    Variable1 = Low[0] - ATR(14)[0] * TickSize;
    These are both price amounts rather than ticks placing the target and trail in some pretty strange locations if you will be using a price you will need to use CalculationMode.Price instead of CalculationMode.Ticks or use an amount of ticks rather than a price.
    [/QUOTE]


    Ok for the variables:


    1. How would I set CalculationMode.Price?

    For Var3, the objective is to have a stop two ticks below the low.

    so how would I formulate V3?

    Code:
     Variable3 = Low[0] + [???????]




    Thanks for the great support Jesse.

    Comment


      #17
      Hello,

      Thank you for the reply.

      For the signal names, This depends on what you are doing.

      If you will only be using one entry at a time you do not need to specify a signal name the "" will default to the single entry.

      The signal names are more for the use if you have multiple entries you can specify ProfitTarget A will go with entry A and ProfitTarget B will go with entry B, etc..

      For the CalculationMode.Price.
      This is a exact price so lets say you have a price of 2000 and want to place a stop at 1990, the price for CalculationMode.Price would be 1990.

      When you are using the Ticks this expects a single number value in ticks so 2 would be used for 2 ticks.

      There is two ways to do this, using the following would use the average fill price and be 2 ticks below.

      Code:
      SetTrailStop("", CalculationMode.Ticks, 2, false);
      Otherwise you can specify a pre calculated price from the low for example by using the Price rather than Ticks.

      Code:
      SetTrailStop("", CalculationMode.Price, Low[0] - 2 * TickSize, false);
      This would be 2 ticks below the Low as an exact price.

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

      Comment


        #18
        There is two ways to do this, using the following would use the average fill price and be 2 ticks below.

        Code:
        SetTrailStop("", CalculationMode.Ticks, 2, false);
        Otherwise you can specify a pre calculated price from the low for example by using the Price rather than Ticks.

        Code:
        SetTrailStop("", CalculationMode.Price, Low[0] - 2 * TickSize, false);
        This would be 2 ticks below the Low as an exact price.

        I look forward to being of further assistance.


        Which option out of the two is more robust?


        Thank You!

        Comment


          #19
          Hello.

          Thank you for the question, I am unsure I understand what you are asking.

          Each would depend on what you need to accomplish. If you are using calculations that in turn give you a price value it may be easier to use Price rather than Ticks. If you just have a set number of ticks that does not change then Ticks may be better.

          If this is not the scope of your question can you please clarify?

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

          Comment


            #20
            Originally posted by NinjaTrader_Jesse View Post
            Hello,

            For the CalculationMode.Price.
            This is a exact price so lets say you have a price of 2000 and want to place a stop at 1990, the price for CalculationMode.Price would be 1990.

            When you are using the Ticks this expects a single number value in ticks so 2 would be used for 2 ticks.

            There is two ways to do this, using the following would use the average fill price and be 2 ticks below.

            Code:
            SetTrailStop("", CalculationMode.Ticks, 2, false);
            Otherwise you can specify a pre calculated price from the low for example by using the Price rather than Ticks.

            Code:
            SetTrailStop("", CalculationMode.Price, Low[0] - 2 * TickSize, false);
            This would be 2 ticks below the Low as an exact price.

            I look forward to being of further assistance.

            Hi Jesse,




            Again , looking at the options you have .


            My trail stop has to be 2 ticks below the low (Long), and 2 ticks above the high (Short) . I cannot use average price, it's not what the model specifies.


            Thanks.

            Comment


              #21
              Hello,

              This line:

              Code:
              SetTrailStop("", CalculationMode.Price, Low[0] - 2 * TickSize, false);
              Would produce an trail stop 2 ticks below the Low using the Price rather than ticks. You will be doing the calculation on how many ticks by using 2 * TickSize this gives a price in which is subtracted from the Low[0].

              To go above the High you would need to change the calculation for that to High[0] + 2 * TickSize

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

              Comment


                #22
                Only supposed to make one trade a day!

                Hi Jesse,

                thought I'd post my updated code and the model requirements and a picture of what it is doing:

                I put the changes I made in red font.
                Code:
                 protected override void Initialize()
                        {
                            
                            EntriesPerDirection = 1;
                    EntryHandling = EntryHandling.AllEntries;
                            
                            SetProfitTarget("", CalculationMode.Price, Variable0);
                            SetProfitTarget("", CalculationMode.Price, Variable1);
                            SetTrailStop("", CalculationMode.Price, Variable2, false);
                            SetTrailStop("", CalculationMode.Price, Variable3, false);
                
                
                            CalculateOnBarClose = true;
                        }
                
                
                        /// <summary>
                        /// Called on each bar update event (incoming tick)
                        /// </summary>
                        protected override void OnBarUpdate()
                        {
                            
                        if
                        
                            // All conditions only work between 930-945am!
                            
                        (ToTime(Time[0]) >= 93000 && ToTime(Time[0]) <= 94500)
                            
                        {        // Condition set 1: If DM+ crosses above DM- AND the open is less than yesterday's close> GO LONG
                                if (CrossAbove(DM(14).DiPlus, DM(14).DiMinus, 1)&& (ToTime(Time[0]) == 93000)
                                    && CurrentDayOHL().CurrentOpen[0] < PriorDayOHLC().PriorClose[0]);
                                    
                                {
                                    EnterLong(DefaultQuantity, "");
                                }
                
                
                                // Condition set 2
                                if (CrossAbove(DM(14).DiMinus, DM(14).DiPlus, 1) && (ToTime(Time[0]) == 93000)
                                    && CurrentDayOHL().CurrentOpen[0] > PriorDayOHLC().PriorClose[0]);
                                
                                {
                                    EnterShort(DefaultQuantity, "");
                                }
                
                
                                // Condition set 3
                                if (Position.MarketPosition == MarketPosition.Long)
                                {
                                    Variable0 = High[0] + ATR(14)[0] * TickSize;
                                    Variable3 = Low[0] -2 * TickSize;
                                }
                
                
                                // Condition set 4
                                if (Position.MarketPosition == MarketPosition.Short)
                                {
                                    Variable1 = Low[0] - ATR(14)[0] * TickSize;
                                    Variable2 = High[0] + 2 * TickSize;
                                }
                So this is my entry conditions:


                1. Compare the open at 9h30, to yesterday`s close
                2. Trade in the direction of yday`s close: If close is higher than open Go long. (and vice versa)
                3. Only make trades between 9h30 - 9h45 (this we achieved)
                4. Only make one trade, when DI+ crosses above DI- (Condition Set 1) .
                5. Target is High of entry candle + ATR
                6. Stop is Low - 2 ticks.


                (Ill leave the exit conditions for later)


                If you look at the image I attached from the 16 Aug, you will see it is making trades on every candle between 9h30 - 9h45


                so my question to you is why is it making trades on every candle


                On this day (16 Aug), if you look at the image, DM+ and DM- never crossed, therefore it should of NOT placed any trades.
                Thanks.
                Attached Files
                Last edited by teenagemutantNT; 11-20-2014, 05:34 PM.

                Comment


                  #23
                  Originally posted by NinjaTrader_Jesse View Post
                  Hello,

                  This line:

                  Code:
                   SetTrailStop("", CalculationMode.Price, Low[0] - 2 * TickSize, false);
                  Would produce an trail stop 2 ticks below the Low using the Price rather than ticks. You will be doing the calculation on how many ticks by using 2 * TickSize this gives a price in which is subtracted from the Low[0].

                  To go above the High you would need to change the calculation for that to High[0] + 2 * TickSize

                  I look forward to being of further assistance.

                  That is the same calculation in the variable blocks anyway:


                  Code:
                  // Condition set 3
                  				if (Position.MarketPosition == MarketPosition.Long)
                  				{
                  					Variable0 = High[0] + ATR(14)[0] * TickSize;
                  					Variable3 = Low[0] -2 * TickSize;
                  				}
                  
                  
                  				// Condition set 4
                  				if (Position.MarketPosition == MarketPosition.Short)
                  				{
                  					Variable1 = Low[0] - ATR(14)[0] * TickSize;
                  					Variable2 = High[0] + 2 * TickSize;
                  				}

                  so would it make a difference in writing it out in the Initialize method?


                  My concern is the program has to know which profit target/ trail stop to use when it's is different positions (long or short)


                  If its short , has to know to use 2 ticks below the low.


                  but right now the main issue is to get it to only make one trade (or skip a trade) after comparing today's open vs yesterday's close, and ONLY WHEN DI+ & DI- crosses over.

                  Comment


                    #24
                    Hello,

                    I believe where the problem is would be on my behalf. I have incorrectly recommended using the SetTrailStop as it actually does not support the Price, I had not remembered this until i re read the help on this but it is in the help guide under which modes are supported.
                    For set trail stop you have two options, Ticks or Percent.

                    So for this you can either set 2 ticks which would be taken from the orders prices (not the high or low) or a percentage from the orders price again not high or low.

                    Alternatively you can use SetStopLoss and update the StopLoss to trail the price as the SetTrailStop does. this would allow you to use a price based off of the Low or high if you wished.

                    I will provide an example script that shows how to update a stop loss to trail, pay attention to the OnMarketData() as this controls the trailing stop.

                    This examples is a one sided example meaning that only the Long side is complete but this gives you a complete framework for learning how to do this so that you can create your own logic like this to achieve a similar result.

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

                    Comment


                      #25
                      Originally posted by NinjaTrader_Jesse View Post
                      Hello,

                      I believe where the problem is would be on my behalf. I have incorrectly recommended using the SetTrailStop as it actually does not support the Price, I had not remembered this until i re read the help on this but it is in the help guide under which modes are supported.
                      For set trail stop you have two options, Ticks or Percent.

                      So for this you can either set 2 ticks which would be taken from the orders prices (not the high or low) or a percentage from the orders price again not high or low.

                      Alternatively you can use SetStopLoss and update the StopLoss to trail the price as the SetTrailStop does. this would allow you to use a price based off of the Low or high if you wished.

                      I will provide an example script that shows how to update a stop loss to trail, pay attention to the OnMarketData() as this controls the trailing stop.

                      This examples is a one sided example meaning that only the Long side is complete but this gives you a complete framework for learning how to do this so that you can create your own logic like this to achieve a similar result.

                      I look forward to being of further assistance.
                      Ok but why is it making trades on every candle?

                      why is it not only making the trade when the DM+ and DM - lines crossover??

                      Comment


                        #26
                        Originally posted by NinjaTrader_Jesse View Post
                        Hello,

                        I believe where the problem is would be on my behalf. I have incorrectly recommended using the SetTrailStop as it actually does not support the Price, I had not remembered this until i re read the help on this but it is in the help guide under which modes are supported.
                        For set trail stop you have two options, Ticks or Percent.

                        So for this you can either set 2 ticks which would be taken from the orders prices (not the high or low) or a percentage from the orders price again not high or low.

                        Alternatively you can use SetStopLoss and update the StopLoss to trail the price as the SetTrailStop does. this would allow you to use a price based off of the Low or high if you wished.

                        I will provide an example script that shows how to update a stop loss to trail, pay attention to the OnMarketData() as this controls the trailing stop.

                        This examples is a one sided example meaning that only the Long side is complete but this gives you a complete framework for learning how to do this so that you can create your own logic like this to achieve a similar result.

                        I look forward to being of further assistance.


                        Hi Jesse,


                        Thanks.


                        so that script is a .cs file? I can't open it in ninja? I would have to copy and paste from visual express?

                        Comment


                          #27
                          Hello,

                          I looked over the original script again and noticed another strange thing I had not noticed before.

                          Looking at your conditions, you have essentially commented them out. Here are the lines:

                          Code:
                          // Condition set 1: If DM+ crosses above DM- AND the open is less than yesterday's close> GO LONG
                          if (CrossAbove(DM(14).DiPlus, DM(14).DiMinus, 1) 
                          && (ToTime(Time[0]) == 93000)
                          && CurrentDayOHL().CurrentOpen[0] < PriorDayOHLC().PriorClose[0]) ;
                          {
                          EnterLong(DefaultQuantity, "");
                          }
                          
                          
                          // Condition set 2
                          if (CrossAbove(DM(14).DiMinus, DM(14).DiPlus, 1) && (ToTime(Time[0]) == 93000)
                          && CurrentDayOHL().CurrentOpen[0] > PriorDayOHLC().PriorClose[0]) ;
                          {
                          EnterShort(DefaultQuantity, "");
                          }
                          The reason this is happening every bar during your give time is because you have added a semi colon at the end of each of your if statements making the curly brackets that follow become outside of the condition.

                          if you look specifically at the end of each if statement there is a semi colon.

                          C# allows you to place code in-between two curly braces
                          {
                          //code
                          }
                          which would be the same as if that code had no braces at all because there is no condition.
                          This is exactly the same as if you were to do a if statement followed by a semi colon, the code in the brakets would not be checked by the condition.
                          Here is a simple example:

                          Code:
                          if(varA == varB);
                          {
                          //this code is outside of the condition because of the ; at the end of the if.
                          }
                          Essentially the conditions are never used at all allowing it to place a entry then reverse right after.

                          For your second question, the zip file can be imported into NinjaTrader by using the File -> Utilities -> import NinjaScript.

                          If you are using visual studio express for coding, you can use this but this is not supported so I do not have the instructions on how load the .cs into the visual studio project so it is visible, I assume this is what you mean by visual express.

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

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by fredfred, Today, 03:41 AM
                          3 responses
                          11 views
                          0 likes
                          Last Post NinjaTrader_ChristopherS  
                          Started by TraderYoda, Today, 03:33 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post TraderYoda  
                          Started by pjsmith, Today, 02:56 AM
                          0 responses
                          5 views
                          0 likes
                          Last Post pjsmith
                          by pjsmith
                           
                          Started by ntbone, Yesterday, 08:10 PM
                          0 responses
                          12 views
                          0 likes
                          Last Post ntbone
                          by ntbone
                           
                          Started by chrislou, 08-28-2015, 03:27 AM
                          14 responses
                          2,884 views
                          0 likes
                          Last Post nkhoi
                          by nkhoi
                           
                          Working...
                          X