有您的持续关注
我们会做得更好

网格智能交易EA



好像淘宝上还有人出售这套系统,网格马丁类型,参考下编程技巧方面或许有点借鉴。

本网收集整理智能交易EA仅为MQL4编程爱好者提供语法及相关编程技巧的学习研究之用,智能交易存在极高的风险测试请用模拟盘,请勿用于实盘。MQL4源码如下:

//+------------------------------------------------------------------+
 //|                                                         网格.mq4 |
 //|                                     Copyright 2014, QQ:125808047 |
 //+------------------------------------------------------------------+
 #property copyright "www.125808047.com"
 #property link      "http://www.125808047.com/"
#include <WinUser32.mqh>
extern string temp = "资金15000  下0.01手起步  EURUSD M15";
 extern bool 弹窗报警开关(默认打开) = TRUE;
 extern bool 当净值小于余额的百分50暂停EA = TRUE;
 extern int K长度大于本点数时暂停运行EA = 15;
 extern int 有几个多单或空单持仓时暂停EA = 18;
 extern double 当点差大于几个点时暂停EA = 5;
 extern int 有几个持仓时见微利就平仓 = 8;
 extern double 多个持仓时到设定的获利额就平仓 = 200.0;
 extern bool 达到设定的获利额就平仓吗 = FALSE;
 extern double 达到设定的获利额就平仓 = 3000.0;
 extern bool 达到设定的亏损额就平仓吗 = FALSE;
 extern double 达到设定的亏损额就平仓 = 1000.0;
 extern int 加码间隔点数一 = 15;//1-7单 加码间隔
 extern int 加码间隔点数二 = 50;//8单以上  加码间隔
 extern int 总体盈利点数 = 5;
 extern string Commentt = "ccktv";
 double gd_216 = 1.0;
 int gi_224 = 5;//盈利点数
 int gi_228 = 13;
 double gd_232 = 1.0;
 int gi_240 = 13;
 int gi_244 = 15;//1-7 加码间隔
 int gi_248 = 500;//8单以上  加码间隔
 int gi_252 = 1;
 bool gi_256 = FALSE;
 bool gi_260 = FALSE;
 bool gi_264 = TRUE;
 bool gi_268 = FALSE;
 double gd_272 = 0.01;
 double gd_280 = 1.3;
 int gi_288 = 15000;
 bool gi_292 = FALSE;
 int gi_296 = 2582969859;
 int gi_300 = 0;
 int gi_304 = 0;
 int gi_308 = 0;
 int gi_312;
 int gi_316;
 bool gi_320;
 bool gi_324;
 double gd_328;
 double gd_336;
 double gd_344;
 double gd_352;
 double gd_376;
 double gd_384;
 int gd_100 = 1;
int init() {
 if(!IsTesting()) {
 if (MessageBox("点击确定表示你理解并承担使用EA的风险,否则,请删除本EA。", "xxxxxxx 友情提醒:" + 
AccountName() + ",账号:" + AccountNumber(), MB_OKCANCEL|MB_ICONEXCLAMATION) != IDOK) return (0);
 }
 if (Digits == 3 || Digits == 5) gd_100 = 10;
 gi_308 = LotDecimal();
 gi_244 = 加码间隔点数一;
 gi_248 = 加码间隔点数二*10;
 gi_224 = 总体盈利点数;
 if (gi_264) gi_260 = FALSE;
 return (0);
 }
int deinit() {
 return (0);
 }
