This ModifyOrder code in MT3 Demo returns a "Modify failed [invalid s/l or t/p)" in the Journal. This same code works OK in the MT3 Backtest.
Could someone advise if they see something wrong in this code.
Thank you,
Wackena
defines: Gap(20),factor(1);
var: ts(0);
for cnt=1 to TotalTrades
{
mode=OrderValue(cnt,VAL_TYPE);
If OrderValue(cnt,VAL_SYMBOL)=Symbol then
{
if mode=OP_BUY then
{
If OrderValue(cnt,VAL_CLOSEPRICE)-OrderValue(cnt,VAL_OPENPRICE)>(Gap*factor)*Point then
{
ts=OrderValue(cnt,VAL_OPENPRICE)+(Gap*factor)*Point;
factor=factor+1;
}
If ts>OrderValue(cnt,VAL_STOPLOSS) then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),ts,OrderValue(cnt,VAL_TAKEPROFIT),Red);
}
}
If mode=OP_SELL then
{
If OrderValue(cnt,VAL_OPENPRICE)-OrderValue(cnt,VAL_CLOSEPRICE)>(Gap*factor)*Point then
{
ts=OrderValue(cnt,VAL_OPENPRICE)-(Gap*factor)*Point;
factor=factor+1;
}
If ts<OrderValue(cnt,VAL_STOPLOSS) then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),ts,OrderValue(cnt,VAL_TAKEPROFIT),Red);
}
}
}
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Could someone advise if they see something wrong in this code.
Thank you,
Wackena
defines: Gap(20),factor(1); var: ts(0); for cnt=1 to TotalTrades { mode=OrderValue(cnt,VAL_TYPE); If OrderValue(cnt,VAL_SYMBOL)=Symbol then { if mode=OP_BUY then { If OrderValue(cnt,VAL_CLOSEPRICE)-OrderValue(cnt,VAL_OPENPRICE)>(Gap*factor)*Point then { ts=OrderValue(cnt,VAL_OPENPRICE)+(Gap*factor)*Point; factor=factor+1; } If ts>OrderValue(cnt,VAL_STOPLOSS) then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),ts,OrderValue(cnt,VAL_TAKEPROFIT),Red); } } If mode=OP_SELL then { If OrderValue(cnt,VAL_OPENPRICE)-OrderValue(cnt,VAL_CLOSEPRICE)>(Gap*factor)*Point then { ts=OrderValue(cnt,VAL_OPENPRICE)-(Gap*factor)*Point; factor=factor+1; } If ts<OrderValue(cnt,VAL_STOPLOSS) then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),ts,OrderValue(cnt,VAL_TAKEPROFIT),Red); } } } }