MFI_RSI_SAR_MA

Author: Copyright 2018, MetaQuotes Software Corp.
Price Data Components
Series array that contains open prices of each barSeries array that contains close prices for each bar
Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
Indicators Used
Parabolic Stop and Reverse systemRelative strength indexBollinger bands indicatorMoving average indicatorMoney flow index
0 Views
0 Downloads
0 Favorites
MFI_RSI_SAR_MA
ÿþ#property copyright "Copyright 2018, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

enum ENUM_HAN_ZEI

  {

   H00M00 =     0,   // 00:00

   H00M30 =  1800,   // 00:30

   H01M00 =  3600,   // 01:00

   H01M30 =  5400,   // 01:30

   H02M00 =  7200,   // 02:00

   H02M30 =  9000,   // 02:30

   H03M00 = 10800,   // 03:00

   H03M30 = 12600,   // 03:30

   H04M00 = 14400,   // 04:00

   H04M30 = 16200,   // 04:30

   H05M00 = 18000,   // 05:00

   H05M30 = 19800,   // 05:30

   H06M00 = 21600,   // 06:00

   H06M30 = 23400,   // 06:30

   H07M00 = 25200,   // 07:00

   H07M30 = 27000,   // 07:30

   H08M00 = 28800,   // 08:00

   H08M30 = 30600,   // 08:30

   H09M00 = 32400,   // 09:00

   H09M30 = 34200,   // 09:30

   H10M00 = 36000,   // 10:00

   H10M30 = 37800,   // 10:30

   H11M00 = 39600,   // 11:00

   H11M30 = 41400,   // 11:30

   H12M00 = 43200,   // 12:00

   H12M30 = 45000,   // 12:30

   H13M00 = 46800,   // 13:00

   H13M30 = 48600,   // 13:30

   H14M00 = 50400,   // 14:00

   H14M30 = 52200,   // 14:30

   H15M00 = 54000,   // 15:00

   H15M30 = 55800,   // 15:30

   H16M00 = 57600,   // 16:00

   H16M30 = 59400,   // 16:30

   H17M00 = 61200,   // 17:00

   H17M30 = 63000,   // 17:30

   H18M00 = 64800,   // 18:00

   H18M30 = 66600,   // 18:30

   H19M00 = 68400,   // 19:00

   H19M30 = 70200,   // 19:30

   H20M00 = 72000,   // 20:00

   H20M30 = 73800,   // 20:30

   H21M00 = 75600,   // 21:00

   H21M30 = 77400,   // 21:30

   H22M00 = 79200,   // 22:00

   H22M30 = 81000,   // 22:30

   H23M00 = 82800,   // 23:00

   H23M30 = 84600    // 23:30

  };



input string I = ""; // +----- Handelszeiten -----+

input ENUM_HAN_ZEI HandelsBeginn = H09M00; // Handelsbeginn

input ENUM_HAN_ZEI HandelsEnde = H21M00; // Handelsende



input string Ii = ""; // +----- Zeit und Preis für alle Indis und Osis -----+

input ENUM_TIMEFRAMES Zeit = PERIOD_CURRENT; // Zeit (M1, M5, M15 usw.)

input ENUM_APPLIED_PRICE Preis = PRICE_CLOSE; // Preis (Close, Open usw.)



input string II =""; // +----- Lots/SL/TP/TS -----+

extern double Lot=0; // Lot

extern double LotBalanceProz =1;

input double SLFaktor = 3; //SL Faktor

input double TPFaktor2 = 6; // TP Faktor



input string IIii = ""; // |----- Spread/Magic/Kommentar/Slippage/Pos. -----|

input int MaxSpread = 10; // Maximaler Spread

input int Magic= 1; // Magic Nummer

input string Commentary=""; // Kommentar

input int Slippage=5; // Slippage



input string IIIiii = ""; // --- RSI Einstellung ---

input int RSIPeriode = 13; // RSI Periode

input double RSIOben = 70; // RSI oben

