Breakeven - keeps executing
Breakeven - keeps executing
21 Oct 2019, 11:45
Hi,
The breakeven adjustment works fine.
but the modifying does not stop. it keeps executing.
It seems like I need another condition in "IF"
but not sure how to do so.. can anyone help me with this?
private void BreakEvenAdjustment()
{
var allPositions = Positions.FindAll(label, SymbolName);
foreach (Position position in allPositions)
{
// if (position.StopLoss != null)
// return;
var entryPrice = position.EntryPrice;
var distance = position.TradeType == TradeType.Buy ? Symbol.Bid - entryPrice : entryPrice - Symbol.Ask;
// move stop loss to break even plus and additional (x) pips
if (distance >= BreakEvenPips * Symbol.PipSize)
{
if (position.TradeType == TradeType.Buy)
{
if (position.StopLoss <= position.EntryPrice + (Symbol.PipSize * breakevenextrapips) || position.StopLoss == null)
{
ModifyPosition(position, position.EntryPrice + (Symbol.PipSize * breakevenextrapips), position.TakeProfit);
Print("Stop Loss to Break Even set for BUY position {0}", position.Id);
}
}
else
{
if (position.StopLoss >= position.EntryPrice - (Symbol.PipSize * breakevenextrapips) || position.StopLoss == null)
{
ModifyPosition(position, entryPrice - (Symbol.PipSize * breakevenextrapips), position.TakeProfit);
Print("Stop Loss to Break Even set for SELL position {0}", position.Id);
}
}
}
}
}
Replies
NyanHtet
21 Oct 2019, 12:07
it seem like i fixed it.
added another loop inside.
testing now.
if (distance >= BreakEvenPips * Symbol.PipSize)
{
if (position.TradeType == TradeType.Buy)
{
if (position.StopLoss <= position.EntryPrice + (Symbol.PipSize * breakevenextrapips) || position.StopLoss == null)
{
//Fixed _21oct19
if (position.StopLoss == position.EntryPrice + (Symbol.PipSize * breakevenextrapips))
{
break;
}
else
{
ModifyPosition(position, position.EntryPrice + (Symbol.PipSize * breakevenextrapips), position.TakeProfit);
Print("Stop Loss to Break Even set for BUY position {0}", position.Id);
}
}
}
@NyanHtet
PanagiotisCharalampous
21 Oct 2019, 12:01
Hi NyanHtet,
Since we do not have the complete cBot code to reproduce the problem, we can only make guesses. Try rounding your calculated values to 5 decimal points and let us know if it resolves the problem. Example
Else please post the complete cBot code and steps to reproduce the behavior.
Best Regards,
Panagiotis
@PanagiotisCharalampous