double TS_Factor = 2;
double TS_MA = iMA(NULL, 0, 3, 0, MODE_EMA, PRICE_CLOSE, 0);
for(int i = 0; i < OrdersTotal(); i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(TP_B == 0 && MS_B == false && OrderMagicNumber() == 1)
{
if(OrderStopLoss() < TS_MA - ATR * TS_Factor)
{
OrderModify(OrderTicket(), OrderOpenPrice(), TS_MA - ATR * TS_Factor, OrderTakeProfit(), 0, Green);
}
}
if(TP_S == 0 && MS_S == false && OrderMagicNumber() == 2)
{
if(OrderStopLoss() > TS_MA + ATR * TS_Factor)
{
OrderModify(OrderTicket(), OrderOpenPrice(), TS_MA + ATR * TS_Factor, OrderTakeProfit(), 0, Green);
}
}
}
u can modify
double TS_Factor = 2;
double TS_MA = iMA(NULL, 0, 3, 0, MODE_EMA, PRICE_CLOSE, 0);
for(int i = 0; i < OrdersTotal(); i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(TP_B == 0 && MS_B == false && OrderMagicNumber() == 1)
{
if(OrderStopLoss() < TS_MA - ATR * TS_Factor)
{
OrderModify(OrderTicket(), OrderOpenPrice(), TS_MA - ATR * TS_Factor, OrderTakeProfit(), 0, Green);
}
}
if(TP_S == 0 && MS_S == false && OrderMagicNumber() == 2)
{
if(OrderStopLoss() > TS_MA + ATR * TS_Factor)
{
OrderModify(OrderTicket(), OrderOpenPrice(), TS_MA + ATR * TS_Factor, OrderTakeProfit(), 0, Green);
}
}
}
u can modify
hey thanks for that
cheers
double TS_Factor = 2;
double TS_MA = iMA(NULL, 0, 3, 0, MODE_EMA, PRICE_CLOSE, 0);
for(int i = 0; i < OrdersTotal(); i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(TP_B == 0 && MS_B == false && OrderMagicNumber() == 1)
{
if(OrderStopLoss() < TS_MA - ATR * TS_Factor)
{
OrderModify(OrderTicket(), OrderOpenPrice(), TS_MA - ATR * TS_Factor, OrderTakeProfit(), 0, Green);
}
}
if(TP_S == 0 && MS_S == false && OrderMagicNumber() == 2)
{
if(OrderStopLoss() > TS_MA + ATR * TS_Factor)
{
OrderModify(OrderTicket(), OrderOpenPrice(), TS_MA + ATR * TS_Factor, OrderTakeProfit(), 0, Green);
}
}
}
u can modify
Hey, mind if you explain on this? i am struggling to understand this and adapt it into my program. Thank you so much in advance :)
TS_MA - ATR * TS_Factor,
What needs explaining? TS = MA ± n × ATR
MT4: Learn to code it.
MT5: Begin learning to code it.
If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hi,
just wondering if anyone can point me in the direction of how to go about making the trailing stoploss of my EA equal to a moving average value.
cheers
geoff