input double RSIUnten = 30; // RSI unten

input int RSIMitte = 50; // RSI mitte

input string IIIiiii = ""; // --- SAR Einstellung als Signal ---

input double SARStep = 0.005; // SAR Step

input double MaxSARStep = 0.5; // MAX SAR Step

input string IIIiiiii = ""; // --- SAR Einstellung für SL/TP ---

input double SARStepSLTP = 0.05; // SL/TP SAR Step 

input double MaxSARStepSLTP = 0.3; // SL/TP MAX SAR Step

input string IIIiiiiii = ""; // --- BB Einstellung als Signal ---

input int BBPeriode = 20; // BB Periode

input double BBVersatz = 0; // BB Versatz

input double BBAbweichung = 2; // BB Abweichung

input string IIIiiiiiii = ""; // --- MFI Einstellung als Signal ---

input int MFIPeriode = 13; // MFI Periode

input double MFIOben = 80; // MFI oben

input double MFIUnten = 20; // MFI unten

input int MFIMitte = 50; // MFI Mitte

input string IIIiiiiiiii = ""; // --- MA Einstellung als Signal ---

input int MAPeriode = 200; // MA Periode

input ENUM_TIMEFRAMES Zeit1 = PERIOD_M15; // kleine Zeiteinheit

input ENUM_TIMEFRAMES Zeit2 = PERIOD_H1; // mittlere Zeiteinheit

input ENUM_TIMEFRAMES Zeit3 = PERIOD_H4; // große Zeiteinheit



datetime TradeStart, TradeEnd;

int orderTicket;





double spread;









void OnTick()

  {

   TradeStart = StringToTime(TimeToString(TimeCurrent(), TIME_DATE)) + HandelsBeginn;

   TradeEnd   = StringToTime(TimeToString(TimeCurrent(), TIME_DATE)) + HandelsEnde;

   double sar = iSAR(_Symbol,Zeit,SARStepSLTP,MaxSARStepSLTP,0);





Trailingstop();

  if(OrderSelect(orderTicket,SELECT_BY_TICKET)) 

     {

      if(OrderCloseTime()>0) 

        {

         orderTicket=0;

        }

     }



  if(TimeCurrent() < TradeStart || TimeCurrent() >= TradeEnd){return;}

     spread = MarketInfo(_Symbol,MODE_SPREAD);

     if(MaxSpread > 0 && MaxSpread < spread) {return;} 

     spread = spread * Point; { 

        if(orderTicket<=0)

     {

            if(checkMFI_SAR_MA()=="sell" || checkRSI_SAR_MA() == "sell") 

        {

            double entry = Bid;

            entry = NormalizeDouble(entry,_Digits);

                     

            double sl =sar;

            sl=NormalizeDouble(sl,_Digits);



                     

            double tp = 0;

            if(TPFaktor2 > 0) tp = entry - (sl - entry) * TPFaktor2;

            tp = NormalizeDouble(tp,_Digits);



            orderTicket= OrderSend(_Symbol,OP_SELL,CalcLot_Balance(),entry,Slippage,sl,tp,Commentary,Magic);

        }

        

            else if(checkMFI_SAR_MA()=="buy" || checkRSI_SAR_MA() == "buy") 

            {

            double entry = Ask;

            entry = NormalizeDouble(entry,_Digits);

            

            double sl =sar;

            sl=NormalizeDouble(sl,_Digits);

            

            

            double tp = 0;

            if(TPFaktor2 > 0) tp = entry + (entry - sl) * TPFaktor2;

            tp = NormalizeDouble(tp,_Digits); 

    

                                  

            orderTicket=OrderSend(_Symbol,OP_BUY,CalcLot_Balance(),entry,Slippage,sl,tp,Commentary,Magic);

            }

           }

          }

         }  



