//+------------------------------------------------------------------+ //| 3!! .mq4 | //| | //+------------------------------------------------------------------+ #property copyright " " #property link "htTakeProfits:// " #property show_inputs #include <stdlib.mqh> extern double Risk = 0.02; input double RR = 2;//盈亏比 //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ void OnStart() { //---- RefreshRates(); double MinLot = MarketInfo(Symbol(), MODE_MINLOT); double MaxLot = MarketInfo(Symbol(), MODE_MAXLOT); double Step = MarketInfo(Symbol(), MODE_LOTSTEP); double StopLoss = WindowPriceOnDropped(); double MoneyRisk = AccountFreeMargin() * Risk; double TickValue = MarketInfo(Symbol(), MODE_TICKVALUE); double PointLoss; int cmd; double price; double TakeProfit=0.0;//takeprofit price if(Ask>StopLoss) { //Open Long PointLoss = (Ask - StopLoss) / Point; cmd = OP_BUY; price = Ask; if(RR>0) { TakeProfit = Ask + RR*PointLoss*Point; } } else { //Open Short PointLoss = (StopLoss - Bid) / Point; cmd = OP_SELL; price = Bid; if(RR>0) { TakeProfit =Bid- RR*PointLoss*Point; } } printf("PointLoss = %.f, StopLoss = %.f, TakeProfit = %.f",PointLoss,StopLoss,TakeProfit); double LotsRough = MoneyRisk / (TickValue * PointLoss); if(LotsRough<MinLot) { printf("Error. You don\'t have enough money! PointLoss = %.f, LotsRough = %.f, MoneyRisk = %.f",PointLoss,LotsRough,MoneyRisk); return; } double Lots = MaxLot; for(double CheckedLot=MinLot; CheckedLot<=MaxLot; CheckedLot+=Step) { if(CheckedLot>LotsRough) { Lots = CheckedLot - Step; break; } } Print("Lots=",Lots); int ticket = OrderSend(Symbol(), cmd, Lots, nd(price), 30, nd(StopLoss), nd(TakeProfit)); if (ticket<0) { printf("Error: ", ErrorDescription(GetLastError())); } //---- return; } //+------------------------------------------------------------------+ double nd(double x) { return NormalizeDouble(x,_Digits); } //+------------------------------------------------------------------+
上面的是大佬
//+------------------------------------------------------------------+
修改内容:增加自动设置止盈,默认止盈是止损的2倍