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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        88 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        135 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        119 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        69 views
        0 likes
        Last Post PaulMohn  
        Working...
        X