Escape Reverse V1.3

Profit factor:
0.52
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reached
Indicators Used
Stochastic oscillator
4 Views
0 Downloads
0 Favorites
Escape Reverse V1.3
//+------------------------------------------------------------------+
//|                                                      robotic.mq4 |
//|                                    Copyright © 2008, OGUZ BAYRAM |
//|                                            es_cape77@hotmail.com |
//+------------------------------------------------------------------+
extern int     MODE=MODE_EMA;
extern int     k=20;
extern int     d=7;
extern int     slowing=20;
extern int     Timeframe=5;

extern int       iTakeProfitCloseValue=300;
extern int       iTakeProfitMaxDecCount=300; 
extern int       maxtrades=60;
extern int       MaxSell=30;
extern int       MaxBuy=30;
extern int       Expiration=10;
static bool      bTakeProfitPrevious=-1;
static int       iTakeProfitDecraeseCount=0;
static int       iTakeProfitMaxValue=-1;
extern double lTakeProfit = 100;
extern double sTakeProfit = 100;
extern double lTrailingStop = 150;
extern double sTrailingStop = 150;
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 = "Robotic";
extern int Slippage = 1;
extern bool UseSound = false;
extern int MaxTradePerBar=5;

extern bool FractionalPips = true;
extern string NameFileSound = "Alert.wav";
extern double lotinc = 50000;
extern double StopLoss=0;

extern bool reverseLogic = true;
int magic_number = 013113324124;



