FozzyExpert_v1.2

Author: Copyright � 2006, TrendLaboratory Ltd.
Price Data Components
Series array that contains open time of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
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 sends emails
0 Views
0 Downloads
0 Favorites
FozzyExpert_v1.2
//+------------------------------------------------------------------+
//|                                             FozzyExpert_v1.2.mq4 |
//|                           Copyright © 2006, TrendLaboratory Ltd. |
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |
//|                                   E-mail: igorad2003@yahoo.co.uk |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, TrendLaboratory Ltd."
#property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"

//---- input parameters
extern string     Expert_Name    = "FozzyExpert_v1.2";

extern int        Magic          = 10000;
extern int        Slippage       =     6;

extern string     Main_data      = " Trade Volume & Trade Method";
extern double     Lots           =   0.1;
extern double     TakeProfit     =     0;    // Take Profit Value 
extern double     InitialStop    =     0;    // Initial Stop Value
extern double     TrailingStop   =    25;    // Trailing Stop Value 
extern double     BreakEven      =    40;    // Break-Even Value
extern int        SessionStart   =     0;    // Start Hour of Trade Session 
extern int        SessionEnd     =    24;    // End Hour of Trade Session
 
extern string     Inputs         = " BBRSI & MA parameters ";
extern int        TimeFrame      =  1440;    // Large Time Frame in min
extern int        Price          =     0;    // O-Close; 1-Open; 2-High; 3-Low; 4-Median; 5-Typical; 6-Weighted 
extern int        RSIPeriod      =     8;    // Period of RSI
extern int        MAPeriod       =     8;    // Period of SMA
extern int        BBPeriod       =    20;    // BBands Period
extern double     K              =     1;    // Deviation ratio
extern int        Mode           =     0;    // RSI mode : 0 - typical(smoothed by SMMA); 1- clssic (smoothed by SMA)

extern string     MM_inputs      = " MoneyManagement by L.Williams ";
extern bool       MM             = false;    // ÌÌ Switch
extern double     MMRisk         =  0.15;    // Risk Factor
extern double     MaxLoss        =  1000;    // Maximum Loss by 1 Lot

int      OrderBar=0;
double   SellStop,BuyStop,SellProfit,BuyProfit, Lotsi;
bool     SignalMail=false;
bool     FirstTime=false;
int      BEvent=0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   
//----
   return(0);
  }

// ---- Scan Trades
int ScanTrades()
{   
   int total = OrdersTotal();
   int numords = 0;
      
   for(int cnt=0; cnt<total; cnt++) 
   {        
   OrderSelect(cnt, SELECT_BY_POS);            
   if(OrderSymbol() == Symbol() && OrderType()<=OP_SELLSTOP && OrderMagicNumber() == Magic) 
   numords++;
   }
   return(numords);
}  

int TradeSignal()
{   
   
   double RSI = iCustom(Symbol(),TimeFrame,"BBRSI&MA_v2",Price,RSIPeriod,MAPeriod,BBPeriod,K,Mode,0,1);
   double MA  = iCustom(Symbol(),TimeFrame,"BBRSI&MA_v2",Price,RSIPeriod,MAPeriod,BBPeriod,K,Mode,1,1);
   
   double prevRSI = iCustom(Symbol(),TimeFrame,"BBRSI&MA_v2",Price,RSIPeriod,MAPeriod,BBPeriod,K,Mode,0,2);
   double prevMA  = iCustom(Symbol(),TimeFrame,"BBRSI&MA_v2",Price,RSIPeriod,MAPeriod,BBPeriod,K,Mode,1,2);
   
   double UpBB  = iCustom(Symbol(),TimeFrame,"BBRSI&MA_v2",Price,RSIPeriod,MAPeriod,BBPeriod,K,Mode,2,1);   
   double DnBB  = iCustom(Symbol(),TimeFrame,"BBRSI&MA_v2",Price,RSIPeriod,MAPeriod,BBPeriod,K,Mode,3,1);   
   double MidBB = iCustom(Symbol(),TimeFrame,"BBRSI&MA_v2",Price,RSIPeriod,MAPeriod,BBPeriod,K,Mode,4,1);   
      
    
   if (TimeHour(CurTime()) >= SessionStart && TimeHour(CurTime()) <= SessionEnd)
   {
   if ( RSI > MA && prevRSI < prevMA && RSI < MidBB && RSI < UpBB ) return( 1);
   if ( RSI < MA && prevRSI > prevMA && RSI > MidBB && RSI > DnBB ) return(-1);
   }
}

double MoneyManagement ( bool flag, double Lots, double risk, double maxloss)
{
   Lotsi=Lots;
	    
   if ( flag ) Lotsi=Lots*NormalizeDouble(Lots*AccountFreeMargin()*risk/maxloss,1);   
     
   if (Lotsi<0.1) Lotsi=0.1;  
      
   return(Lotsi);
}   


