I am trying to implement the following in a strategy:
- Increase my position size (Forex), with each winning trade by 10000 units. The starting size is also 10000.
- After three consecutive wins, reset the position size to 10000. If a loss occurs, also reset the position size to 10000.
I can't seem to figure this out.
Please see my code below:
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if ((CrossAbove(RSI1.Default, 10, 1))
&& (Close[0] > SMA1[0]))
{
EnterLong(10000*size);
}
if (SystemPerformance.AllTrades.Count > 0) // Check to make sure there is at least one trade in the collection
{
Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
// Calculate the PnL for the last completed real-time trade
lastProfitCurrency = lastTrade.ProfitCurrency;
lastTradeQty = lastTrade.Quantity;
}
if (lastProfitCurrency > 0)
{
size++;
temp=size;
}
if (lastProfitCurrency < 0 || temp==3)
{
size=1;
}
Comment