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

Account Cash Value Account Initial Margin Instrument Initial Margin

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

  • NinjaTrader_ChrisL
    replied
    Hi GTBrooks, thanks for your reply.

    I am sorry but I do not understand the question. What is the issue you are seeing with OnAccountItemUpdate? Did you try printing the values coming from that method to see if you are getting what you expect?

    Leave a comment:


  • GTBrooks
    replied
    Are you saying there is no reason to run code in my automated strategy?
    Code:
            // This method is fired on any change of an AccountItem  
             protected override void OnAccountItemUpdate(Account account, AccountItem accountItem, double value)         {         }

    Leave a comment:


  • NinjaTrader_ChrisL
    replied
    Hi GTBrooks, thanks for your reply.

    All this stuff will be class level, so you would place all of this below OnBarUpdate() {}. (or anywhere at the class level)

    OnBarUpdate()
    {
    }

    //paste code block here.

    If you already have this in your script and it works in historical, then it should work in real-time.

    If you would like for me to try this on my end then please let me know/provide an example of the problem.

    Kind regards.

    Leave a comment:


  • GTBrooks
    replied
    let me ask this another way.

    In what section of me Automated Strategy should I insert this code, for it to function properly in real-time trading?
    Code:
            //Acount check Long and Short
            private bool LongMoneyInAccountToTrade;
            private bool ShortMoneyInAccountToTrade;
    
            //My Account
            LongMoneyInAccountToTrade    = true;
            ShortMoneyInAccountToTrade    = true;
    
            ///AccountInformation (Copy / Paste)
            // This method is fired on any change of an AccountItem
            protected override void OnAccountItemUpdate(Account account, AccountItem accountItem, double value)
            {
                    //My Account
                    // Check Money in Account to Trade
                    if ((((Account.Get(AccountItem.CashValue, Currency.UsDollar) * 0.85) - Account.Get(AccountItem.InitialMargin, Currency.UsDollar)) > ((Account.Get(AccountItem.CashValue, Currency.UsDollar) - Account.Get(AccountItem.InitialMargin, Currency.UsDollar)) / (10 / LongMinimumCheckLotsToTradeLogicGTB)))
                        && ((Account.Get(AccountItem.CashValue, Currency.UsDollar) * 0.85) - Account.Get(AccountItem.InitialMargin, Currency.UsDollar)) > Risk.Get("GTB ForexDotCom").ByMasterInstrument[Instrument.MasterInstrument].InitialMargin)
                    {
                        LongMoneyInAccountToTrade = true;
                    }
                    else
                    {
                        LongMoneyInAccountToTrade = false;
                    }
                    if ((((Account.Get(AccountItem.CashValue, Currency.UsDollar) * 0.85) - Account.Get(AccountItem.InitialMargin, Currency.UsDollar)) > ((Account.Get(AccountItem.CashValue, Currency.UsDollar) - Account.Get(AccountItem.InitialMargin, Currency.UsDollar)) / (10 / ShortMinimumCheckLotsToTradeLogicGTB)))
                        && ((Account.Get(AccountItem.CashValue, Currency.UsDollar) * 0.85) - Account.Get(AccountItem.InitialMargin, Currency.UsDollar)) > Risk.Get("GTB ForexDotCom").ByMasterInstrument[Instrument.MasterInstrument].InitialMargin)
                    {
                        ShortMoneyInAccountToTrade = true;
                    }
                    else
                    {
                        ShortMoneyInAccountToTrade = false;
                    }
            }

    Leave a comment:


  • NinjaTrader_ChrisL
    replied
    Hi GTBrooks, thanks for the follow up.

    What is the exact error you get? Does anything show up in the log tab or through a popup window?

    Leave a comment:


  • GTBrooks
    replied
    I worked out all the errors in the Logs and Popups Using Print, BUT when I run it on Strategy Tab under Sim101 account I found an error. The Strategy generates Historical data, BUT the error Stops the Strategy from entering any real-time trades.
    I believe the error occurs when the strategy tries to see if there is money in the account to trade
    Code:
    if(Account.Get(AccountItem.CashValue, Currency.UsDollar) - Account.Get(AccountItem.InitialMargin, Currency.UsDollar)>Close[0]
    What error could stop my Strategy from trading Real-Time?

    Leave a comment:


  • GTBrooks
    replied
    found the output = NinjaScript Output

    I was passing values between variables incorrectly. this helped out.
    thank you,

    Leave a comment:


  • GTBrooks
    replied
    where should I expect to see the Print function output?

    Leave a comment:


  • NinjaTrader_ChrisL
    replied
    Hello GTBrooks, thanks for your question.

    More often than not, a false false are a bug in the custom code. Consider making a detailed "bread crumb" trail of prints to identify a problem e.g.

    Code:
    if (Account.Name != "Sim101")
                {
                    if ((LongMoneyInAccountToTrade[0] == false) && (((OverallCashValueOfAccountCurrentlyTrading[0] * 0.85) - InitialMarginHeldInAccountAsTrades[0]) > ((12 / LongMinimumCheckLotsToTradeLogicGTB) * (RiskMarginRequirementsOnTradedInstrument[0]))))
                    {
                        Print("LongMoneyInAccountToTrade[0] " + LongMoneyInAccountToTrade[0]);
                        Print("((OverallCashValueOfAccountCurrentlyTrading[0] * 0.85) - InitialMarginHeldInAccountAsTrades[0]) " + ((OverallCashValueOfAccountCurrentlyTrading[0] * 0.85) - InitialMarginHeldInAccountAsTrades[0]));
                        Print("((12 / LongMinimumCheckLotsToTradeLogicGTB) * (RiskMarginRequirementsOnTradedInstrument[0])) " + ((12 / LongMinimumCheckLotsToTradeLogicGTB) * (RiskMarginRequirementsOnTradedInstrument[0])));
                        //rinse and repeat for all condition groups
                        LongMoneyInAccountToTrade[0] = true;
                    }      
    
                    else if ((LongMoneyInAccountToTrade[0] == true) && (((Account.Get(AccountItem.CashValue, Currency.UsDollar) * 0.85) - InitialMarginHeldInAccountAsTrades[0]) <= ((12 / LongMinimumCheckLotsToTradeLogicGTB) * (RiskMarginRequirementsOnTradedInstrument[0]))))
                    {
                        LongMoneyInAccountToTrade[0] = false;
                    }
                    if ((ShortMoneyInAccountToTrade[0] == false) && (((Account.Get(AccountItem.CashValue, Currency.UsDollar) * 0.85) - InitialMarginHeldInAccountAsTrades[0]) > ((12 / ShortMinimumCheckLotsToTradeLogicGTB) * (RiskMarginRequirementsOnTradedInstrument[0]))))
                    {
                        ShortMoneyInAccountToTrade[0] = true;
                    }
                    else if ((ShortMoneyInAccountToTrade[0] == true) && (((Account.Get(AccountItem.CashValue, Currency.UsDollar) * 0.85) - InitialMarginHeldInAccountAsTrades[0]) <= ((12 / ShortMinimumCheckLotsToTradeLogicGTB) * (RiskMarginRequirementsOnTradedInstrument[0]))))
                    {
                        ShortMoneyInAccountToTrade[0] = false;
                    }
                }
                else if (Account.Name == "Sim101")
                {
                    LongMoneyInAccountToTrade[0] = true;
                    ShortMoneyInAccountToTrade[0] = true;
                }
    I look forward to assisting.

    Leave a comment:


  • Account Cash Value Account Initial Margin Instrument Initial Margin

    Hello,

    There where no errors in the programming and no errors in the logs. BUT... when I use Strategy Analyzer or run it on the Sim101 account in real-time Errors occure. There are NO trades occuring due to this code. Currently this code outputs a false false when the values say it should be a true output.

    when 85% OverallCash value is Greater than the RiskMargin and InitialMarginHeldInAccount combined the output should read as true.

    I Created a Risk profile for my Forex.com trading called "GTB ForexDotCom"
    I used CashValue - InitialMargin > (Long/Short)MinimumCheckLotsToTradeLogicGTB * Risk.Get("GTB ForexDotCom")
    exsample Account has $1000, where there is $400 currently in use. the Next Trade will cost $60 [<Risk.Get("GTB ForexDotCom") = $20>*<Multiplier = 3>]

    these all pull correctly
    Account.Get(AccountItem.CashValue, Currency.UsDollar);
    Account.Get(AccountItem.InitialMargin, Currency.UsDollar);
    Risk.Get("GTB ForexDotCom").ByMasterInstrument[Instrument.MasterInstrument].InitialMargin;

    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class GTBsAutomatedTradingStrategyAccount : Strategy
        {
            private Account account;
    
            //Account check Long and Short
            private Series<double> OverallCashValueOfAccountCurrentlyTrading;
            private Series<double> InitialMarginHeldInAccountAsTrades;
            private Series<double> RiskMarginRequirementsOnTradedInstrument;
            private Series<bool> LongMoneyInAccountToTrade;
            private Series<bool> ShortMoneyInAccountToTrade;
                }
                 else if (State == State.DataLoaded)
                {
                   //My Account
                    OverallCashValueOfAccountCurrentlyTrading         = new Series<double>(this, MaximumBarsLookBack.Infinite);
                    InitialMarginHeldInAccountAsTrades         = new Series<double>(this, MaximumBarsLookBack.Infinite);
                    RiskMarginRequirementsOnTradedInstrument         = new Series<double>(this, MaximumBarsLookBack.Infinite);
                    LongMoneyInAccountToTrade         = new Series<bool>(this, MaximumBarsLookBack.Infinite);
                    ShortMoneyInAccountToTrade         = new Series<bool>(this, MaximumBarsLookBack.Infinite);
                }
            protected override void OnAccountItemUpdate(Account account, AccountItem accountItem, double value)
            {
                /// Real-Time Trade Logic
    
                    //My Account
                    // Check Money in Account to Trade
                    OverallCashValueOfAccountCurrentlyTrading[0]         = Account.Get(AccountItem.CashValue, Currency.UsDollar);
                    InitialMarginHeldInAccountAsTrades[0]         = Account.Get(AccountItem.InitialMargin, Currency.UsDollar);
                    RiskMarginRequirementsOnTradedInstrument[0]         = Risk.Get("GTB ForexDotCom").ByMasterInstrument[Instrument.MasterInstrument].InitialMargin;
                    if (Account.Name != "Sim101")
                        {
                        if ((LongMoneyInAccountToTrade[0] == false)
                            && (((OverallCashValueOfAccountCurrentlyTrading[0] * 0.85) - InitialMarginHeldInAccountAsTrades[0]) > ((12 / LongMinimumCheckLotsToTradeLogicGTB) * (RiskMarginRequirementsOnTradedInstrument[0]))))
                              LongMoneyInAccountToTrade[0] = true;
                        else if ((LongMoneyInAccountToTrade[0] == true)
                            && (((OverallCashValueOfAccountCurrentlyTrading[0] * 0.85) - InitialMarginHeldInAccountAsTrades[0]) <= ((12 / LongMinimumCheckLotsToTradeLogicGTB) * (RiskMarginRequirementsOnTradedInstrument[0]))))
                              LongMoneyInAccountToTrade[0] = false;
                        if ((ShortMoneyInAccountToTrade[0] == false)
                            && (((OverallCashValueOfAccountCurrentlyTrading[0] * 0.85) - InitialMarginHeldInAccountAsTrades[0]) > ((12 / ShortMinimumCheckLotsToTradeLogicGTB) * (RiskMarginRequirementsOnTradedInstrument[0]))))
                              ShortMoneyInAccountToTrade[0] = true;
                        else if ((ShortMoneyInAccountToTrade[0] == true)
                            && (((OverallCashValueOfAccountCurrentlyTrading[0] * 0.85) - InitialMarginHeldInAccountAsTrades[0]) <= ((12 / ShortMinimumCheckLotsToTradeLogicGTB) * (RiskMarginRequirementsOnTradedInstrument[0]))))
                              ShortMoneyInAccountToTrade[0] = false;
                        }
                    else if (Account.Name == "Sim101")
                        {
                               LongMoneyInAccountToTrade[0] = true;
                            ShortMoneyInAccountToTrade[0] = true;
                        }
              }
    }
    Last edited by GTBrooks; 07-13-2020, 03:55 PM.

Latest Posts

Collapse

Topics Statistics Last Post
Started by andrewtrades, Today, 04:57 PM
1 response
5 views
0 likes
Last Post NinjaTrader_Manfred  
Started by chbruno, Today, 04:10 PM
0 responses
3 views
0 likes
Last Post chbruno
by chbruno
 
Started by josh18955, 03-25-2023, 11:16 AM
6 responses
436 views
0 likes
Last Post Delerium  
Started by FAQtrader, Today, 03:35 PM
0 responses
6 views
0 likes
Last Post FAQtrader  
Started by rocketman7, Today, 09:41 AM
5 responses
19 views
0 likes
Last Post NinjaTrader_Jesse  
Working...
X