CashMachine

Author: Copyright � 2008, Mark Johnson.
Price Data Components
Series array that contains close prices for each bar
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Moving average indicatorRelative strength index
0 Views
0 Downloads
0 Favorites

Profitability Reports

GBP/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
CashMachine
//+------------------------------------------------------------------+
//|                                                  Cashmachine.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Mark Johnson."
#property link      "mark.johnson.uk@hotmail.com"

//+------------------------------------------------------------------+
//| Input parameters                                                 |
//+------------------------------------------------------------------+

extern int TakeProfit=10;

extern string Base="EURUSD";
extern string Hedge="USDCHF";

extern int EMAShortPeriod=8;
extern int EMALongPeriod=21;

//+------------------------------------------------------------------+
//| Lets start trading                                               |
//+------------------------------------------------------------------+

int start()

  {

    double FastEMA=0, SlowEMA=0, RSI=0, CorDiff=0;
     
    if( TotalProfit() > TakeProfit )
  
      {
      CloseOrders();
      }

    if( Day() > 5 || ( Day() == 5 && Hour() > 18 ) )
  
      {
      return(0);
      }
   
    FastEMA = iMA(Base,0,EMAShortPeriod,0,MODE_EMA,PRICE_CLOSE,1);

    SlowEMA = iMA(Base,0,EMALongPeriod,0,MODE_EMA,PRICE_CLOSE,1);

    RSI     = iRSI(Base,0,14,PRICE_CLOSE,0);
    
    CorDiff = Cor(Base,Hedge);
         
    if( OrdersTotal() == 0 )
    
      {
      
        if( FastEMA-SlowEMA > 0 && RSI <= 30 && CorDiff < 0 )
      
          {

            if( IsTradeAllowed() )
        
                {
          
                OrderSend(Base,OP_BUY,LotsOptimized(),MarketInfo(Base,MODE_ASK),3,0,0,Base,255,0,CLR_NONE);
          
                OrderSend(Hedge,OP_BUY,LotsOptimized(),MarketInfo(Hedge,MODE_ASK),3,0,0,Hedge,255,0,CLR_NONE);
          
                }

          }
         
       if( FastEMA-SlowEMA < 0 && RSI >= 70 && CorDiff < 0 )
      
         {

            if( IsTradeAllowed() )
        
                {
          
                OrderSend(Base,OP_SELL,LotsOptimized(),MarketInfo(Base,MODE_BID),3,0,0,Base,255,0,CLR_NONE);

                OrderSend(Hedge,OP_SELL,LotsOptimized(),MarketInfo(Hedge,MODE_BID),3,0,0,Hedge,255,0,CLR_NONE);
          
                }
       
          }
        
      }
            
    return(0);
   
  }

//+------------------------------------------------------------------+
//| CLOSE ORDERS                                                     |
//+------------------------------------------------------------------+

bool CloseOrders()

  {  

  if( IsTradeAllowed() )
  
    {
    
    for(int i = OrdersTotal() - 1; i >= 0; i--)

      {         

      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) )

        {

        OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), MarketInfo(OrderSymbol(), MODE_SPREAD), CLR_NONE);

        }

      }
      
    }

  RefreshRates();

  }   

//+------------------------------------------------------------------+
//| CORRELATION                                                      |
//+------------------------------------------------------------------+

double symboldif(string symbol, int shift)

  {

   return(iClose(symbol, 1440, shift) - 
          iMA(symbol, 1440, Period(), 0, MODE_SMA, PRICE_CLOSE, shift));

  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

double powdif(double val)

  {

   return(MathPow(val, 2));

  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

double u(double val1, double val2)

  {

   return((val1*val2));

  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

double Cor(string base, string hedge)

  {  

   double u1 = 0, l1 = 0, s1 = 0;

   for(int i = Period() - 1; i >= 0; i--)

     {

       u1 += u(symboldif(base, i), symboldif(hedge, i));

       l1 += powdif(symboldif(base, i));

       s1 += powdif(symboldif(hedge, i));

     }

   if(l1*s1 > 0) 
       return(u1 / MathSqrt(l1*s1));

  }

//+------------------------------------------------------------------+
//| TOTAL PROFIT                                                     |
//+------------------------------------------------------------------+

double TotalProfit()

  {   

   double MyCurrentProfit = 0;

   for(int cnt = 0; cnt < OrdersTotal(); cnt++)

     {

       OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

       MyCurrentProfit += (OrderProfit() + OrderSwap());

     }

   return(MyCurrentProfit);

  }

//+------------------------------------------------------------------+
//| LOTS OPTIMIZED                                                   |
//+------------------------------------------------------------------+

double LotsOptimized()
  
  {
  
  double Lots = 0;
  
  Lots = NormalizeDouble( AccountFreeMargin() / 100000, 1 );
    
  if( Lots < 0.1 ) Lots = 0.1;
  
    return( Lots );
  
  }

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