I am trying to code a strategy where I enter long when a candlestick pattern forms. I then take profit at the first profitable close.
However if the strategy shows a loss of -$100 and the candlestick pattern forms again, I want to add to my position.
I can't get that part of the strategy to work, it always just goes long with both contracts.
Code and screenshot below:
protected override void OnBarUpdate()
{
//Gets Strategy Unrealized PL
currentPnL = SystemPerformance.AllTrades.TradesPerformance.NetP rofit;
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 3)
return;
// Set 1
if <pattern>
{
EnterLong(1, 10000, "Enter Long 10000");
}
if ((IsFirstTickOfBar))
{
if(Position.GetUnrealizedProfitLoss(PerformanceUni t.Points, Close[0]) > 0)
{
ExitLong(10000);
}
}
else if <pattern> && (Position.MarketPosition != MarketPosition.Flat) && (Position.GetUnrealizedProfitLoss(PerformanceUnit. Currency, Close[0]) < -100))
{
EnterLong(1, 20000, "Enter Long Again");
}
if (IsFirstTickOfBar)
{
if(Position.GetUnrealizedProfitLoss(PerformanceUni t.Points, Close[0]) > 0)
{
ExitLong(30000);
}
}
I have Entries Per Direction set to 2, and Entry Handling set to Unique Entries.
Comment