Hello,
My MQL4 skills are not particularly good, and I am unable to see what is the issue with this EA. I would like my SL to move to BE + some pips (given by variable LockInPips) when price is at "LockInPipsAt". This part works.
However I would like to move the SL again to protect more profit when price goes in my favor by "LockInPipsAt2", and change the stop to BE + "LockInPips2". (That does not work).
In the numerical example below, SL would be to BE+10 when prices goes in my favour 40 pips, (this works), and then SL should be moved to BE+50 when price goes in my favor by 100 pips.
I would appreciate any help given to fix the EA.
string str1 = "BreakEven";
extern int LockInPipsAt = 40;
extern int LockInPips = 10;
extern int LockInPipsAt2 = 100;
extern int LockInPips2 = 50;
extern bool ModifyTrades = TRUE;
extern bool ModifyTrade3 = TRUE;
extern int FontSize = 8;
extern color FontColour = White;
bool TP2achieved = FALSE;
bool TP1achieved = FALSE;
double punto;
double modpoint;
double merc;
string sonido = "expert.wav";
int slip1 = 3;
int slip2 = 0;
int unod = 0;
int init() {
modpoint = Point;
punto = Digits;
slip2 = slip1;
if (Digits == 5 || Digits == 3) {
punto = Digits - 1;
modpoint = 10.0 * Point;
slip2 = 10 * slip1;
}
if (NormalizeDouble(MarketInfo(Symbol(), MODE_LOTSTEP), 2) == 0.01) unod = 2;
else unod = 1;
ObjectCreate("EA_Version", OBJ_LABEL, 0, 0, 0);
ObjectSetText("EA_Version", str1 + " - Lock in " + LockInPips + " pips after " + LockInPipsAt + " pips profit", FontSize, "Arial Bold", FontColour);
ObjectSet("EA_Version", OBJPROP_XDISTANCE, 240);
ObjectSet("EA_Version", OBJPROP_YDISTANCE, 0);
return (0);
}
int deinit() {
ObjectDelete("EA_Version");
ObjectDelete("Monitor1");
ObjectDelete("Monitor2");
ObjectDelete("Monitor3");
return (0);
}
int start() {
if (Digits == 5 || Digits == 3) merc = MarketInfo(Symbol(), MODE_SPREAD) / 10.0;
else merc = MarketInfo(Symbol(), MODE_SPREAD);
if (LockInPipsAt > 0) {
for (int hh = 0; hh < OrdersTotal(); hh++) {
OrderSelect(hh, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol()) {
switch (OrderType()) {
case OP_BUY:
if (iClose(OrderSymbol(), 0, 0) - OrderOpenPrice() >= LockInPipsAt * modpoint && TP1achieved == FALSE) {
if (OrderStopLoss() < OrderOpenPrice()) {
OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + LockInPips * modpoint, OrderTakeProfit(), 0, CLR_NONE);
Print("Stop Loss adjusted to ", LockInPips, " pips");
PlaySound(sonido);
TP1achieved = TRUE;
}
}
if (iClose(OrderSymbol(),0, 0) - OrderOpenPrice() >= LockInPipsAt2 * modpoint && TP2achieved == FALSE){
OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + LockInPips2 * modpoint, OrderTakeProfit(), 0, CLR_NONE);
Print("Stop Loss 2 adjusted to ", LockInPips2, " pips");
PlaySound(sonido);
TP2achieved = TRUE;
}
break;
case OP_SELL:
if (OrderOpenPrice() - iClose(OrderSymbol(), 0, 0) >= LockInPipsAt * modpoint && TP1achieved == FALSE) {
if (OrderStopLoss() > OrderOpenPrice()) {
OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - LockInPips * modpoint, OrderTakeProfit(), 0, Yellow);
Print("Stop Loss adjusted to ", LockInPips, " pips");
PlaySound(sonido);
TP1achieved = TRUE;
}
}
if (OrderOpenPrice() - iClose(OrderSymbol(),0, 0) >= LockInPipsAt2 * modpoint && TP2achieved == FALSE){
OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + LockInPips2 * modpoint, OrderTakeProfit(), 0, CLR_NONE);
Print("Stop Loss 2 adjusted to ", LockInPips2, " pips");
PlaySound(sonido);
TP2achieved = TRUE;
}
}
}
}
}
return (0);
}
My MQL4 skills are not particularly good, and I am unable to see what is the issue with this EA. I would like my SL to move to BE + some pips (given by variable LockInPips) when price is at "LockInPipsAt". This part works.
However I would like to move the SL again to protect more profit when price goes in my favor by "LockInPipsAt2", and change the stop to BE + "LockInPips2". (That does not work).
In the numerical example below, SL would be to BE+10 when prices goes in my favour 40 pips, (this works), and then SL should be moved to BE+50 when price goes in my favor by 100 pips.
I would appreciate any help given to fix the EA.
string str1 = "BreakEven";
extern int LockInPipsAt = 40;
extern int LockInPips = 10;
extern int LockInPipsAt2 = 100;
extern int LockInPips2 = 50;
extern bool ModifyTrades = TRUE;
extern bool ModifyTrade3 = TRUE;
extern int FontSize = 8;
extern color FontColour = White;
bool TP2achieved = FALSE;
bool TP1achieved = FALSE;
double punto;
double modpoint;
double merc;
string sonido = "expert.wav";
int slip1 = 3;
int slip2 = 0;
int unod = 0;
int init() {
modpoint = Point;
punto = Digits;
slip2 = slip1;
if (Digits == 5 || Digits == 3) {
punto = Digits - 1;
modpoint = 10.0 * Point;
slip2 = 10 * slip1;
}
if (NormalizeDouble(MarketInfo(Symbol(), MODE_LOTSTEP), 2) == 0.01) unod = 2;
else unod = 1;
ObjectCreate("EA_Version", OBJ_LABEL, 0, 0, 0);
ObjectSetText("EA_Version", str1 + " - Lock in " + LockInPips + " pips after " + LockInPipsAt + " pips profit", FontSize, "Arial Bold", FontColour);
ObjectSet("EA_Version", OBJPROP_XDISTANCE, 240);
ObjectSet("EA_Version", OBJPROP_YDISTANCE, 0);
return (0);
}
int deinit() {
ObjectDelete("EA_Version");
ObjectDelete("Monitor1");
ObjectDelete("Monitor2");
ObjectDelete("Monitor3");
return (0);
}
int start() {
if (Digits == 5 || Digits == 3) merc = MarketInfo(Symbol(), MODE_SPREAD) / 10.0;
else merc = MarketInfo(Symbol(), MODE_SPREAD);
if (LockInPipsAt > 0) {
for (int hh = 0; hh < OrdersTotal(); hh++) {
OrderSelect(hh, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol()) {
switch (OrderType()) {
case OP_BUY:
if (iClose(OrderSymbol(), 0, 0) - OrderOpenPrice() >= LockInPipsAt * modpoint && TP1achieved == FALSE) {
if (OrderStopLoss() < OrderOpenPrice()) {
OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + LockInPips * modpoint, OrderTakeProfit(), 0, CLR_NONE);
Print("Stop Loss adjusted to ", LockInPips, " pips");
PlaySound(sonido);
TP1achieved = TRUE;
}
}
if (iClose(OrderSymbol(),0, 0) - OrderOpenPrice() >= LockInPipsAt2 * modpoint && TP2achieved == FALSE){
OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + LockInPips2 * modpoint, OrderTakeProfit(), 0, CLR_NONE);
Print("Stop Loss 2 adjusted to ", LockInPips2, " pips");
PlaySound(sonido);
TP2achieved = TRUE;
}
break;
case OP_SELL:
if (OrderOpenPrice() - iClose(OrderSymbol(), 0, 0) >= LockInPipsAt * modpoint && TP1achieved == FALSE) {
if (OrderStopLoss() > OrderOpenPrice()) {
OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - LockInPips * modpoint, OrderTakeProfit(), 0, Yellow);
Print("Stop Loss adjusted to ", LockInPips, " pips");
PlaySound(sonido);
TP1achieved = TRUE;
}
}
if (OrderOpenPrice() - iClose(OrderSymbol(),0, 0) >= LockInPipsAt2 * modpoint && TP2achieved == FALSE){
OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + LockInPips2 * modpoint, OrderTakeProfit(), 0, CLR_NONE);
Print("Stop Loss 2 adjusted to ", LockInPips2, " pips");
PlaySound(sonido);
TP2achieved = TRUE;
}
}
}
}
}
return (0);
}