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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      47 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      38 views
      0 likes
      Last Post CarlTrading  
      Working...
      X