查看:486回复:3
[MT4-EA]macd怎么加仓
请问macd如何加仓呢?我想写个macd交叉时自动加仓的指标,在我忙的时候可以自己加仓,然后我手动平仓。
问题是我写的这个代码,它会在一瞬间开了所有仓,不会每次MACD交叉加仓。
请问该如何修改,谢谢。
input double TakeProfit =50;
input double Lots =0.1;
input double TrailingStop =30;
input double MACDOpenLevel =3;
input double MACDCloseLevel=2;
input int MATrendPeriod =26;
extern int zq30m=PERIOD_M30;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick(void)
{
double MacdCurrent30M,MacdPrevious30M;
double SignalCurrent30M,SignalPrevious30M;
int ticket,total;
if(Bars<100)
{
Print("bars less than 100");
return;
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return;
}
//--- to simplify the coding and speed up access data are put into internal variables
MacdCurrent30M=iMACD(NULL,zq30m,12,26,9,1,MODE_MAIN,0);
MacdPrevious30M=iMACD(NULL,zq30m,12,26,9,1,MODE_MAIN,1);
SignalCurrent30M=iMACD(NULL,zq30m,12,26,9,1,MODE_SIGNAL,0);
SignalPrevious30M=iMACD(NULL,zq30m,12,26,9,1,MODE_SIGNAL,1);
total=OrdersTotal();
if(total<6)
{
//--- no opened orders identified
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ",AccountFreeMargin());
return;
}
if(MacdCurrent30M>SignalCurrent30M && MacdPrevious30M
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"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;
}
//--- exit from the "no opened orders" block
return;
}
//--- it is important to enter the market correctly, but it is more important to exit it correctly...
//---
}
问题是我写的这个代码,它会在一瞬间开了所有仓,不会每次MACD交叉加仓。
请问该如何修改,谢谢。
input double TakeProfit =50;
input double Lots =0.1;
input double TrailingStop =30;
input double MACDOpenLevel =3;
input double MACDCloseLevel=2;
input int MATrendPeriod =26;
extern int zq30m=PERIOD_M30;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick(void)
{
double MacdCurrent30M,MacdPrevious30M;
double SignalCurrent30M,SignalPrevious30M;
int ticket,total;
if(Bars<100)
{
Print("bars less than 100");
return;
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return;
}
//--- to simplify the coding and speed up access data are put into internal variables
MacdCurrent30M=iMACD(NULL,zq30m,12,26,9,1,MODE_MAIN,0);
MacdPrevious30M=iMACD(NULL,zq30m,12,26,9,1,MODE_MAIN,1);
SignalCurrent30M=iMACD(NULL,zq30m,12,26,9,1,MODE_SIGNAL,0);
SignalPrevious30M=iMACD(NULL,zq30m,12,26,9,1,MODE_SIGNAL,1);
total=OrdersTotal();
if(total<6)
{
//--- no opened orders identified
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ",AccountFreeMargin());
return;
}
if(MacdCurrent30M>SignalCurrent30M && MacdPrevious30M
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"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;
}
//--- exit from the "no opened orders" block
return;
}
//--- it is important to enter the market correctly, but it is more important to exit it correctly...
//---
}
发表于:2016-04-12 13:23只看该作者
2楼
謝謝分享。非常感謝樓主!
韬客社区www.talkfx.co
发表于:2016-07-18 13:49只看该作者
3楼
多谢分享
韬客社区www.talkfx.co
发表于:2016-07-19 13:59只看该作者
4楼
多谢分享
韬客社区www.talkfx.co