FOREX CASH COW - MM - MN

Author: Copyright � 2007, GwadaTradeBoy Software Corp.
Price Data Components
Series array that contains open time of each bar
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
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
98.00 %
Total Trades 15
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -0.10
Gross Profit 59.10
Gross Loss -60.60
Total Net Profit -1.50
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
18.00 %
Total Trades 13
Won Trades 1
Lost trades 12
Win Rate 0.08 %
Expected payoff -3.62
Gross Profit 10.40
Gross Loss -57.40
Total Net Profit -47.00
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
13.00 %
Total Trades 15
Won Trades 1
Lost trades 14
Win Rate 0.07 %
Expected payoff -4.69
Gross Profit 10.10
Gross Loss -80.50
Total Net Profit -70.40
-100%
-50%
0%
50%
100%
FOREX CASH COW - MM - MN
//+------------------------------------------------------------------+
//|                                               FOREX CASH COW.mq4 |
//|                   Copyright © 2007, GwadaTradeBoy Software Corp. |
//|                                           GwadaTradeBoy@yahoo.fr |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, GwadaTradeBoy Software Corp."
#property link      "GwadaTradeBoy@yahoo.fr"

//---- Conditions
extern int     Delta       = 140;
extern int     Rule2Dist   = 70;
extern int     Rule3Dist   = 30;
extern int     SL          = 60;
extern int     TP          = 100;

//---- Variables
int            PrevBarHiLo, LastDayTrade,ecnt, total;
int            JT_SL,                                 // Jumlah Trades Sell Limit
               JT_BL,                                 // Jumlah Trades Buy Limit
               JT_SS,                                 // Jumlah Trades Sell Stop
               JT_BS,                                 // Jumlah Trades Buy Stop
               JT_OS,                                 // Jumlah Trades Open Sell
               JT_OB;                                 // Jumlah Trades Open Buy
double         PriceRule2, PriceRule3;

//---- Money Management
extern bool    MoneyManagement   = true;
extern double  Lots              = 0.1;
extern double  MaximumRisk       = 0.02;
extern double  DecreaseFactor    = 3;
extern bool    AcountIsMini      = false;
double   lot;
int      orders, losses, spread;

//----- Identification
extern int     MagicEA           = 080307;
extern string  NameEA            = "Forex Cash Cow";

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
   {
//---- Expert Advisor
      spread = MarketInfo(Symbol(),MODE_SPREAD);
//----
      return(0);
   }

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
   {
//----
      
//----
      return(0);
   }

//+------------------------------------------------------------------+
//| Calculs preliminaires de l'expert                                |
//+------------------------------------------------------------------+
//********** Calcul de la taille optimale du lot **********//
double LotsOptimized()
   {
      if (AcountIsMini)
         Lots = 0.01;
      lot=Lots;
      orders=HistoryTotal();     // Historique des ordres
      losses=0;                  // Nombre de trade perdants consécutif
/* Selection de la taille du lot */
      lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000,1);
/* Calcul du nombre de perte consecutive */
      if(DecreaseFactor>0)
         {
            for(int i=orders-1;i>=0;i--)
               {
                  if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==False) 
                     { 
                        Print("Erreur dans l historique!"); 
                        break; 
                     }
                  if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) 
                     continue;
//----
                  if(OrderProfit()>0) 
                     break;
                  if(OrderProfit()<0) 
                     losses++;
               }
            if(losses>1) 
               lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
         }
/* Retour de la taille du lot */
      if (AcountIsMini)
         if(lot<0.01) 
            lot=0.01;
      if(lot<0.1) 
         lot=0.1;
