Fix critical EA architecture issues
This commit is contained in:
@@ -98,17 +98,32 @@ private:
|
||||
{
|
||||
double break_even_trigger = CUtilities::PointsToPrice(mp_market_data.GetSymbol(),
|
||||
g_break_even_profit);
|
||||
double break_even_distance = CUtilities::PointsToPrice(mp_market_data.GetSymbol(),
|
||||
double break_even_buffer = CUtilities::PointsToPrice(mp_market_data.GetSymbol(),
|
||||
g_break_even_sl);
|
||||
double current_price = (pos_type == POSITION_TYPE_BUY) ? mp_market_data.GetBid() : mp_market_data.GetAsk();
|
||||
double price_move = 0.0;
|
||||
|
||||
// Break-even only if profit threshold is reached
|
||||
if(profit < break_even_trigger)
|
||||
return false;
|
||||
|
||||
// For BUY: move SL to BE (open price + distance)
|
||||
if(pos_type == POSITION_TYPE_BUY)
|
||||
{
|
||||
double be_sl = open_price + break_even_distance;
|
||||
price_move = current_price - open_price;
|
||||
}
|
||||
else if(pos_type == POSITION_TYPE_SELL)
|
||||
{
|
||||
price_move = open_price - current_price;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Break-even only if price has moved enough from entry
|
||||
if(price_move < break_even_trigger)
|
||||
return false;
|
||||
|
||||
// For BUY: move SL to entry price plus optional buffer
|
||||
if(pos_type == POSITION_TYPE_BUY)
|
||||
{
|
||||
double be_sl = open_price + break_even_buffer;
|
||||
be_sl = CUtilities::NormalizePrice(mp_market_data.GetSymbol(), be_sl);
|
||||
|
||||
if(be_sl > current_sl)
|
||||
@@ -119,10 +134,10 @@ private:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// For SELL: move SL to BE (open price - distance)
|
||||
// For SELL: move SL to entry price minus optional buffer
|
||||
else if(pos_type == POSITION_TYPE_SELL)
|
||||
{
|
||||
double be_sl = open_price - break_even_distance;
|
||||
double be_sl = open_price - break_even_buffer;
|
||||
be_sl = CUtilities::NormalizePrice(mp_market_data.GetSymbol(), be_sl);
|
||||
|
||||
if(be_sl < current_sl)
|
||||
|
||||
Reference in New Issue
Block a user