诚信为本
量力而为
当前位置:首页MetaTrader 4MT4 EAForex Smart S System EA

Forex Smart S System EA

Forex Smart S System EA是结合NonLagMA_v7指标和KD信号开发的MT4智能交易系统。

Forex Smart S System EA源码:

//+------------------------------------------------------------------+
//|                                      Forex Smart S System EA.mq4 |
//|                               Copyright @2008, TradingSytemForex |
//+------------------------------------------------------------------+
#property copyright "Copyright @2008, TradingSytemForex"
#property link "http://www.125808047.com"

#define EAName "Forex Smart S System EA"

extern string S1="---------------- NonLagMA Settings";
extern int Price=0;  //Apply to Price(0-Close;1-Open;2-High;3-Low;4-Median price;5-Typical price;6-Weighted Close) 
extern int Length=12;  //Period of NonLagMA
extern int Displace=0;  //DispLace or Shift 
extern double PctFilter=0;  //Dynamic filter in decimal
extern int Color=1;  //Switch of Color mode (1-color)  
extern int ColorBarBack=-3;  //Bar back for color mode
extern double Deviation=0;  //Up/down deviation        
extern int SoundAlertMode=0;  //Sound Alert switch 
extern string separator1b="---------------- NonLagMA Settings";
extern int StochKP=12;
extern int StochDP=12;
extern int StochSP=5;
extern string S2="---------------- Money Management";
extern double Lots=0.1; //lots
extern bool RiskManagement=false; //money management
extern double RiskPercent=10; //risk in percentage

extern string S3="---------------- Order Management";
extern string S3a="------- Order#1";
extern int StopLoss1=500; //stop loss
extern int TakeProfit1=300; //take profit
extern string S3b="------- Order#2";
extern bool UseSecondOrder=true;
extern int StopLoss2=500; //stop loss
extern int TakeProfit2=0; //take profit
extern string S3c="------- Order#3";
extern bool UseThirdOrder=true;
extern int StopLoss3=500; //stop loss
extern int TakeProfit3=0; //take profit
extern string S3d="------- Pending Order";
extern bool UsePendingOrder=true;
extern int PendingStopLoss=200; //stop loss
extern int PendingTakeProfit=300; //take profit
extern string S3e="------- Extra Order";
extern int TrailingStop=0; //trailing stop
int TrailingStep=1; //margin allowe to the price before to enable the ts
extern int BreakEven=0; //breakeven
extern bool AddPositions=false; //positions cumulated
extern int MaxOrders=100; //maximum number of orders

extern int Slippage=3;
extern int Magic=0; // magic number

extern string S5="---------------- Extras";
extern bool ReverseTheSystem=false; //sell/buy instead of buy/sell

