诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4 EA > 正文

根据Renko_v1指标信号开发的EA Renko v1 Expert Advisor.mq4

Renko v1 Expert Advisor自动交易系统是根据Renko_v1指标的信号在进行交易。

源码:

//+------------------------------------------------------------------+
//|                                      Renko v1 Expert Advisor.mq4 |
//|                               Copyright @2008, TradingSytemForex |
//+------------------------------------------------------------------+
#property copyright "Copyright @2008, TradingSytemForex"
#property link "http://www.125808047.com"

#define EAName "Renko v1 Expert Advisor"

extern string separator1="---------------- Entry Settings";
extern int PeriodATR=10;
extern double Katr=1.00;

extern string separator2="---------------- Money Management";
extern double Lots=0.1; 
extern bool RiskManagement=false; 
extern double RiskPercent=10; 
extern bool Martingale=false;
extern double Multiplier=1.5; 
extern double MinProfit=0; 
extern bool UseBasketOptions=false; 
extern int BasketProfit=1000; 
extern int BasketLoss=9999; 

extern string separator3="---------------- Order Management";
extern int StopLoss=0; 
extern int TakeProfit=0; 
extern int TrailingStop=0; 
extern int TrailingStep=1;
extern int BreakEven=0; 
extern bool AddPositions=false; 
extern int MaxOrders=100; 
extern bool UseHiddenSL=false; 
extern int HiddenSL=5;
extern bool UseHiddenTP=false; 
extern int HiddenTP=10;
extern int Magic=0;
extern int Slippage=3;

extern string separator4="---------------- Filters";
extern bool MAFilter=false; 
extern int MAPeriod=20;
extern int MAMethod=1;
extern int MAPrice=0;
extern bool TradeOnSunday=true;
extern bool MondayToThursdayTimeFilter=false;
extern int MondayToThursdayStartHour=8;
extern int MondayToThursdayEndHour=17;
extern bool FridayTimeFilter=false;
extern int FridayStartHour=8;
extern int FridayEndHour=14;

extern string separator5="---------------- Extras";
extern bool ReverseTheSystem=false;

int Slip=3;
int err=0;
int TK;
static int TL=0;
double Balance=0.0;
double maxEquity;
double minEquity;
double CECount;
double CEProc;
double CEBuy;
double CESell;
bool cg = false;

int OnInit()
{  
Comment("www.125808047.com");
return(INIT_SUCCEEDED);
}

void OnTick()
{
int j=0,
limit=1;
double BV=0,SV=0;BV=0;SV=0;
if(CntO(OP_BUY,Magic)>0)TL=1;if(CntO(OP_SELL,Magic)>0)TL=-1;
for(int i=1;i<=limit;i++)
{
if ((TradeOnSunday==false&&DayOfWeek()==0)||(MondayToThursdayTimeFilter&&DayOfWeek()>=1&&DayOfWeek()<=4&&!(Hour()>=MondayToThursdayStartHour&&Hour()<=MondayToThursdayEndHour))||
(FridayTimeFilter&&DayOfWeek()==5&&!(Hour()>=FridayStartHour&&Hour()<=FridayEndHour))){CloseEverything();}

//Basket profit or loss
double CurrentProfit=0;double CurrentBasket=0;CurrentBasket=AccountEquity()-AccountBalance();
if(UseBasketOptions&&CurrentBasket>maxEquity)maxEquity=CurrentBasket;if(UseBasketOptions&&CurrentBasket<minEquity) minEquity=CurrentBasket;
if((UseBasketOptions&&CurrentBasket>=BasketProfit)||(CurrentBasket<=(BasketLoss*(-1)))){CloseEverything();CECount++;}

//ma filter
double MAF=iMA(Symbol(),0,MAPeriod,0,MAMethod,MAPrice,i);string MAFIB="false";string MAFIS="false";
if((MAFilter==false)||(MAFilter&&Bid>MAF))MAFIB="true";if((MAFilter==false)||(MAFilter&&Ask<MAF))MAFIS="true";

//main signal
double REN1=iCustom(Symbol(),0,"Renko_v1",PeriodATR,Katr,0,i+1);
double REN2=iCustom(Symbol(),0,"Renko_v1",PeriodATR,Katr,0,i);
string SBUY="false";string SSEL="false";
if(REN2>REN1)SBUY="true";if(REN2<REN1)SSEL="true";

//entry conditions
if(MAFIB=="true"&&SBUY=="true"){if(ReverseTheSystem)SV=1;else BV=1;break;}
if(MAFIS=="true"&&SSEL=="true"){if(ReverseTheSystem)BV=1;else SV=1;break;}}

//risk management
bool MM=RiskManagement;
if(MM){if(RiskPercent<0.1||RiskPercent>100){Comment("Invalid Risk Value.");}
else{Lots=MathFloor((AccountFreeMargin()*AccountLeverage()*RiskPercent*Point*100)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*
MarketInfo(Symbol(),MODE_MINLOT)))*MarketInfo(Symbol(),MODE_MINLOT);}}
if(MM==false){Lots=Lots;}

//martingale
if(Balance!=0.0&&Martingale==True){if(Balance>AccountBalance())Lots=Multiplier*Lots;else if((Balance+MinProfit)<AccountBalance())Lots=Lots/Multiplier;
else if((Balance+MinProfit)>=AccountBalance()&&Balance<=AccountBalance())Lots=Lots;}Balance=AccountBalance();if(Lots<0.01)Lots=0.01;if(Lots>100)Lots=100;

