public classMyStrategy : Strategy
{
private bool OktoTrade = true;
private double Accumulated = 0;
if (State == State.SetDefaults)
{
Max_Profit = 200;
Max_Loss = -200;
protected override void OnBarUpdate()
{
if (this.CurrentBar < this.BarsRequiredToPlot || this.CurrentBar < this.BarsRequiredToTrade)
return;
if (SystemPerformance.AllTrades.TradesPerformance.Cur rency.CumProfit - Accumulated > Max_Profit
|| SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit - Accumulated < Max_Loss)
{
OktoTrade = false;
}
if (!TimeToTrade(_startTimeInt, _endTimeInt, Time[0])) // reset at the end of the session
{
OktoTrade = true;
Accumulated = SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit;
}
The check if OKtoTrade before entering a new trade || !OktoTrade if I'm in a trade and I reach my max loss or max profit to exit the trade.
// enter my values for the strategy
[Range(0, int.MaxValue)]
[Display(Name="Max_Profit", Description="", Order=16, GroupName="Parameters")]
public double Max_Profit
{ get; set; }
This doesn't allow me to enter a negative number , if I set this to 0 it doesn't check for Max_loss but does enter trades.
[NinjaScriptProperty]
[Range(0, int.MaxValue)]
[Display(Name="Max_Loss", Description="", Order=17, GroupName="Parameters")]
public double Max_Loss
{ get; set; }
Comment