I noticed that my be +1 is not working all the time.... I guess it is because my strategy is calculated at bar close... And that be+1 should be in real time, as soon price is reaching the trigger for the be +1....
Here's my code :
Variables :
private int rangePriceLong = 15; // Default setting for RangePrice private int rangePriceShort = 15; // Default setting for RangePrice // Default setting for StopLoss private int stopL = 12; // Default setting for Target 1 private int target1 = 12; // Default setting for position Size private int nbcontracts = 1; // Default setting for buffer entry private int bufferentry = 2; // Default setting for break even +1 level private int breakeven = 6;
protected override void Initialize()
{
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{
// Resets the stop loss to the original value when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, stopL);
}
/////////// Break even part /////////
// If a long position is open, allow for stop loss modification to breakeven
else if (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price +x ticks, set stop loss to breakeven +1
if (High[0] >= Position.AvgPrice + breakeven * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice +1 * TickSize);
}
}
// If a short position is open, allow for stop loss modification to breakeven
else if (Position.MarketPosition == MarketPosition.Short)
{
// Once the price is greater than entry price -x ticks, set stop loss to breakeven +1
if (Low[0] <= Position.AvgPrice - breakeven * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice -1 * TickSize);
}
}
/////////// End Break even part /////////
/////////////
// The Short Signal case
////////////
if (My conditions )
{
EnterShortStop(nbcontracts, Low[0] - bufferentry * TickSize, "WIISignalShort1");
SetProfitTarget("WIISignalShort1", CalculationMode.Ticks, target1);
}
/////////////
// The Long Signal case
////////////
if ((Myconditions)
{
EnterLongStop(nbcontracts, High[0] + bufferentry * TickSize, "WIISignalLong1");
SetProfitTarget("WIISignalLong1", CalculationMode.Ticks, target1);
}
}
So, is there a problem because my strat is at bar close and I want the auto be +1 intra bar ?
How can I solve that ?
Thank you very much for your help !

but I think the solution is in there !
Comment