int start() {
 double ld_4 = 0;
 if (MathAbs(iHigh(NULL, PERIOD_M5, 1) - iLow(NULL, PERIOD_M5, 1)) >= K长度大于本点数时暂停运行EA * gd_100 * Point) 
{
 if (弹窗报警开关(默认打开) != TRUE) return (0);
 Alert("上根K线的长度大于设定的长度,可能仍然在单边行情中,所以在本根K线暂停运行EA");
 return (0);
 }
 if (MathAbs(Bid - iOpen(NULL, PERIOD_M5, 0)) >= K长度大于本点数时暂停运行EA * gd_100 * Point) {
 if (弹窗报警开关(默认打开) != TRUE) return (0);
 Alert("本根的现价-开盘价大于设定的长度,可能是单边行情的起点或仍然在单边行情中,所以在本根K线立即暂停运行EA");
 return (0);
 }
 gd_384 = MathAbs(Bid - gd_376);
 gd_376 = Bid;
 int li_16 = 0;
 int li_20 = 0;
 for (int li_24 = 0; li_24 < OrdersTotal(); li_24++) {
 bool cg = OrderSelect(li_24, SELECT_BY_POS);
 if (OrderSymbol() == Symbol() && OrderType() == OP_BUY && OrderMagicNumber() == gi_296) li_16++;
 if (OrderSymbol() == Symbol() && OrderType() == OP_SELL && OrderMagicNumber() == gi_296) li_20++;
 }
 if (li_16 == 有几个多单或空单持仓时暂停EA || li_20 == 有几个多单或空单持仓时暂停EA) return (0);
 if ((li_16 >= 有几个持仓时见微利就平仓 || li_20 >= 有几个持仓时见微利就平仓) && AccountProfit() >= 
多个持仓时到设定的获利额就平仓) {
 for (int li_28 = OrdersTotal() - 1; li_28 >= 0; li_28--) {
 cg = OrderSelect(li_28, SELECT_BY_POS, MODE_TRADES);
 if (OrderType() == OP_BUY && OrderSymbol() == Symbol()) {
 cg = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, CLR_NONE);
 Alert("有多个多单持仓时,当获利达到设定的获利额多空单就一次性全部平仓");
 }
 if (OrderType() == OP_SELL && OrderSymbol() == Symbol()) {
 cg = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, CLR_NONE);
 Alert("有多个空单持仓时,当获利达到设定的获利额多空单就一次性全部平仓");
 }
 }
 }
 if (Ask - Bid >= 当点差大于几个点时暂停EA * gd_100 * Point) return (0);
 if (当净值小于余额的百分50暂停EA == TRUE && AccountEquity() < 0.2 * AccountBalance()) {
 if (弹窗报警开关(默认打开) != TRUE) return (0);
 Alert(Symbol(), "【", Period(), "】当前的净值小于余额的50%,已经自动暂停EA的运行! 净值= ", AccountEquity(), ",
余额= ", AccountBalance(), ",余额的百分20= ", AccountBalance() / 2.0);
 return (0);
 }
 if (达到设定的亏损额就平仓吗 == TRUE && AccountProfit() <= (-达到设定的亏损额就平仓)) {
 for (int li_32 = OrdersTotal() - 1; li_32 >= 0; li_32--) {
 cg = OrderSelect(li_32, SELECT_BY_POS, MODE_TRADES);
 if (OrderType() < OP_BUYLIMIT && OrderSymbol() == Symbol()) {
 cg = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, CLR_NONE);
 Alert("持仓浮亏达到设定的亏损额全部平仓");
 }
 }
 }
 if (达到设定的获利额就平仓吗 == TRUE && AccountProfit() >= 达到设定的获利额就平仓) {
 for (int li_36 = OrdersTotal() - 1; li_36 >= 0; li_36--) {
 cg = OrderSelect(li_36, SELECT_BY_POS, MODE_TRADES);
 if (OrderType() < OP_BUYLIMIT && OrderSymbol() == Symbol()) {
 cg = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, CLR_NONE);
 Alert("持仓浮盈达到设定的获利额全部平仓");
 }
 }
 }
 if (gi_308 == 0) gi_308 = LotDecimal();
 Information();
 if (gi_264 != gi_268) {
 gi_320 = TRUE;
 gi_324 = TRUE;
 }
 if (gi_300 != iTime(NULL, PERIOD_M1, 0)) {
 gi_312 = 0;
 gi_316 = CountTrades("buy");
 if (gi_316 == 0 && gi_320 == TRUE) {
 gd_344 = NewLot("buy");
 while (gi_312 < 1) {
 gi_312 = OrderSend(Symbol(), OP_BUY, gd_344, Ask, 3, 0, 0, Commentt, gi_296, 0, Blue);
 if (gi_312 < 1) {
 Sleep(1000 * (60 * gi_252));
 } else yerrect("buy");
 RefreshRates();
 }
 }
 gi_316 = CountTrades("sell");
 if (gi_316 == 0 && gi_324 == TRUE) {
 gd_352 = NewLot("sell");
 while (gi_312 < 1) {
 gi_312 = OrderSend(Symbol(), OP_SELL, gd_352, Bid, 3, 0, 0, Commentt, gi_296, 0, Red);
 if (gi_312 < 1) {
 Sleep(1000 * (60 * gi_252));
 } else yerrect("sell");
 RefreshRates();
 }
 }
 gi_300 = iTime(NULL, PERIOD_M1, 0);
 }
 if (gi_304 != iTime(NULL, PERIOD_M1, 0)) {
 gi_312 = 0;
 gi_316 = CountTrades("buy");
 if (gi_316 > 0 && NextOrder("buy")) {
 gd_328 = NextLot("buy");
 while (gi_312 < 1) {
 gi_312 = OrderSend(Symbol(), OP_BUY, gd_328, Ask, 3, 0, 0, Commentt, gi_296, 0, Blue);
 if (gi_312 < 1) {
 Sleep(1000 * (60 * gi_252));
 } else yerrect("buy");
 RefreshRates();
 }
 }
 gi_316 = CountTrades("sell");
 if (gi_316 > 0 && NextOrder("sell")) {
 gd_336 = NextLot("sell");
 while (gi_312 < 1) {
 gi_312 = OrderSend(Symbol(), OP_SELL, gd_336, Bid, 3, 0, 0, Commentt, gi_296, 0, Red);
 if (gi_312 < 1) {
 Sleep(1000 * (60 * gi_252));
 } else yerrect("sell");
 RefreshRates();
 }
 }
 gi_304 = iTime(NULL, PERIOD_M1, 0);
 }
 return (0);
 }
