Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with coding related to accounts and risk management

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

    Help with coding related to accounts and risk management

    new to coding looking for the proper way for dealing account items. here is some if the examples ideas , any help would be appreciated



    private int CalculatePositionSize(double accountBalance)

    {

    return (int)((accountBalance * RiskPercentage) / (StopLossDistance * RiskRewardRatio));

    }




    {

    int positionSize = CalculatePositionSize(Account.Equity);

    EnterLong(positionSize, "Long Entry", OrderType.Stop, High[0] + StopLossDistance * TickSize, 0, High[0] + (StopLossDistance * RiskRewardRatio) * TickSize, "");

    }




    protected override void OnOrderUpdate(IOrder order)

    {

    if (order.OrderState == OrderState.Filled)

    {

    if (order.IsLong)

    {

    double currentEquity = Account.Get(AccountItem.Equity);

    double avgFillPrice = order.AvgFillPrice;

    if ((currentEquity / avgFillPrice) / (currentEquity - avgFillPrice) < MaximumDrawdown)

    {

    ExitLong();

    }

    }

    else

    {

    double currentEquity = Account.Get(AccountItem.Equity);

    double avgFillPrice = order.AvgFillPrice;

    if ((currentEquity / avgFillPrice) / (currentEquity + avgFillPrice) < MaximumDrawdown)

    {

    ExitShort();

    }

    }

    }

    }

    }



    Thanks !​

    #2
    i was able to figure a few things out but still having problems with this section

    {

    double cashValue = Account.Get(AccountItem.CashValue, Currency.UsDollar);

    int positionSize = CalculatePositionSize(cashValue);

    EnterLong(positionSize, "Long Entry", OrderType.StopMarket, 0, High[0] + StopLossDistance * TickSize, 0, High[0] + (StopLossDistance * RiskRewardRatio) * TickSize, "");

    }


    getting this error message

    No overload For Method 'EnterLong' takes 8 arguments

    Comment


      #3
      Is your code part of a Strategy? Looking at EnterLong() reference, https://ninjatrader.com/es/support/h...ount_class.htm, you can use:
      EnterLong()
      EnterLong(string signalName)
      EnterLong(int quantity)
      EnterLong(int quantity, string signalName)

      So it appears you are passing to many arguments.


      Comment


        #4
        Thanks for the response and insight. Yes I was using it to build a strategy

        I was able to fix it this way

        {

        double cashValue = Account.Get(AccountItem.CashValue, Currency.UsDollar);

        int positionSize = CalculatePositionSize(cashValue);

        EnterLongStopMarket(positionSize, High[0] + StopLossDistance * TickSize, "Long Entry");

        }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        56 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        133 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 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
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X