请老师们帮我解决一个问题,编程里面的

楼主  收藏   举报   帖子创建时间:  2019-05-05 13:34 回复:0 关注量:854
  1. extern int shoudan=1;
  2. extern double shoushu=0.01;
  3. extern int Szhiyin=40;
  4. extern int jiacang=40;
  5. extern int beishu=2;
  6. extern int cishu=8;
  7. extern int zhisun=20;
  8. int a,chicangdan,kaicang;

  9. //+------------------------------------------------------------------+
  10. //| expert initialization function |
  11. //+------------------------------------------------------------------+
  12. int init()
  13. {
  14. //----

  15. //----
  16. return(0);
  17. }
  18. //+------------------------------------------------------------------+
  19. //| expert deinitialization function |
  20. //+------------------------------------------------------------------+
  21. int deinit()
  22. {
  23. //----

  24. //----
  25. return(0);
  26. }
  27. //+------------------------------------------------------------------+
  28. //| expert start function |
  29. //+------------------------------------------------------------------+
  30. int start()
  31. {
  32. //----
  33. if(Bars<100)
  34. {
  35. Print("bars less than 100");
  36. return(0);
  37. }
  38. Print("持仓单方向1为买,2为卖:",TheLastOrderType());
  39. chicangdan=GetHoldingOrderCnt();
  40. if(chicangdan<1)
  41. {
  42. if(TheLastOrderType()==-1)
  43. {
  44. if(shoudan==1)
  45. {

  46. mairu();
  47. Print("测试111");

  48. }
  49. if(shoudan==2)
  50. {

  51. Print("测试222");

  52. }
  53. }
  54. if(TheLastOrderType()==0)
  55. {

  56. Print("测试11");

  57. }
  58. if(TheLastOrderType()==1)
  59. {

  60. Print("测试22");
  61. return(0);
  62. }
  63. }
  64. //----
  65. return(0);
  66. }
  67. //+------------------------------------------------------------------+
  68. int TheLastOrderType()//返回最后历史单的方向 如果返回-1表示没有持仓
  69. {
  70. int P=-1;
  71. for(int i=OrdersTotal()-1;i>=0;i--)
  72. {
  73. OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
  74. if(OrderSymbol()==Symbol() && OrderMagicNumber()==123 )
  75. {
  76. P=OrderType();
  77. break;
  78. }
  79. }
  80. return(P);
  81. }

  82. //+------------------------------------------------------------------+
  83. int GetHoldingOrderCnt()
  84. {
  85. int j=0;
  86. for(int i=0;i<OrdersTotal();i++)
  87. {
  88. OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
  89. if(OrderSymbol()==Symbol() )
  90. {
  91. j=j+1;
  92. }
  93. }
  94. return(j);
  95. }

  96. void mairu()
  97. {
  98. kaicang=OrderSend(Symbol(),OP_BUY,shoushu,Ask,3,Ask-500*Point,Ask+Szhiyin*Point,"My order #2",123,0,Lime);
  99. }

  100. void maichu()
  101. {
  102. kaicang=OrderSend(Symbol(),OP_SELL,shoushu,Bid,3,Bid+500*Point,Bid-Szhiyin*Point,"My order #2",123,0,Magenta);
  103. }
打赏