移动止盈怎么写,请大神帮忙
bool MobileTradeActionSl(string symbol,long magic,int my_sl)
{
ZeroMemory(request);
ZeroMemory(result);
bool res=false;
int total=PositionsTotal();
for(int i=0;i<total;i++)
{
if(PositionGetTicket(i)>0)
{
if(PositionGetString(POSITION_SYMBOL)==symbol&&PositionGetInteger(POSITION_MAGIC)==magic)
{
int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS);
//ulong magic=PositionGetInteger(POSITION_MAGIC);
double volume=PositionGetDouble(POSITION_VOLUME); // 持仓交易量
double sl=PositionGetDouble(POSITION_SL); // 持仓止损
double sls=sl;
ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); // type of the position
double price=PositionGetDouble(POSITION_PRICE_OPEN);
if(sl==0)
{
if(type==POSITION_TYPE_BUY)
{
if(SymbolInfoDouble(symbol,SYMBOL_BID)-my_sl*SymbolInfoDouble(symbol,SYMBOL_POINT)>price)
{
sls=NormalizeDouble(SymbolInfoDouble(symbol,SYMBOL_BID)-my_sl*SymbolInfoDouble(symbol,SYMBOL_POINT),digits);
}
}
else
{
if(SymbolInfoDouble(symbol,SYMBOL_ASK)+my_sl*SymbolInfoDouble(symbol,SYMBOL_POINT)<price)
sls=NormalizeDouble(SymbolInfoDouble(symbol,SYMBOL_ASK)+my_sl*SymbolInfoDouble(symbol,SYMBOL_POINT),digits);
}
}
else
{
if(type==POSITION_TYPE_BUY)
{
if(SymbolInfoDouble(symbol,SYMBOL_BID)-my_sl*SymbolInfoDouble(symbol,SYMBOL_POINT)>price&&
SymbolInfoDouble(symbol,SYMBOL_BID)-my_sl*SymbolInfoDouble(symbol,SYMBOL_POINT)>sl )
{
sls=NormalizeDouble(SymbolInfoDouble(symbol,SYMBOL_BID)-my_sl*SymbolInfoDouble(symbol,SYMBOL_POINT),digits);
}
}
else
{
if(SymbolInfoDouble(symbol,SYMBOL_ASK)+my_sl*SymbolInfoDouble(symbol,SYMBOL_POINT)<price&&
sl-SymbolInfoDouble(symbol,SYMBOL_ASK)>my_sl*SymbolInfoDouble(symbol,SYMBOL_POINT))
sls=NormalizeDouble(SymbolInfoDouble(symbol,SYMBOL_ASK)+my_sl*SymbolInfoDouble(symbol,SYMBOL_POINT),digits);
}
}
//--- 设置操作参数
request.action =TRADE_ACTION_SLTP; // 交易操作类型
request.position=PositionGetTicket(i); // 持仓价格
request.symbol=symbol;
request.magic=magic;
if(sl!=sls)
{
request.sl =sls; // 持仓止损
res=OrderSend(request,result);
}
else
return(false);
}
}
}
return(res);
}
- 2021.08.19
- www.mql5.com
移动止盈怎么写,请大神帮忙