I currently have this code setting variables for performance metrics. They're supposed to be defined whenever a trade completes:
private void calculate_Performance() { profit_GrossProfit = Math.Round(SystemPerformance.AllTrades.TradesPerformance.GrossProfit,2); profit_GrossLoss = Math.Round(SystemPerformance.AllTrades.TradesPerformance.GrossLoss,2); profit_Commissions = Math.Round(SystemPerformance.AllTrades.TradesPerformance.Commission,2); profit_Totals = Math.Round((profit_GrossProfit + profit_GrossLoss) - profit_Commissions,2); }
I also have one for risk tolerance that's currently sitting in State.Configure, but again, thinking it should be considered for OnBarUpdate instead, based on what the Help Guide outlines as being candidates for State.Configure:
private void calculate_RiskTolerance() { profit_targetLevel = Math.Round(GetAccountValue(AccountItem.CashValue) / 100,0); // Calculate our target level, based on available cash profit_failureLevel = profit_targetLevel * -1; // Define the failure level based on reverse of the former if (profit_Totals >= profit_targetLevel) // If we are above our target level for profit, { profit_riskLevel = 2; } // our risk tolerance is high. else if (profit_Totals >= 0 && profit_Totals < profit_targetLevel) // If we haven't cleared our target level, { profit_riskLevel = 1; } // our risk tolerance is normal. else if (profit_Totals < 0 && profit_Totals > profit_failureLevel) // If we are underperforming or close to shutting down, { profit_riskLevel = 0; } // our risk tolerance is low. }
Comment