本帖最后由 krishya 于 2020-3-7 10:13 编辑
#property copyright "Copyright ?2020, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
extern double Lots = 0.1;
extern int Slippage = 3;
extern int MagicNumber = 999999;
extern int Boll周期 = 20;
extern int Boll偏差 = 2;
bool OrderOpen = false;
int OrderTime;
int Ticket;
int HoldingOrderType;
double MaxBid = 0;
double MinAsk = 0;
double MovePoint = 0;
double BollUpper1;
double BollLower1;
double BollMiddle1;
double BollUpper2;
double BollLower2;
double BollMiddle2;
double BollUpper3;
double BollLower3;
double BollMiddle3;
int init()
{
return(0);
}
int deinit()
{
return(0);
}
int start()
{
//----
BollUpper1 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_UPPER , 1);
BollLower1 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_LOWER , 1);
BollMiddle1 = (BollUpper1 + BollLower1)/2;
BollUpper2 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_UPPER , 2);
BollLower2 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_LOWER , 2);
BollMiddle2 = (BollUpper2 + BollLower2)/2;
BollUpper3 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_UPPER , 3);
BollLower3 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_LOWER , 3);
BollMiddle3 = (BollUpper3 + BollLower3)/2;
if (Time[0] != OrderTime) OrderOpen = false; //每根k线只能下单一次
if (Bid > MaxBid) MaxBid = Bid;
if (Ask < MinAsk) MinAsk = Ask;
if (HoldingOrderType == OP_BUY){
if (OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES) == true){
if (MaxBid - OrderOpenPrice() < 15 * Point) MovePoint = 8 * Point ; // 盈利小于15刀,定义止损止盈为回落8刀
if (MaxBid - OrderOpenPrice() >= 15 * Point)MovePoint = (MaxBid - OrderOpenPrice()) * 0.3 * Point ; // 盈利大于15刀,定义止损止盈为回落盈利的30%
}
if ((MaxBid - Bid >MovePoint) || (Close[2]>BollMiddle2 && Close[1]<BollMiddle1) || OrderProfit() > 10.0)CloseAllBuy();
}
if (HoldingOrderType == OP_SELL){
if (OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES) == true){
if (OrderOpenPrice() - MinAsk < 15 * Point) MovePoint = 8 * Point ;
if (OrderOpenPrice() - MinAsk >= 15 * Point)MovePoint = (OrderOpenPrice() - MinAsk) * 0.3 * Point ;
}
if ((Ask - MinAsk > MovePoint) || (Close[2]<BollMiddle2 && Close[1]>BollMiddle1) || OrderProfit() > 10.0) CloseAllSell();
}
if(Boll(OP_BUY) == true && OrderOpen == false) // 上轨 中轨 初次向上 下轨向下 买单
{
Ticket=OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask, Digits),Slippage,0,0,"dummy-buy",MagicNumber,0,Red);
if(Ticket>0)
{
if (OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES))
{
OrderOpen = true;
OrderTime = Time[0];
MaxBid = Bid;
HoldingOrderType = OrderType();
Print("Pivot dummy-buy order opened : ",OrderOpenPrice());
}
else
{
Print("Error opening Pivot dummy-buy order : ",GetLastError());
return(0);
}
}
}
else if(Boll(OP_SELL) == true && OrderOpen == false) // 上轨 中轨 初次向下 下轨向上 卖单
{
Ticket=OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid, Digits),Slippage,0,0,"dummy-sell",MagicNumber,0,Blue);
if(Ticket>0)
{
if (OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES))
{
OrderOpen = true;
OrderTime = Time[0];
MinAsk = Ask;
HoldingOrderType = OrderType();
Print("Pivot dummy-sell order opened : ",OrderOpenPrice());
}
else
{
Print("Error opening Pivot dummy-sell order : ",GetLastError());
return(0);
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
全部源码在附件下载里
|