//positions initialization
int cnt=0,OP=0,OS=0,OB=0,CS=0,CB=0;OP=0;for(cnt=0;cnt<OrdersTotal();cnt++){ cg = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if((OrderType()==OP_SELL||OrderType()==OP_BUY)&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0))OP=OP+1;}
if(OP>=1){OS=0; OB=0;}OB=0;OS=0;CB=0;CS=0;int SL=StopLoss;int TP=TakeProfit;

//entry conditions verification
if(SV>0){OS=1;OB=0;}if(BV>0){OB=1;OS=0;}

//conditions to close position
if((SV>0)||(UseHiddenSL&&(OrderOpenPrice()-Bid)/Point>=HiddenSL)||(UseHiddenTP&&(Ask-OrderOpenPrice())/Point>=HiddenTP)){if(ReverseTheSystem)CS=1;else CB=1;}
if((BV>0)||(UseHiddenSL&&(Ask-OrderOpenPrice())/Point>=HiddenSL)||(UseHiddenTP&&(OrderOpenPrice()-Bid)/Point>=HiddenTP)){if(ReverseTheSystem)CB=1;else CS=1;}
for(cnt=0;cnt<OrdersTotal();cnt++){ cg = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0)){if(CB==1){ cg = OrderClose(OrderTicket(),OrderLots(),Bid,Slip,Red);}}
if(OrderType()==OP_SELL&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0)){if(CS==1){ cg = OrderClose(OrderTicket(),OrderLots(),Ask,Slip,Red);}}}
double SLI=0,TPI=0; TK=0;

//open position
if((AddP()&&AddPositions&&OP<=MaxOrders)||(OP==0&&!AddPositions)){
if(OS==1){if(TP==0)TPI=0;else TPI=Bid-TP*Point;if(SL==0)SLI=0;else SLI=Bid+SL*Point;
TK=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slip,SLI,TPI,EAName,Magic,0,Red);OS=0;}	
if(OB==1){if(TP==0)TPI=0;else TPI=Ask+TP*Point;if(SL==0)SLI=0;else SLI=Ask-SL*Point;
TK=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slip,SLI,TPI,EAName,Magic,0,Lime);OB=0;}}
for(j=0;j<OrdersTotal();j++){if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)){if(OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0)){TrP();}}}}

int CntO(int Type,int Magic_1)
{int _CntO;_CntO=0;
for(int j=0;j<OrdersTotal();j++)
{
if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol())
{
if(OrderType()==Type &&(OrderMagicNumber()==Magic_1 ||Magic_1==0))
_CntO++;
}
}return(_CntO);
}

int CloseEverything(){double myAsk;double myBid;int myTkt;double myLot;int myTyp;int i;bool result = false;
for(i=OrdersTotal();i>=0;i--){ cg = OrderSelect(i,SELECT_BY_POS);myAsk=MarketInfo(OrderSymbol(),MODE_ASK);            
myBid=MarketInfo(OrderSymbol(),MODE_BID);myTkt=OrderTicket();myLot=OrderLots();myTyp=OrderType();
switch(myTyp){case OP_BUY:result=OrderClose(myTkt,myLot,myBid,Slippage,Red);CEBuy++;break;
case OP_SELL:result=OrderClose(myTkt,myLot,myAsk,Slippage,Red);CESell++;break;
case OP_BUYLIMIT:case OP_BUYSTOP:case OP_SELLLIMIT:case OP_SELLSTOP:result=OrderDelete(OrderTicket());}
if(result == false){Alert("Order",myTkt,"failed to close. Error:",GetLastError());
Print("Order",myTkt,"failed to close. Error:",GetLastError());Sleep(3000);}Sleep(1000);CEProc++;}return(0);}

void TrP(){int BE=BreakEven;int TS=TrailingStop;double pb,pa,pp;pp=MarketInfo(OrderSymbol(),MODE_POINT);if(OrderType()==OP_BUY){pb=MarketInfo(OrderSymbol(),MODE_BID);if(BE>0){
if((pb-OrderOpenPrice())>BE*pp){if((OrderStopLoss()-OrderOpenPrice())<0){ModSL(OrderOpenPrice()+0*pp);}}}if(TS>0){if((pb-OrderOpenPrice())>TS*pp){
if(OrderStopLoss()<pb-(TS+TrailingStep-1)*pp){ModSL(pb-TS*pp);return;}}}}if(OrderType()==OP_SELL){pa=MarketInfo(OrderSymbol(),MODE_ASK);
if(BE>0){if((OrderOpenPrice()-pa)>BE*pp){if((OrderOpenPrice()-OrderStopLoss())<0){ModSL(OrderOpenPrice()-0*pp);}}}if(TS>0){if(OrderOpenPrice()-pa>TS*pp){
if(OrderStopLoss()>pa+(TS+TrailingStep-1)*pp||OrderStopLoss()==0){ModSL(pa+TS*pp);return;}}}}}

void ModSL(double ldSL){bool fm;fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSL,OrderTakeProfit(),0,CLR_NONE);}

bool AddP()
{
int _num=0; int _ot=0;
for (int j=0;j<OrdersTotal();j++)
{
if(OrderSelect(j,SELECT_BY_POS)==true && OrderSymbol()==Symbol()&&OrderType()<3&&((OrderMagicNumber()==Magic)||Magic==0))
{	
_num++;
if(OrderOpenTime()>_ot) _ot=OrderOpenTime();
}
}
if(_num==0) return(true);
if(_num>0 && ((Time[0]-_ot))>0) return(true);else return(false);

if(TK<0){if (GetLastError()==134){err=1;Print("NOT ENOGUGHT MONEY!!");}return (-1);}
return (0);}
打赏
版权所有转载请注明标题及链接:峰汇在线 » 根据Renko_v1指标信号开发的EA Renko v1 Expert Advisor.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