I want ea to detect 3 lows and 3 high with loop bars

Back to topics list To post a new topic, please log in or register
avatar
4
icoword 2015.09.18 20:09
 

I have spent too much time to developed ea that will detect 3 low and 3 high in the loop bar count. I created three loop called Total_Bars1, Total_Bars2, Total_Bars3 respectively. Like give same low for minimum 1, minimum 2 minimum 3 also for maximum 1 , maximum 2, maximum 3. I created three loop count instead of one loop.

I need help to correct this code.

//+------------------------------------------------------------------+

//|                                                       RSI EA.mq4 |

//|                        Copyright 2015, MetaQuotes Software Corp. |

//|                           http://free-bonus-deposit.blogspot.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2015, dXerof"

#property link      "http://free-bonus-deposit.blogspot.com"

#property version   "1.00"

#property strict

extern int Total_Bars1=15;                       // Amount of bars

extern int Total_Bars2=30;                       // Amount of bars

extern int Total_Bars3=45;                       // Amount of bars

bool New_Bar=false;                             // Flag of a new bar

extern int Max_Buy = 3;

extern int Max_Sell = 3;

input int    MagicNumber=123; 

input string Koment="RSIea";


input double StopLoss=100;

input double TakeProfit=100;

input int RSIperiod=14;

input double BuyLevel=30;

input double SellLevel=70;

input bool   AutoLot=True;

input double Risk=10;

input double ManualLots=0.1;

input int Slippage=10;

int OrderBuy,OrderSell;

int ticket;

int LotDigits;

double

   Level_1=1.2850,                          // Set level 1

   Level_2=1.2800,                          // Set level 2

   Price=Bid;                               // Request price

   double Minimum1,                              // Minimal price

          Minimum2,ref=0.8810,

          Maximum1, buy1,buy2,buy3,                             // Maximal price

          Maximum2,sell1,sell2,sell3,          

          Minimum3,dif1,dif2, dif3,

          Maximum3;

//-

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int start()

  {

//--------------------------------------------------------------------

   int Ind_max1 =ArrayMaximum(High,Total_Bars1,0);// Bar index of max. price 

   int Ind_min1 =ArrayMinimum(Low, Total_Bars1,0);// Bar index of min. price 

   int Ind_max2 =ArrayMaximum(High,Total_Bars2,0);// Bar index of max. price 

   int Ind_min2 =ArrayMinimum(Low, Total_Bars2,0);// Bar index of min. price 

   int Ind_max3 =ArrayMaximum(High,Total_Bars3,0);// Bar index of max. price 

   int Ind_min3 =ArrayMinimum(Low, Total_Bars3,0);// Bar index of min. price 

   Maximum1=High[Ind_max1];                       // Desired max. price

   Minimum1=Low[Ind_min1];                        // Desired min. price

   Maximum2=High[Ind_max2];                       // Desired max. price

   Minimum2=Low[Ind_min2];                        // Desired min. price

   Maximum3=High[Ind_max3];                       // Desired max. price

   Minimum3=Low[Ind_min3];                        // Desired min. price

   double Total =3;

   // (Max_Buy + Max_Sell);

//+------------------------------------------------------------------+

//| Calculate open positions                                         |

//+------------------------------------------------------------------+


   for(int i=0;i<Total;i++)

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;

      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)

        {

         if(OrderType()==OP_BUY)  Max_Buy++;

         if(OrderType()==OP_SELL) Max_Sell++;

        }

        if(Max_Buy>0) return(Max_Buy);

          else return(-Max_Sell);


     }

//--- return orders volume

     

//+------------------------------------------------------------------+

//.................................................................................

   dif3= (Maximum3-Minimum3); 

   if (Maximum1<=Maximum2 && Maximum2 <= Maximum3)

   if (dif3>=ref && Bid >=Maximum3)

   sell3=dif3;OPSELL(); 

 

   //..................................................................................

   if (Minimum1<=Minimum2 && Minimum2 <= Minimum3)

   if (dif3>=ref && Bid >=Minimum3)

    buy3=dif3; OPBUY();

   

 //...................................................................................  

   dif2= (Maximum2-Minimum2); 

   if (Maximum2<=Maximum1)

   if (dif2>=ref && Bid >=Maximum2)

   sell2=dif2;OPSELL();

 

 //...................................................................................  

   dif2= (Maximum2-Minimum2); 

   if (Minimum2>=Minimum1)

   if (dif2>=ref && Bid >=Minimum2)

   buy2=dif2;OPBUY();

   //.....................................................................  

   dif1= (Maximum1-Minimum1); 

   if (dif1>=ref && Bid >=Maximum1)

   sell1=dif1;OPSELL();

    //................................................................... 

   dif1= (-Maximum1+Minimum1); 

  if (dif1>=ref && Bid <=Minimum1)

      buy1=dif1; OPSELL();

   // Alert("For the last ",Total_Bars1,            // Show message  

  // " Pip_Div = ",buy1,"Min bar=",Minimum1,"High bar=","Max bar=",Maximum1); 