void yerrect(string as_0) {
 double ld_8;
 double ld_16 = AveragePrice(as_0);
 for (int li_24 = OrdersTotal() - 1; li_24 >= 0; li_24--) {
 bool cg = OrderSelect(li_24, SELECT_BY_POS, MODE_TRADES);
 if (OrderSymbol() != Symbol() || OrderMagicNumber() != gi_296) continue;
 if (OrderSymbol() == Symbol() && OrderMagicNumber() == gi_296) {
 if (as_0 == "buy") {
 if (OrderType() == OP_BUY) {
 ld_8 = ld_16 + gi_224 * gd_100 * Point;
 if (OrderTakeProfit() != ld_8) {
 cg = OrderModify(OrderTicket(), ld_16, OrderStopLoss(), ld_8, 0, Yellow);
 }
 }
 }
 if (as_0 == "sell") {
 if (OrderType() == OP_SELL) {
 ld_8 = ld_16 - gi_224 * gd_100 * Point;
 if (OrderTakeProfit() != ld_8) {
 cg = OrderModify(OrderTicket(), ld_16, OrderStopLoss(), ld_8, 0, Yellow);
 }
 }
 }
 }
 }
 }
double NewLot(string as_0) {
 double ld_8;
 double ld_16 = MarketInfo(Symbol(), MODE_MINLOT);
 if (as_0 == "buy") {
 if (gi_260) ld_8 = gd_272;
 else ld_8 = NormalizeDouble(gd_272 * NormalizeDouble(AccountBalance() / gi_288, 0), gi_308);
 }
 if (as_0 == "sell") {
 if (gi_260) ld_8 = gd_272;
 else ld_8 = NormalizeDouble(gd_272 * NormalizeDouble(AccountBalance() / gi_288, 0), gi_308);
 }
 if (ld_8 < ld_16) ld_8 = ld_16;
 return (ld_8);
 }
double NextLot(string as_0) {
 double ld_8;
 if (gi_268) gd_280 = LotExponent();
 if (as_0 == "buy") ld_8 = NormalizeDouble(FindLastOrder(as_0, "Lots") * gd_280, gi_308);
 if (as_0 == "sell") ld_8 = NormalizeDouble(FindLastOrder(as_0, "Lots") * gd_280, gi_308);
 return (ld_8);
 }
