//+------------------------------------------------------------------+ //| Ten Wave Stoch Pop Laguerre EA.mq4 | //| Copyright © 2008, TradingSytemForex | //| http://www.tradingsystemforex.com | //| modify by przem81621@o2.pl | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, TradingSytemForex" #property link "http://www.tradingsystemforex.com" #define OrSt "Ten Wave Stoch Pop Laguerre EA " extern string STO="---------------- Stochs"; extern double First_Stoch_KP=4; extern double Stoch_PERIOD=2; extern double Stoch_Slowing=2; extern double Hig_l=80; extern double Lo_l =20; extern int quantity=10; extern bool usestochopen=true; extern string LRSI="---------------- Laguerre RSI"; extern double gamma=0.7; extern bool UseLagforOpen =true; extern double LagBuySig = 55, LagSellSig = 45; extern string Slop="---------------- Slopy for close"; extern bool openslopy=true; extern int period=8; extern int method=0; // MODE_SMA 0,1,2,3 extern int price=0; // PRICE_CLOSE 0,1 extern bool closeonslopy=true; extern int periodcl=8; extern int methodcl=0; // MODE_SMA 0,1,2,3 extern int pricecl=0; // PRICE_CLOSE 0,1 extern double distanceslope=200; extern string SFC="---------------- Stoch for close"; extern bool closeoncross=true; extern int KPeriodclose=8; extern int DPeriodclose=3; extern int Slowingclose=3; extern int MAStoch=0; //0-simple;1-exponential;2-smoothed;3-linear weight extern int PriceStoch=0; //1-close/close ; 0-low/High extern double Distanceclose=5; extern string timeframe="5-5min,15-15min,30-30min,60-1h,240-4h,"; extern double Timeframe=5; // 5-5min,15-15min,30-30min,60-1h,240-4h, extern bool closestochonthesametimeframe=true; // if false - trade will be close by cross stoch on the former timeframe // extern bool closeonmaxstoch=true; extern double Distanceclosemax=5; extern bool usesleep=true; extern double stopacttime=1; // ea will stop act by time= stopacttime * period timeframe ex. 1*4h or 3*30min extern bool stopopen_1=true; extern bool stopopen_2=true; //extern bool stopopen_3=true; //extern bool stopopen_4=true; //extern double delta=5; extern string MM_Parameters = "---------- Money Management"; extern double Lots = 0.01; extern bool MM = true, //Use Money Management or not AccountIsMicro = true; //Use Micro-Account or not extern int Risk = 5; //10% extern string TSTB="---------------- TP SL TS BE"; bool RealSL_Enabled=false; int RealSL=5; //stop loss under 15 pīps bool RealTP_Enabled=false; int RealTP=10; //take profit under 10 pīps extern int SL=0; //stop loss extern int TP=0; //take profit - better no to use extern int TS=0; //trailing stop extern int TS_Step=1; //trailing stop step extern int BE=0; //breakeven extern string EXT="---------------- Extras"; extern bool Reverse=false; extern bool Add_Positions=false; //positions cumulated extern int MaxOrders=100; //maximum number of orders extern int Magic=0; extern string Safety="Equity Baskett"; extern bool UseMargincut = true; extern double Margincutoff = 0.50; // Expert will stop trading if equity decreases to 0.5 * balance . extern bool Usetarget = true; extern bool Usebasket = true; extern double TargetEquity =1000000; //value of win extern double BasketLoss =10000; //value of loses string TicketComment = "Ten Wave Stoch Pop Laguerre EA "; extern int MaxTradePerBar=1; datetime Time0;int TradePerBar=0;int BarCount=-1; int init(){Time0=Time[0];return(0); TicketComment = StringConcatenate(TicketComment, "-", Symbol(), "-", Period());} int deinit(){return(0);} int Slip=3; static int TL=0; // expert start function int start(){ double Bal=AccountBalance(); if((UseMargincut&&AccountFreeMargin()< Bal*Margincutoff) ||(Usetarget&&AccountEquity()>=TargetEquity) || (Usebasket&&AccountEquity()<=(AccountBalance()-BasketLoss) )) { Comment( "\nSTOP TRADING....", "\nAccountEquity = ", AccountEquity(), "\nTarget Balance or Target Loss or FreeMargin hit !!!!!"); closeall(); return(0); } int j=0,limit=1; double BV=0,SV=0; double STOM1,STOM2,STOM3,STOM4,STOM5,STOM6,STOM7,STOM8,STOM9,STOM10,STOM11,czas,High_l,Low_l; int x; if(CntO(OP_BUY,Magic)>0) TL=1;if(CntO(OP_SELL,Magic)>0) TL=-1;for(int i=1;i<=limit;i++){ //stoch for open -base condition STOM1 =iStochastic(NULL,0,First_Stoch_KP,Stoch_PERIOD,Stoch_Slowing,MODE_SMA,0,MODE_MAIN,i); STOM2 =iStochastic(NULL,0,First_Stoch_KP+1,Stoch_PERIOD,Stoch_Slowing,MODE_SMA,0,MODE_MAIN,i); STOM3 =iStochastic(NULL,0,First_Stoch_KP+2,Stoch_PERIOD,Stoch_Slowing,MODE_SMA,0,MODE_MAIN,i); STOM4 =iStochastic(NULL,0,First_Stoch_KP+3,Stoch_PERIOD,Stoch_Slowing,MODE_SMA,0,MODE_MAIN,i); STOM5 =iStochastic(NULL,0,First_Stoch_KP+4,Stoch_PERIOD,Stoch_Slowing,MODE_SMA,0,MODE_MAIN,i); STOM6 =iStochastic(NULL,0,First_Stoch_KP+5,Stoch_PERIOD,Stoch_Slowing,MODE_SMA,0,MODE_MAIN,i); STOM7 =iStochastic(NULL,0,First_Stoch_KP+6,Stoch_PERIOD,Stoch_Slowing,MODE_SMA,0,MODE_MAIN,i); STOM8 =iStochastic(NULL,0,First_Stoch_KP+7,Stoch_PERIOD,Stoch_Slowing,MODE_SMA,0,MODE_MAIN,i); STOM9 =iStochastic(NULL,0,First_Stoch_KP+8,Stoch_PERIOD,Stoch_Slowing,MODE_SMA,0,MODE_MAIN,i); STOM10=iStochastic(NULL,0,First_Stoch_KP+9,Stoch_PERIOD,Stoch_Slowing,MODE_SMA,0,MODE_MAIN,i); STOM11=iStochastic(NULL,0,First_Stoch_KP+9,Stoch_PERIOD,Stoch_Slowing,MODE_SMA,0,MODE_MAIN,i+1); //additional condition stoch for open string Stochbuy="false";string Stochsel="false"; if(usestochopen==true){if(STOM11>STOM10)Stochsel="true";if(STOM11LagBuySig //&& Lag>=Lag2 )LagFIB="true";if(LagSDL7)Slopbuy="true";} if(openslopy==false)Slopbuy="true";Slopsel="true"; //stoch for close {if(closestochonthesametimeframe==true) {if(Timeframe==5){czas=PERIOD_M5;x=300000;}if(Timeframe==15){czas=PERIOD_M15;x=900000;}if(Timeframe==30){czas=PERIOD_M30;x=1800000;}if(Timeframe==60){czas=PERIOD_H1;x=3600000;}if(Timeframe==240){czas=PERIOD_H4;x=14400000;}} else{if(Timeframe==5){czas=PERIOD_M1;x=300000;}if(Timeframe==15){czas=PERIOD_M5;x=900000;}if(Timeframe==30){czas=PERIOD_M15;x=1800000;}if(Timeframe==60){czas=PERIOD_M30;x=3600000;}if(Timeframe==240){czas=PERIOD_H1;x=14400000;}}} double SCA=iStochastic(NULL,czas,KPeriodclose,DPeriodclose,Slowingclose,MAStoch,PriceStoch,MODE_MAIN,0); double SCB=iStochastic(NULL,czas,KPeriodclose,DPeriodclose,Slowingclose,MAStoch,PriceStoch,MODE_SIGNAL,0); double SC1=iStochastic(NULL,czas,KPeriodclose,DPeriodclose,Slowingclose,MAStoch,PriceStoch,MODE_MAIN,i); double SC2=iStochastic(NULL,czas,KPeriodclose,DPeriodclose,Slowingclose,MAStoch,PriceStoch,MODE_SIGNAL,i); double SC3=iStochastic(NULL,czas,KPeriodclose,DPeriodclose,Slowingclose,MAStoch,PriceStoch,MODE_MAIN,i+1); double SC4=iStochastic(NULL,czas,KPeriodclose,DPeriodclose,Slowingclose,MAStoch,PriceStoch,MODE_MAIN,i+2); //slope for close double SDL8 =iCustom(Symbol(),0,"Slope Direction Line",periodcl,methodcl,pricecl,2,0); double SDL9 =iCustom(Symbol(),0,"Slope Direction Line",periodcl,methodcl,pricecl,2,i); double SDL10=iCustom(Symbol(),0,"Slope Direction Line",periodcl,methodcl,pricecl,2,i+1); double SDL11=iCustom(Symbol(),0,"Slope Direction Line",periodcl,methodcl,pricecl,2,i+2); if( quantity==10){ if( ((stopopen_1&&SCASC2)||(stopopen_2&&SC1>=SC3 && SC1-SCA>=Distanceclosemax*Point)||(closeonslopy&&SDL11SDL9)) && STOM1>Hig_l && STOM2>Hig_l && STOM3>Hig_l && STOM4>Hig_l && STOM5>Hig_l && STOM6>Hig_l && STOM7>Hig_l && STOM8>Hig_l && STOM9>Hig_l && STOM10>Hig_l){High_l=100;}else {High_l=Hig_l ;} if( ((stopopen_1&&SCA>SCB&&SC2>SC1)||(stopopen_2&&SC1<=SC3 && SCA-SC1>=Distanceclosemax*Point)||(closeonslopy&&SDL11>SDL10 && SDL10SC2)||(stopopen_2&&SC1>=SC3 && SC1-SCA>=Distanceclosemax*Point)||(closeonslopy&&SDL11SDL9)) && STOM1>Hig_l && STOM2>Hig_l && STOM3>Hig_l && STOM4>Hig_l && STOM5>Hig_l && STOM6>Hig_l && STOM7>Hig_l && STOM8>Hig_l && STOM9>Hig_l ){High_l=100;}else {High_l=Hig_l ;} if( ((stopopen_1&&SCA>SCB&&SC2>SC1)||(stopopen_2&&SC1<=SC3 && SCA-SC1>=Distanceclosemax*Point)||(closeonslopy&&SDL11>SDL10 && SDL10SC2)||(stopopen_2&&SC1>=SC3 && SC1-SCA>=Distanceclosemax*Point)||(closeonslopy&&SDL11SDL9)) && STOM1>Hig_l && STOM2>Hig_l && STOM3>Hig_l && STOM4>Hig_l && STOM5>Hig_l && STOM6>Hig_l && STOM7>Hig_l && STOM8>Hig_l ){High_l=100;}else {High_l=Hig_l ;} if( ((stopopen_1&&SCA>SCB&&SC2>SC1)||(stopopen_2&&SC1<=SC3 && SCA-SC1>=Distanceclosemax*Point)||(closeonslopy&&SDL11>SDL10 && SDL10SC2)||(stopopen_2&&SC1>=SC3 && SC1-SCA>=Distanceclosemax*Point)||(closeonslopy&&SDL11SDL9)) && STOM1>Hig_l && STOM2>Hig_l && STOM3>Hig_l && STOM4>Hig_l && STOM5>Hig_l && STOM6>Hig_l && STOM7>Hig_l ){High_l=100;}else {High_l=Hig_l ;} if( ((stopopen_1&&SCA>SCB&&SC2>SC1)||(stopopen_2&&SC1<=SC3 && SCA-SC1>=Distanceclosemax*Point)||(closeonslopy&&SDL11>SDL10 && SDL10SC2)||(stopopen_2&&SC1>=SC3 && SC1-SCA>=Distanceclosemax*Point)||(closeonslopy&&SDL11SDL9)) && STOM1>Hig_l && STOM2>Hig_l && STOM3>Hig_l && STOM4>Hig_l && STOM5>Hig_l && STOM6>Hig_l ){High_l=100;}else {High_l=Hig_l ;} if( ((stopopen_1&&SCA>SCB&&SC2>SC1)||(stopopen_2&&SC1<=SC3 && SCA-SC1>=Distanceclosemax*Point)||(closeonslopy&&SDL11>SDL10 && SDL10SC2)||(stopopen_2&&SC1>=SC3 && SC1-SCA>=Distanceclosemax*Point)||(closeonslopy&&SDL11SDL9)) && STOM1>Hig_l && STOM2>Hig_l && STOM3>Hig_l && STOM4>Hig_l && STOM5>Hig_l ){High_l=100;}else {High_l=Hig_l ;} if( ((stopopen_1&&SCA>SCB&&SC2>SC1)||(stopopen_2&&SC1<=SC3 && SCA-SC1>=Distanceclosemax*Point)||(closeonslopy&&SDL11>SDL10 && SDL10SC2)||(stopopen_2&&SC1>=SC3 && SC1-SCA>=Distanceclosemax*Point)||(closeonslopy&&SDL11SDL9)) && STOM1>Hig_l && STOM2>Hig_l && STOM3>Hig_l && STOM4>Hig_l ){High_l=100;}else {High_l=Hig_l ;} if( ((stopopen_1&&SCA>SCB&&SC2>SC1)||(stopopen_2&&SC1<=SC3 && SCA-SC1>=Distanceclosemax*Point)||(closeonslopy&&SDL11>SDL10 && SDL10SC2)||(stopopen_2&&SC1>=SC3 && SC1-SCA>=Distanceclosemax*Point)||(closeonslopy&&SDL11SDL9)) && STOM1>Hig_l && STOM2>Hig_l && STOM3>Hig_l ){High_l=100;}else {High_l=Hig_l ;} if( ((stopopen_1&&SCA>SCB&&SC2>SC1)||(stopopen_2&&SC1<=SC3 && SCA-SC1>=Distanceclosemax*Point)||(closeonslopy&&SDL11>SDL10 && SDL10SC2)||(stopopen_2&&SC1>=SC3 && SC1-SCA>=Distanceclosemax*Point)||(closeonslopy&&SDL11SDL9)) && STOM1>Hig_l && STOM2>Hig_l ){High_l=100;}else {High_l=Hig_l ;} if( ((stopopen_1&&SCA>SCB&&SC2>SC1)||(stopopen_2&&SC1<=SC3 && SCA-SC1>=Distanceclosemax*Point)||(closeonslopy&&SDL11>SDL10 && SDL10SC2)||(stopopen_2&&SC1>=SC3 && SC1-SCA>=Distanceclosemax*Point)||(closeonslopy&&SDL11SDL9)) && STOM1>Hig_l ){High_l=100;}else {High_l=Hig_l ;} if( ((stopopen_1&&SCA>SCB&&SC2>SC1)||(stopopen_2&&SC1<=SC3 && SCA-SC1>=Distanceclosemax*Point)||(closeonslopy&&SDL11>SDL10 && SDL10High_l && STOM2>High_l && STOM3>High_l && STOM4>High_l && STOM5>High_l && STOM6>High_l && STOM7>High_l && STOM8>High_l && STOM9>High_l && STOM10>High_l&&TradePerBarHigh_l && STOM2>High_l && STOM3>High_l && STOM4>High_l && STOM5>High_l && STOM6>High_l && STOM7>High_l && STOM8>High_l && STOM9>High_l &&TradePerBar<=MaxTradePerBar){if(Reverse) {SV=1;} else {BV=1;} break;}} if( quantity==8){ if( LagFIS=="true" && Stochsel=="true"&& Slopsel=="true"&& STOM1High_l && STOM2>High_l && STOM3>High_l && STOM4>High_l && STOM5>High_l && STOM6>High_l && STOM7>High_l &&TradePerBar<=MaxTradePerBar){if(Reverse) {SV=1;} else {BV=1;} break;}} if( quantity==7){ if( LagFIS=="true" && Stochsel=="true"&& Slopsel=="true"&& STOM1High_l && STOM2>High_l && STOM3>High_l && STOM4>High_l && STOM5>High_l && STOM6>High_l && STOM7>High_l &&TradePerBar<=MaxTradePerBar){if(Reverse) {SV=1;} else {BV=1;} break;}} if( quantity==6){ if( LagFIS=="true" && Stochsel=="true"&& Slopsel=="true"&& STOM1High_l && STOM2>High_l && STOM3>High_l && STOM4>High_l && STOM5>High_l && STOM6>High_l &&TradePerBar<=MaxTradePerBar){if(Reverse) {SV=1;} else {BV=1;} break;}} if( quantity==5){ if( LagFIS=="true" && Stochsel=="true"&& Slopsel=="true"&& STOM1High_l && STOM2>High_l && STOM3>High_l && STOM4>High_l && STOM5>High_l &&TradePerBar<=MaxTradePerBar){if(Reverse) {SV=1;} else {BV=1;} break;}} if( quantity==4){ if( LagFIS=="true" && Stochsel=="true"&& Slopsel=="true"&& STOM1High_l && STOM2>High_l && STOM3>High_l && STOM4>High_l &&TradePerBar<=MaxTradePerBar){if(Reverse) {SV=1;} else {BV=1;} break;}} if( quantity==3){ if( LagFIS=="true" && Stochsel=="true"&& Slopsel=="true"&& STOM1High_l && STOM2>High_l && STOM3>High_l &&TradePerBar<=MaxTradePerBar){if(Reverse) {SV=1;} else {BV=1;} break;}} if( quantity==2){ if( LagFIS=="true" && Stochsel=="true"&& Slopsel=="true"&& STOM1High_l && STOM2>High_l &&TradePerBar<=MaxTradePerBar){if(Reverse) {SV=1;} else {BV=1;} break;}} if( quantity==1){ if( LagFIS=="true" && Stochsel=="true"&& Slopsel=="true"&& STOM1High_l && TradePerBar<=MaxTradePerBar){if(Reverse) {SV=1;} else {BV=1;} break;}}} // expert money management if(MM==true) Lots = subLotSize(); // expert init positions int cnt=0,OP=0,OS=0,OB=0,CS=0,CB=0,CLoseBuy=0,CLoseSel=0,Closebuymax=0,Closesellmin=0,Stopsell=0,Stopbuy=0; OP=0;for(cnt=0; cnt=1){OS=0; OB=0;}OB=0;OS=0;CB=0;CS=0;Closebuymax=0;Closesellmin=0;CLoseBuy=0;CLoseSel=0;Stopsell=0;Stopbuy=0; // expert conditions to open position if(SV>0&&TradePerBar0&&TradePerBarSC2&&((SCB-SCA)>=Distanceclose*Point)){CLoseBuy=1;} if(closeoncross && SCA>SCB&&SC2>SC1&&((SCA-SCB)>=Distanceclose*Point)){CLoseSel=1;} if(closeonmaxstoch && SC1SC4){Closebuymax=1;} if(closeonmaxstoch && SC3SC3){Closesellmin=1;} // if(closeonslopy && SDL11>SDL10 && SDL10SDL9){Stopbuy=1;} if(closeonslopy && SDL10>=SDL9 && SDL8-SDL9>=distanceslope*Point){Stopsell=1;} if(closeonslopy && SDL10<=SDL9 && SDL9-SDL8>=distanceslope*Point ){Stopbuy=1;} if((Stopbuy==1) ||(CLoseBuy==1)||(Closebuymax==1)|| (RealSL_Enabled && (OrderOpenPrice()-Bid)/Point>=RealSL)||(RealTP_Enabled && (Ask-OrderOpenPrice())/Point>=RealTP)){CB=1;} if((Stopsell==1)|| (CLoseSel==1)||(Closesellmin==1)|| (RealSL_Enabled && (Ask-OrderOpenPrice())/Point>=RealSL)||(RealTP_Enabled && (OrderOpenPrice()-Bid)/Point>=RealTP)){CS=1;} for(cnt=0;cnt0)TradePerBar++;return(0);}} if(OB==1){if (TP==0) TPI=0; else TPI=Ask+TP*Point;if(SL==0) SLI=0; else SLI=Ask-SL*Point;if(Time0!=Time[0]){TK=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slip,SLI,TPI,OrSt,Magic,0,Lime);OB=0;PlaySound("alert.wav");Comment("buy order opened","\n","magic number : ",Magic); Time0=Time[0];if(TK>0)TradePerBar++;return(0);}}} for(j=0;j0){if((pb-OrderOpenPrice())>BE*pp){if((OrderStopLoss()-OrderOpenPrice())<0){ModSL(OrderOpenPrice()+0*pp);}}} if(TS>0){if((pb-OrderOpenPrice())>TS*pp){if(OrderStopLoss()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+TS_Step-1)*pp || OrderStopLoss()==0){ModSL(pa+TS*pp);return;}}}}} //expert stoploss void ModSL(double ldSL){bool fm;fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSL,OrderTakeProfit(),0,CLR_NONE);} //expert add positions function bool AddP(){int _num=0; int _ot=0; for (int j=0;j_ot) _ot=OrderOpenTime();}} if(_num==0) return(true);if(_num>0 && ((Time[0]-_ot))>0) return(true);else return(false);} // void closeall() { for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderCloseTime()==0) { if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,3,Blue); if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,3,Red); } }} double subLotSize() { double lotMM = MathCeil(AccountFreeMargin() * Risk / 1000) / 100; if(AccountIsMicro==false) //normal account { if(lotMM < 0.1) lotMM = Lots; if((lotMM > 0.5) && (lotMM < 1)) lotMM = 0.5; if(lotMM > 1.0) lotMM = MathCeil(lotMM); if(lotMM > 100) lotMM = 100; } else //micro account { if(lotMM < 0.01) lotMM = Lots; if(lotMM > 1.0) lotMM = MathCeil(lotMM); if(lotMM > 100) lotMM = 100; } return (lotMM); }