string checkRSI_SAR_MA(){

       string RSI_SAR_MA;

       double sarSignal = iSAR(_Symbol,Zeit,SARStep,MaxSARStep,1);

       double sarSignalAlt = iSAR(_Symbol,Zeit,SARStep,MaxSARStep,2);

       double rsi = iRSI(_Symbol,Zeit,RSIPeriode,Preis,1);

       double sar = iSAR(_Symbol,Zeit,SARStepSLTP,MaxSARStepSLTP,1);

       double sarAlt = iSAR(_Symbol,Zeit,SARStepSLTP,MaxSARStepSLTP,2);



       double BBOben = iBands(_Symbol,Zeit,BBPeriode,BBAbweichung,BBVersatz,Preis,MODE_UPPER,1); 

       double BBMitte = iBands(_Symbol,Zeit,BBPeriode,BBAbweichung,BBVersatz,Preis,MODE_MAIN,1);      

       double BBUnten = iBands(_Symbol,Zeit,BBPeriode,BBAbweichung,BBVersatz,Preis,MODE_LOWER,1);    

       

       double maCurrent = iMA(_Symbol,Zeit,MAPeriode,0,MODE_EMA,Preis,1);

       double maM15 = iMA(_Symbol,Zeit1,MAPeriode,0,MODE_EMA,Preis,1);

       double maH1 = iMA(_Symbol,Zeit2,MAPeriode,0,MODE_EMA,Preis,1);

       double maH4 = iMA(_Symbol,Zeit3,MAPeriode,0,MODE_EMA,Preis,1);

              

       if(BBMitte > maCurrent &&

          

          iOpen(_Symbol,0,2) > maCurrent &&

          iOpen(_Symbol,0,1) > maCurrent &&

          

          iOpen(_Symbol,0,2) > maM15 &&

          iOpen(_Symbol,0,1) > maM15 &&

          

          iOpen(_Symbol,0,2) > maH1 &&

          iOpen(_Symbol,0,1) > maH1 &&

          

          iOpen(_Symbol,0,2) > maH4 &&

          iOpen(_Symbol,0,1) > maH4 &&

          

          sarSignal > sar &&

          iClose(_Symbol,0,2) < sarSignalAlt &&

          iClose(_Symbol,0,1) > sarSignal &&

          rsi > RSIMitte &&

          rsi < RSIOben)

          {RSI_SAR_MA = "buy";}

          

          else if(BBMitte < maCurrent &&

                  

                  iOpen(_Symbol,0,2) < maCurrent &&

                  iOpen(_Symbol,0,1) < maCurrent &&

                  

                  iOpen(_Symbol,0,2) < maM15 &&

                  iOpen(_Symbol,0,1) < maM15 &&

                  

                  iOpen(_Symbol,0,2) < maH1 &&

                  iOpen(_Symbol,0,1) < maH1 &&

                  

                  iOpen(_Symbol,0,2) < maH4 &&

                  iOpen(_Symbol,0,1) < maH4 &&

          

                  sarSignal < sar &&

                  iClose(_Symbol,0,2) > sarSignalAlt &&

                  iClose(_Symbol,0,1) < sarSignal &&

                  rsi < RSIMitte &&

                  rsi > RSIUnten)

                  {RSI_SAR_MA = "sell";}

                  

                  return RSI_SAR_MA;

}

