//+------------------------------------------------------------------+ //| Profit Generator 3.3.2.mq4 | //| | //| No Copyright, created 20 March 2006, Open Source | //| http://www.forex-tsd.com | //| http://www.tradingintl.com | //| | //| Freely receive, Freely give. Please post updated version. | //| Default Settings on EURUSD, GBPUSD, and USDCHF | //+------------------------------------------------------------------+ #property copyright "Created in 2006, Open Source Project" #property link "http://www.forex-tsd.com" #include #include ///////////////////////////////////////////////////Variables////////////////////////////// extern string EAname="Pro-Gen_3"; extern int ID_BASE=100000; // Change this number if running more than one EA on the same pair extern int LongBar=15; // sets the minimum length of the bar extern double BarOpenPercent=0.50;// Set this to determine the percent of the bar which the trade takes place. extern int MaxTrades=1; //maximum number of trades open at a time extern double lots=1.0; // This number will not matter if using Money Management extern int stoploss=30,takeprofit=40; extern bool MM = false; //Use Money Management or not extern double Risk = 10; //percent of available margin to risk. extern int PairsTraded=0; //if set to 0 then std MM. If set to the number of Pairs traded then the risk is divided amongst the number of pairs. extern bool UseClose=false; // This will use the SuperClose(). extern int TSactivation=40,TrailPips=5; // TSactivation will set the point where the TS will start. extern bool UseHourTrade = false; // Time filter extern int FromHourTrade = 7; // start trading on this hour extern int ToHourTrade = 20; // end trading on this hour extern bool UseSimpleTF=false; extern int period=0; // leave this number as zero to use the period from the chart. extern bool OneTradeperPeriod=false; //This will only allow one new trade per period. extern bool Alerts=false,AlertOnlyMode=false;// Alerts will alert when trade signal is present. AOM will not place trades, but will alert to the platform extern bool WeekendMode=true;//True=Will close all trades on and after the hour to close. extern int hour_to_close=21; extern bool EMAconfirm=false; // Uses EMA direction to confirm trades. eg. If Low EMA (lower of two MAperiods)>HighEMA then the market is bearish. extern int LowEMA=10;// lower of EMA TF extern int HighEMA=16;// higher of EMA TF extern int EMAtf=0;// if 0 then it uses the chart TF, otherwise it will use the period based on period settings. extern bool UseStoOpen=false; extern int StoTF=1; extern bool Reverse=false;// reverses orders regardless of ALL signal direction extern bool UseObsoleteMethod=True; extern bool OMwhenLossOnly=false; extern int ObsoleteMinutes=10; extern bool Use50maFilter=true; extern int MApips=10; extern bool UseTE=false; extern int badtrades=2; extern int ReEnter=2; string xname,start; int ID; int bar;//tracks the period where a trade was placed. double Hi, Lo, Op; int tsTicket[21]; double tsPrice[21]; bool tsok[21]; bool lopen,sopen; int TEticket[40]; double TEpips[40]; int TEtype[40]; double TEopen[40]; bool TEclosed[40]; datetime ot; //bool hedged; bool bad; ////////////////////////////////////////////////////////////////////////////////////////////// int init(){ ID=ID_BASE+P(period); start=TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS); xname=EAname+"_"+DoubleToStr(ID,0); // Comment("\n",xname," started @ ",start,"\n","Floating P&L: ",profit(),"\n",presentpos()); ot=CurTime(); } /////////////START FUNCTION///////////////////START FUNCTION//////////////////////START FUNCTION///// int CheckOpen(int f){ if(lopen){ stoopen(1); return; } if(sopen){ stoopen(2); return; } double lwma=iMA(NULL,0,50,0,MODE_LWMA,MODE_CLOSE,0); int x=0; Hi = iHigh(NULL, P(period), x); Lo = iLow (NULL, P(period), x); Op = iOpen(NULL, P(period), x); //Print("CHECKOPEN()"); // Print(Hi, ",", Lo); // This shows how the value of hi and lo changes during the day // Comment("if (",(Hi-Lo)," > ",LongBar*Point," && ",Op," < ",Hi+Lo/2," && ",Ask," < ",Op); if( (Hi-Lo > LongBar*Point && Op < baropen(1) && Ask < Op) && ( !EMAconfirm || EMA(1,P(EMAtf))> EMA(2,P(EMAtf)) )&& (!Use50maFilter || Ask > lwma+MApips*Point) ){ if(f==1){ if(!UseStoOpen){ openorder(1); }else{ lopen=true; stoopen(1); } } else if(f==2){ return(1); } } else if( (Hi-Lo > LongBar*Point && Op > baropen(2)&& Bid > Op) && ( !EMAconfirm || EMA(1,P(EMAtf))< EMA(2,P(EMAtf)) ) && (!Use50maFilter || Bid < lwma-MApips*Point) ){ // Print("shrtOPEN"); if(f==1){ if(!UseStoOpen){ openorder(2); }else{ sopen=true; stoopen(2); } } else if(f==2){ return(2); } } // Comment(Hi-Lo," > ",LongBar*Point," && ",Op," > ",baropen(2)," && ",Bid," > ",Op); return(0); } ////////////////////////////////////////////////////////////////////////////////////////////// double baropen(int t){ double barpr; if(t==1){ barpr= Lo + (Hi-Lo) * BarOpenPercent; // Print("Lo ",Lo," + ",(Hi-Lo) * BarOpenPercent / 100); } else if(t==2){ barpr= Hi - (Hi-Lo) * BarOpenPercent; } return(barpr); } ////////////////////////////////////////////////////////////////////////////////////////////// void stoopen(int t){ double sto1,sto2; sto1=iStochastic(NULL,P(StoTF),5,3,3,MODE_SMA,0,MODE_MAIN,0); sto2=iStochastic(NULL,P(StoTF),5,3,3,MODE_SMA,0,MODE_SIGNAL,0); Print("stoopen() ",sto1, " " , sto2); if( t==1 ){ if(sto1>sto2){ openorder(1); Print("open order on sto"); } } else if( t==2 ){ if(sto1 1.0) lotMM = MathCeil(lotMM); if (lotMM > 100) lotMM = 100; return (lotMM); } ////////////////////////////////////////////////////////////////////////////////////////////// void SuperClose(){ for(int i=0;i= TSactivation*Point || TSactivation==0 ) ) { tsPrice[pos]=Bid-TrailPips*Point; tsok[pos]=true; if(TrailPips>8){ ModifyStopLoss(Bid-TrailPips*Point); } } if (tsok[pos] && Bid-TrailPips*Point > tsPrice[pos] ){ tsPrice[pos]=Bid-TrailPips*Point; if(TrailPips > 8){ ModifyStopLoss(Bid-TrailPips*Point); } } if (tsok[pos] && Bid <= tsPrice[pos] ){ CloseOrder(1); Print("Long Order ",tsTicket[pos]," Closed from TS"); } } } } } for(i=0;i<21;i++){// this searches the array for ticket numbers that are now obsolete due to an order that has closed if(tsTicket[i]>0){ bool found=false; for(b=0;b= ObsoleteMinutes * 60){ if(!OMwhenLossOnly || OrderProfit()<0){ if(OrderType()==OP_BUY){ if(CheckOpen(2)==2){ CloseOrder(1); openorder(2); Print("Order Swap due to sada"); } } else if(OrderType()==OP_SELL){ if(CheckOpen(2)==1){ CloseOrder(2); openorder(1); Print("Order Swap due to sada"); } } } } } } } } ////////////////////////////////////////////////////////////////////////////////////////////// /* string profit(){ double pro; for(int i =0;i h[i]){ string dir=" ( UP ) "; }else if(OrderProfit()< h[i]){ dir=" ( DN ) "; } pp=pp+"\n"+OrderSymbol()+" ("+DoubleToStr(OrderProfit(),2)+")"+dir; h[i]=OrderProfit(); } } } if(cnt>0){ return(pp); }else{ return("\n"+"No Open Trades"); } } */ ////////////////////////////////////////////////////////////////////////////////////////////// bool WE(){ if(orderscnt()>0){ if(DayOfWeek()>=5 && Hour()>=hour_to_close){ CloseAllTrades(); return(true); } }else{ if(DayOfWeek()>=5 && Hour()>=hour_to_close -2){ return(true); } } return(false); } //////////////////////////////////////////////////////////////////////////////////////////////////// // Nicholishen nick@barker.net ///////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////// //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~TRADE EMULATION~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void TE(){ if(!TE1()){ if( 1==1)TEnew(1); else if( CheckOpen(2)==2) TEnew(2); } } bool TE1(){ bool ok=false;double sl; if(UseClose && TSactivation!=0)sl=TSactivation;else sl=stoploss; for(int i=0;i<200;i++){ if(TEticket[i]!=0 && !TEclosed[i]){ ok=true; if(TEtype[i]==1){ TEpips[i]=Bid-TEopen[i]; if(TEopen[i]-Bid>=sl*Point){TEclosed[i]=true;Print("TE trade closed from SL (",TEpips[i],")");Comment("");} if(Bid-TEopen[i]>=takeprofit*Point){TEclosed[i]=true;Print("TE trade closed from TP (",TEpips[i],")");Comment("");} } if(TEtype[i]==2){ TEpips[i]=TEopen[i]-Ask; if(Ask-TEopen[i]>=sl*Point){TEclosed[i]=true;Print("TE trade closed from SL (",TEpips[i],")");} if(TEopen[i]-Ask>=takeprofit*Point){TEclosed[i]=true;Print("TE trade closed from SL (",TEpips[i],")");} } Comment("\n","TE Open Order: ",TEtype[i]," Tkt ",TEticket[i]," Profit ",TEpips[i]); } } if(ok)return(true); return(false); } void TEnew(int t){ static int cnt;int pos; for(int i=0;i<40;i++){ if(TEticket[i]==0){pos=i;break;} } cnt++; TEticket[pos]=cnt; if(t==1){TEtype[pos]=1;TEopen[pos]=Ask;} else if(t==2){TEtype[pos]=2;TEopen[pos]=Bid;} } int TEprocnt(){ int total; for(int i=39;i>=0;i--){ if(TEticket[i]>0){ if(TEpips[i]>0 && TEclosed[i])total++; if(TEpips[i]<0 && TEclosed[i])total=0; } } return(total); } void TEpurge(){ for(int i=0;i<40;i++){ TEticket[i]=0; TEpips[i]=0; TEtype[i]=0; TEopen[i]=0; TEclosed[i]=false; ot=CurTime(); bad=false; } } int BadTrades(){ for(int i=HistoryTotal();i>=0;i--){ if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){ if(OrderSymbol()==Symbol() && OrderMagicNumber()==ID){ if(OrderOpenTime()>ot){ if(OrderProfit()>0)int tr=0; if(OrderProfit()<0)tr++; } } } } return(tr); } //////////////START FUNCTION//////////////////START FUNCTION//////////////////START FUNCTION/////// int start(){ int rderscnt=orderscnt(); if( WeekendMode ){ if( WE() )return(0); } if( UseClose ){ if(rderscnt>0)SuperClose(); } if( UseHourTrade ){ if((( FromHourTrade <= ToHourTrade ) && ( Hour() < FromHourTrade || Hour() > ToHourTrade )) || // Allow for Overnight Trading (( FromHourTrade > ToHourTrade ) && ( Hour() < FromHourTrade && Hour() > ToHourTrade )) ) { return(0); } } if(rderscnt==0){ if(UseTE){ if(BadTrades()>=badtrades){ if(TEprocnt()>=ReEnter){TEpurge();return(0);} TE(); bad=true; } } } if(!bad && (rderscnt