设为首页 收藏本站 切换语言

头皮源码交流,切勿实盘  

| 发表于 2020-8-19 21:41:43 | 显示全部楼层 |复制链接
  1. #property strict
  2. extern bool k_g_1 =false;
  3. extern int fx_yc =100; //Abnormal fluctuation
  4. extern double lots =0.02; //lots
  5. extern float zhi_s =1; //stop($)
  6. extern int zhi_y =15; //Take profit
  7. extern int xiao_b =6; //1 hour profit multiple
  8. extern int jie_j =10; //Long position profit multiple
  9. extern int dian_c=2; //Spread
  10. extern int magic =88888888;
  11. int wei_z =2,
  12. wei_s =100;
  13. double dian_z=0.01,
  14. lots_s;
  15. int f_z=0;
  16. int take;
  17. datetime time;
  18. bool fx_jj =false;
  19. int OnInit()
  20. {
  21. datetime tom=0;
  22. int AA_1=OrdersTotal();
  23. if(Point < 0.001)
  24. {
  25. dian_z=0.00001;
  26. wei_z=5;
  27. wei_s=100000;
  28. }
  29. else if(Point == 0.001)
  30. {
  31. dian_z=0.001;
  32. wei_z=3;
  33. wei_s=1000;
  34. }
  35. EventSetTimer(1);
  36. for(int AA=0; AA<AA_1; AA++)
  37. {
  38. if(!OrderSelect(AA, SELECT_BY_POS, MODE_TRADES)) break;
  39. if(OrderSymbol() != Symbol()) continue;
  40. if(OrderMagicNumber() != magic) continue;
  41. if(OrderOpenTime() > tom)
  42. {
  43. take=OrderTicket();
  44. tom=OrderOpenTime();
  45. continue;
  46. }
  47. }
  48. //---
  49. return(INIT_SUCCEEDED);
  50. }
  51. void OnDeinit(const int reason)
  52. {
  53. EventKillTimer();
  54. }
  55. //+------------------------------------------------------------------+
  56. //| |
  57. //+------------------------------------------------------------------+
  58. void OnTick()
  59. {
  60. static double prof_lr;
  61. static double prof_lr_1=0;
  62. static datetime time_1 =0;
  63. int or_d=0;
  64. double jj_ok=0;
  65. bool bo=false;
  66. int AA_1=OrdersTotal();
  67. double stop_lr=0;
  68. datetime tme=0;
  69. int xy=0;
  70. double min_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
  71. if(lots<min_volume)
  72. {
  73. Print("交易量小于允许的最小交易量,SYMBOL_VOLUME_MIN=%.2f");
  74. return;
  75. }
  76. for(int A=0; A < AA_1; A++)
  77. {
  78. if(!OrderSelect(A, SELECT_BY_POS, MODE_TRADES)) break;
  79. if(OrderSymbol() != Symbol()) continue;
  80. if(OrderMagicNumber() != magic) continue;
  81. or_d++;
  82. if(OrderProfit() < 0)
  83. stop_lr +=OrderSwap()+OrderProfit()+OrderCommission();
  84. if(TimeCurrent()-14400 <= OrderOpenTime()) fx_jj=true;
  85. if(OrderType() == OP_BUY)
  86. {
  87. if(OrderClosePrice() - OrderOpenPrice() > zhi_y*dian_z)
  88. {
  89. jj_ok=OrderSwap()+OrderProfit()+OrderCommission();
  90. prof_lr += jj_ok;
  91. prof_lr_1 +=jj_ok;
  92. if(OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), dian_c))
  93. {
  94. if(OrderTicket() != take) continue;
  95. if(f_z==2 && Close[0] - Open[0] < fx_yc*dian_z && Close[0] - Open[0] > 0)
  96. {
  97. take=OrderSend(Symbol(), OP_SELL, lots_s, Ask, dian_c, 0, 0, "12", magic);
  98. time=Time[0];
  99. continue;
  100. }
  101. else if(f_z==1)
  102. {
  103. take=OrderSend(Symbol(), OP_BUY, lots_s, Bid, dian_c, 0, 0, "11", magic);
  104. time=Time[0];
  105. continue;
  106. }
  107. take=0;
  108. }
  109. }
  110. if(OrderTicket() != take) continue;
  111. if(OrderOpenPrice()-OrderClosePrice() > zhi_y*dian_z)
  112. {
  113. if(f_z==2)
  114. {
  115. take=OrderSend(Symbol(), OP_SELL, lots_s, Ask, dian_c, 0, 0, "10", magic);
  116. time=Time[0];
  117. continue;
  118. }
  119. else if(f_z==1)
  120. {
  121. take=OrderSend(Symbol(), OP_BUY, lots_s, Bid, dian_c, 0, 0, "9", magic);
  122. time=Time[0];
  123. continue;
  124. }
  125. }
  126. }
  127. else if(OrderType() == OP_SELL)
  128. {
  129. if(OrderOpenPrice() - OrderClosePrice() > zhi_y*dian_z)
  130. {
  131. jj_ok=OrderSwap()+OrderProfit()+OrderCommission();
  132. prof_lr += jj_ok;
  133. prof_lr_1 +=jj_ok;
  134. if(OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), dian_c))
  135. {
  136. if(TimeHour(TimeCurrent())==0) continue;
  137. if(OrderTicket()!=take) continue;
  138. if(f_z==2 && Open[0] - Close[0] < fx_yc*dian_z && Open[0] - Close[0] > 0)
  139. {
  140. take=OrderSend(Symbol(), OP_BUY, lots_s, Bid, dian_c, 0, 0, "8", magic);
  141. time=Time[0];
  142. continue;
  143. }
  144. else if(f_z==1)
  145. {
  146. take=OrderSend(Symbol(), OP_SELL, lots_s, Ask, dian_c, 0, 0, "7", magic);
  147. time=Time[0];
  148. continue;
  149. }
  150. take=0;
  151. }
  152. }
  153. if(OrderTicket()!= take) continue;
  154. if(OrderClosePrice() - OrderOpenPrice() > zhi_y*dian_z)
  155. {
  156. if(f_z==2)
  157. {
  158. take=OrderSend(Symbol(), OP_BUY, lots_s, Bid, dian_c, 0, 0, "6", magic);
  159. time=Time[0];
  160. continue;
  161. }
  162. else if(f_z==1)
  163. {
  164. take=OrderSend(Symbol(), OP_SELL, lots_s, Ask, dian_c, 0, 0, "5", magic);
  165. time=Time[0];
  166. continue;
  167. }
  168. }
  169. }
  170. }
  171. if(or_d==0)
  172. {
  173. lots_s=lots;
  174. time=0;
  175. }
  176. if(time_1==0 && prof_lr_1 > 0)
  177. {
  178. time_1=TimeCurrent()+900;
  179. }
  180. if(time != Time[0])
  181. {
  182. if(fx_jj) jj_ok=or_ls();
  183. xy=0;
  184. for(int AA=0; AA<AA_1; AA++)
  185. {
  186. if(!OrderSelect(AA, SELECT_BY_POS, MODE_TRADES)) break;
  187. if(OrderSymbol() != Symbol()) continue;
  188. if(OrderMagicNumber() != magic) continue;
  189. if(xy >= 3)
  190. {
  191. bo=OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), dian_c);
  192. continue;
  193. }
  194. if(prof_lr + stop_lr >= zhi_s || prof_lr + stop_lr >= NormalizeDouble(zhi_s/2, 2))
  195. {
  196. bo=OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), dian_c);
  197. take=0;
  198. xy=3;
  199. prof_lr=0;
  200. continue;
  201. }
  202. if(prof_lr_1 + stop_lr >= zhi_s*xiao_b && time_1 < TimeCurrent())
  203. {
  204. bo=OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), dian_c);
  205. xy=4;
  206. take=0;
  207. time_1=TimeCurrent()+900;
  208. prof_lr_1=0;
  209. continue;
  210. }
  211. if(fx_jj)
  212. {
  213. if(jj_ok <= 0) continue;
  214. if(jj_ok + stop_lr >= zhi_s*jie_j)
  215. {
  216. bo=OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), dian_c);
  217. xy=5;
  218. continue;
  219. }
  220. }
  221. }
  222. xy=0;
  223. if(or_d > 0 && take > 0) return;
  224. for(int xx=OrdersTotal()-1; xx>=0; xx--)
  225. {
  226. if(!OrderSelect(xx, SELECT_BY_POS, MODE_TRADES)) break;
  227. if(OrderSymbol() != Symbol()) continue;
  228. if(OrderMagicNumber() != magic) continue;
  229. if(OrderOpenTime() > tme && OrderType()==OP_BUY)
  230. {
  231. time=OrderOpenTime();
  232. xy=1;
  233. }
  234. else if(OrderOpenTime() > tme && OrderType()==OP_SELL)
  235. {
  236. time=OrderOpenTime();
  237. xy=2;
  238. }
  239. }
  240. if(xy==1)
  241. {
  242. take=OrderSend(Symbol(), OP_SELL, lots_s, Ask, dian_c, 0, 0, "4", magic);
  243. if(take > 0)
  244. time=Time[0];
  245. }
  246. else if(xy==2)
  247. {
  248. take=OrderSend(Symbol(), OP_BUY, lots_s, Bid, dian_c, 0, 0, "3", magic);
  249. if(take > 0)
  250. time=Time[0];
  251. }
  252. else
  253. {
  254. if(Open[1] > Close[1])
  255. {
  256. take=OrderSend(Symbol(), OP_SELL, lots_s, Ask, dian_c, 0, 0, "2", magic);
  257. if(take > 0)
  258. time=Time[0];
  259. }
  260. else
  261. {
  262. take=OrderSend(Symbol(), OP_BUY, lots_s, Bid, dian_c, 0, 0, "1", magic);
  263. if(take > 0)
  264. time=Time[0];
  265. }
  266. }
  267. if(take<0) f_z=0;
  268. }
  269. }
  270. void OnTimer()
  271. {
  272. int seconds=0;// the left seconds of the current bar
  273. int h = 0; //Hour
  274. int m = 0; //Minute
  275. int s = 0; //Second hh:mm:ss
  276. int xy=0;
  277. datetime timee=iTime(Symbol(),PERIOD_CURRENT,0),
  278. tme=0;
  279. //double close = iClose(Symbol(),PERIOD_CURRENT,0);
  280. seconds=PeriodSeconds(PERIOD_CURRENT) -(int)(TimeCurrent()-timee);
  281. h = seconds/3600;
  282. m = (seconds - h*3600)/60;
  283. s = (seconds - h*3600 - m*60);
  284. if(m >= 3 && s>=0) f_z=1;
  285. else if(m < 3) f_z=2;
  286. }
  287. double or_ls()
  288. {
  289. static datetime tim=0;
  290. double prof_lr4=0;
  291. datetime tome;
  292. if(!k_g_1) return(0);
  293. tome=TimeCurrent()-72000;
  294. for(int x=OrdersHistoryTotal()-1; x>=0; x--)
  295. {
  296. if(!OrderSelect(x, SELECT_BY_POS, MODE_HISTORY))
  297. {
  298. tim=TimeCurrent()+600;
  299. break;
  300. }
  301. if(OrderSymbol() != Symbol()) continue;
  302. if(OrderMagicNumber() != magic) continue;
  303. if(OrderOpenTime() > tome)
  304. {
  305. prof_lr4 += OrderSwap()+OrderProfit()+OrderCommission();
  306. }
  307. }
  308. return(prof_lr4);
  309. }
