Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

MAE/MFE moving average

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

    MAE/MFE moving average

    Hello,

    I currently have a strategy that utilizes MAE of the total trade average to set a stop. "SystemPerformance.AllTrades.TradesPerformance.Cur rency.AverageMae"

    I would like to create a stop that utilizes a moving average of the individual trade MAE (for example, the last 30 trades) rather than the alltrades average. Can someone point me in the right direction on how I would code this?

    Thanks,
    eleven

    #2
    Hello eleven,

    Unfortunately, the TradesPerformance does not have this value for individual trades.
    https://ninjatrader.com/support/help...erformance.htm

    This means you would need to custom calculate this with code.
    https://ninjatrader.com/support/help...dingAverageMae
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Here is the code that I came up with. I think it works.

      //This namespace holds Strategies in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Strategies
      {
      public class TestMAEAvg : Strategy
      {
      private int i;

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Period = 4;
      }
      }
      protected override void OnBarUpdate() ////////////////////////////////////////////////////////////////////////////////////
      {
      double itCalc = 0;
      double avgMAE = 0;

      if (SystemPerformance.AllTrades.Count > (Period - 1))
      {

      for (i = 1; i <= Period; i++)
      {
      itCalc = itCalc + lastTrade.MaeCurrency;
      }
      }
      avgMAE = itCalc / Period;

      } //OnBarUpdate

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(ResourceType = typeof(Custom.Resource), Name="Period", Order=1, GroupName="Strategy risk")]
      public int Period
      { get; set; }

      #endregion
      }
      }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Columbcille, Today, 02:04 PM
      0 responses
      1 view
      0 likes
      Last Post Columbcille  
      Started by Bhavika, Yesterday, 09:03 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by slimcactus, Today, 10:26 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by Monares, Today, 10:49 AM
      3 responses
      19 views
      0 likes
      Last Post NinjaTrader_JustinD  
      Started by d122y, Today, 10:20 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Working...
      X