//.............................................................

  

double rsi=iRSI(Symbol(),0,RSIperiod,PRICE_CLOSE,0);//feature not used

double rsi1=iRSI(Symbol(),0,RSIperiod,PRICE_CLOSE,1); //feature not used


//open position

double MA1=iMA(Symbol(),PERIOD_M5,6,0,MODE_EMA,PRICE_TYPICAL,0); //Defines the moving average.

double MA2=iMA(Symbol(),PERIOD_M5,3,0,MODE_EMA,PRICE_TYPICAL,0); //Defines the moving average.


  if(Max_Sell<1 && Price <= MA1)CloseSell();

  if(Max_Buy<1 && Price >= MA1)CloseBuy(); 

   

//close position by signal

//double minProfit = -100000000;

//int minTicket = 0;


int timeout=5; // minutes

for (int cnt=0; cnt<Total; cnt++) {

   if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))

   if ((TimeCurrent()-OrderOpenTime())>=(60*timeout)) {

      if (OrderType()==OP_BUY) {

         ticket=OrderClose(OrderTicket(),OrderLots(),Bid,0,Red);

      }

      if (OrderType()==OP_SELL) {

        ticket= OrderClose(OrderTicket(),OrderLots(),Ask,0,Red);

      }

   }

}

//if (OP_BUY>=minProfit) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(), MODE_BID), 5, Red); 

//if ( OrderType() == OP_SELL ) OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); 

     

return(0);

     

  }

  

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void OPBUY()

  {

   double StopLossLevel;

   double TakeProfitLevel;

   if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0;

   if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0;


   ticket=OrderSend(Symbol(),OP_BUY,LOT(),Ask,Slippage,StopLossLevel,TakeProfitLevel,Koment,MagicNumber,0,DodgerBlue);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void OPSELL()

  {

   double StopLossLevel;

   double TakeProfitLevel;

   if(StopLoss>0) StopLossLevel=Ask+StopLoss*Point; else StopLossLevel=0.0;

   if(TakeProfit>0) TakeProfitLevel=Bid-TakeProfit*Point; else TakeProfitLevel=0.0;


   ticket=OrderSend(Symbol(),OP_SELL,LOT(),Bid,Slippage,StopLossLevel,TakeProfitLevel,Koment,MagicNumber,0,DeepPink);


  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void CloseSell()

  {

   int  total=OrdersTotal();

   for(int y=OrdersTotal()-1; y>=0; y--)

     {

      if(OrderSelect(y,SELECT_BY_POS,MODE_TRADES))

         if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && OrderMagicNumber()==MagicNumber)

           {

            ticket=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,Black);

           }

     }

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void CloseBuy()

  {

   int  total=OrdersTotal();

   for(int y=OrdersTotal()-1; y>=0; y--)

     {

      if(OrderSelect(y,SELECT_BY_POS,MODE_TRADES))

         if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderMagicNumber()==MagicNumber)

           {

            ticket=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,Black);

           }

     }

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

double LOT()

  {

   double lotsi;

   double ilot_max =MarketInfo(Symbol(),MODE_MAXLOT);

   double ilot_min =MarketInfo(Symbol(),MODE_MINLOT);

   double tick=MarketInfo(Symbol(),MODE_TICKVALUE);


   double  myAccount=AccountBalance();


   if(ilot_min==0.01) LotDigits=2;

   if(ilot_min==0.1) LotDigits=1;

   if(ilot_min==1) LotDigits=0;


   if(AutoLot)

     {

      lotsi=NormalizeDouble((myAccount*Risk)/1000000,LotDigits);

        } else { lotsi=ManualLots;

     }


   if(lotsi>=ilot_max) { lotsi=ilot_max; }


   return(lotsi);

  }



 

avatar
13010
WHRoeder 2015.09.19 00:27 #
 
Don't paste code
Play video
Please edit your post.
For large amounts of code, attach it.
Back to topics list  

To add comments, please log in or register