Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Risk Aversion Switch

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

    #16
    Hello GTBrooks,

    I am stating that if you want to fetch Instrument Initial Margin in your script that is consistent with your broker's configs, you could take the same approach you are doing, but reference a Risk template that you create instead referencing the pre-made Risk template.

    I have submitted a feature request on your behalf to be able to get instrument margin and other risk settings straight from your broker. The ticket ID is SFT-3796.

    We collect interest in feature requests before determining if the feature should be implemented. For that reason we cannot offer an ETA or promise of fulfillment. Upon implementation, the number for the ticket ID can be publicly found in the Release Notes page of the help guide. I will provide a link below.

    Release Notes - https://ninjatrader.com/support/help...ease_notes.htm

    Please let us know if you have any questions.

    Comment


      #17
      Thank you for all your Help. I finished polishing the code. Do not use this code. It is NOT approved for use in NinjaTrader 8. Thank you again for all your help. I will follow the Ticket to see if Forex.com ever automate their Margin Requirements.

      Code:
      //This namespace holds Strategies in this folder and is required. Do not change it. 
      namespace NinjaTrader.NinjaScript.Strategies.AlanStrategies
      {
          public class StrategyNameHere : Strategy
          {
      
              private Account account;
      
              protected override void OnStateChange()
              {
      
                  if (State == State.SetDefaults)
                  {
                      ProfitTargetPips                = 1;
                      TrailingStopLossPips                = 1;
                      StopLossPips                    = 1;
                  }
                  else if (State == State.Configure)
                  {
      
                  }
                  else if (State == State.DataLoaded)
                  {
      
                      SetProfitTarget("", CalculationMode.Pips, (ProfitTargetPips + TrailingStopLossPips + StopLossPips));
                      SetTrailStop("", CalculationMode.Pips, (TrailingStopLossPips + StopLossPips), false);
                      SetStopLoss("", CalculationMode.Pips, StopLossPips, false);
      
              }
      
              protected override void OnBarUpdate()
              {
      
                  if(CurrentBar < 1) return;    
      
                  if (Close[0] > Close[1])
                  && ((Account.Get(AccountItem.CashValue, Currency.UsDollar) * 0.85) - (Account.Get(AccountItem.InitialMargin, Currency.UsDollar))) >= (Math.Max( (int) Math.Floor(( (Account.Get(AccountItem.CashValue, Currency.UsDollar) / 18) / (Risk.Get("GTB ForexDotCom").ByMasterInstrument[Instrument.MasterInstrument].InitialMargin) )), 0 ) * (Risk.Get("GTB ForexDotCom").ByMasterInstrument[Instrument.MasterInstrument].InitialMargin))
                  && (SystemPerformance.LongTrades.TradesPerformance.ProfitFactor >= 1)
                  && (PositionAccount.Quantity = Position.Quantity))    
                  {
                      EnterLong((Math.Max( (int) Math.Floor( (Account.Get(AccountItem.CashValue, Currency.UsDollar) / 18) / (Risk.Get("GTB ForexDotCom").ByMasterInstrument[Instrument.MasterInstrument].InitialMargin) ), 0 ) * 1000), "");
                  }
      
                  if (Close[0] <= Close[1]))    
                  {
                      ExitLong(Position.Quantity);
                  }
      
                  if (Close[0] < Close[1])
                  && ((Account.Get(AccountItem.CashValue, Currency.UsDollar) * 0.85) - (Account.Get(AccountItem.InitialMargin, Currency.UsDollar))) >= Math.Max( (int) Math.Floor(( (Account.Get(AccountItem.CashValue, Currency.UsDollar) / 18) / (Risk.Get("GTB ForexDotCom").ByMasterInstrument[Instrument.MasterInstrument].InitialMargin) )), 0 ) * (Risk.Get("GTB ForexDotCom").ByMasterInstrument[Instrument.MasterInstrument].InitialMargin)
                  && (SystemPerformance.ShortTrades.TradesPerformance.ProfitFactor >= 1)
                  && (PositionAccount.Quantity = Position.Quantity))    
                  {            
                      EnterShort((Math.Max( (int) Math.Floor( (Account.Get(AccountItem.CashValue, Currency.UsDollar) / 18) / (Risk.Get("GTB ForexDotCom").ByMasterInstrument[Instrument.MasterInstrument].InitialMargin) ), 0 ) * 1000), "");
                  }
      
                  if (Close[0] >= Close[1]))    
                  {
                      ExitShort(Position.Quantity);
                  }
      
              }
      
          }
      
              #region Properties
      
              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="ProfitTargetPips", Description="ProfitTarget set in Pips", Order=0, GroupName="Parameters")]
              public int ProfitTargetPips
              { get; set; }
      
              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="TrailingStopLossPips", Description="TrailingStopLoss set in Pips", Order=0, GroupName="Parameters")]
              public int TrailingStopLossPips
              { get; set; }
      
              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="StopLossPips", Description="StopLoss set in Pips", Order=0, GroupName="Parameters")]
              public int StopLossPips
              { get; set; }
      
              #endregion
      
          }
      }
      Last edited by GTBrooks; 02-28-2019, 07:01 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      59 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      134 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      74 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X