FXCasino_v1





//+------------------------------------------------------------------+
//|                                                  FXCasino_v1.mq4 |
//|                                  Copyright © 2006, Forex-TSD.com |
//|                         Written by IgorAD,igorad2003@yahoo.co.uk |   
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |                                      
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link      "http://www.forex-tsd.com/"

//---- input parameters
extern string     Expert_Name = "---- FXCasino_v1 ----";

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

extern string     Main_Parameters = " Trade Volume & Trade Method";
extern double     Lots           =     0.1;    // Lot size
extern bool       StopTrade      =   false;  // Stop of Trade switch

extern string     Data = " Input Data ";

extern int        TimeZone       =       0; // Difference between server time and local time   
extern int        StartTime      =       0; // Start time for openning of orders 
extern int        FinTime        =      23; // Time of closing pending orders
extern double     BetSize        =      50; // Bet Size in pips
extern bool       UseMM          =    true; // MM Switch
extern int        SpinNumber     =     100; // Min Number of Spins(Trades) for Profit
extern double     DeltaLong      =      10; // Momentum Filter for Long in pips
extern double     DeltaShort     =      10; // Momentum Filter for Short in pips
extern bool       UseSound       =    true; // Roulette Sound Switch

int      cnt=0, ticket, mode=0, digit=0, numords, CountLong, CountShort, trade, contr =0;
double   SellProfit=0,BuyProfit=0, Bulls, Bears, SigBulls, SigBears, Bulls1, Bears1, SigBulls1, SigBears1;
double   BuyStop=0, SellStop=0, SL = 0, Lotsi=0, PrevLotsi;
bool     BuyInTrade=false, SellInTrade=false;

int      OrdDel;
double   pastpips[];


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 

//----
   return(0);
  }
  
// ---- Money Management
double MoneyManagement (int flag)
{
   if(flag>0)
   { 
   PastTradeProfit();
   double PastProfit = pastpips[1];
   if ( PastProfit < 0 ) Lotsi += Lots;
   else Lotsi -= Lots;
   if(Lotsi<Lots) Lotsi=Lots;
   }
   else Lotsi=Lots;
   return(Lotsi);
}   

// ---- Open Sell Orders
void SellOrdOpen()
{		     

   
	double SellPrice=Low[1] - DeltaShort*Point;	  
	  if (BetSize   > 0) 
	  {
	  SellStop  = SellPrice + 0.1*BetSize/Lots*Point; 
     SellProfit= SellPrice - 0.1*BetSize/Lots*Point;
     }
     else
     {SellStop  = 0; SellProfit = 0;}
      
	     
	ticket = OrderSend( Symbol(),OP_SELLSTOP,Lotsi,
	                    NormalizeDouble(SellPrice, digit),
	                    Slippage,
	                    NormalizeDouble(SellStop , digit),
	                    NormalizeDouble(SellProfit   , digit),
	                    "SELL",Magic,0,Red);
            
   SellInTrade=false;            
            
      if(ticket<0)
      {
      Print("SELLSTOP: OrderSend failed with error #",GetLastError());
      }
 
   return(0);
}

// ---- Open Buy Orders
void BuyOrdOpen()
{		     

   
	double BuyPrice =High[1] + DeltaLong*Point;
	
	  if ( BetSize > 0) 
	  {
	  BuyStop = BuyPrice - 0.1*BetSize/Lots*Point; 
     BuyProfit=BuyPrice + 0.1*BetSize/Lots*Point;    
	  }
	  else
	  {BuyStop=0;BuyProfit=0;} 
	  
		 
   ticket = OrderSend(Symbol(),OP_BUYSTOP, Lotsi,
	                   NormalizeDouble(BuyPrice, digit),
	                   Slippage,
	                   NormalizeDouble(BuyStop , digit), 
	                   NormalizeDouble(BuyProfit  , digit),
	                   "BUY",Magic,0,Blue);
                
   BuyInTrade=false;            
            
   if(ticket<0)
   {
   Print("BUYSTOP: OrderSend failed with error #",GetLastError());
   //return(0);
   }
   return(0);
}      

