//+------------------------------------------------------------------+ //| Build_Own_Strategy!.mq4 | //| Copyright © 2010 Seletsky R.V.| //| Copyleft @ 2011 Gloodun J. D.| //| Copyleft © 2010-2011, AnonymousMMMMMMMMMI| //+------------------------------------------------------------------+ #property copyright "S R V; Anon 9001; So" #property link "MQL4.com; Strategy4you.ru" //-----------------------------------------------------------------------------------------------------------+ // Instructions | //------------------------------------------------------------------------------------------------------ 1 --+ // This advisor is built as a shell for your genius ideas. // Has unusual thigs like money managemnt, stops management (very rare bird in bots!) // Actually, I saw all that attempts of writting lame "grails", so I had to... GIVE AN OPPORTUNITY! // Srsly. But I have to put MY OWN strategy just for a test... // I've spent two months of free time for previos version. // But the previous version was 3/10 rated, so I have to make some more... examples... // But hey, it is also a collection of free scripts! // For example, you can find a block of "condition screening", // or learn, how to use custom indicators, or even input own strategy you was using two years. // The point is both writting own strategy in minutes and inputting all the scripts and advisor-followers together with the advisor itself. // Well, 95% of "robots" on MQL4 are empty grails... so I decided to make "Lvl. 11 Universal" robot. // My point is providing customisability among closing methods... // Right now, you can write/get own "indicator(s)" for defining closes separately from opens. // I also capitalised ATR as TP and SL setter. Well, he slows the system, so // Anyway, an attempt to put "two different closes at once" was a sort of pain in butt. So I had to make very unnice "dirty hack" way: // - mount away limits and makes Open Size and Close Size of LOTS different, after what, use same blocks of Signals (Open\Close) for signalling. Looks murky, // but the worst is possibilty to bug the strategy. // Well, I can give some examples of coding. // //CCI:------------------------------- // if(otkr_CCI==true) // { // if (iCCI(NULL, 0,CCI_period,PRICE_MEDIAN, 1)<-100) See? // { * * * * * * In's like some highschool math. // CCI_By =true; Variable are in the left and in the right. Also: print : "iCCI(" here: // You'll see some brief info. Normally, write after: NULL,0 // } // if (iCCI(NULL, 0,CCI_period,PRICE_MEDIAN,1)>100) // { // CCI_Sell =true; // } // } // // if(zakr_CCI==true) // { // if (iCCI(NULL, 0,CCI_period,PRICE_MEDIAN, 1)<-100) // { // Cls_CCI_Sell=true; // } // if (iCCI(NULL, 0,CCI_period,PRICE_MEDIAN,1)>100) // { // Cls_CCI_By=true; // } // } // // // Or another one (custom, this time. Really may be found here): // if(otkr_Custom_14==true) // Well, ZigZag is not too very good example. // { // if(iCustom(NULL,0,"ZigZag",0,0)>PRICE_CLOSE)// Not for profit! // { //Actually, all the paramethers are just basic ZZ's 5-7-12 or whatever... BASIC ones.) // Custom_14_By=true; // } // // if(iCustom(NULL,0,"ZigZag",0,0)PRICE_CLOSE) // { // Cls_Custom_14_By=true; // } // // if(iCustom(NULL,0,"ZigZag",0,0)=0;t0--) // Search among closed orders if(OrderSelect(t0, SELECT_BY_POS,MODE_HISTORY )==true) // A-a-and it we found it... { if( iTime(NULL,0,1)-OrderOpenTime() < 600 && SleepBars==true ) //We're pausing. This string has the terms of pause. { // // BTW, time is in seconds by standard. S_Bar=true; Alert("Gimme a break..."); } // return(0); // Hey, it's first time I had a bug. Remember - "switched off" by True/False cosesnippet can make it's influence. } //---------------------------------------------------------------------- //-------------------- Pre-Work Sorting-------------------------- 4 - if(Bars<15) // Insufficient quantity of bars { Alert("Bars<15, need more bars of history."); return; // Exit from start() } if(Work==false) // Critical error { Alert("Critical Error occured."); return; // Exit from start() } //------------------------------------------------------------------------------ //------------------------------Orders counting--------------------------------- 4 -- Symb=Symbol(); Total=0; for(int i=1; i<=OrdersTotal(); i++) { if (OrderSelect(i-1,SELECT_BY_POS)==true) { if (OrderSymbol()!=Symb)continue; if (OrderType()>1) { Alert("Unusual order detected. Pause."); // Well, I'll leave it here since first author made it... return; } Total++; // if (Total>3) // Only one order on one pair. Made for brokers and their trust. { Alert("Too much orders. Pause."); // Normally ONE, but I am not against. return; // exit from start() } Ticket=OrderTicket(); // Tip =OrderType(); // It's info about lots... Price =OrderOpenPrice(); // SL =OrderStopLoss(); // TP =OrderTakeProfit(); // Lot =OrderLots(); // Lots in the order } } //------------Indicators Zone--------(Here they're switching on)------------ 6 -- //Tune the indicators, huh? //------------- Pre-Installed indicators // NOTE: THE PARAMETHERS OF "OPED" AND "CLOSE" ARE SUPPOSED // TO BE DEFINED BY YOUR OWN, IT DEPENDS ON SELECTED STRATEGY. // MAKE SURE THE SELECTED INDICATOR OPENS AND CLOSES PROPERLY! //ATR for TP and SL is here------------------------------ if(ATR_SL==true && iATR(NULL,0,ATR_Period,1)>=ATR_Reach) StopLoss=iATR(NULL,0,ATR_Period,0)*ATR_Multiply/0.0001; //Yes, not the "price", but the "pips". if(ATR_TP==true && iATR(NULL,0,ATR_Period,1)>=ATR_Reach) TakeProfit=iATR(NULL,0,ATR_Period,0)*ATR_Multiply/0.0001; //MAs------------------------------------ if(otkr_MA==true) { if( iMA(NULL,0,MA1,0,MA_sort_avoidit,PRICE_CLOSE,Shift_ma)>iMA(NULL,0,MA2,0,MODE_SMA,PRICE_CLOSE,Shift_ma)) { MA_By =true;// Normally SMA, but here is my edit. } if(iMA(NULL,0,MA1,0,MA_sort_avoidit,PRICE_CLOSE,Shift_ma)iMA(NULL,0,MA2,0,MODE_SMA,PRICE_CLOSE,Shift_ma)) { Cls_MA_Sell=true; } if(iMA(NULL,0,MA1,0,MA_sort_avoidit,PRICE_CLOSE,Shift_ma)iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,1,1) && iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,1,1)zoneSELL) { Stoh_Sell =true; } } if(zakr_Stoh==true) { if(iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,0,1)>iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,1,1) && iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,1,1)zoneSELL) { Cls_Stoh_By=true; } } //Awesome-------------------------------- if(otkr_AO==true) { if(iAO(NULL,0,0)+iAO(NULL,0,1)>iAO(NULL,0,2)+iAO(NULL,0,3)) { AO_By =true; } if(iAO(NULL,0,0)+iAO(NULL,0,1)iAO(NULL,0,2)+iAO(NULL,0,3)) { Cls_AO_Sell=true; } if(iAO(NULL,0,0)+iAO(NULL,0,1)PRICE_CLOSE) { Fractals_Sell =true; } } if(zakr_Fractals==true) { if (iFractals(NULL,0,1,0)PRICE_CLOSE) { Cls_Fractals_By=true; } } //Accelerator--------------------------- if(otkr_AC==true) { if (iAC(NULL,0,0)>=0 && iAC(NULL,0,0)>iAC(NULL,0,1) && iAC(NULL,0,1)>iAC(NULL,0,2) || iAC(NULL,0,0)<=0 && iAC(NULL,0,0)>iAC(NULL,0,1) && iAC(NULL,0,1)>iAC(NULL,0,2) && iAC(NULL,0,2)>iAC(NULL,0,3)) { AC_By =true; } if (iAC(NULL,0,0)<=0 && iAC(NULL,0,0)=0 && iAC(NULL,0,0)=0 && iAC(NULL,0,0)>iAC(NULL,0,1) && iAC(NULL,0,1)>iAC(NULL,0,2) || iAC(NULL,0,0)<=0 && iAC(NULL,0,0)>iAC(NULL,0,1) && iAC(NULL,0,1)>iAC(NULL,0,2) && iAC(NULL,0,2)>iAC(NULL,0,3)) { Cls_AC_Sell=true; } if (iAC(NULL,0,0)<=0 && iAC(NULL,0,0)=0 && iAC(NULL,0,0)verx_ur) { Dema_Sell =true; } } if(zakr_Dema==true) { if (iDeMarker(NULL, 0, DeMa_period, 1)verx_ur) { Cls_Dema_By=true; } } //CCI:------------------that's how I've made a hook method here if(otkr_CCI==true) { if (iCCI(NULL, 0,CCI_period,PRICE_MEDIAN,0)>iCCI(NULL, 0, CCI_period,PRICE_MEDIAN,1) && iCCI(NULL, 0, CCI_period,PRICE_MEDIAN,1)iCCI(NULL, 0, CCI_period,PRICE_MEDIAN,2)) { CCI_Sell =true; } } if(zakr_CCI==true) { if (iCCI(NULL, 0,CCI_period,PRICE_MEDIAN, 1)<-CCI_Level) // Тоже по крюку. { Cls_CCI_Sell=true; } if (iCCI(NULL, 0,CCI_period,PRICE_MEDIAN, 1)>CCI_Level) // CCI используется как осциллятор перекуп.\перепрод. Как Стохастик. { Cls_CCI_By=true; } } //Heh-heh, the example is here, but it's (coolface.jpg) disabled!1one // //CCI:------------------------------- // if(otkr_CCI==true) // { // if (iCCI(NULL, 0,CCI_period,PRICE_MEDIAN, 1)<-100) // { // CCI_By =true; // } // if (iCCI(NULL, 0,CCI_period,PRICE_MEDIAN,1)>100) // { // CCI_Sell =true; // } // } // // if(zakr_CCI==true) // { // if (iCCI(NULL, 0,CCI_period,PRICE_MEDIAN, 1)<-100) // { // Cls_CCI_Sell=true; // } // if (iCCI(NULL, 0,CCI_period,PRICE_MEDIAN,1)>100) // { // Cls_CCI_By=true; // } // } // // //RSI--------------------------------------------------------------------- if(otkr_RSI==true) { if (iRSI(NULL,0,RSI_Period,1,0)>RSI_High) { RSI_By=true; } if (iRSI(NULL,0,RSI_Period,1,0)RSI_High) { Cls_RSI_Sell=true; } if (iRSI(NULL,0,RSI_Period,1,0)MFI_High) { MFI_By=true; } if (iMFI(NULL,0,MFI_Period,0)MFI_High/2+MFI_Low/2) { Cls_MFI_Sell=true; } if (iMFI(NULL,0,MFI_Period,0)-20) { WPR_By=true; } if (iWPR(NULL,0,WPR_Period,0)<-80) { WPR_Sell=true; } } if(zakr_WPR==true) { if (iWPR(NULL,0,WPR_Period,0)>-20) { Cls_WPR_Sell=true; } if (iWPR(NULL,0,WPR_Period,0)<-80) { Cls_WPR_By=true; } } //MACD------------------------------- if(otkr_MACD==true) { if (iMACD(NULL,0,MACD_Fast,MACD_Slow,MACD_Signal,1,1,0)>iMACD(NULL,0,9,26,14,1,1,1)) { MACD_By=true; } if (iMACD(NULL,0,MACD_Fast,MACD_Slow,MACD_Signal,1,1,0)iMACD(NULL,0,MACD_Fast,MACD_Slow,MACD_Signal,1,1,1)) { Cls_MACD_Sell=true; } if (iMACD(NULL,0,MACD_Fast,MACD_Slow,MACD_Signal,1,1,0)iMACD(NULL,0,9,26,14,1,1,1)) { MACD_By=true; } if (iOsMA(NULL,0,MACD_Fast,MACD_Slow,MACD_Signal,1,0)iMACD(NULL,0,MACD_Fast,MACD_Slow,MACD_Signal,1,1,1)) { Cls_MACD_Sell=true; } if (iOsMA(NULL,0,MACD_Fast,MACD_Slow,MACD_Signal,1,0)70) { ADX_By=true; } if (iADX(NULL,0,ADX_Period,1,0,0)<30) { ADX_Sell=true; } } if(zakr_ADX==true) { if (iADX(NULL,0,ADX_Period,1,0,0)>70) { Cls_ADX_Sell=true; } if (iADX(NULL,0,ADX_Period,1,0,0)<30) { Cls_ADX_By=true; } } //SAR------------------------------- if(otkr_SAR==true) { if(iSAR(NULL,0,SAR_Step,SAR_MaxStep,0)>Close[0]) { SAR_By=true; } if(iSAR(NULL,0,SAR_Step,SAR_MaxStep,0)Close[0]) { Cls_SAR_Sell=true; } if(iSAR(NULL,0,SAR_Step,SAR_MaxStep,0)PRICE_CLOSE) // You know, you're supposed to tune the custom indicator by yourself. { // I mean, all the tunes are saved in code (as basiccal\standard) Custom_1__By=true; // As a rule, the custom inds don't need any tunes... mostly... } // Well, if any problems, you just need to edit an indicator simply by changing the digits "in case". //"Theese \/ ones" // Snippet: between name ("ZZ") and last two (,0,0)) digits you can put variables if(iCustom(NULL,0,"StochasticStack",example1,example2,0,0)PRICE_CLOSE) { Cls_Custom_1__By=true;// _1__ , because there are up to 16 custom inds aviliable - you can find _10_, _16_, _9__... } if(iCustom(NULL,0,"StochasticStack",0,0)PRICE_CLOSE) // Just don't use my "filler". { // It won't work anyway. Custom_2__By=true; } if(iCustom(NULL,0,"Parabolic_ZZ",0,0)PRICE_CLOSE) // Lamest ever :) { Cls_Custom_2__By=true; } if(iCustom(NULL,0,"Parabolic_ZZ",0,0)PRICE_CLOSE) { Custom_3__By=true; } if(iCustom(NULL,0,"ZigZag",0,0)PRICE_CLOSE) { Cls_Custom_3__By=true; } if(iCustom(NULL,0,"ZigZag",0,0)PRICE_CLOSE) { Custom_4__By=true; } if(iCustom(NULL,0,"ZigZag",0,0)PRICE_CLOSE) { Cls_Custom_4__By=true; } if(iCustom(NULL,0,"ZigZag",0,0)PRICE_CLOSE) // { // Custom_16_By=true; // } // // if(iCustom(NULL,0,"ZigZag",0,0)PRICE_CLOSE) - 16th is here as an example. Try to barely de"//" it, then solve the "errors" occured. // { // Cls_Custom_16_By=true; // } // // if(iCustom(NULL,0,"ZigZag",0,0)=0;t--) //Exhaustive search among closed orders. { if(OrderSelect(t,SELECT_BY_POS,MODE_HISTORY)) // Searching. . . { if(OrderSymbol() == Symbol()) // Our pair. . . { if(time= 0 && StakeMode==2 && OrdersTotal()<1) {Lts=Lts1;} //if last order was profitful. Maybe, you will want to raise the stake if(profit < 0 && StakeMode==2 && OrdersTotal()<1) {Lts=lot*IK;} //if last order was a fail. IK may also make next deal smaller. } } if (Lts*One_Lot > Free) { Alert(" Not enough money for ", Lts," lots. Quit."); return; // exit from start() } //------------------------------------------------------------------------------ // Заметка - "Стратегия Белая Лестница" не требует особых условий закрытия и т. д. Это значит, что можно начать с неё. //------------------------------Opening an order--------------------------------- 10 -- while(true) // Cycle { if (Total==0 && Opn_B==true && Cls_B==false) // if there is no any orders (what if there is any?) { // Buy-for criteria RefreshRates(); // Refresh je! SL=Bid - New_Stop(StopLoss)*Point; // SL calculation TP=Bid + New_Stop(TakeProfit)*Point; // TP Alert("Buying in process. Wait for answer."); Ticket=OrderSend(Symb,OP_BUY,Lts,Ask,Slippage,SL,TP,NULL,ID_of_EA,0,RoyalBlue);//Открытие Buy if (Ticket > 0) // Success :) { Alert ("Buy Order Opened",Ticket); return; // exit from start() } if (Fun_Error(GetLastError())==1) // Errors handling continue; // Re-attempt return; // exit from start() } if (Total==0 && Opn_S==true && Cls_S==false) // this is for one order per one pair. { // Opening a Sell RefreshRates(); // Update SL=Ask + New_Stop(StopLoss)*Point; // Calculating SL TP=Ask - New_Stop(TakeProfit)*Point; // Calculating TP Alert("Selling in process. Wait for answer."); Ticket=OrderSend(Symb,OP_SELL,Lts,Bid,Slippage,SL,TP,NULL,ID_of_EA,0,RoyalBlue);//Открытие Sell///////\\//\\////// if (Ticket > 0) // Success :) { Alert ("Sell Order Opened",Ticket); return; // Exit from start() } if (Fun_Error(GetLastError())==1) // Errors handling continue; // Re-attempt return; // exit from start() } break; // exit from while } return; // exit from start() } //--------------------------Функцияия обработки ошибок------------------------------------ 11 -- int Fun_Error(int Error) { switch(Error) { // defeatable errors case 4: Alert("Trade Server is overcrowded. Re-attempt."); Sleep(3000); // simplest solution return(1); // exit from function case 130:Alert("Wrong stops."); while(RefreshRates()==false) // till new tick Sleep(1); // delay in a cycle return(1); // exit from... case 135:Alert("Price have changed. Re-attempt."); RefreshRates(); // update return(1); // exit from function (from error!) case 136:Alert("No prices. Waiting for a new tick."); while(RefreshRates()==false) // till new tick Sleep(1); // delay in a cycle return(1); // exit from... case 137:Alert("Brocker is busy. Re-attempt."); Sleep(3000); // Simplest solution. return(1); // exit from function (from error) case 146:Alert("Trading system is busy. Re-attempt"); Sleep(500); // Простое решение return(1); // exit from function (from error) // Критические ошибки case 2: Alert("General error"); return(1); // exit from function (from error) case 5: Alert("Old version of terminal"); Work=false; // Screw oldies! Exit! return(1); // exit from function (from error) case 64: Alert("Account is a blocked one."); Work=false; // What? Exit! return(0); // exit case 133:Alert("Dealing is closed"); return(0); // exit case 134:Alert("Not enough of money."); return(0); // exit default: Alert("Unsampled Error, exiting...",Error); // if there is any different sort of error return(0); // we're out... untill the error is solved manually... } } //-------------------------------------------------------------- 12 -- int New_Stop(int Parametr) // Stop-order check. { int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);// Minimal distance. if (Parametr