感谢论坛大神!从他们那里学到很多,一起感谢!!
现在有个问题:有时好使有时却不好使,滑价点也调整了,有时点按钮却没有反应,只有多,空是正常开,其他就有时开,有时不开。本人学了一段时间因断断续续,所以学的不扎实,搞了三、四天了,也解决不了。放到520FX,请大神帮看看,哪里出了问题(源码文件在二楼):
[C++] 纯文本查看 复制代码#property strict
//+------------------------------------------------------------------+
//| 全局参数 自定义指标初始化函数 |
//+------------------------------------------------------------------+
extern ENUM_BASE_CORNER Corner =1;//显示位置
extern int FontSize =12;//字体大小
extern int 框高=18;//框体高度
extern color Fontcolor=clrWhite;//字体颜色
extern color BGcolor=clrBlack;//背景颜色C'255,255,255'
extern color BRcolor=clrCoral;//框框边界颜色
extern double 交易手数=0.5;
extern double 止损点数=200;
//extern double 止盈点数=200;
extern int 滑价点数=5;
int Win=0;//0是主屏;1是副图
int 魔术号=0;
//+------------------------------------------------------------------+
//| 初始化内置函数 |
//+------------------------------------------------------------------+
int OnInit()
{
框架();
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
for(int j=0;j=0;cnt--)
{
int ticket=0;
total=OrdersTotal();
// if(!OrderSelect(cnt,SELECT_BY_POS))continue;
// if(OrderSymbol()!=Symbol())continue;
// if(!(OrderMagicNumber()==魔术号 || 魔术号==0))continue;
if(OrderType()==OP_BUY)
{
if(total>0)
{
for(cnt=total-1;cnt>=0;cnt--)
{if(OrderSymbol()!=Symbol())continue;
if(!(OrderMagicNumber()==魔术号 || 魔术号==0))continue;
if(!OrderSelect(cnt,SELECT_BY_POS))continue;
if(OrderType()==OP_BUY)
{
bool res=OrderClose(OrderTicket(),OrderLots(),Bid,滑价点数,0);
}
}
}
ticket=OrderSend(OrderSymbol(),1,OrderLots(),Bid,滑价点数,stoploss1,0,"反手1倍"+IntegerToString(OrderTicket()),OrderMagicNumber(),0,clrNONE);
}
if(OrderType()==OP_SELL)
{
if(total>0)
{
for(cnt=total-1;cnt>=0;cnt--)
{if(OrderSymbol()!=Symbol())continue;
// if(!(OrderMagicNumber()==魔术号 || 魔术号==0))continue;
if(!OrderSelect(cnt,SELECT_BY_POS))continue;
if(OrderType()==OP_SELL)
{
bool res=OrderClose(OrderTicket(),OrderLots(),Ask,滑价点数,0);
}
}
}
ticket=OrderSend(OrderSymbol(),0,OrderLots(),Ask,滑价点数,stoploss,0,"反手1倍"+IntegerToString(OrderTicket()),OrderMagicNumber(),0,clrNONE);
}
if(ticket>0)break;
}
}
////////反手2倍开单/////////////////////////////////
if(sparam=="hekc"+(string)2)
{
if( ObjectGetInteger(0,"hekc"+(string)2,OBJPROP_STATE)==1) //这里判断框是否被鼠标点击而赋色值
{
ObjectSetInteger(0,"hekc"+(string)2,OBJPROP_BGCOLOR,clrBlack);//这里判断框是否被鼠标点击而赋色值
}
else
{
ObjectSetInteger(0,"hekc"+(string)2,OBJPROP_BGCOLOR,clrDodgerBlue);//这里判断框是否被鼠标点击而赋色值
}
double stoploss1=NormalizeDouble(Bid+Point*止损点数,Digits);
double stoploss=NormalizeDouble(Ask-Point*止损点数,Digits);
for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
int ticket=0;
total=OrdersTotal();
// if(!OrderSelect(cnt,SELECT_BY_POS))continue;
// if(OrderSymbol()!=Symbol())continue;
// if(!(OrderMagicNumber()==魔术号 || 魔术号==0))continue;
if(OrderType()==OP_BUY)
{
if(total>0)
{
for(cnt=total-1;cnt>=0;cnt--)
{if(OrderSymbol()!=Symbol())continue;
if(!(OrderMagicNumber()==魔术号 || 魔术号==0))continue;
if(!OrderSelect(cnt,SELECT_BY_POS))continue;
if(OrderType()==OP_BUY)
{
bool res=OrderClose(OrderTicket(),OrderLots(),Bid,滑价点数,0);
}
}
}
ticket=OrderSend(OrderSymbol(),1,OrderLots()*2,Bid,滑价点数,stoploss1,0,"反手2倍"+IntegerToString(OrderTicket()),OrderMagicNumber(),0,clrNONE);
}
if(OrderType()==OP_SELL)
{
if(total>0)
{
for(cnt=total-1;cnt>=0;cnt--)
{if(OrderSymbol()!=Symbol())continue;
if(!(OrderMagicNumber()==魔术号 || 魔术号==0))continue;
if(!OrderSelect(cnt,SELECT_BY_POS))continue;
if(OrderType()==OP_SELL)
{
bool res=OrderClose(OrderTicket(),OrderLots(),Ask,滑价点数,0);
}
}
}
ticket=OrderSend(OrderSymbol(),0,OrderLots()*2,Ask,滑价点数,stoploss,0,"反手2倍"+IntegerToString(OrderTicket()),OrderMagicNumber(),0,clrNONE);
}
if(ticket>0)break;
}
}
//////全平//////////////////////////////////
if(sparam=="hekc"+(string)3)
{
if( ObjectGetInteger(0,"hekc"+(string)3,OBJPROP_STATE)==1)
{
ObjectSetInteger(0,"hekc"+(string)3,OBJPROP_BGCOLOR,clrBlack);
}
else
{
ObjectSetInteger(0,"hekc"+(string)3,OBJPROP_BGCOLOR,clrDodgerBlue);
}
total=OrdersTotal();
if(total>0)
{
for(cnt=total-1;cnt>=0;cnt--)
{
if(OrderSymbol()!=Symbol())continue;
if(!(OrderMagicNumber()==魔术号 || 魔术号==0))continue;
if(!OrderSelect(cnt,SELECT_BY_POS))continue;
if(OrderType()==OP_BUY)
{
bool res=OrderClose(OrderTicket(),OrderLots(),Bid,滑价点数,clrNONE);
}
if(OrderType()==OP_SELL)
{
bool res=OrderClose(OrderTicket(),OrderLots(),Ask,滑价点数,clrNONE);
}
}
}
}
////////全平1/2///////////////////
if(sparam=="hekc"+(string)4)
{
if( ObjectGetInteger(0,"hekc"+(string)4,OBJPROP_STATE)==1)
{
ObjectSetInteger(0,"hekc"+(string)4,OBJPROP_BGCOLOR,clrBlack);
}
else
{
ObjectSetInteger(0,"hekc"+(string)4,OBJPROP_BGCOLOR,clrDodgerBlue);
}
total=OrdersTotal();
if(total>0)
{
for(cnt=total-1;cnt>=0;cnt--)
{if(OrderSymbol()!=Symbol())continue;
if(!(OrderMagicNumber()==魔术号 || 魔术号==0))continue;
if(!OrderSelect(cnt,SELECT_BY_POS))continue;
double lot=NormalizeDouble(OrderLots()*1/2,2); //取得单子的手数,然后算出要平仓的手数,并精确到小数点后两位
if(OrderType()==OP_SELL)
{
bool res=OrderClose(OrderTicket(),lot,Ask,滑价点数,clrNONE);
}
if(OrderType()==OP_BUY)
{
bool res=OrderClose(OrderTicket(),lot,Bid,滑价点数,clrNONE);
}
}
}
}
///////全平1/3///////////
if(sparam=="hekc"+(string)5)
{
if( ObjectGetInteger(0,"hekc"+(string)5,OBJPROP_STATE)==1)//函数返回相应的对象属性的值。对象属性必须为DateTime,int,char类型bool或颜色。有2个变种的功能。
{
ObjectSetInteger(0,"hekc"+(string)5,OBJPROP_BGCOLOR,clrBlack);//函数设置了相应的对象属性的值。对象属性必须为DateTime,int,char类型bool或颜色。有2个变种的功能。
}
else
{
ObjectSetInteger(0,"hekc"+(string)5,OBJPROP_BGCOLOR,clrDodgerBlue);
}
total=OrdersTotal();
if(total>0)
{
for(cnt=total-1;cnt>=0;cnt--)
{
if(OrderSymbol()!=Symbol())continue;
if(!(OrderMagicNumber()==魔术号 || 魔术号==0))continue;
if(!OrderSelect(cnt,SELECT_BY_POS))continue;
double lot=NormalizeDouble(OrderLots()*1/3,2); //取得单子的手数,然后算出要平仓的手数,并精确到小数点后两位
if(OrderType()==OP_SELL)
{
bool res=OrderClose(OrderTicket(),lot,Ask,滑价点数,clrNONE);
}
if(OrderType()==OP_BUY)
{
bool res=OrderClose(OrderTicket(),lot,Bid,滑价点数,clrNONE);
}
}
}
}
///////全平多单//////////////////////////////////////
if(sparam=="hekc"+(string)6)
{
if( ObjectGetInteger(0,"hekc"+(string)6,OBJPROP_STATE)==1)
{
ObjectSetInteger(0,"hekc"+(string)6,OBJPROP_BGCOLOR,clrViolet);
}
else
{
ObjectSetInteger(0,"hekc"+(string)6,OBJPROP_BGCOLOR,clrDodgerBlue);
}
total=OrdersTotal();
if(total>0)
{
for(cnt=total-1;cnt>=0;cnt--)
{
if(OrderSymbol()!=Symbol())continue;
if(!(OrderMagicNumber()==魔术号 || 魔术号==0))continue;
if(!OrderSelect(cnt,SELECT_BY_POS))continue;
if(OrderType()==OP_BUY)
{
bool res=OrderClose(OrderTicket(),OrderLots(),Bid,滑价点数,clrNONE);
}
}
}
}
////////全平空单/////////////////////////
if(sparam=="hekc"+(string)7)
{
if( ObjectGetInteger(0,"hekc"+(string)7,OBJPROP_STATE)==1)
{
ObjectSetInteger(0,"hekc"+(string)7,OBJPROP_BGCOLOR,clrViolet);
}
else
{
ObjectSetInteger(0,"hekc"+(string)7,OBJPROP_BGCOLOR,clrDodgerBlue);
}
total=OrdersTotal();
if(total>0)
{
for(cnt=total-1;cnt>=0;cnt--)
{
if(OrderSymbol()!=Symbol())continue;
if(!(OrderMagicNumber()==魔术号 || 魔术号==0))continue;
if(!OrderSelect(cnt,SELECT_BY_POS))continue;
if(OrderType()==OP_SELL)
{
bool res=OrderClose(OrderTicket(),OrderLots(),Ask,滑价点数,clrNONE);
}
}
}
}
///////多///////////////////////
if(sparam=="hekc"+(string)8)
{
if( ObjectGetInteger(0,"hekc"+(string)8,OBJPROP_STATE)==1)
{
ObjectSetInteger(0,"hekc"+(string)8,OBJPROP_BGCOLOR,clrRed);
}
else
{
ObjectSetInteger(0,"hekc"+(string)8,OBJPROP_BGCOLOR,clrRed);
}
double stoploss=NormalizeDouble(Ask-Point*止损点数,Digits);// Digits当前符号价格的小数点后的数字。
int ticket=OrderSend(Symbol(),OP_BUY,交易手数,Ask,滑价点数,stoploss,0,"多"+IntegerToString(OrderTicket()),OrderMagicNumber(),0,clrNONE);
}
//////空单//////////////////////////////////////////
if(sparam=="hekc"+(string)9)
{
if( ObjectGetInteger(0,"hekc"+(string)9,OBJPROP_STATE)==1)
{
ObjectSetInteger(0,"hekc"+(string)9,OBJPROP_BGCOLOR,clrGreen);
}
else
{
ObjectSetInteger(0,"hekc"+(string)9,OBJPROP_BGCOLOR,clrGreen);
}
double minstoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
double stoploss=NormalizeDouble(Bid+Point*止损点数,Digits);// Digits当前符号价格的小数点后的数字。
int ticket=OrderSend(Symbol(),OP_SELL,交易手数,Bid,滑价点数,stoploss,0,"空"+IntegerToString(OrderTicket()),OrderMagicNumber(),0,clrNONE);
}
}
}
//////--- 通过按下鼠标键检测事件 尾 ////////////////////////////////////
//+------------------------------------------------------------------+
void start()
{
}
//+------------------------------------------------------------------+
//| 自定义框体函数 |
//+------------------------------------------------------------------+
void CreateLabel(long chart_ID,
string Name,
int Window,
int xPos,
int yPos,
int 宽,
int 高,
int FontSz,
color FontColor1,
color BGcolor1,
color BRcolor1,
int Corner1,
string LblTxt)
{
if
(ObjectFind(Name)!=0) ObjectCreate(chart_ID,Name,OBJ_BUTTON,Window,0,0);
ObjectSetInteger(chart_ID,Name,OBJPROP_CORNER,Corner1);
ObjectSetInteger(chart_ID,Name,OBJPROP_XDISTANCE,xPos);
ObjectSetInteger(chart_ID,Name,OBJPROP_YDISTANCE,yPos);
//--- 设置按钮大小
ObjectSetInteger(chart_ID,Name,OBJPROP_XSIZE,宽);//105); //高
ObjectSetInteger(chart_ID,Name,OBJPROP_YSIZE,高);//25); //宽
//--- 设置文本 --- 设置文本字体 --- 设置字体大小 --- 设置文本颜色
ObjectSetString(chart_ID,Name,OBJPROP_FONT,"黑体");
ObjectSetInteger(chart_ID,Name,OBJPROP_FONTSIZE,FontSz);
ObjectSetInteger(chart_ID,Name,OBJPROP_COLOR,FontColor1);
//--- 设置背景颜色
ObjectSetInteger(chart_ID,Name,OBJPROP_BORDER_COLOR,BRcolor1); //边界线
ObjectSetInteger(chart_ID,Name,OBJPROP_BGCOLOR,BGcolor1); //背景
//--- 启用 (true) 或禁用 (false) 通过鼠标移动按钮的模式
ObjectSetInteger(chart_ID,Name,OBJPROP_SELECTABLE,0); //+----设置对象是否可用(0能按下)
ObjectSetInteger(chart_ID,Name,OBJPROP_SELECTED,0);
ObjectSetInteger(chart_ID,Name,OBJPROP_BACK,false);
ObjectSetInteger(chart_ID,Name,OBJPROP_ALIGN,ALIGN_LEFT);
ObjectSetString(chart_ID,Name,OBJPROP_TEXT,LblTxt);
}
//+------------------------------------------------------------------+
//| 实际显示框体界面 调用窗体函数 |
//+------------------------------------------------------------------+
void 框架()
{
for(int j=0;j
|