韬客社区 收藏
蓝山886 25-07-11 17:32
1楼
[求助] 求个订单一键平保指标

手速慢,不会编程,那位好心人有一键平保指标可以分享一下吗?

梅花红
2楼
25-07-11 23:50 回复

jiaoben


#include <stderror.mqh>

#include <stdlib.mqh>


//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

double  TakeProfit;

double StopLoss;

color clr = Blue;


void OnStart()

 {

//---

  if(Digits==5 ||Digits==3)

  {

     TakeProfit*=10;

     StopLoss*=10;

  }

  if(!IsTradeAllowed()){Alert("脚本检测到你没有允许自动交易,请先设置允许自动交易,再重新加载脚本");

      return;

  }

  if(OrdersTotal()==0)  

      return;

  double sl;

     

     for(int i=0;i<OrdersTotal();i++)  {

       if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){

      // if (OrderSymbol()==Symbol()) {

      //设置止损,和开仓价格

       double stp=NormalizeDouble(OrderStopLoss(),Digits);  

       double OpenPrice = NormalizeDouble(OrderOpenPrice(),Digits);

       if(OrderType()==OP_BUY)

            {

              if( stp == 0 && (Bid - OpenPrice) > 0 )sl = OpenPrice;else sl =OrderStopLoss();  

                 sl=NormalizeDouble(sl,Digits); clr=Blue;            

               if(!OrderModify(OrderTicket(),OrderOpenPrice(),sl,0,0,clr))

               Print("OrderModify Error: " ,ErrorDescription(GetLastError()));                                  

             }

       else if(OrderType()==OP_SELL)

            {

               if( stp == 0 && (OpenPrice-Ask) > 0 ) sl=OpenPrice;else sl=OrderStopLoss();

                  sl=NormalizeDouble(sl,Digits); clr=Blue;

               if(!OrderModify(OrderTicket(),OrderOpenPrice(),sl,0,0,clr))

                Print("OrderModify Error: " ,ErrorDescription(GetLastError()));

              }

         //}

         }//if OrderSelect

       }//for    

 }

//+------------------------------------------------------------------+


1神无月1
3楼
25-07-12 03:33 回复

AI这代码写得人不人鬼不鬼的

蓝山886
4楼
25-07-12 16:29 回复

ai写的不行啊 运行一下几十处错误