int deinit(){return(0);}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start(){

    double SL = StopLoss;
    int totalOrderCount=OrdersTotal();
    for(int pos=0;pos<totalOrderCount;pos++)
    {
        if( OrderSelect(pos,SELECT_BY_POS)==false ) continue;
        //orderý seçtik þu an
        if (OrderSymbol() == Symbol()) //bu satýr sadece ea'yý attýðýnýz grafiðin sembolündeki para ile açýlan emirleriniz üzerinde iþlem yapmak için konuldu
        { 
            if ( OrderProfit() > 0 )
            {


                //TAKE PROFÝT DÜÞMEYE BAÞLARSA KAPAT
                //eðer kârdaysak ve peþpeþe iTakeProfitMaxDecCount sayýsýndan daha çok düþüþ yaþamýþsak, (TP: 100, 90, 80, 70 gibi, burada 4 kez düþüþ oldu demektir) pozisyonu hiç gözünün yaþýna bakmadan kapatýr
                //fakat kapatabilmek için birde istenilen minimum deðeri geçmiþmi bakýyorum hesabý þöyle (Profit > iTakeProfitCloseValue * 7.0) isterseniz bu kýsýtý kaldýrýn if'den 
                
                if (OrderProfit()> iTakeProfitMaxValue)
                iTakeProfitMaxValue = OrderProfit();

                if (bTakeProfitPrevious > OrderProfit())
                iTakeProfitDecraeseCount = iTakeProfitDecraeseCount + 1;
                else if (bTakeProfitPrevious < OrderProfit())
                {
                    iTakeProfitDecraeseCount = iTakeProfitDecraeseCount - 1;
                    if (iTakeProfitDecraeseCount<0)
                    iTakeProfitDecraeseCount = 0;
                }
                //Print(Symbol()," TPCount: ",iTakeProfitDecraeseCount);
                bTakeProfitPrevious = OrderProfit();         
                
                if (( iTakeProfitMaxDecCount <= iTakeProfitDecraeseCount) && (OrderProfit() >= (iTakeProfitCloseValue * 7.0))  )
                {
                    bool cticket;
                    Print(Symbol()," P:",Period()," take profit ",iTakeProfitDecraeseCount," kez düþtü kapattýk. Fiyat:",Ask);
                    /*if ( OrderType() == OP_BUY )
            {  
                    Print(Symbol()," P:",Period()," take profit ",iTakeProfitDecraeseCount," kez düþtü kapattýk. Fiyat:",Ask);
                    cticket = OrderClose(OrderTicket(),OrderLots(),Ask,3,Yellow);                    
            }
            if ( OrderType() == OP_SELL )
            {  
                    Print(Symbol()," P:",Period()," take profit ",iTakeProfitDecraeseCount," kez düþtü kapattýk. Fiyat:",Bid);
                    cticket = OrderClose(OrderTicket(),OrderLots(),Bid,3,Yellow);                    
            }*/

                    //yeni close iþlemi
                    double Price=OrderOpenPrice();       
                    int Ticket=OrderTicket();         
                    double Lot=OrderLots();           

                    //artýk pozisyonu kapatmayý kafaya koyduk hemen kapatýyoruz ama bazen broker kapatmýyor istediðimiz yerden, 
                    //onun için 7 kez peþ peþe deniyoruz
                    int AttemptCount=0;
                    while(true)                                 
                    {
                        switch(OrderType())                       
                        {
                        case 0: double Price_Cls=Bid;
                            string Text="Buy ";       
                            break;                    
                        case 1: Price_Cls=Ask;       
                            Text="Sell ";             
                        }
                        //Print("Kapatmaya çalýþýyoruz ",Text," ",Ticket);
                        bool Ans=OrderClose(Ticket,Lot,Price_Cls,2);

                        if (Ans==true)                            // kapantý
                        {
                            Print("Kapattýk :) ",Text," ",Ticket," Attemp: ",AttemptCount);
                            break;                                 //while'ý kýrýyoruz
                        }

                        //hata var tekrar deneyelim
                        Sleep(300);                
                        RefreshRates();   
                        AttemptCount++;  
                        if (AttemptCount > 7) break;       
                        continue;                  
                    }//while
                }//kapatma if'inin sonu







                //BURALAR STOP LOSS AYAR ÝÞLEMLERÝ 
                //SL YOKSA KOYARMI BÝLMÝYORUM DENEMEDÝM :)), 
                //BURASI SL'yi eðer kârda ise pozisyon daha iyi yere taþýr sürekli olarak, böylece sert dönüþlerde daha az zarar görmemize yarar
                int temp = -1;
                if (OrderType() == OP_BUY)
                {
                    double ftemp = SL;               
                    if (Digits > 4)
                    {  
                        ftemp = ftemp*MathPow(100,(Digits-4));//  
                    } else {
                        ftemp = ftemp*MathPow(100,(4-Digits));//                    
                    }
                    
                    if ( OrderStopLoss() < (Bid-ftemp*Point) )
                    {
                        OrderModify(OrderTicket(),OrderOpenPrice(),Bid-ftemp*Point,OrderTakeProfit(),0,Blue);
                    }
                    
                    temp = GetLastError();
                    if (temp>0)
                    {
                        Print(Symbol()," P: ",Period(),", ORDER DEÐÝÞTÝ HATA - SL: ", Bid-ftemp*Point," Err: ",temp);
                    }            
                } else {
                    double ftemp2 = SL;
                    if (Digits > 4)
                    {  
                        ftemp2 = ftemp2*MathPow(100,(Digits-4));//  
                    } else {
                        ftemp2 = ftemp2*MathPow(100,(4-Digits));//                    
                    }
                    
                    
                    if (OrderStopLoss() > ( Ask+ftemp2*Point ))
                    OrderModify(OrderTicket(),OrderOpenPrice(),Ask+ftemp2*Point,OrderTakeProfit(),0,Blue);
                    
                    temp = GetLastError();
                    if (temp>0)
                    {
                        Print(Symbol()," P: ",Period(),", ORDER DEÐÝÞTÝ HATA - SL:", Ask+ftemp2*Point," Err: ",temp);
                    }
                }//if orderType
                
            }//if orderprofit
        }//if ordersymbol
    }//for
    if(Bars<100){
        Print("bars less than 100");
        return(0);
    }
    if (Digits==3 || Digits==5)

    if(lTakeProfit<1){
        Print("TakeProfit less than 1");
        return(0);
    }
    if(sTakeProfit<1){
        Print("TakeProfit less than 1");
        return(0);
    }

    double diClose0=iClose(NULL,5,0);
    double diMA1=iMA(NULL,5,5,0,MODE_SMA,PRICE_OPEN,1);
    double diClose2=iClose(NULL,5,0);
    double diMA3=iMA(NULL,5,4,0,MODE_SMA,PRICE_OPEN,1);

    if(AccountFreeMargin()<(1000*AccountBalance()/lotinc)){
        Print("We have no money. Free Margin = ", AccountFreeMargin());
        return(0);
   }
   
   
int BuyCnt = 0;
int SellCnt = 0;

  
  int abo = OrdersTotal();
  for (int i=0; i < abo; i++) 
  {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
    //if (OrderSymbol() != Symbol()) continue;
    //if (OrderMagicNumber() != Magic) continue;
    
    int type = OrderType();
    if (type == OP_BUY) BuyCnt++;
    if (type == OP_SELL) SellCnt++;

  }
  
    if (!ExistPositions()){   // included by Frederik

        if ((diClose0<diMA1) && SellCnt<MaxSell && iStochastic(NULL,Timeframe,k,d,slowing,MODE,1,MODE_MAIN,0)<iStochastic(NULL,Timeframe,k,d,slowing,MODE,1,MODE_SIGNAL,0)){
            if (reverseLogic) OpenSell();
            else OpenBuy();
        }

        if ((diClose2>diMA3) && BuyCnt<MaxBuy && iStochastic(NULL,Timeframe,k,d,slowing,MODE,1,MODE_MAIN,0)>iStochastic(NULL,Timeframe,k,d,slowing,MODE,1,MODE_SIGNAL,0)){
            if (reverseLogic) OpenBuy();
            else OpenSell();
        }
    }
    TrailingPositionsBuy(lTrailingStop);
    TrailingPositionsSell(sTrailingStop);
    return (0);
}



