Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to write script for this condition

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

    how to write script for this condition

    hello sir

    how to write a script for this condition :
    for mnq instrument

    Hma200 -Hma70 < 3 point (12 ticks ) .

    thanks for any help

    #2
    Hello traderMNQ, thanks for your question.

    Do you want to do this in the Strategy Builder or with an Indicator in the NinjaScript editor?

    I look forward to hearing from you.

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hello traderMNQ, thanks for your question.

      Do you want to do this in the Strategy Builder or with an Indicator in the NinjaScript editor?

      I look forward to hearing from you.
      Iwant to do with an Indicator in the NinjaScript editor

      Comment


        #4
        Hello

        I made a quick example to demonstrate:

        Code:
        public class TestHMAStrategy : Strategy
            {
                HMA _HMA0;
                HMA _HMA1;
                protected override void OnStateChange()
                {
                    if (State == State.SetDefaults)
                    {
                        //Setup
                    }
                    else if (State == State.Configure)
                    {
                        _HMA0 = HMA(200);
                        _HMA1 = HMA(70);
                    }
                }
        
                protected override void OnBarUpdate()
                {
                    if(CurrentBar < 200) return;
        
                    if(_HMA0[0] - _HMA1[0] < 3)
                    {
                        Print("Condition True");
                    }
                }
        The idea here is the same for all indicators. We declare two indicator objects at the class level (in this case, two HMA objects titled _HMA0 and_HMA1) and initialize them in State.SetDefaults. The indicator values are then accessed in OnBarUpdate.

        Please let me know if I can assist any further.

        Comment


          #5
          Originally posted by NinjaTrader_ChrisL View Post
          Hello

          I made a quick example to demonstrate:

          Code:
          public class TestHMAStrategy : Strategy
          {
          HMA _HMA0;
          HMA _HMA1;
          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          //Setup
          }
          else if (State == State.Configure)
          {
          _HMA0 = HMA(200);
          _HMA1 = HMA(70);
          }
          }
          
          protected override void OnBarUpdate()
          {
          if(CurrentBar < 200) return;
          
          if(_HMA0[0] - _HMA1[0] < 3)
          {
          Print("Condition True");
          }
          }
          The idea here is the same for all indicators. We declare two indicator objects at the class level (in this case, two HMA objects titled _HMA0 and_HMA1) and initialize them in State.SetDefaults. The indicator values are then accessed in OnBarUpdate.

          Please let me know if I can assist any further.
          Thank you very much ...i will try it ..

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          66 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          141 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          76 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          47 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          51 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X