void TrailStop()
{
   for (int cnt=0;cnt<OrdersTotal();cnt++)
   { 
   OrderSelect(cnt, SELECT_BY_POS);   
   int mode=OrderType();    
      if ( OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) 
      {
         if (mode==OP_BUY) 
         {
			   if ( BreakEven > 0 && BreakEven > TrailingStop && BEvent==0 )
			   {
			   double Gain = (Bid - OrderOpenPrice())/Point;
			      if( Gain >= BreakEven && OrderStopLoss()<=OrderOpenPrice()+1*Point) 
			      {
			      BuyStop = OrderOpenPrice()+1*Point;
			      BEvent=1;
			      }
			   }
			   else
			   if( TrailingStop > 0 && BEvent==1) BuyStop = Bid - TrailingStop*Point;
			   
			   if( OrderOpenPrice() <= BuyStop || OrderStopLoss() == 0 ) 
            {   
			      if ( BuyStop > OrderStopLoss() ) 
			      {
			      OrderModify(OrderTicket(),OrderOpenPrice(),
			                  NormalizeDouble(BuyStop, Digits),
			                  OrderTakeProfit(),0,LightGreen);
			         if( GetLastError()>0 )
                  {
                  Print("BUY: OrderModify failed with error #",GetLastError());
                  }
			      return(0);
               }            
            }
         }   
// - SELL Orders          
         if (mode==OP_SELL)
         {
            if ( BreakEven > 0 && BreakEven > TrailingStop && BEvent==0)
			   {
			   Gain = (OrderOpenPrice()-Ask)/Point;
			      if( Gain >= BreakEven && OrderStopLoss()>=OrderOpenPrice()-1*Point) 
			      {
			      SellStop = OrderOpenPrice()-1*Point;
			      BEvent=-1;
			      }
			   }
			   else
			   if( TrailingStop > 0 && BEvent==-1) SellStop = Ask + Point * TrailingStop;   
            
            if( OrderOpenPrice() > SellStop) 
            {
               if( OrderStopLoss() > SellStop || OrderStopLoss() == 0 ) 
               {
               OrderModify(OrderTicket(), OrderOpenPrice(),
                           NormalizeDouble(SellStop, Digits),
			                  OrderTakeProfit(),0,DarkOrange);
                  if( GetLastError()>0 )
                  {
                  Print("SELL: OrderModify failed with error #",GetLastError());
                  }
               return(0);
               }   
   			}	    
         }
      }
   }     
}

// ---- Open Sell Orders
void SellOrdOpen()
{		     
   double SellPrice = Bid;
   double StopPrice = Bid;
   int    Mode = OP_SELL;
        	  
   if (InitialStop > 0) SellStop  = StopPrice + InitialStop*Point; 
	else SellStop = iHigh(Symbol(),TimeFrame,1);
   if (TakeProfit  > 0) SellProfit = SellPrice - TakeProfit*Point; 
   else SellProfit=0;
   
	int ticket = OrderSend( Symbol(),Mode,MoneyManagement ( MM, Lots, MMRisk, MaxLoss),
	                        NormalizeDouble(SellPrice , Digits),
	                        Slippage,
	                        NormalizeDouble(SellStop  , Digits),
	                        NormalizeDouble(SellProfit, Digits),
	                        Expert_Name+" SELL",Magic,0,Red);
   
   if(ticket > 0) 
   {
      if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)) 
      {
		OrderBar =iBars(OrderSymbol(),TimeFrame);
		Print("SELL order opened : ", OrderOpenPrice());
      BEvent=0;
      if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
		}
   }
	else 	
   if(GetLastError()>0)
   Print("SELL: OrderSend failed with error #",GetLastError());
   
   return(0);
}
// ---- Open Buy Orders
void BuyOrdOpen()
{		     
   double BuyPrice  = Ask;
   double StopPrice = Ask;
   int    Mode      = OP_BUY;
      
   if (InitialStop > 0) BuyStop  = StopPrice - InitialStop*Point; 
	else BuyStop = iLow(Symbol(),TimeFrame,1);
   if (TakeProfit  > 0) BuyProfit= BuyPrice + TakeProfit*Point;  
   else BuyProfit=0;  
		 
	int ticket = OrderSend(Symbol(),Mode, MoneyManagement ( MM, Lots, MMRisk, MaxLoss),
	                   NormalizeDouble(BuyPrice , Digits),
	                   Slippage,
	                   NormalizeDouble(BuyStop  , Digits), 
	                   NormalizeDouble(BuyProfit, Digits),
	                   Expert_Name+" BUY",Magic,0,Blue);
      
   if(ticket > 0) 
   {
      if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)) 
      {
		OrderBar =iBars(OrderSymbol(),TimeFrame); 
		Print("BUY order opened : ", OrderOpenPrice());
      BEvent=0;
      if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
		}
   }
	else 	
   if(GetLastError()>0)      
   Print("BUY : OrderSend failed with error #",GetLastError());

   return(0);
} 

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
  if(iBars(Symbol(),TimeFrame)< 100 || IsTradeAllowed()==false) return; 
      
  if(AccountFreeMargin()< 1000*MoneyManagement ( MM, Lots, MMRisk, MaxLoss))
  {
  Print("We have no money. Free Margin = ", AccountFreeMargin());
  return(0);  
  }
    
  if (ScanTrades()<1 && ( iBars(Symbol(),TimeFrame) != OrderBar || !FirstTime))
  {
  if (TradeSignal()>0) {BuyOrdOpen() ;FirstTime=true;}
  if (TradeSignal()<0) {SellOrdOpen();FirstTime=true;}
  
  }
  else
  {
  if(BreakEven>0 || TrailingStop>0) TrailStop();
  }
  
//----
   return(0);
} //start()
//+------------------------------------------------------------------+

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