bool ExistPositions() {
    for (int i=maxtrades-1; i<OrdersTotal(); i++) {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
            if (OrderSymbol()==Symbol()) {
                return(True);
            }
        } 
    } 
    return(false);
}
void TrailingPositionsBuy(int trailingStop) { 
    for (int i=maxtrades-1; i<OrdersTotal(); i++) { 
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { 
            if (OrderSymbol()==Symbol()) { 
                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=maxtrades-1; i<OrdersTotal(); i++) { 
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { 
            if (OrderSymbol()==Symbol()) { 
                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 = 0; 
    ldTake = GetTakeProfitBuy(); 
    lsComm = GetCommentForOrder(); 
    OrderSend(Symbol(),OP_BUY,ldLot,Ask,Slippage,ldStop,ldTake,lsComm,magic_number,0,clOpenBuy);
   
    //if (UseSound) PlaySound(NameFileSound); 
} 
void OpenSell() { 
    double ldLot, ldStop, ldTake; 
    string lsComm; 
    ldLot = GetSizeLot(); 
    ldStop = 0; 
    ldTake = GetTakeProfitSell(); 
    lsComm = GetCommentForOrder(); 
   
    OrderSend(Symbol(),OP_SELL,ldLot,Bid,Slippage,ldStop,ldTake,lsComm,magic_number,0,clOpenSell);
    
    //if (UseSound) PlaySound(NameFileSound); 
} 
string GetCommentForOrder() { return(Name_Expert); } 
double GetSizeLot() { return(AccountBalance()/lotinc); } 
double GetTakeProfitBuy() { return(Ask+lTakeProfit*Point); } 
double GetTakeProfitSell() { return(Bid-sTakeProfit*Point); } 

Profitability Reports

EUR/USD Jul 2025 - Sep 2025
0.00
Total Trades 871
Won Trades 841
Lost trades 30
Win Rate 96.56 %
Expected payoff -12228.80
Gross Profit 8255.77
Gross Loss -10659543.46
Total Net Profit -10651287.69
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.49
Total Trades 733
Won Trades 703
Lost trades 30
Win Rate 95.91 %
Expected payoff -10.87
Gross Profit 7711.69
Gross Loss -15677.23
Total Net Profit -7965.54
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.48
Total Trades 2369
Won Trades 2309
Lost trades 60
Win Rate 97.47 %
Expected payoff -3.18
Gross Profit 6947.70
Gross Loss -14473.04
Total Net Profit -7525.34
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.41
Total Trades 1094
Won Trades 1034
Lost trades 60
Win Rate 94.52 %
Expected payoff -5.44
Gross Profit 4190.18
Gross Loss -10140.89
Total Net Profit -5950.71
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.59
Total Trades 1828
Won Trades 1768
Lost trades 60
Win Rate 96.72 %
Expected payoff -3.88
Gross Profit 10012.59
Gross Loss -17111.07
Total Net Profit -7098.48
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.27
Total Trades 905
Won Trades 871
Lost trades 34
Win Rate 96.24 %
Expected payoff -9.60
Gross Profit 3173.30
Gross Loss -11865.77
Total Net Profit -8692.47
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.54
Total Trades 355
Won Trades 295
Lost trades 60
Win Rate 83.10 %
Expected payoff -17.50
Gross Profit 7437.00
Gross Loss -13648.10
Total Net Profit -6211.10
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.48
Total Trades 510
Won Trades 450
Lost trades 60
Win Rate 88.24 %
Expected payoff -12.79
Gross Profit 6052.47
Gross Loss -12573.19
Total Net Profit -6520.72
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.64
Total Trades 708
Won Trades 648
Lost trades 60
Win Rate 91.53 %
Expected payoff -8.00
Gross Profit 9916.91
Gross Loss -15582.43
Total Net Profit -5665.52
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.60
Total Trades 445
Won Trades 385
Lost trades 60
Win Rate 86.52 %
Expected payoff -14.25
Gross Profit 9519.60
Gross Loss -15862.68
Total Net Profit -6343.08
-100%
-50%
0%
50%
100%

Comments