Cross Angry Miserable-EURUSD-M15 1.05

Author: Copyright � 2006, Don Perry
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategyIt Closes Orders by itself
Indicators Used
Moving average indicatorStandard Deviation indicatorRelative strength index
0 Views
0 Downloads
0 Favorites

Profitability Reports

GBP/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 2
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff 45.00
Gross Profit 90.00
Gross Loss 0.00
Total Net Profit 90.00
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 1
Won Trades 0
Lost trades 1
Win Rate 0.00 %
Expected payoff -80.00
Gross Profit 0.00
Gross Loss -80.00
Total Net Profit -80.00
-100%
-50%
0%
50%
100%
Cross Angry Miserable-EURUSD-M15 1.05
//+------------------------------------------------------------------+
//|                                       Cross Angry Miserable .mq4 |
//|                                      Copyright © 2006, Don Perry |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Don Perry"
#property link      "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
double EMAF;
double EMAS; 
double EMAF1;
double EMAS1; 
bool crossedUp=false;

int SBStat=0;
int FromHourTrade=7;
int ToHourTrade=20;
double RSI;
bool Firstry=true;
extern int FastPeriod=21;
extern bool UseHourTrade= true;
extern int SlowPeriod=55;
extern int SL=80;
extern int TakeProfit=100;
extern double Lots=1;
extern int TrailingStop=18;
extern int incTp=5;
extern int Risk=10;
extern bool MM = true;
extern int MaxTrades=2;
int ticket [];
 double RSITrend=0;
extern int Selectivity=37;
bool buying,selling;
int iTick=0;
double barsAVG=0;
int total;
int cnt;
int index;
bool sellable;
bool buyable;
double low,high;

int init()
  { 
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  { if(checkParams()!=0)
  {
  
  if( UseHourTrade ){
      if((( FromHourTrade <= ToHourTrade ) && ( Hour() < FromHourTrade || Hour() > ToHourTrade ))
         || // Allow for Overnight Trading
         (( FromHourTrade >  ToHourTrade ) && ( Hour() < FromHourTrade && Hour() > ToHourTrade ))
        ) {
         return(0);
      }

}
  
  CheckEquity();
//EMAF = iMA(NULL,PERIOD_M15,FastPeriod,0,MODE_EMA,PRICE_WEIGHTED,0); //fast
//EMAS = iMA(NULL,PERIOD_M15,SlowPeriod,0,MODE_EMA,PRICE_WEIGHTED,0); //slow
   
EMAF1 = iMA(NULL,0,FastPeriod,0,MODE_EMA,PRICE_TYPICAL,0); //fast
EMAS1 = iMA(NULL,0,SlowPeriod,0,MODE_EMA,PRICE_TYPICAL,0); //slow
double SDev = iStdDev(Symbol(),0,23,MODE_EMA,0,PRICE_TYPICAL,0)/Point;
RSI = iRSI(NULL,PERIOD_M1,27,PRICE_TYPICAL,0);
RSITrend =  iRSI(NULL,PERIOD_H4,Selectivity,PRICE_TYPICAL,0);

 if(MM==true) Lots = LotSize();


double difference2 =  MathAbs((EMAF1)-(EMAS1))/Point;

//Print(EMAF+"EMA FAst");
//Print(EMAS+"EMA Slow");

sellable=(RSI<45&&!selling);
buyable=(RSI>55&&!buying );
if(difference2<4) //remember this number was once 4
 {
if(buyable)// &&RSITrend>55
{//Closeall();
if(OrdersTotal()<=1)
 //if(difference<=30&&difference>0)
{Print("===========>buy"+difference2);

   
 
//Closeall();

iTick=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-(SL*Point),Ask+(TakeProfit*Point),"Cross Buy",16384,0,Lime);
 buying=true;
 selling=false;
}

 }
}





if(difference2<4)
{
if(sellable )//&&RSITrend<45
{
//Closeall(); 
if(OrdersTotal()<MaxTrades)
 //if(difference<=30&&difference>0)
{
Print("===========>sell"+difference2);
             
      
iTick=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+(SL*Point),Bid-(TakeProfit*Point),"Cross Sell",16384,0,Orange);
  
    buying=false;
 selling=true;    
       
}
}
}

}
 total  = OrdersTotal();
 
   
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     if(OrderTakeProfit()-Ask<incTp*Point)
                     {
                     OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit()+incTp*Point,0,Pink);
                   // Print("-=--=--=--=--=--=--"+"is the ask, TP="+OrderTakeProfit());
                     }
                     if(OrderOpenPrice()<Ask&&OrderStopLoss()<OrderOpenPrice())
                     {OrderModify(OrderTicket(),OrderOpenPrice(),Ask,OrderTakeProfit(),0,Pink);
                     }
                     return(0);
                    }
                 }
              }
           }
         else // go to short position
           {
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit()-incTp*Point,0,Red);
                    if(Bid-OrderTakeProfit()<incTp*Point)
                     {
                     OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit()-incTp*Point,0,Pink);
                   //  Print("-=--=--=--=--=--=--"+Bid+"is the ask, TP="+OrderTakeProfit());
                     }
                      if(OrderOpenPrice()>Bid&&OrderStopLoss()>OrderOpenPrice())
                     {OrderModify(OrderTicket(),OrderOpenPrice(),Ask,OrderTakeProfit(),0,Pink);
                     }
                     
                     return(0);
                    }
                 }
              }
           }
        }
     }
 
   return(0);
  }
//+------------------------------------------------------------------+

double LotSize()
{
     double lotMM = MathCeil(AccountFreeMargin() * Risk / 10000) / 10;
	  if (lotMM < 0.1) lotMM = Lots;
	  if (lotMM > 1.0) lotMM = MathCeil(lotMM);
	  if  (lotMM > 100) lotMM = 100;
	  return (lotMM);
}

int checkParams()
{if(DayOfWeek()>=5 && Hour()>=21){
         
         return(0);
      }
      
      
  if(Bars<100){
      Print("bars less than 100");
      return(0);
   }
   if(SL<10){
      Print("StopLoss less than 10");
      return(0);
   }
   if(TakeProfit<5){
      Print("TakeProfit less than 10");
      return(0);
   }
   if(TrailingStop<10){
      Print("StopLoss less than 10");
      return(0);
   }
 return(1);
  

}

 int CheckEquity()
 {double pcnt = 100+(AccountEquity()-AccountBalance())/AccountBalance()*100;
 //Print("Account equity = ",AccountEquity());
//Print("Account balance = ",AccountBalance());
//Print("EQ%= ",pcnt);
 if(false)// pcnt>180)
 { 

Closeall();
    // Print("ALL ORDERS CLOSE-->Locked in EQUITY Profit");
 }
 return(0);
 }
 
 void Closeall()
 {
 total=OrdersTotal();
 for(cnt=0;cnt<=total;cnt++)
     {OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
     OrderClose(OrderTicket(),OrderLots(),Ask,2,White);
     
     }   
 }

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