我自己编程的一个平衡止损加移动止损脚本,总报错请大大帮忙看看
//+------------------------------------------------------------------+ //| EMA保本追踪止损程序.mq4 | //| Copyright 2015, metaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, metaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict //---- input parameters extern double 平衡止损增加点数=10; extern double 追踪止损=1; extern double Magic=0; extern string 参数说明="ZHUCHAOJIAN"; extern double MAPeriod=20; //指数均线周期 extern double CloseSpred = 200; //盈亏平衡后止损离均线的点数 int start() { //---- //追踪止损 _MoveStop(Magic, 追踪止损); //设置止损 _StopLoss(Magic,平衡止损增加点数); //---- return(0); } //+------------------------------------------------------------------+ //| _MoveStop 移动止损函数 function | //+------------------------------------------------------------------+ int _MoveStop(int MAGIC, int MOVE)//_MoveStop(MAGIC, MOVE); { //---- if (MOVE<=0) return(0); double MoveStopPrice; int Ma=iMA(NULL,5,MAPeriod,0,MODE_EMA,PRICE_CLOSE,1); for ( int z = OrdersTotal() - 1; z >= 0; z -- ) { if ( !OrderSelect( z, SELECT_BY_POS ) ) { Print("OrderSelect(", z, ",SELECT_BY_POS) - Error #",GetLastError() ); continue; } if (OrderSymbol()!=Symbol())continue; if (OrderMagicNumber() != MAGIC )continue; switch (OrderType()) { case OP_BUY : { MoveStopPrice=NormalizeDouble(Ma-CloseSpred*Point,Digits); if (MoveStopPrice>OrderStopLoss() && OrderOpenPrice()<=OrderStopLoss()) { if(!OrderModify(OrderTicket(),OrderOpenPrice(),MoveStopPrice,OrderTakeProfit(),OrderExpiration())) { alert("MoveStop_OrderModify Error #",GetLastError()); return(-1); } } continue; } case OP_SELL: { MoveStopPrice=NormalizeDouble(Ma+CloseSpred*Point,Digits); if (MoveStopPrice<OrderStopLoss() && OrderOpenPrice()>=OrderStopLoss()) { if(!OrderModify(OrderTicket(),OrderOpenPrice(),MoveStopPrice,OrderTakeProfit(),OrderExpiration())) { alert("MoveStop_OrderModify Error #",GetLastError()); return(-1); } } continue; } default: continue; } } //---- return(0); } //+------------------------------------------------------------------+ //| _MoveStop 移动止损函数 function | //+------------------------------------------------------------------+ int _StopLoss(int MAGIC, int SL)//_MoveStop(MAGIC, MOVE); { //---- if (SL<=0) return(0); double StopLoss; for ( int z = OrdersTotal() - 1; z >= 0; z -- ) { if ( !OrderSelect( z, SELECT_BY_POS ) ) { Print("OrderSelect(", z, ",SELECT_BY_POS) - Error #",GetLastError()); continue; } if (OrderSymbol()!=Symbol())continue; if (OrderMagicNumber() != MAGIC )continue; switch (OrderType()) { case OP_BUY : { StopLoss=NormalizeDouble(OrderOpenPrice()+SL*Point,Digits); if (Ask-OrderOpenPrice()>OrderOpenPrice()-OrderStopLoss() && OrderOpenPrice()>OrderStopLoss()) { if(!OrderModify(OrderTicket(),OrderOpenPrice(),StopLoss,OrderTakeProfit(),OrderExpiration())) { alert("StopLoss_OrderModify Error #",GetLastError()); } } continue; } case OP_SELL: { StopLoss=NormalizeDouble(OrderOpenPrice()-SL*Point,Digits); if (OrderOpenPrice()-Bid>OrderStopLoss()-OrderOpenPrice() && OrderOpenPrice()<OrderStopLoss()) { if(!OrderModify(OrderTicket(),OrderOpenPrice(),StopLoss,OrderTakeProfit(),OrderExpiration())) { alert("StopLoss_OrderModify Error #",GetLastError()); } } continue; } default: continue; } } //---- return(0); } //+------------------------------------------------------------------+ |
打赏
最新创建圈子
- 新闻EA运行效果图圈 2019-05-05
圈主:admin 帖子:1