I would like to include a logic in my strategy where to keep trading until profits drops to 75% of the max profit reached. For example, if I'm trading and I've reached $100 in profits. I would keep trading until the profits fall 75%.
So far, I’ve been able to successfully create the logic to get the currentPL for the day where it resets at the beginning of the day. I need help with creating a logic to get 75% of the max profit reached?
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class DynamicPLExample : Strategy
{
private bool stoptrading = false;
private double Accumulated = 0;
private double UnrealizedPL;
private double RealizedPL;
private double CurrentPL;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "DynamicPLExample";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
RealizedPL = SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit - Accumulated;
UnrealizedPL = Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Closes[0][0]);
CurrentPL = RealizedPL + UnrealizedPL;
if (Bars.IsFirstBarOfSession)
{
Print(Instrument.FullName + "|" + "ProfitLoss:" + "|" + ProfitLoss);
Print(Instrument.FullName + "|" + "CurrentPL:" + "|" + CurrentPL);
Accumulated = SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit;
stoptrading = false;
}
//Entry Logic
if ((Position.MarketPosition == MarketPosition.Long) || (Position.MarketPosition == MarketPosition.Short))
{
[COLOR=#e74c3c]if (CurrentPL > {Need Logic Here} If CurrentPL is 75% OffsetTextConverter max profit preached)[/COLOR]
{
stoptrading = true;
}
}
}
}

Comment