int err=0;int TK1,TK2,TK3,TK14;double Balance=0.0;double maxEquity;double minEquity;double CECount;double CEProc;double CEBuy;double CESell;
int numbuyord,numsellord;int numbuystop;int numsellstop;
bool cg = false;
//start function
void OnTick()
{
int SL1=StopLoss1;int TP1=TakeProfit1;int SL2=StopLoss2;int TP2=TakeProfit2;
int SL3=StopLoss3;int TP3=TakeProfit3;int SL4=PendingStopLoss;int TP4=PendingTakeProfit;
double SLI1=0,TPI1=0,SLI2=0,TPI2=0,SLI3=0,TPI3=0,SLI4=0,TPI4=0;
TK1=0;TK2=0;TK3=0;int TK4=0;int j=0,limit=1;double BV=0,SV=0;
for(int i=1;i<=limit;i++){

numbuyord=0;numsellord=0;numbuystop=0;numsellstop=0;
for(int k=0;k<OrdersTotal();k++){cg = OrderSelect(k,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol()&&(OrderMagicNumber()==Magic)&&(OrderType()==OP_BUYSTOP)){numbuystop++;}
if(OrderSymbol()==Symbol()&&(OrderMagicNumber()==Magic)&&(OrderType()==OP_SELLSTOP)){numsellstop++;}
if(OrderSymbol()==Symbol()&&(OrderMagicNumber()==Magic)&&(OrderType()==OP_BUY)){numbuyord++;}
if(OrderSymbol()==Symbol()&&(OrderMagicNumber()==Magic)&&(OrderType()==OP_SELL)){numsellord++;}}

if(numbuyord==0&&numbuystop==1){for(int n=0;n<OrdersTotal();n++){cg = OrderSelect(n,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol()&&(OrderMagicNumber()==Magic)&&(OrderType()==OP_BUYSTOP)){cg = OrderDelete(OrderTicket());return;}}}
if(numsellord==0&&numsellstop==1){for(int o=0;o<OrdersTotal();o++){cg = OrderSelect(o,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol()&&(OrderMagicNumber()==Magic)&&(OrderType()==OP_SELLSTOP)){cg = OrderDelete(OrderTicket());return;}}}

double NLM1a=iCustom(Symbol(),0,"NonLagMA_v7",Price,Length,Displace,PctFilter,Color,ColorBarBack,Deviation,SoundAlertMode,2,i+1);
double NLM1=iCustom(Symbol(),0,"NonLagMA_v7",Price,Length,Displace,PctFilter,Color,ColorBarBack,Deviation,SoundAlertMode,2,i);//down
double NLM2=iCustom(Symbol(),0,"NonLagMA_v7",Price,Length,Displace,PctFilter,Color,ColorBarBack,Deviation,SoundAlertMode,2,0);
double NLM3a=iCustom(Symbol(),0,"NonLagMA_v7",Price,Length,Displace,PctFilter,Color,ColorBarBack,Deviation,SoundAlertMode,0,i+1);
double NLM3=iCustom(Symbol(),0,"NonLagMA_v7",Price,Length,Displace,PctFilter,Color,ColorBarBack,Deviation,SoundAlertMode,0,i);//mid
double NLM4=iCustom(Symbol(),0,"NonLagMA_v7",Price,Length,Displace,PctFilter,Color,ColorBarBack,Deviation,SoundAlertMode,0,0);
double NLM5a=iCustom(Symbol(),0,"NonLagMA_v7",Price,Length,Displace,PctFilter,Color,ColorBarBack,Deviation,SoundAlertMode,1,i+1);
double NLM5=iCustom(Symbol(),0,"NonLagMA_v7",Price,Length,Displace,PctFilter,Color,ColorBarBack,Deviation,SoundAlertMode,1,i);//up
double NLM6=iCustom(Symbol(),0,"NonLagMA_v7",Price,Length,Displace,PctFilter,Color,ColorBarBack,Deviation,SoundAlertMode,1,0);

double STO1=iStochastic(NULL,0,StochKP,StochDP,StochSP,MODE_LWMA,0,MODE_MAIN,i+1);
double STO2=iStochastic(NULL,0,StochKP,StochDP,StochSP,MODE_LWMA,0,MODE_SIGNAL,i+1);
double STO3=iStochastic(NULL,0,StochKP,StochDP,StochSP,MODE_LWMA,0,MODE_MAIN,i);
double STO4=iStochastic(NULL,0,StochKP,StochDP,StochSP,MODE_LWMA,0,MODE_SIGNAL,i);

string BUY="false";string SELL="false";
if(
(!(NLM5a!=EMPTY_VALUE&&NLM5!=EMPTY_VALUE&&NLM3a!=NLM5)&&NLM5!=EMPTY_VALUE&&NLM6!=EMPTY_VALUE&&NLM3!=NLM6)&&
(STO2>STO1&&STO4<STO3)
)BUY="true";
if(
(!(NLM1a!=EMPTY_VALUE&&NLM1!=EMPTY_VALUE&&NLM3a!=NLM1)&&NLM1!=EMPTY_VALUE&&NLM2!=EMPTY_VALUE&&NLM3!=NLM2)&&
(STO2<STO1&&STO4>STO3)
)SELL="true";

if(
BUY=="true"){if(ReverseTheSystem)SV=1;else BV=1;break;}
if(
SELL=="true"){if(ReverseTheSystem)BV=1;else SV=1;break;}}

bool MM=RiskManagement;
if(MM){if(RiskPercent<0.1||RiskPercent>100){Comment("Invalid Risk Value.");return;}
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;}

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;

if(SV>0){OS=1;OB=0;}if(BV>0){OB=1;OS=0;}

if((SV>0)
){CB=1;}
if((BV>0)
){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,Slippage,Red);}}
if(OrderType()==OP_SELL&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0)){if(CS==1){cg = OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);}}
if(OrderType()==OP_BUYSTOP&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0)){if(CB==1){cg = OrderDelete(OrderTicket());}}
if(OrderType()==OP_SELLSTOP&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0)){if(CS==1){cg = OrderDelete(OrderTicket());}}}