double LotExponent() {
 double ld_0 = 0;
 for (double ld_8 = 1; ld_0 < AccountBalance(); ld_0 += 10.0 * (gd_272 * MathPow(ld_8, 12) * 
(gi_248 - gi_248 * gd_100 / 4))) {
 ld_8 = (100.0 * ld_8 + 1.0) / 100.0;
 ld_0 = 0;
 for (int li_16 = 0; li_16 <= 5; li_16++) ld_0 += 10.0 * (gd_272 * MathPow(ld_8, li_16) * 
(gi_248 - gi_244 * gd_100 * li_16));
 for (li_16 = 6; li_16 <= 9; li_16++) ld_0 += 10.0 * (gd_272 * MathPow(ld_8, li_16) * (gi_248 - gi_248 / 10));
 for (li_16 = 10; li_16 <= 11; li_16++) ld_0 += 10.0 * (gd_272 * MathPow(ld_8, li_16) * (gi_248 - gi_248 / 6));
 }
 Print("下单量: = " + DoubleToStr(ld_8, 2));
 return (ld_8);
 }
int NextOrder(string as_0) {
 int li_8;
 bool li_12 = FALSE;
 double ld_16 = iClose(Symbol(), PERIOD_M15, 1);
 double ld_24 = iOpen(Symbol(), PERIOD_M15, 1);
 if (as_0 == "buy") {
 li_8 = NormalizeDouble(gi_244 * MathPow(gd_216, CountTrades(as_0)), 0);
 if (CountTrades(as_0) == 7) li_8 = gi_248 / 10;
 if (CountTrades(as_0) == 8) li_8 = gi_248 / 10;
 if (CountTrades(as_0) == 9) li_8 = gi_248 / 10;
 if (CountTrades(as_0) == 10) li_8 = gi_248 / 10;
 if (CountTrades(as_0) == 11) li_8 = gi_248 / 6;
 if (CountTrades(as_0) == 12) li_8 = gi_248 / 6;
 if (CountTrades(as_0) == 13) li_8 = gi_248 / 4;
 if (FindLastOrder(as_0, "Price") - Ask >= li_8 * gd_100 * Point && CountTrades(as_0) < gi_228) {
 if (gi_256) {
 if (ld_24 <= ld_16) li_12 = TRUE;
 else li_12 = FALSE;
 } else li_12 = TRUE;
 }
 }
 if (as_0 == "sell") {
 li_8 = NormalizeDouble(gi_244 * MathPow(gd_232, CountTrades(as_0)), 0);
 if (CountTrades(as_0) == 7) li_8 = gi_248 / 10;
 if (CountTrades(as_0) == 8) li_8 = gi_248 / 10;
 if (CountTrades(as_0) == 9) li_8 = gi_248 / 10;
 if (CountTrades(as_0) == 10) li_8 = gi_248 / 10;
 if (CountTrades(as_0) == 11) li_8 = gi_248 / 6;
 if (CountTrades(as_0) == 12) li_8 = gi_248 / 6;
 if (CountTrades(as_0) == 13) li_8 = gi_248 / 4;
 if (Bid - FindLastOrder(as_0, "Price") >= li_8 * gd_100 * Point && CountTrades(as_0) < gi_240) {
 if (gi_256) {
 if (ld_24 >= ld_16) li_12 = TRUE;
 else li_12 = FALSE;
 } else li_12 = TRUE;
 }
 }
 return (li_12);
 }
double FindLastOrder(string as_0, string as_8) {
 double ld_16;
 double ld_24;
 int li_32 = 0;
 for (int li_36 = OrdersTotal() - 1; li_36 >= 0; li_36--) {
 bool cg = OrderSelect(li_36, SELECT_BY_POS, MODE_TRADES);
 if (OrderSymbol() != Symbol() || OrderMagicNumber() != gi_296) continue;
 if (OrderSymbol() == Symbol() && OrderMagicNumber() == gi_296) {
 if (as_0 == "buy") {
 if (OrderType() == OP_BUY) {
 if (OrderTicket() > li_32) {
 ld_16 = OrderOpenPrice();
 ld_24 = OrderLots();
 li_32 = OrderTicket();
 }
 }
 }
 if (as_0 == "sell") {
 if (OrderType() == OP_SELL) {
 if (OrderTicket() > li_32) {
 ld_16 = OrderOpenPrice();
 ld_24 = OrderLots();
 li_32 = OrderTicket();
 }
 }
 }
 }
 }
 if (as_8 == "Price") return (ld_16);
 if (as_8 == "Lots") return (ld_24);
 return (0.0);
 }
