具体设置参数按照默认参数,1000美金;如果小于1000美金需要自行调整开仓手数。感兴趣的可以好好去研究一下,这可以通过2001年到现在为止都没有爆仓并盈利的马丁策略源码,你们且用且珍惜。
#########源码部分
extern double StepLens = 160;
extern double ProfitPoints = 150;
double Lots=0.01;
extern double MaxLots = 0.05;
extern double MinLots = 0.01;
extern int nMagicNumber = 198815;
extern int TF = 200;
extern double StopK = 0.618;
extern bool bECN = false;
bool TrailingStop = false;
string comment = "AOEA_";
double SLSpread = 0;
double Fee = 0;
extern double ProfitPoints = 150;
double Lots=0.01;
extern double MaxLots = 0.05;
extern double MinLots = 0.01;
extern int nMagicNumber = 198815;
extern int TF = 200;
extern double StopK = 0.618;
extern bool bECN = false;
bool TrailingStop = false;
string comment = "AOEA_";
double SLSpread = 0;
double Fee = 0;
double NetOrderPrice = 0;
int arrID[255]
;
int arrK[255]
;
int nPos = 0;
int nLayer = 3;
int nDir = 0;//buy = 1, sell = -1, no = 0
double nLots = 0.01;
double LLV, LLV1, HHV, HHV1;
bool bReady = false;
//+------------------------------------------------------------------+
//| Init function |
//+------------------------------------------------------------------+
void init ()
{
int i = 0;
arrK[i]
= 1;
arrK[i + 1]
= 2;
arrK[i]
= 1;
arrK[i + 1]
= 2;
nDir = 0;
RebuildID();
for(i = 2; i < nLayer; i++)
{
arrK[i]
= arrK[i-2]
+ arrK[i-1]
;
arrK[i]
= arrK[i-1]
* 2;
}
if(bECN)
{
SLSpread = 25;
Fee = 3;
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double Sl = 0;
int ticket;
int k;
string str;
int arrID[255]

int arrK[255]

int nPos = 0;
int nLayer = 3;
int nDir = 0;//buy = 1, sell = -1, no = 0
double nLots = 0.01;
double LLV, LLV1, HHV, HHV1;
bool bReady = false;
//+------------------------------------------------------------------+
//| Init function |
//+------------------------------------------------------------------+
void init ()
{
int i = 0;
arrK[i]

arrK[i + 1]

arrK[i]

arrK[i + 1]

nDir = 0;
RebuildID();
for(i = 2; i < nLayer; i++)
{
arrK[i]



arrK[i]


}
if(bECN)
{
SLSpread = 25;
Fee = 3;
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double Sl = 0;
int ticket;
int k;
string str;
if(Bars<100)
{
Print("K线少于100根!");
return(0);
}
if(!bReady)
{
k = OrdersTotal();
nPos = 0;
for(int i=0; i<k; i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==nMagicNumber)
{
if(OrderCloseTime()>0) break;
arrID[nPos]
= OrderTicket();
NetOrderPrice = OrderOpenPrice();
if(OrderType() == OP_BUY) nDir = 1;
else nDir = -1;
Print("n = ",nPos, " nDir = ", nDir, " p = ", NetOrderPrice, " id = ", arrID[nPos]
);
nPos++;
}
}
}
Print("Orders = ", k);
bReady = true;
}
LLV = iCustom(NULL, 0, "HLV", TF, 0, 1);
HHV = iCustom(NULL, 0, "HLV", TF, 1, 1);
LLV1 = iCustom(NULL, PERIOD_H4, "HLV", TF, 0, 1);
HHV1 = iCustom(NULL, PERIOD_H4, "HLV", TF, 1, 1);
{
Print("K线少于100根!");
return(0);
}
if(!bReady)
{
k = OrdersTotal();
nPos = 0;
for(int i=0; i<k; i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==nMagicNumber)
{
if(OrderCloseTime()>0) break;
arrID[nPos]

NetOrderPrice = OrderOpenPrice();
if(OrderType() == OP_BUY) nDir = 1;
else nDir = -1;
Print("n = ",nPos, " nDir = ", nDir, " p = ", NetOrderPrice, " id = ", arrID[nPos]

nPos++;
}
}
}
Print("Orders = ", k);
bReady = true;
}
LLV = iCustom(NULL, 0, "HLV", TF, 0, 1);
HHV = iCustom(NULL, 0, "HLV", TF, 1, 1);
LLV1 = iCustom(NULL, PERIOD_H4, "HLV", TF, 0, 1);
HHV1 = iCustom(NULL, PERIOD_H4, "HLV", TF, 1, 1);
double AT = iAlligator(NULL, PERIOD_H4,13,6,8,3,5,3,MODE_SMA,PRICE_MEDIAN,MODE_GATORTEETH,1);
double AJ = iAlligator(NULL, 0,13,6,8,3,5,3,MODE_SMA,PRICE_MEDIAN,MODE_GATORJAW,1);
double MA = iMA(NULL,PERIOD_H4,60,0,MODE_SMA,PRICE_CLOSE, 1);
double AJ = iAlligator(NULL, 0,13,6,8,3,5,3,MODE_SMA,PRICE_MEDIAN,MODE_GATORJAW,1);
double MA = iMA(NULL,PERIOD_H4,60,0,MODE_SMA,PRICE_CLOSE, 1);
//开单检查
if(nDir == 0) //在没有持仓的情况下才能开新仓
{
// 检查资金
if(AccountFreeMargin()<(1000*Lots))
{
Print("资金不足: ", AccountFreeMargin());
return(0);
}
// 检查开多单的可能性
if(Ask <= LLV - Fee * Point() && Ask > LLV1 + (HHV1 - LLV1)*StopK + SLSpread * Point())
{
Sl = NormalizeDouble(HHV1 - (HHV1 - LLV1)*StopK, Digits);
if(Ask < AT || Ask < MA) Lots = MinLots;
else
{
Lots = MaxLots;
}
str = comment + "BUY_" + Period();
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,10,Sl,0,str,nMagicNumber,0,Blue);
if(ticket>0)
{
NetOrderPrice = Ask;
nPos = 0;
arrID[nPos]
= ticket;
nDir = 1;
}
else Print("first多单发生错误 : ",GetLastError());
return(0);
}
// 检查开空单的可能性
if(Bid>= HHV + Fee * Point() && Bid < HHV1 - (HHV1 - LLV1)*StopK - SLSpread * Point())
{
Sl = NormalizeDouble(LLV1 + (HHV1 - LLV1)*StopK, Digits);
if(Bid > AT || Bid > MA) Lots = MinLots;
else
{
Lots = MaxLots;
}
str = comment + "SELL_" + Period();
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,10,Sl,0,str,nMagicNumber,0,Red);
if(ticket>0)
{
NetOrderPrice = Bid;
nPos = 0;
arrID[nPos]
= ticket;
nDir = -1;
}
else Print("first空单发生错误 : ",GetLastError());
return(0);
}
return(0);
}
else
{
TrailingST();
if(CloseWin())
{
nDir = 0;
nPos = 0;
NetOrderPrice = 0;
}
if(NetOrderPrice != 0)
{
if(AJ > NetOrderPrice+arrK[nPos]
*StepLens*Point && Bid < AJ && nDir == -1)
{
k = nPos + 1;
if(k >= nLayer) return(0);
if(nDir == -1)
{
nLots = NormalizeDouble(arrK[k]
*Lots, 2);
str = comment + "SELL_" + Period();
ticket=OrderSend(Symbol(),OP_SELL,nLots,Bid,10,0,0,str,nMagicNumber,0,Red);
if(ticket>0)
{
NetOrderPrice = Bid+arrK[nPos]
*StepLens*Point;
arrID[k]
= ticket;
nPos = k;
}
else Print("开空单发生错误 : ",GetLastError());
}
return(0);
}
if(AJ < NetOrderPrice-arrK[nPos]
*StepLens*Point && Ask > AJ && nDir == 1)
{
k = nPos + 1;
if(k >= nLayer) return(0);
if(nDir == 1)
{
nLots = NormalizeDouble(arrK[k]
*Lots, 2);
str = comment + "BUY_" + Period();
ticket=OrderSend(Symbol(),OP_BUY,nLots,Ask,10,0,0,str,nMagicNumber,0,Blue);
if(ticket>0)
{
NetOrderPrice = Ask-arrK[nPos]
*StepLens*Point;
arrID[k]
= ticket;
nPos = k;
}
else Print("开多单发生错误 : ",GetLastError());
}
return(0);
}
}
}
return(0);
}
if(nDir == 0) //在没有持仓的情况下才能开新仓
{
// 检查资金
if(AccountFreeMargin()<(1000*Lots))
{
Print("资金不足: ", AccountFreeMargin());
return(0);
}
// 检查开多单的可能性
if(Ask <= LLV - Fee * Point() && Ask > LLV1 + (HHV1 - LLV1)*StopK + SLSpread * Point())
{
Sl = NormalizeDouble(HHV1 - (HHV1 - LLV1)*StopK, Digits);
if(Ask < AT || Ask < MA) Lots = MinLots;
else
{
Lots = MaxLots;
}
str = comment + "BUY_" + Period();
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,10,Sl,0,str,nMagicNumber,0,Blue);
if(ticket>0)
{
NetOrderPrice = Ask;
nPos = 0;
arrID[nPos]

nDir = 1;
}
else Print("first多单发生错误 : ",GetLastError());
return(0);
}
// 检查开空单的可能性
if(Bid>= HHV + Fee * Point() && Bid < HHV1 - (HHV1 - LLV1)*StopK - SLSpread * Point())
{
Sl = NormalizeDouble(LLV1 + (HHV1 - LLV1)*StopK, Digits);
if(Bid > AT || Bid > MA) Lots = MinLots;
else
{
Lots = MaxLots;
}
str = comment + "SELL_" + Period();
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,10,Sl,0,str,nMagicNumber,0,Red);
if(ticket>0)
{
NetOrderPrice = Bid;
nPos = 0;
arrID[nPos]

nDir = -1;
}
else Print("first空单发生错误 : ",GetLastError());
return(0);
}
return(0);
}
else
{
TrailingST();
if(CloseWin())
{
nDir = 0;
nPos = 0;
NetOrderPrice = 0;
}
if(NetOrderPrice != 0)
{
if(AJ > NetOrderPrice+arrK[nPos]

{
k = nPos + 1;
if(k >= nLayer) return(0);
if(nDir == -1)
{
nLots = NormalizeDouble(arrK[k]

str = comment + "SELL_" + Period();
ticket=OrderSend(Symbol(),OP_SELL,nLots,Bid,10,0,0,str,nMagicNumber,0,Red);
if(ticket>0)
{
NetOrderPrice = Bid+arrK[nPos]

arrID[k]

nPos = k;
}
else Print("开空单发生错误 : ",GetLastError());
}
return(0);
}
if(AJ < NetOrderPrice-arrK[nPos]

{
k = nPos + 1;
if(k >= nLayer) return(0);
if(nDir == 1)
{
nLots = NormalizeDouble(arrK[k]

str = comment + "BUY_" + Period();
ticket=OrderSend(Symbol(),OP_BUY,nLots,Ask,10,0,0,str,nMagicNumber,0,Blue);
if(ticket>0)
{
NetOrderPrice = Ask-arrK[nPos]

arrID[k]

nPos = k;
}
else Print("开多单发生错误 : ",GetLastError());
}
return(0);
}
}
}
return(0);
}
bool CloseWin()
{
int i;
double A = Ask;
double B = Bid;
int flag = 0;
{
int i;
double A = Ask;
double B = Bid;
int flag = 0;
if(CalProfit() == 0)
{
return(false);
}
{
return(false);
}
for(i = nPos; i >=0; i--)
{
if(arrID[i]
== -1) continue;
do{
if(OrderSelect(arrID[i]
,SELECT_BY_TICKET,MODE_TRADES))
{
if(OrderType() == OP_SELL && OrderMagicNumber() == nMagicNumber)
{
OrderClose(OrderTicket(),OrderLots(),A,10,Green);
arrID[i]
= -1;
}
if(OrderType() == OP_BUY && OrderMagicNumber() == nMagicNumber)
{
OrderClose(OrderTicket(),OrderLots(),B,10,Violet);
arrID[i]
= -1;
}
}
while (!IsTradeAllowed()) Sleep(1000);
RefreshRates();
}while(arrID[i]
!= -1);
}
RebuildID();
return(true);
}
{
if(arrID[i]

do{
if(OrderSelect(arrID[i]

{
if(OrderType() == OP_SELL && OrderMagicNumber() == nMagicNumber)
{
OrderClose(OrderTicket(),OrderLots(),A,10,Green);
arrID[i]

}
if(OrderType() == OP_BUY && OrderMagicNumber() == nMagicNumber)
{
OrderClose(OrderTicket(),OrderLots(),B,10,Violet);
arrID[i]

}
}
while (!IsTradeAllowed()) Sleep(1000);
RefreshRates();
}while(arrID[i]

}
RebuildID();
return(true);
}
void TrailingST()
{
double Sl = 0;
if(OrderSelect(arrID
,SELECT_BY_TICKET,MODE_TRADES))
{
if(OrderType() == OP_SELL && OrderMagicNumber() == nMagicNumber)
{
Sl = NormalizeDouble(LLV1 + (HHV1 - LLV1)*StopK, Digits);
if(Sl < OrderStopLoss())
{
OrderModify(OrderTicket(), OrderOpenPrice(), Sl, OrderTakeProfit(), 0, Red);
}
}
if(OrderType() == OP_BUY && OrderMagicNumber() == nMagicNumber)
{
Sl = NormalizeDouble(HHV1 - (HHV1 - LLV1)*StopK, Digits);
if(Sl > OrderStopLoss())
{
OrderModify(OrderTicket(), OrderOpenPrice(), Sl, OrderTakeProfit(), 0, Red);
}
}
}
}
{
double Sl = 0;
if(OrderSelect(arrID


{
if(OrderType() == OP_SELL && OrderMagicNumber() == nMagicNumber)
{
Sl = NormalizeDouble(LLV1 + (HHV1 - LLV1)*StopK, Digits);
if(Sl < OrderStopLoss())
{
OrderModify(OrderTicket(), OrderOpenPrice(), Sl, OrderTakeProfit(), 0, Red);
}
}
if(OrderType() == OP_BUY && OrderMagicNumber() == nMagicNumber)
{
Sl = NormalizeDouble(HHV1 - (HHV1 - LLV1)*StopK, Digits);
if(Sl > OrderStopLoss())
{
OrderModify(OrderTicket(), OrderOpenPrice(), Sl, OrderTakeProfit(), 0, Red);
}
}
}
}
int CalProfit()
{
int i;
double dProfit =0;
int flag = 0;
int n = 0;
for(i = 0; i < nLayer; i++)
{
if(arrID[i]
== -1) continue;
{
int i;
double dProfit =0;
int flag = 0;
int n = 0;
for(i = 0; i < nLayer; i++)
{
if(arrID[i]

if(OrderSelect(arrID[i]
,SELECT_BY_TICKET,MODE_TRADES))
{
if(OrderCloseTime() != 0) return(2);
dProfit += OrderProfit() + OrderCommission();
}
}
for(i = OrdersTotal()-1; i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == nMagicNumber)
{
if(OrderTicket() == arrID
)
{
n = nPos + 1;
break;
}
else
{
n++;
}
}
}
}
if(n != nPos +1)
{
flag = 1;
}
double AT = iAlligator(NULL, PERIOD_H4,13,6,8,3,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORTEETH,1);
bool bCon = (Bid > AT && nDir == -1) || (Ask < AT && nDir == 1);

{
if(OrderCloseTime() != 0) return(2);
dProfit += OrderProfit() + OrderCommission();
}
}
for(i = OrdersTotal()-1; i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == nMagicNumber)
{
if(OrderTicket() == arrID


{
n = nPos + 1;
break;
}
else
{
n++;
}
}
}
}
if(n != nPos +1)
{
flag = 1;
}
double AT = iAlligator(NULL, PERIOD_H4,13,6,8,3,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORTEETH,1);
bool bCon = (Bid > AT && nDir == -1) || (Ask < AT && nDir == 1);
if(!bCon && dProfit >= Lots * ProfitPoints)
{
flag = 1;
}
else if(bCon && dProfit >= Lots * ProfitPoints / 3)
{
flag = 1;
}
return(flag);
}
{
flag = 1;
}
else if(bCon && dProfit >= Lots * ProfitPoints / 3)
{
flag = 1;
}
return(flag);
}
void RebuildID()
{
for(int i = 0; i < nLayer; i++)
{
{
arrID[i]

}
}
}
风险提示:以上内容仅代表作者或嘉宾的观点,不代表 FOLLOWME 的任何观点及立场,且不代表 FOLLOWME 同意其说法或描述,也不构成任何投资建议。对于访问者根据 FOLLOWME 社区提供的信息所做出的一切行为,除非另有明确的书面承诺文件,否则本社区不承担任何形式的责任。
FOLLOWME 交易社区网址: www.followme.ceo
喜欢的话,赞赏支持一下
加载失败()