Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Condition

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

    Strategy Condition

    Hello Everyone.
    I have a strategy when Ema cross above Sma and Sma rising enter long and vice versa.
    The problem is, when Ema cross above Sma and Sma not rising, nothing happens (is normal), but if Ema stay above Sma and Sma is starting to rising i want my strategy to start and get me long fill. Is any way to do this?
    Thank you in advance.
    This is my strategy
    // Condition set 1
    if (CrossAbove(SMA(Ema), SMA(Sma), 1)
    && Rising(SMA(Sma)))
    {
    EnterLong(DefaultQuantity, "");
    SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
    }

    // Condition set 2
    if (CrossBelow(SMA(Ema), SMA(Sma), 1)
    && Falling(SMA(Sma)))
    {
    EnterShort(DefaultQuantity, "");
    SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
    }

    #2
    Hello,

    I just wanted to clarify with you,

    You are trying to detect when the when the EMA is above the SMA and also the SMA is rising correct?

    For this instead of using a cross above you may want to just check if the EMA is greater than the SMA.

    The cross above as you have seen only will trigger at the time when the cross above is detected but once it is above the price the condition will remain false. if you are checking if the EMA is greater than the SMA this will be true every bar that this is the case.

    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Can you show me please how can i do this in my strategy (Ema greater than the Sma and vice versa)?
      Thank you.

      Comment


        #4
        Hello,

        Thank you for the question.

        From the code provided it looks like you have used the wizard, Are you still using the wizard or manually coding this so that I can provide a relevant example.

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

        Comment


          #5
          Manually coding

          Comment


            #6
            Hello,

            You could use something along the lines of this:

            Code:
            if (SMA(Ema)[0] > SMA(Sma)[0] && Close[0] > SMA(Sma)[0])
            {
            				
            }
            This would be checking if the SMA(Ema) current value is greater than SMA(Sma) and the current Close is greater than the SMA(Sma)

            This would be true for every bar that the condition is met so you would need additional logic to determine if you are in a position already otherwise this would try to submit orders every bar it is true.

            Something you can use for checking your position would be as follows:

            Code:
            if (SMA(Ema)[0] > SMA(Sma)[0] && Close[0] > SMA(Sma)[0])
            {
                if(Position.MarketPosition == MarketPosition.Flat)
                {
            	 EnterLong(DefaultQuantity, "");
            	 SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
                 }
            }
            This would allow the order to go through if you are currently flat and the SMA(Ema) > SMA(Sma) and the current Close is > SMA(Sma)

            once you are not flat it would not allow orders to go through until you are flat and the condition is true again.

            Please let me know if I may be of additional assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Now i have a better fill but i have 2 problems.
              1- I put my stop loss to move to breakeven -5 ticks when i get 8 ticks in profit and my stop loss not move.
              2- I still have that problem with SMA, i want to get an long entry when Ema is greater than the Sma and the Sma is rising.
              If the Ema is greater than the Sma but initially the Sma is not rising, i do not want to get an entry, but if the Ema stay above Sma and the Sma starting to rising i want to get an entry.
              This problem i wanted to solve initially.
              Thank you.

              Comment


                #8
                Hello,

                For your 1st question, Are you looking for a stop loss or a trailing stop?

                If you are not resetting the value each bar update the stop would not move, this would be expected. I would recommend taking a look at the documentation as it lists the different ways it can be used.


                If you are looking to trail there is the SetTrailStop method located here:


                The notes at the top of the help guide documentation explain the available usages of these methods.
                If you want to only set this after X amount of profit you would need to create that condition using logic otherwise this would be at a tick by tick basis.

                For your 2nd question the code provided would only work if both the SMA(Ema) is greater than the SMA(Sma) AND the Close[0] is greater than the SMA(Sma)

                If you want to also check for rising you would just need to add that in as well using the && sign to state the condition includes this as another condition. if you want to check for OR it would be || sign.

                Code:
                if (SMA(Ema)[0] > SMA(Sma)[0] && Close[0] > SMA(Sma)[0] && Rising(SMA(Sma)))
                Please let me know if I may be of additional assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  I looking for a stop loss and i want only set the stop loss after X amount of profit, but it does not work and i do not know how to do this exactly. My stop loss stay fix.
                  Before to change Ema cross Sma with Ema > Sma it works.
                  I will put here my strategy to see
                  protected override void OnBarUpdate()
                  {
                  if (Position.MarketPosition == MarketPosition.Flat)
                  {
                  SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
                  }
                  else if (Position.MarketPosition == MarketPosition.Long)
                  {
                  if (Close[0] > Position.AvgPrice + 15 * TickSize)
                  {
                  SetStopLoss(CalculationMode.Price, Position.AvgPrice - 5 * TickSize);
                  }
                  }
                  if (Position.MarketPosition == MarketPosition.Flat)
                  {
                  SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
                  }
                  else if (Position.MarketPosition == MarketPosition.Short)
                  {
                  if (Close[0] < Position.AvgPrice - 15 * TickSize)
                  {
                  SetStopLoss(CalculationMode.Price, Position.AvgPrice + 5 * TickSize);
                  }
                  }

                  // Condition set 1
                  if (EMA(Ema)[0] > SMA(Sma)[0] && Rising(SMA(Sma)))
                  {
                  EnterLong(DefaultQuantity, "");
                  SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
                  }


                  // Condition set 2
                  if (EMA(Ema)[0] < SMA(Sma)[0] && Falling(SMA(Sma)))
                  {
                  EnterShort(DefaultQuantity, "");
                  SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
                  }

                  }
                  Thank you

                  Comment


                    #10
                    Hello mario2306,

                    Thank you for your post.

                    Your Stop Loss always has a value:
                    Code:
                    if (Position.MarketPosition == MarketPosition.Flat)
                    {
                    SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
                    Instead, just place the exit orders via ExitLongStop() for example.

                    Comment


                      #11
                      I understand, but i do not know how to do this.
                      Can you show me, please?
                      I will put a zip file here with my strategy.
                      And another problem is, when the target is reached, start another position in the same direction, and is not normal. After the target is reached must begin another position when the Ema > or < than Sma.
                      Thank you.
                      Attached Files
                      Last edited by mario2306; 10-07-2014, 07:47 AM.

                      Comment


                        #12
                        Hello mario2306,

                        Thank you for your response.

                        In place of the SetStopLoss() method use the ExitLongStop() for long positions and ExitShortStop() for the short positions.

                        For example:
                        Code:
                        			if (Position.MarketPosition == MarketPosition.Long)
                        			{	
                        				if (Close[0] > Position.AvgPrice + 8 * TickSize)
                        				{
                        					ExitLongStop(Position.AvgPrice - 5 * TickSizel);
                        				}
                        			}	
                        			if (Position.MarketPosition == MarketPosition.Short)
                        			{
                        				if (Close[0] < Position.AvgPrice - 8 * TickSize)
                        				{	
                        					ExitShortStop(Position.AvgPrice + 5 * TickSize);
                        				}
                        			}

                        Comment


                          #13
                          I changed but still does not work, stop loss stay fix.
                          You can try, please to see what is the problem?
                          Thank you.

                          Comment


                            #14
                            Hello mario2306,

                            Thank you for your response.

                            This line of code as well as the ExitShortStop() are using a static value: ExitLongStop(Position.AvgPrice - 5 * TickSize);

                            If you want to trail the current price by five ticks, try the following:
                            ExitLongStop(Close[0] - 5 * TickSize);

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by PhillT, 04-19-2024, 02:16 PM
                            4 responses
                            34 views
                            0 likes
                            Last Post PhillT
                            by PhillT
                             
                            Started by ageeholdings, 05-01-2024, 05:22 AM
                            5 responses
                            37 views
                            0 likes
                            Last Post ageeholdings  
                            Started by reynoldsn, Today, 02:34 PM
                            0 responses
                            11 views
                            0 likes
                            Last Post reynoldsn  
                            Started by nightstalker, Today, 02:05 PM
                            0 responses
                            18 views
                            0 likes
                            Last Post nightstalker  
                            Started by llanqui, Yesterday, 09:59 AM
                            8 responses
                            30 views
                            0 likes
                            Last Post llanqui
                            by llanqui
                             
                            Working...
                            X