string checkMFI_SAR_MA(){

       string MFI_SAR_MA;

       double sarSignal = iSAR(_Symbol,Zeit,SARStep,MaxSARStep,1);

       double sarSignalAlt = iSAR(_Symbol,Zeit,SARStep,MaxSARStep,2);

       double mfi = iMFI(_Symbol,Zeit,MFIPeriode,1);

       double sar = iSAR(_Symbol,Zeit,SARStepSLTP,MaxSARStepSLTP,1);

       double sarAlt = iSAR(_Symbol,Zeit,SARStepSLTP,MaxSARStepSLTP,2);

       

       double BBOben = iBands(_Symbol,Zeit,BBPeriode,BBAbweichung,BBVersatz,Preis,MODE_UPPER,1);  

       double BBMitte = iBands(_Symbol,Zeit,BBPeriode,BBAbweichung,BBVersatz,Preis,MODE_MAIN,1);      

       double BBUnten = iBands(_Symbol,Zeit,BBPeriode,BBAbweichung,BBVersatz,Preis,MODE_LOWER,1);       

       

       double maCurrent = iMA(_Symbol,Zeit,MAPeriode,0,MODE_EMA,Preis,1);

       double maM15 = iMA(_Symbol,Zeit1,MAPeriode,0,MODE_EMA,Preis,1);

       double maH1 = iMA(_Symbol,Zeit2,MAPeriode,0,MODE_EMA,Preis,1);

       double maH4 = iMA(_Symbol,Zeit3,MAPeriode,0,MODE_EMA,Preis,1);

              

       if(BBMitte > maCurrent &&

          

          iOpen(_Symbol,0,2) > maCurrent &&

          iOpen(_Symbol,0,1) > maCurrent &&

          

          iOpen(_Symbol,0,2) > maM15 &&

          iOpen(_Symbol,0,1) > maM15 &&

          

          iOpen(_Symbol,0,2) > maH1 &&

          iOpen(_Symbol,0,1) > maH1 &&

          

          iOpen(_Symbol,0,2) > maH4 &&

          iOpen(_Symbol,0,1) > maH4 &&

          

          sarSignal > sar &&

          iClose(_Symbol,0,2) < sarSignalAlt &&

          iClose(_Symbol,0,1) > sarSignal &&

          mfi > MFIMitte &&

          mfi < MFIOben)

          {MFI_SAR_MA = "buy";}

          

          else if(BBMitte < maCurrent &&

                  

                  iOpen(_Symbol,0,2) < maCurrent &&

                  iOpen(_Symbol,0,1) < maCurrent &&

                  

                  iOpen(_Symbol,0,2) < maM15 &&

                  iOpen(_Symbol,0,1) < maM15 &&

                  

                  iOpen(_Symbol,0,2) < maH1 &&

                  iOpen(_Symbol,0,1) < maH1 &&

                  

                  iOpen(_Symbol,0,2) < maH4 &&

                  iOpen(_Symbol,0,1) < maH4 &&

          

                  sarSignal < sar &&

                  iClose(_Symbol,0,2) > sarSignalAlt &&

                  iClose(_Symbol,0,1) < sarSignal &&

                  mfi < MFIMitte &&

                  mfi > MFIUnten)

                  {MFI_SAR_MA = "sell";}

                  

                  return MFI_SAR_MA;

}



  double CalcLot_Balance()

   {

   double Lots=0;

   if(Lot>0)Lots=Lot;

   else Lots=MathFloor(AccountBalance()*LotBalanceProz*0.01/MarketInfo(NULL,MODE_MARGINREQUIRED)/MarketInfo(NULL,MODE_LOTSTEP))*MarketInfo(NULL,MODE_LOTSTEP);

   return(Lots);

   } 

void Trailingstop(){

      for(int i = 0; i < OrdersTotal(); i++) {

          if(OrderSelect(orderTicket,SELECT_BY_TICKET)){



       double sar = iSAR(_Symbol,Zeit,SARStepSLTP,MaxSARStepSLTP,1);

          double sl = NormalizeDouble(sar,_Digits);

          

                if(OrderType() == OP_BUY && Bid > sl && (sl > OrderStopLoss() || OrderStopLoss() == 0)) {

                  if(OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration())){

                     Print("Trade #"+IntegerToString(OrderTicket())+" Long Position wurde angepasst...");

                 }

                }

                else if(OrderType() == OP_SELL && Ask < sl && (sl < OrderStopLoss() || OrderStopLoss() == 0)) {

                  if(OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration())){

                     Print("Trade #"+IntegerToString(OrderTicket())+" Short Position wurde angepasst...");

       }

      }

     }

    }

   } 

  

      

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---