int CountTrades(string as_0) {
 int li_8 = 0;
 for (int li_12 = OrdersTotal() - 1; li_12 >= 0; li_12--) {
 bool cg = OrderSelect(li_12, SELECT_BY_POS, MODE_TRADES);
 if (OrderSymbol() != Symbol() || OrderMagicNumber() != gi_296) continue;
 if (OrderSymbol() == Symbol() && OrderMagicNumber() == gi_296) {
 if (as_0 == "buy")
 if (OrderType() == OP_BUY) li_8++;
 if (as_0 == "sell")
 if (OrderType() == OP_SELL) li_8++;
 }
 }
 return (li_8);
 }
double AveragePrice(string as_0) {
 double ld_8 = 0;
 double ld_16 = 0;
 for (int li_24 = OrdersTotal() - 1; li_24 >= 0; li_24--) {
 bool cg = OrderSelect(li_24, SELECT_BY_POS, MODE_TRADES);
 if (OrderSymbol() != Symbol() || OrderMagicNumber() != gi_296) continue;
 if (OrderSymbol() == Symbol() && OrderMagicNumber() == gi_296) {
 if (as_0 == "buy") {
 if (OrderType() == OP_BUY) {
 ld_8 += OrderOpenPrice() * OrderLots();
 ld_16 += OrderLots();
 }
 }
 if (as_0 == "sell") {
 if (OrderType() == OP_SELL) {
 ld_8 += OrderOpenPrice() * OrderLots();
 ld_16 += OrderLots();
 }
 }
 }
 }
 ld_8 = NormalizeDouble(ld_8 / ld_16, Digits);
 return (ld_8);
 }
void Information() {
 if (gi_292) {
 Comment("" + "                              www.125808047.com " + Symbol() + " EA整理QQ:125808047"
 + "\n"
 + "                              ------------------------------------------------"
 + "\n"
 + "                              平台商: " + AccountCompany() + " 杠杆 1:" + DoubleToStr(AccountLeverage(), 0)
 + "\n"
 + "                              ------------------------------------------------"
 + "\n"
 + "                              多单个数:" + CountTrades("buy")
 + "\n"
 + "                              多单获利:" + DoubleToStr(Balance("buy", "Balance"), 2)
 + "\n"
 + "                              多单手数: " + DoubleToStr(Balance("buy", "Lot"), 2)
 + "\n"
 + "                              ------------------------------------------------"
 + "\n"
 + "                              空单个数:" + CountTrades("sell")
 + "\n"
 + "                              空单获利:" + DoubleToStr(Balance("sell", "Balance"), 2)
 + "\n"
 + "                              空单手数: " + DoubleToStr(Balance("sell", "Lot"), 2)
 + "\n"
 + "                              ------------------------------------------------"
 + "\n"
 + "                              浮动盈亏: " + DoubleToStr(Balance("buy", "Balance") + 
Balance("sell", "Balance"), 2)
 + "\n"
 + "                              ------------------------------------------------"
 + "\n"
 + "                              EA整理 www.125808047.com"
 + "\n"
 + "                               ");
 }
 }
double Balance(string as_0, string as_8) {
 double ld_16 = 0;
 for (int li_24 = OrdersTotal() - 1; li_24 >= 0; li_24--) {
 bool cg = OrderSelect(li_24, SELECT_BY_POS, MODE_TRADES);
 if (OrderSymbol() != Symbol() || OrderMagicNumber() != gi_296) continue;
 if (OrderSymbol() == Symbol() && OrderMagicNumber() == gi_296) {
 if (as_0 == "buy") {
 if (OrderType() == OP_BUY) {
 if (as_8 == "Balance") ld_16 = ld_16 + OrderProfit() - OrderSwap() - OrderCommission();
 if (as_8 == "Lot") ld_16 += OrderLots();
 }
 }
 if (as_0 == "sell") {
 if (OrderType() == OP_SELL) {
 if (as_8 == "Balance") ld_16 = ld_16 + OrderProfit() - OrderSwap() - OrderCommission();
 if (as_8 == "Lot") ld_16 += OrderLots();
 }
 }
 }
 }
 return (ld_16);
 }
double LotDecimal() {
 double ld_0 = MarketInfo(Symbol(), MODE_LOTSTEP);
 int li_8 = MathCeil(MathAbs(MathLog(ld_0) / MathLog(10)));
 return (li_8);
 }

如您喜欢此文章请点下面分享按钮↴峰汇在线 » 网格智能交易EA
上一篇:
下一篇:
分享到:更多 ()