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

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.
    JimNinjaTrader Customer Service

    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 kevinenergy, 02-17-2023, 12:42 PM
      117 responses
      2,766 views
      1 like
      Last Post jculp
      by jculp
       
      Started by Mongo, Today, 11:05 AM
      5 responses
      15 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by SightCareAubetter, Today, 12:55 PM
      0 responses
      3 views
      0 likes
      Last Post SightCareAubetter  
      Started by traderqz, Today, 12:06 AM
      8 responses
      16 views
      0 likes
      Last Post traderqz  
      Started by SightCareAubetter, Today, 12:50 PM
      0 responses
      2 views
      0 likes
      Last Post SightCareAubetter  
      Working...
      X