哪位好心达人 帮我加一个设置止损 句子 谢啦
mt4吧
全部回复
仅看楼主
level 1
yt77 楼主
//+------------------------------------------------------------------+//| MACD Sample.mq4 |//| Copyright ?2005, MetaQuotes Software Corp. |//| http://www.metaquotes.net/ |//+------------------------------------------------------------------+
extern double TakeProfit = 50;extern double Lots = 0.1;extern double StopLoss = 20;extern double MACDOpenLevel=3;extern double MACDCloseLevel=2;extern double MATrendPeriod=26;
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+int start() { double MacdCurrent, MacdPrevious, SignalCurrent; double SignalPrevious, MaCurrent, MaPrevious; int cnt, ticket, total;// initial data checks// it is important to make sure that the expert works with a normal// chart and the user did not make any mistakes setting external // variables (Lots, StopLoss, TakeProfit, // TrailingStop) in our case, we check TakeProfit// on a chart of less than 100 bars if(Bars<100) { Print("bars less than 100"); return(0); } if(TakeProfit<10) { Print("TakeProfit less than 10"); return(0); // check TakeProfit }// to simplify the coding and speed up access// data are put into internal variables MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1); SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0); SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0); MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);
total=OrdersTotal(); if(total<1) { // no opened orders identified if(AccountFreeMargin()<(1000*Lots)) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return(0); } // check for long position (BUY) possibility if(MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious && MathAbs(MacdCurrent)>(MACDOpenLevel*Point) && MaCurrent>MaPrevious) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"macd sample",16384,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); return(0); } // check for short position (SELL) possibility if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious && MacdCurrent>(MACDOpenLevel*Point) && MaCurrent<MaPrevious) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"macd sample",16384,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else Print("Error opening SELL order : ",GetLastError()); return(0); } return(0); } if (OrderType() == OP_BUY) { if (StopLoss == 0.0 || TakeProfit == 0.0 && StopLoss != 0.0 && TakeProfit != 0.0) OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask - Point * StopLoss, Digits), NormalizeDouble(Ask + Point * TakeProfit, Digits), 0, Green); } if (OrderType() == OP_SELL) { if (StopLoss == 0.0 || TakeProfit == 0.0 && StopLoss != 0.0 && TakeProfit != 0.0) OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid + Point * StopLoss, Digits), NormalizeDouble(Bid - Point * TakeProfit, Digits), 0, Green); } }// the end.
2013年02月23日 14点02分 1
1