Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Comparing EMAs e order entry

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

    Comparing EMAs e order entry

    Hi Guys,

    I am trying to create a simple script to capture the beginning of the trend resumption,
    so I want to compare two EMAs 17 and 72, to see if one is bigger than other. So if the price reaches the EMA 72, I want to enter a buy order.
    Here is the script that I have written, there is no compile error but there is no action when simulation or backtesting.

    protected override void OnBarUpdate()
    {
    // Condition set 1 Long
    if (EMA(17)[0] > EMA(72)[0] && Position.MarketPosition == MarketPosition.Flat && Close[0] == EMA(72)[0])
    {
    EnterLong(Posicao, "Long");
    }

    Can anyone help me?

    Thanks and best regards

    #2
    Hello,

    Thank you for the question.

    I want to ask, in your condition I see that you are comparing if the Close[0] == EMA(72)[0].

    Is this the portion of the script where you are intending to do the "if the price reaches the EMA 72" enter a buy order?

    If so I believe what is happening is that the price would need to be exactly the EMA amount which is unlikely.

    If you are looking to check if it is higher than the EMA you would need to use >= or if you are only looking for the point where it crosses above or below you can use the CrossAbove or CrossBelow to detect when the price moves above or below the line but would only happen once where as a >= would happen every bar it is true.

    If this is not the correct thinking on your question please clarify with me.

    I look forward to being of further assistance.

    Comment


      #3
      This condition:
      Close[0] == EMA(72)[0]
      will almost never be met. You need to use a condition where the Close[0] is within some small delta of EMA(72).

      Comment


        #4
        For sure, the price will never be the same. So I should use CrossAbove or Below, the problem is, some times the price do not cross the EMA but get very close.

        The script is running now. Thanks a lot

        Comment


          #5
          Hello,

          Glad to hear that has helped.

          As for the price not crossing above sometimes this could pose a problem if you were to use one of the Cross methods as it would not detect anything if there is no cross.

          An alternate solution would be to have a hard value for your cross and then another condition that subtracts X amount from the hard value which I will call the soft value. If the price is to be higher than the soft value but less than the hard value then do something otherwise if a cross is detected stick to the original condition.

          This would be one way that may work depending on the situation, unfortunately being that it may or may not cross this would be something that most likely would need to be addressed with some logic.

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

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          558 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X