// ---- Delete Extra Orders
void ExtraOrdDel()
{
   int total = OrdersTotal();
   for (cnt=0;cnt<total;cnt++)
   { 
   OrderSelect(cnt, SELECT_BY_POS);   
   mode=OrderType();
      if ( OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)     
      {
         if (mode==OP_BUY  && !BuyInTrade) BuyInTrade =true; 
        
         if (mode==OP_SELL && !SellInTrade) SellInTrade=true;

         if (mode > OP_SELL && (BuyInTrade || SellInTrade)) 
         {
         OrderDelete(OrderTicket());
         }
      }
   }        
}
// ---- Scan Trades
int ScanTrades()
{   
   int total = OrdersTotal();
   numords = 0;
      
   for(cnt=0; cnt<total; cnt++) 
   {        
   OrderSelect(cnt, SELECT_BY_POS);            
   if(OrderSymbol() == Symbol() && OrderType()>=OP_BUY && OrderMagicNumber() == Magic) 
   numords++;
   }
   return(numords);
}

// Closing of Pending Orders      
void PendOrdDel()
{
    int total=OrdersTotal();
    for (int cnt=total-1;cnt>=0;cnt--)
    { 
      OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES);   
      
        if ( OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)   
        {
        int mode=OrderType();
        
        bool result = false;
          switch(mode)
          {
            
            case OP_BUYSTOP   : result = OrderDelete( OrderTicket() ); 
          
            case OP_SELLSTOP  : result = OrderDelete( OrderTicket() ); 
          if(!result)
            {
            Print("OrderSend failed with error #",GetLastError());
            }
          OrdDel = 1;
          return(0); 
          }
        }
      } 
  return;
  }    


void PastTradeProfit()
{
   double Balance=0;
   int total=HistoryTotal(), n=0;
   ArrayResize(pastpips,total);
   for (int cnt=total-1;cnt>=0;cnt--) 
   {
      if ( OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)     
      {
         if (!OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY) && OrderType() > OP_SELL ) continue;
         
         if (OrderType()==OP_BUY)
         {n = n+1;
         pastpips[n] = MathRound((OrderClosePrice()-OrderOpenPrice())/MarketInfo(Symbol(),MODE_POINT));}
         
         if (OrderType()==OP_SELL)
         {n = n+1;
         pastpips[n] = MathRound((OrderOpenPrice()-OrderClosePrice())/MarketInfo(Symbol(),MODE_POINT));}
         Balance = Balance + pastpips[n];
      }
   if ( n > SpinNumber && Lotsi==Lots && Balance>0) StopTrade = true;
   }
} 


//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
   if(Bars < 1) {Print("Not enough bars for this strategy");return(0);}
   
   if(AccountFreeMargin()<(1000*Lots)){
   Print("We have no money. Free Margin = ", AccountFreeMargin());
   return(0);}
//---- 

   int start  = StartTime + TimeZone;
   int finish = FinTime   + TimeZone;  
      
   digit  = MarketInfo(Symbol(),MODE_DIGITS);
   double Tolernce = 5;
   
   if(!StopTrade && ScanTrades()==0 && (Hour() >= start && Hour() < finish ) && CurTime()>= Time[0] && CurTime()<= Time[0]+60)
   {
   if ( OrdDel == 0) Lotsi = MoneyManagement(UseMM);
   else Lotsi=PrevLotsi;
      if (!StopTrade)
      {
      if(UseSound) PlaySound("rulette.wav");
      BuyOrdOpen();
      SellOrdOpen();
      PrevLotsi=Lotsi;
      OrdDel = 0;
      }
   }

   if (ScanTrades()>0) 
   {
   ExtraOrdDel();
   if (Hour() >= finish || StopTrade) {PendOrdDel();} 
   }
   
 return(0);
}//int start
//+------------------------------------------------------------------+









Sample





Analysis



Market Information Used:

Series array that contains the lowest prices of each bar
Series array that contains the highest prices of each bar
Series array that contains open time of each bar


Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders


Other Features:

It plays sound alerts