- #property strict
- extern double my_lots= 0.01;
- extern int zhi_s =100;
- extern string magic ="QQ:1354167644";
- int dian_c=6,
- wei_s =100;
- double dian_z=0.1;
- int OnInit()
- {
- if(Point < 0.001)
- {
- dian_z=0.0001;
- wei_s=100000;
- }
- else if(Point == 0.001)
- {
- dian_z=0.01;
- wei_s=1000;
- }
-
- return(INIT_SUCCEEDED);
- }
- void OnDeinit(const int reason)
- {
- }
- void OnTick()
- {
- static datetime time=0;
- static double zhi_y =0;
- int ab=0;
- bool bo=false;
- double close_1=Close[1],
- close_2=Close[2],
- open_1=Open[1],
- open_2=Open[2];
- double MA_5 =iMA(NULL, 0,14,0,MODE_SMMA,PRICE_MEDIAN,0);
- dian_c=StrToInteger(DoubleToStr((Ask-Bid)*wei_s, 0));
- for(int i=OrdersTotal()-1; i>=0; i--)
- {
- bo= OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
- if(bo==false)break;
- if(OrderSymbol()!=Symbol())continue;
- if(OrderType() == OP_BUY && Bid >= zhi_y)
- {
- bo=OrderClose(OrderTicket(), OrderLots(), Bid, 5);
- if(bo==true)
- {
- for(int L=OrdersTotal()-1; L>=0; L--)
- {
- bo=OrderSelect(L, SELECT_BY_POS, MODE_HISTORY);
- if(bo==false)break;
- if(OrderSymbol()!=Symbol())continue;
- if(OrderType() == OP_BUY)
- {
- OrderClose(OrderTicket(), OrderLots(), Bid, 5);
- zhi_y=0;
- }
- RefreshRates();
- }
- }
- }
- else if(OrderType() == OP_SELL && Ask <= zhi_y)
- {
- bo=OrderClose(OrderTicket(), OrderLots(), Ask, 5);
- if(bo==true)
- {
- for(int LI=OrdersTotal()-1; LI>=0; LI--)
- {
- bo=OrderSelect(LI, SELECT_BY_POS, MODE_HISTORY);
- if(bo==false)break;
- if(OrderSymbol()!=Symbol())continue;
- if(OrderType() == OP_SELL)
- {
- OrderClose(OrderTicket(), OrderLots(), Ask, 5);
- zhi_y=0;
- }
- RefreshRates();
- }
- }
-
-
- }
- }
- if(close_2 > MA_5 && close_1 > MA_5 && open_2 - close_2 >0 && open_1 - close_1 > 0 && time != Time[0])
- {
- if(!Check(Symbol(), my_lots, OP_SELL)) return;
- if(my_lots<SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN))
- {
- Comment("交易量过小无法交易");
- return;
- }
- OrderSend(Symbol(), OP_BUY, my_lots, Bid, dian_c, 0, 0, magic, 00000000);
-
-
- time=Time[0];
- zhi_y=Low[1];
- }
- else if(close_2 < MA_5 && close_1 < MA_5 && close_2 - close_2 >0 && close_1 - open_1 > 0 && time != Time[0])
- {
- if(!Check(Symbol(), my_lots, OP_SELL)) return;
- if(my_lots<SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN))
- {
- Comment("交易量过小无法交易");
- return;
- }
- OrderSend(Symbol(), OP_SELL, my_lots, Ask, dian_c, 0, 0, magic, 0000000);
- time=Time[0];
- zhi_y=High[1];
- }
- }
-
- bool Check(string symb, double lots,int type)
- {
- double free_margin=AccountFreeMarginCheck(symb,type, lots);
-
- if(free_margin<0)
- {
- string oper=(type==OP_BUY)?"买入":"卖出";
- Print("资金不足以进行", oper," ",lots, " ", symb, " 错误编号",GetLastError());
- return(false);
- }
-
- return(true);
- }
-
复制代码
|