The thing is I am trying to make a counter so that when a stop loss is hitted, Add +1 to the counter and then in the next entry double the contracts for this entry, if it hit the stop loss again, add +1 and double the contracts, so that I can set a limit of Stop losses that I can handle + double my contracts for the every next entry.
Every day I want to set the counter to 0, and the initial contracts like the strategy settings (default is 1 contract).
Here Whats I made, but it doesnt update the contracts I dont know why...See the image for better understanding... How can I acomplish this? I did something wrong?
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
{
if (Bars.IsFirstBarOfSession)
{
counterLong = 0;
counterShort = 0;
Ncontratos_trade1 = 1;
Ncontratos_trade2 = 1;
}
if ((execution.Order.Name == "StopLong1")
&& (Ncontratos_trade1 == 1))
{
counterLong = counterLong++;
Ncontratos_trade1 = (counterLong * 2);
Ncontratos_trade2 = (counterLong * 2);
}
if ((execution.Order.Name == "StopShort1")
&& (Ncontratos_trade1 == 1))
{
counterShort = counterShort++;
Ncontratos_trade1 = (counterShort * 2);
Ncontratos_trade2 = (counterShort * 2);
}
}
Protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if ((RangoHighLowBROKOLI1.HighestHigh[0] != 0)
&& (RangoHighLowBROKOLI1.LowestLow[0] != 0))
{
Draw.FibonacciRetracements(this, Convert.ToString(Bars.IsFirstBarOfSession), false, 0, RangoHighLowBROKOLI1.HighestHigh[0], 0, RangoHighLowBROKOLI1.LowestLow[0]);
Draw.Rectangle (this, "Rectangle", false, HoraInicio, RangoHighLowBROKOLI1.HighestHigh[0], HoraFin, RangoHighLowBROKOLI1.LowestLow[0], Brushes.Transparent, Brushes.Yellow, 20);
}
[HASHTAG="t3322"]region[/HASHTAG] Entradas
[HASHTAG="t3322"]region[/HASHTAG] 1 CONTRATO
/* When our indicator gives us a bull signal we enter long. Notice that we are accessing the
public BoolSeries we made in the indicator. */
if (GetCurrentAsk(0) >= RangoHighLowBROKOLI1.HighestHigh[0]
&& (GetCurrentBid(0) >= RangoHighLowBROKOLI1.HighestHigh[0])
&& (Open[0] <= RangoHighLowBROKOLI1.HighestHigh[0])
&& (Open[1] <= RangoHighLowBROKOLI1.HighestHigh[0])
&& (Close[1] <= RangoHighLowBROKOLI1.HighestHigh[0])
&& (Open[1] >= RangoHighLowBROKOLI1.LowestLow[0])
&& (Close[1] >= RangoHighLowBROKOLI1.LowestLow[0])
&& (Trade_1 == true)
&& (Trade_2 == false)
&& (Buy_activar == true)
)
{
EnterLong(Ncontratos_trade1, @"EntryLong1");
ProfitLong1 = Instrument.MasterInstrument.RoundToTickSize(RangoH ighLowBROKOLI1.HighestHigh[0] + ((RangoHighLowBROKOLI1.HighestHigh[0]-RangoHighLowBROKOLI1.LowestLow[0])*Porcentaje_fibo_TP1/100));
}
// When our indicator gives us a bear signal we enter shor t
if (GetCurrentBid(0) <= RangoHighLowBROKOLI1.LowestLow[0]
&& (GetCurrentAsk(0) <= RangoHighLowBROKOLI1.LowestLow[0])
&& (Open[0] >= RangoHighLowBROKOLI1.LowestLow[0])
&& (Open[1] >= RangoHighLowBROKOLI1.LowestLow[0])
&& (Close[1] >= RangoHighLowBROKOLI1.LowestLow[0])
&& (Open[1] <= RangoHighLowBROKOLI1.HighestHigh[0])
&& (Close[1] <= RangoHighLowBROKOLI1.HighestHigh[0])
&& (Trade_1 == true)
&& (Trade_2 == false)
&& (Sell_activar == true)
)
{
EnterShort(Ncontratos_trade1, @"EntryShort1");
ProfitShort1 = Instrument.MasterInstrument.RoundToTickSize(RangoH ighLowBROKOLI1.LowestLow[0] - ((RangoHighLowBROKOLI1.HighestHigh[0]-RangoHighLowBROKOLI1.LowestLow[0])*Porcentaje_fibo_TP1/100));
}
#endregion

Comment