if((AddP()&&AddPositions&&OP<=MaxOrders)||(OP==0&&!AddPositions)){
if(OS==1){

if(TP1==0)TPI1=0;else TPI1=Bid-TP1*Point;if(SL1==0)SLI1=0;else SLI1=Bid+SL1*Point;
TK1=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SLI1,TPI1,EAName,Magic,0,Red);
if(TP2==0)TPI2=0;else TPI2=Bid-TP2*Point;if(SL2==0)SLI2=0;else SLI2=Bid+SL2*Point;
if(UseSecondOrder)TK2=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SLI2,TPI2,EAName,Magic,0,Red);
if(TP3==0)TPI3=0;else TPI3=Bid-TP3*Point;if(SL3==0)SLI3=0;else SLI3=Bid+SL3*Point;
if(UseThirdOrder)TK3=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SLI3,TPI3,EAName,Magic,0,Red);
if(TP4==0)TPI4=0;else TPI4=TPI1-TP4*Point;if(SL4==0)SLI4=0;else SLI4=TPI1+SL4*Point;
if(UsePendingOrder)TK4=OrderSend(Symbol(),OP_SELLSTOP,Lots,TPI1,Slippage,SLI4,TPI4,EAName,Magic,0,Red);

OS=0;}	
if(OB==1){

if(TP1==0)TPI1=0;else TPI1=Ask+TP1*Point;if(SL1==0)SLI1=0;else SLI1=Ask-SL1*Point;
TK1=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SLI1,TPI1,EAName,Magic,0,Lime);
if(TP2==0)TPI2=0;else TPI2=Ask+TP2*Point;if(SL2==0)SLI2=0;else SLI2=Ask-SL2*Point;
if(UseSecondOrder)TK2=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SLI2,TPI2,EAName,Magic,0,Lime);
if(TP3==0)TPI3=0;else TPI3=Ask+TP3*Point;if(SL3==0)SLI3=0;else SLI3=Ask-SL3*Point;
if(UseThirdOrder)TK3=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SLI3,TPI3,EAName,Magic,0,Lime);
if(TP4==0)TPI4=0;else TPI4=TPI1+TP4*Point;if(SL4==0)SLI4=0;else SLI4=TPI1-SL4*Point;
if(UsePendingOrder)TK4=OrderSend(Symbol(),OP_BUYSTOP,Lots,TPI1,Slippage,SLI4,TPI4,EAName,Magic,0,Lime);

OB=0;return;}}
for(j=0;j<OrdersTotal();j++){if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)){if(OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0)){TrP();}}}

if(TK1<0&&TK2<0&&TK3<0&&TK4<0){if (GetLastError()==134){err=1;Print("NOT ENOGUGHT MONEY!!");}return;}

return;}


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);}
版权所有转载请注明标题及链接:峰汇在线 » Forex Smart S System EA
上一篇:
下一篇:
分享到: 更多 (0)