//----
      return(lot);
   }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
   {
//----
      PrevBarHiLo = (High[1]-Low[1])/Point;
//---- Req.#1 - Price Explosion
      if (PrevBarHiLo >= Delta)
         {
//---- SELL Direction            
            if (Open[1]>Close[1])
               {
                  PriceRule3 = (Low[1]-(Rule3Dist*Point));
                  Print (PriceRule3);
//---- Req.#2 - 70 pips move in the direction of the price explosion
                  if ((High[0]-Bid)/Point>=Rule2Dist)
                     {
//---- Req.#3 - 30 pips between Low[1] et PriceRule2
                        //if (PriceRule2 <= PriceRule3)
                        //if ((Low[1]-Bid)/Point>=Rule3Dist)
                           //{
                              if (OrdersTotal()<=0 && TimeDayOfYear(CurTime())!=LastDayTrade)
                                 {
                                    LastDayTrade=TimeDayOfYear(CurTime());
                                    //OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,0,Bid+(SL*Point),Bid-(TP*Point),"Sell",0,0,Red);
                                    OrderSend(Symbol(),OP_SELLLIMIT,LotsOptimized(),PriceRule3,0,Bid+(SL*Point),Bid-(TP*Point),NameEA+"Sell",MagicEA,0,Red);
                                 }
                           //}
                     }
               }
//---- BUY Direction      
            if (Open[1]<Close[1])
               {
                  PriceRule3 = (High[1]+(Rule3Dist*Point));
                  Print (PriceRule3);
//---- Req.#2 - 70 pips move in the direction of the price explosion
                  if ((Ask-Low[0])/Point>=Rule2Dist)
                     {
//---- Req.#3 - 30 pips between High[1] et PriceRule2
                        //if ((Ask-High[1])/Point>=Rule3Dist) 
                           //{
                              if (OrdersTotal()<=0 && TimeDayOfYear(CurTime())!=LastDayTrade)
                                 {
                                    LastDayTrade=TimeDayOfYear(CurTime());
                                    //OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,0,Ask-(SL*Point),Ask+(TP*Point),"Buy",0,0,Blue);
                                    OrderSend(Symbol(),OP_BUYLIMIT,LotsOptimized(),PriceRule3,0,Ask-(SL*Point),Ask+(TP*Point),NameEA+"Buy",MagicEA,0,Blue);
                                 }
                           //}
                     }
               }
         }
      CheckAllTrade();
      if (JT_OS>0 || JT_OB>0)
         {
            SetSLtoBEP();
            if (TimeHour(CurTime())==23 && TimeMinute(CurTime())==30)
               {
                  TutupOpenPosisi();
               }
         }
//----
      return(0);
   }
//+------------------------------------------------------------------+

void CheckAllTrade()
   {
      JT_SL=0;
      JT_BL=0;
      JT_SS=0;
      JT_BS=0;
      JT_OS=0;
      JT_OB=0;
      total=OrdersTotal();
      for (ecnt=0;ecnt<total;ecnt++)
         {
            OrderSelect(ecnt,SELECT_BY_POS, MODE_TRADES);
            if (
            OrderType()==OP_SELLLIMIT 
            && OrderSymbol()==Symbol()
            && OrderMagicNumber() == MagicEA
            )
               JT_SL++;
            else 
               if (
               OrderType()==OP_BUYLIMIT 
               && OrderSymbol()==Symbol()
               && OrderMagicNumber() == MagicEA
               )
                  JT_BL++;         
               else 
                  if (
                  OrderType()==OP_SELLSTOP 
                  && OrderSymbol()==Symbol()
                  && OrderMagicNumber() == MagicEA
                  )
                     JT_SS++;
                  else 
                     if (
                     OrderType()==OP_BUYSTOP 
                     && OrderSymbol()==Symbol()
                     && OrderMagicNumber() == MagicEA
                     )
                        JT_BS++;         
                     else 
                        if (
                        OrderType()==OP_SELL 
                        && OrderSymbol()==Symbol()
                        && OrderMagicNumber() == MagicEA
                        )
                           JT_OS++;
                        else 
                           if (
                           OrderType()==OP_BUY 
                           && OrderSymbol()==Symbol()
                           && OrderMagicNumber() == MagicEA
                           )
                              JT_OB++;         
         }
   }

void SetSLtoBEP()
   {
      total=OrdersTotal();
      for (ecnt=0;ecnt<total;ecnt++)
         {
            OrderSelect(ecnt,SELECT_BY_POS, MODE_TRADES);
            if (
            OrderMagicNumber() == MagicEA
            && OrderProfit()/10>=30
            )
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Brown);
               }
         }
   }
   
void TutupOpenPosisi()
   {
      total=OrdersTotal();
      for (ecnt=0;ecnt<total;ecnt++)
         {
            OrderSelect(ecnt,SELECT_BY_POS, MODE_TRADES);
            if (OrderMagicNumber() == MagicEA)
               {
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Indigo);
               }
         }
   }


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