How to code stop at breakeven?

 

Hi guys!

Can I have an example of stop at breakeven?


 
Marco Garthi:

Hi guys!

Can I have an example of stop at breakeven?


extern double BreakEvenProfit = 25;
for(int Counter = 0; Counter <= OrdersTotal()-1; Counter++)
{
OrderSelect(Counter,SELECT_BY_POS);
RefreshRates();
double PipsProfit = Bid – OrderOpenPrice();
double MinProfit = BreakEvenProfit * PipPoint(OrderSymbol()));
if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol()
&& OrderType() == OP_BUY && PipsProfit >= MinProfit 
&& OrderOpenPrice() != OrderStopLoss())
{
bool BreakEven = OrderModify(OrderTicket(),OrderOpenPrice(),
OrderOpenPrice(),OrderTakeProfit(),0);
if(BreakEven == false)
{
ErrorCode = GetLastError();
string ErrDesc = ErrorDescription(ErrorCode);
string ErrAlert = StringConcatenate("Buy Break Even - Error ",
ErrorCode,": ",ErrDesc);
Alert(ErrAlert);
string ErrLog = StringConcatenate("Bid: ",Bid,", Ask: ",Ask,
", Ticket: ",CloseTicket,", Stop: ",OrderStopLoss(),", Break: ",
MinProfit);
 Print(ErrLog);
}
}
}
 
Ridwan Icus:


Please edit your post and

use the code button (Alt+S) when pasting code

 
Ridwan Icus:
extern double BreakEvenProfit = 25;
for(int Counter = 0; Counter <= OrdersTotal()-1; Counter++)
{
OrderSelect(Counter,SELECT_BY_POS);
RefreshRates();
double PipsProfit = Bid – OrderOpenPrice();
double MinProfit = BreakEvenProfit * PipPoint(OrderSymbol()));
if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol()
&& OrderType() == OP_BUY && PipsProfit >= MinProfit 
&& OrderOpenPrice() != OrderStopLoss())
{
bool BreakEven = OrderModify(OrderTicket(),OrderOpenPrice(),
OrderOpenPrice(),OrderTakeProfit(),0);
if(BreakEven == false)
{
ErrorCode = GetLastError();
string ErrDesc = ErrorDescription(ErrorCode);
string ErrAlert = StringConcatenate("Buy Break Even - Error ",
ErrorCode,": ",ErrDesc);
Alert(ErrAlert);
string ErrLog = StringConcatenate("Bid: ",Bid,", Ask: ",Ask,
", Ticket: ",CloseTicket,", Stop: ",OrderStopLoss(),", Break: ",
MinProfit);
 Print(ErrLog);
}
}
}

Please do not post code which do not work

ErrorCode : undeclared identifier

CloseTicket : undeclared identifier

double MinProfit = BreakEvenProfit * PipPoint(OrderSymbol()));

PipPoint(OrderSymbol() : fonction not defined

and there is a parenthesis superflu

PipsProfit = Bid - OrderOpenPrice();

the minus (-) is not recognised as a minus

Reason: