easyLMA_v6MM

Author: newdigital
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reached
Miscellaneous
It plays sound alerts
0 Views
0 Downloads
0 Favorites
easyLMA_v6MM
//+------------------------------------------------------------------+
//|                                                      easyLMA.mq4 |
//|                                        code by Newdigital        |
//|                                        http://www.forex-tsd.com  |
//|                                           using Gordago software |
//|                                          http://www.gordago.com  |
//|                                                                  |
//| 08.02.2006  easyLMA by idea of Easy fx                           |
//| (see the thread http://www.forex-tsd.com/members/easy-fx.html    |
//|  M30 timeframe                                                   |
//|  GBPUSD                                                          |
//+------------------------------------------------------------------+

#property copyright "newdigital"
#property link      "http://www.forex-tsd.com"

extern int MAGIC = 363278;

extern string PARAMETERS_TRADE = "PARAMETERS TRADE";
extern int Slippage = 4;
extern double lStopLoss = 60;
extern double sStopLoss = 60;
extern double lTakeProfit = 100;
extern double sTakeProfit = 100;
extern double lTrailingStop = 50;
extern double sTrailingStop = 50;

extern string PARAMETERS_EXPERT = "PARAMETERS EXPERT";
extern color clOpenBuy = Blue;
extern color clCloseBuy = Aqua;
extern color clOpenSell = Red;
extern color clCloseSell = Violet;
extern color clModiBuy = Blue;
extern color clModiSell = Red;
extern string Name_Expert = "easyLMA";
extern bool UseSound = False;
extern string NameFileSound = "alert.wav";
extern bool UseHourTrade = False;
extern int FromHourTrade = 8;
extern int ToHourTrade = 19;

extern string MONEY_MANAGEMENT = "LWC:0 fixed lot;1 % deposit;2-ratio fractional;3-fraction fixed"; 
#include <b-Lots.mqh>

extern string PARAMETERS_INDICATOR_ONE  = "Moving Average";
extern int MAsmallMode =  1; //0=sma, 1=ema, 2=smma, 3=lwma
extern double MAsmall = 55;
extern double MAbig = 200;
extern int MAbigMode =  1; //0=sma, 1=ema, 2=smma, 3=lwma

extern string PARAMETERS_INDICATOR_TWO = "Stochastic";
extern int KPeriod=14;
extern int DPeriod=5;
extern int Slowing=5;

extern string PARAMETERS_INDICATOR_THREE  = "Parabolic SAR";
extern double    Step=0.008;
extern double    Maximum=0.05;

extern string PARAMETERS_INDICATOR_FOUR  = "Parabolic SAR";
extern double    Step2=0.02;
extern double    Maximum2=0.2;

extern string PARAMETERS_INDICATOR_FIVE  = "I_XO_A_H";
extern int       BoxSize=34;










void deinit() {
   Comment("");
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start(){
   if (UseHourTrade){
      if (!(Hour()>=FromHourTrade && Hour()<=ToHourTrade)) {
         Comment("Time for trade has not come else!");
         return(0);
   }  
   }
   if(Bars<100){
      Print("bars less than 100");
      return(0);
   }
   if(lStopLoss<10){
      Print("StopLoss less than 10");
      return(0);
   }
   if(lTakeProfit<10){
      Print("TakeProfit less than 10");
      return(0);
   }
   if(sStopLoss<10){
      Print("StopLoss less than 10");
      return(0);
   }
   if(sTakeProfit<10){
      Print("TakeProfit less than 10");
      return(0);
   }

   double diMA0=iMA(NULL,0,MAsmall,0,MAsmallMode,PRICE_CLOSE,0);
   double diMA1=iMA(NULL,0,MAbig,0,MAbigMode,PRICE_CLOSE,0);
   double diMA2=iMA(NULL,0,MAsmall,0,MAsmallMode,PRICE_CLOSE,1);
   double diMA3=iMA(NULL,0,MAbig,0,MAbigMode,PRICE_CLOSE,1);
   double diStochastic4=iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MODE_EMA,PRICE_CLOSE,MODE_MAIN,0);
   double diStochastic5=iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MODE_EMA,PRICE_CLOSE,MODE_SIGNAL,0);
   double diSAR6=iSAR(NULL,0,Step,Maximum,1);
   double diSAR7=iSAR(NULL,0,Step,Maximum,0);
   double diSAR8=iSAR(NULL,0,Step2,Maximum2,1);
   double diSAR9=iSAR(NULL,0,Step2,Maximum2,0);
   double diIXO10=iCustom(NULL,0,"I_XO_A_H",BoxSize,0,0);
   double diMA11=iMA(NULL,0,MAsmall,0,MAsmallMode,PRICE_CLOSE,0);
   double diMA12=iMA(NULL,0,MAbig,0,MAbigMode,PRICE_CLOSE,0);
   double diMA13=iMA(NULL,0,MAsmall,0,MAsmallMode,PRICE_CLOSE,1);
   double diMA14=iMA(NULL,0,MAbig,0,MAbigMode,PRICE_CLOSE,1);
   double diStochastic15=iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MODE_EMA,PRICE_CLOSE,MODE_MAIN,0);
   double diStochastic16=iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MODE_EMA,PRICE_CLOSE,MODE_SIGNAL,0);
   double diSAR17=iSAR(NULL,0,Step,Maximum,1);
   double diSAR18=iSAR(NULL,0,Step,Maximum,0);
   double diSAR19=iSAR(NULL,0,Step2,Maximum2,1);
   double diSAR20=iSAR(NULL,0,Step2,Maximum2,0);
   double diIXO21=iCustom(NULL,0,"I_XO_A_H",BoxSize,1,0);
   double d22=(0);
   

   if(AccountFreeMargin()<(1000*Lots)){
      Print("We have no money. Free Margin = ", AccountFreeMargin());
      return(0);
   }
   if (!ExistPositions()){

      if ((diMA0>=diMA1 && diMA2<diMA3 && diStochastic4>diStochastic5 && diSAR6<diSAR7 && diSAR8<diSAR9 && diIXO10 > d22)){
         OpenBuy();
         return(0);
      }

      if ((diMA11<=diMA12 && diMA13>diMA14 && diStochastic15<diStochastic16 && diSAR17>diSAR18 && diSAR19>diSAR20 && diIXO21< d22)){
         OpenSell();
         return(0);
      }
   }
   TrailingPositionsBuy(lTrailingStop);
   TrailingPositionsSell(sTrailingStop);
   return (0);
}

bool ExistPositions() {
	for (int i=0; i<OrdersTotal(); i++) {
		if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
			if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
				return(True);
			}
		} 
	} 
	return(false);
}
void TrailingPositionsBuy(int trailingStop) { 
   for (int i=0; i<OrdersTotal(); i++) { 
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { 
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) { 
            if (OrderType()==OP_BUY) { 
               if (Bid-OrderOpenPrice()>trailingStop*Point) { 
                  if (OrderStopLoss()<Bid-trailingStop*Point) 
                     ModifyStopLoss(Bid-trailingStop*Point); 
               } 
            } 
         } 
      } 
   } 
} 
void TrailingPositionsSell(int trailingStop) { 
   for (int i=0; i<OrdersTotal(); i++) { 
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { 
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) { 
            if (OrderType()==OP_SELL) { 
               if (OrderOpenPrice()-Ask>trailingStop*Point) { 
                  if (OrderStopLoss()>Ask+trailingStop*Point || OrderStopLoss()==0)  
                     ModifyStopLoss(Ask+trailingStop*Point); 
               } 
            } 
         } 
      } 
   } 
} 
void ModifyStopLoss(double ldStopLoss) { 
   bool fm;
   fm = OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE); 
   if (fm && UseSound) PlaySound(NameFileSound); 
} 

void OpenBuy() { 
   double ldLot, ldStop, ldTake; 
   string lsComm; 
   ldLot = GetSizeLot(); 
   ldStop = GetStopLossBuy(); 
   ldTake = GetTakeProfitBuy(); 
   lsComm = GetCommentForOrder();
   Lots=GetSizeLot(); 
   OrderSend(Symbol(),OP_BUY,ldLot,Ask,Slippage,ldStop,ldTake,lsComm,MAGIC,0,clOpenBuy); 
   if (UseSound) PlaySound(NameFileSound); 
} 
void OpenSell() { 
   double ldLot, ldStop, ldTake; 
   string lsComm; 

   ldLot = GetSizeLot(); 
   ldStop = GetStopLossSell(); 
   ldTake = GetTakeProfitSell(); 
   lsComm = GetCommentForOrder();
   Lots=GetSizeLot(); 
   OrderSend(Symbol(),OP_SELL,ldLot,Bid,Slippage,ldStop,ldTake,lsComm,MAGIC,0,clOpenSell); 
   if (UseSound) PlaySound(NameFileSound); 
} 
string GetCommentForOrder() { 	return(Name_Expert); } 
double GetStopLossBuy() { 	return (Bid-lStopLoss*Point);} 
double GetStopLossSell() { 	return(Ask+sStopLoss*Point); } 
double GetTakeProfitBuy() { 	return(Ask+lTakeProfit*Point); } 
double GetTakeProfitSell() { 	return(Bid-sTakeProfit*Point); } 

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 ---