复制代码
举报

评论 使用道具

精彩评论18

ajax9999
未及格
| 发表于 2021-5-26 13:36:30 来自手机 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

fxbienhild
未及格
| 发表于 2021-5-26 14:57:32 | 显示全部楼层
thanks for sharing
举报

点赞 评论 使用道具

daerwushen
DD
| 发表于 2021-5-26 19:04:01 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

升龙
DD
| 发表于 2021-5-26 21:24:04 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

winson
D
| 发表于 2021-6-4 15:00:52 | 显示全部楼层
谢谢啊!
举报

点赞 评论 使用道具

宝宝
DD
| 发表于 2021-8-7 22:12:49 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

zm0688
未及格
| 发表于 2021-8-8 23:52:24 | 显示全部楼层
想了解下,不能实盘的话干嘛用呢?
举报

点赞 评论 使用道具

allensky
DDD
| 发表于 2021-9-5 21:03:30 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

yifu0821
未及格
| 发表于 2021-9-5 21:46:15 来自手机 | 显示全部楼层
感謝分享
举报

点赞 评论 使用道具

twb818
C
| 发表于 2021-9-5 22:41:43 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

nanaliu
CC
| 发表于 2022-3-23 00:22:04 | 显示全部楼层
看看。。关注下。。
举报

点赞 评论 使用道具

小雨点
未及格
| 发表于 2022-3-27 20:35:13 | 显示全部楼层
路过
举报

点赞 评论 使用道具

MXY
DDD
| 发表于 2022-3-27 21:59:02 | 显示全部楼层
看不懂,慢慢学习
举报

点赞 评论 使用道具

紫竹青荷
CC
| 发表于 2022-6-15 18:36:00 | 显示全部楼层
感谢楼主分享
举报

点赞 评论 使用道具

6669
DDD
| 发表于 2022-6-15 18:50:50 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

pengjhl
CC
| 发表于 2022-6-15 19:37:03 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

ea12213
C
| 发表于 2022-6-15 19:43:37 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

刘先生io
未及格
| 发表于 2022-6-15 20:00:27 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

发新帖
EA交易
您需要登录后才可以评论 登录 | 立即注册

简体中文
繁體中文
English(英语)
日本語(日语)
Deutsch(德语)
Русский язык(俄语)
بالعربية(阿拉伯语)
Türkçe(土耳其语)
Português(葡萄牙语)
ภาษาไทย(泰国语)
한어(朝鲜语/韩语)
Français(法语)