Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategy
Indicators Used
Bill Williams Accelerator/Decelerator oscillatorStochastic oscillatorMoving average indicator
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/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%
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%
OzFx v1.42
//+------------------------------------------------------------------+
//|                             OzFx Expert Advisor for MetaTrader 4 |
//|                                                     version 1.42 |
//|                                          original idea from OzFx |
//|                                           EA conversion by Azmel |
//+------------------------------------------------------------------+
//| INSTRUCTIONS                                                     |
//| To be used on any chart (except JPY) with D1 timeframe.          |
//+------------------------------------------------------------------+
//| VERSION HISTORY                                                  |
//| 1.0  - Initial version with AC and Stochastic indicators.        |
//| 1.1  - 200SMA filter added by Matt Ebersviller.                  |
//| 1.2  - Recorrected the 200SMA rules and rewrote closing          |
//|        subroutine when new signal arrives.                       |
//| 1.3  - Debug the closing routine of the 5th trade                |
//| 1.4  - Debug a bug not taking longs when a valid signal arrives  |
//| 1.41 - Improved Money Management. Debug multiple buys in one day |
//| 1.42 - Init section to retrieve ticket data if EA is restarted.  |
//|        Open/Close trade signals reorganised.                     |
//+------------------------------------------------------------------+

#include <stdlib.mqh>

//+------------------------------------------------------------------+
//| External Variables                                               |
//+------------------------------------------------------------------+

extern int    Magic           = 887453;
extern double Lots            = 0.01;
extern bool   MoneyManagement = true;
extern int    Risk            = 1;
extern bool   StartUp         = true;

//+------------------------------------------------------------------+
//| Internal variables                                               |
//+------------------------------------------------------------------+

int    PricePerPip;
double DecimalCorrection;
int    DecimalPlaces;
double MaxLots;

bool   OKToTrade;
int    i;
int    x;
int    OpenOrders;

double ACSignalCurrent;
double ACSignalPrevious;
double StochasticMain;
double StochasticSignal;
double SMA200;
bool   BuyFlag;
bool   SellFlag;
bool   StopLossAdjust;

int    ticket[6];

int    TP1 = 50;
int    TP2 = 100;
int    TP3 = 150;
int    TP4 = 200;

int    SL  = 100;

int    slippage = 5;

int    StochasticUpper = 50;
int    StochasticLower = 50;

double EntryPrice;

int init()
{
   OpenOrders=0;
   for(i=0;i<OrdersTotal();i++)
   {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
      {
         OpenOrders++;
      }
   }

   if(OpenOrders==0)
   {
      BuyFlag=0;
      SellFlag=0;
      return(0);
   }
   else
   {
      StartUp=false;
      EntryPrice=OrderOpenPrice();
      if(OpenOrders==5)
      {
         StopLossAdjust=false;
      }
      else
      {
         StopLossAdjust=true;
      }
      if(OrderType()==OP_BUY)
      {
         BuyFlag=true;
         SellFlag=false;
      }
      if(OrderType()==OP_SELL)
      {
         BuyFlag=false;
         SellFlag=true;
      }

      x=5-OpenOrders;
      for(i=0;i<OrdersTotal();i++)
      {
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
         {
            x++;
            ticket[x]=OrderTicket();
         }
      }
   }
   return(0);
}


//+------------------------------------------------------------------+
//| Main code                                                        |
//+------------------------------------------------------------------+

int start()
{
   //+---------------------------------------------------------------+
   //| Money Management Routine                                      |
   //+---------------------------------------------------------------+

   if (MoneyManagement)
   {
      if (Risk<1 || Risk>20)
      {
         Comment("Invalid Risk Value.");
         return(0);
      }
      else
      {
         Lots=MathFloor((AccountFreeMargin()*AccountLeverage()*Risk*Point*100)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*MarketInfo(Symbol(),MODE_MINLOT)))*MarketInfo(Symbol(),MODE_MINLOT);
      }
   }
   

   //+---------------------------------------------------------------+
   //| Time Frame Check                                              |
   //+---------------------------------------------------------------+
   
   if (Period() != 1440)
   {
      Comment("Wrong Time Frame. Please switch to D1.");
      return(0);
   }
   
   //+---------------------------------------------------------------+
   //| Start-Up Routine (To Prevent Immediate Entry During Start-Up) |
   //+---------------------------------------------------------------+

   if (StartUp)
   {
      if (Hour()==0)
      {
         StartUp   = false;
      }
      else
      {
         Comment("Staring Up Delay. Awaiting Next Candle.");
         return(0);
      }
   }

   //+---------------------------------------------------------------+
   //| Main Trading Routine                                          |
   //+---------------------------------------------------------------+


      //+------------------------------------------------------------+
      //| Signal & Indicators                                        |
      //+------------------------------------------------------------+

      ACSignalCurrent  = iAC(NULL,0,0);
      ACSignalPrevious = iAC(NULL,0,1);
      StochasticMain   = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0);
      StochasticSignal = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
      SMA200           = iMA(NULL,0,200,0,MODE_SMA,PRICE_OPEN,0);

      // SMA200 Options: PRICE_CLOSE, PRICE_OPEN, PRICE_HIGH, PRICE_LOW, 
      //                 PRICE_MEDIAN, PRICE_TYPICAL, PRICE_WEIGHTED
      
      Comment("\nOzFx EA version 1.42\nCopyright (2008) OzFx\nEA Conversion by Azmel\n\nTrading ",Lots," Lots");

      //+------------------------------------------------------------+
      //| Check Condition To Open Long                               |
      //+------------------------------------------------------------+

      if (ACSignalCurrent>0 && ACSignalPrevious<0 && BuyFlag==false)
      {
         for(i=0;i<OrdersTotal();i++)   
         {
            OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
            if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic)
	         {				
               OrderClose(OrderTicket(),OrderLots(),Ask,slippage,CLR_NONE);
            }
         } 

         SellFlag=false;
         BuyFlag=true;
         
         if (Ask>SMA200 && StochasticMain>StochasticUpper && StochasticSignal>StochasticUpper)
         {
            ticket[1]=OrderSend(Symbol(),OP_BUY,Lots,Ask,slippage,Ask-SL*Point,Ask+TP1*Point,"OzFx-1B",Magic,CLR_NONE);
            ticket[2]=OrderSend(Symbol(),OP_BUY,Lots,Ask,slippage,Ask-SL*Point,Ask+TP2*Point,"OzFx-2B",Magic,CLR_NONE);
            ticket[3]=OrderSend(Symbol(),OP_BUY,Lots,Ask,slippage,Ask-SL*Point,Ask+TP3*Point,"OzFx-3B",Magic,CLR_NONE);
            ticket[4]=OrderSend(Symbol(),OP_BUY,Lots,Ask,slippage,Ask-SL*Point,Ask+TP4*Point,"OzFx-4B",Magic,CLR_NONE);
            ticket[5]=OrderSend(Symbol(),OP_BUY,Lots,Ask,slippage,Ask-SL*Point,0,"OzFx-5B",Magic,CLR_NONE);

            EntryPrice=Ask;         
            StopLossAdjust=false;
         }
      }

      //+------------------------------------------------------------+
      //| Check Condition To Open Short                              |
      //+------------------------------------------------------------+

      if (ACSignalCurrent<0 && ACSignalPrevious>0 && SellFlag==false)
      {
         for(i=0;i<OrdersTotal();i++)   
         {
            OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
            if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic)
            {				
               OrderClose(OrderTicket(),OrderLots(),Bid,slippage,CLR_NONE);
            }
         } 

         BuyFlag=false;
         SellFlag=true;
         
         if (Bid<SMA200 && StochasticMain<StochasticLower && StochasticSignal<StochasticLower)
         {
            ticket[1]=OrderSend(Symbol(),OP_SELL,Lots,Bid,slippage,Bid+SL*Point,Bid-TP1*Point,"OzFx-1S",Magic,CLR_NONE);
            ticket[2]=OrderSend(Symbol(),OP_SELL,Lots,Bid,slippage,Bid+SL*Point,Bid-TP2*Point,"OzFx-2S",Magic,CLR_NONE);
            ticket[3]=OrderSend(Symbol(),OP_SELL,Lots,Bid,slippage,Bid+SL*Point,Bid-TP3*Point,"OzFx-3S",Magic,CLR_NONE);
            ticket[4]=OrderSend(Symbol(),OP_SELL,Lots,Bid,slippage,Bid+SL*Point,Bid-TP4*Point,"OzFx-4S",Magic,CLR_NONE);
            ticket[5]=OrderSend(Symbol(),OP_SELL,Lots,Bid,slippage,Bid+SL*Point,0,"OzFx-5S",Magic,CLR_NONE);

            EntryPrice=Bid;
            StopLossAdjust=false;
          }
      }

      //+------------------------------------------------------------+
      //| If Trade one hit TakeProfit, move StopLoss to BreakEven    |
      //+------------------------------------------------------------+

      if (StopLossAdjust==false)
      {
         if ((BuyFlag && Bid>=EntryPrice+TP1*Point) || (SellFlag && Ask<=EntryPrice-TP1*Point))
         {
            for(i=2;i<=5;i++)
            {
               OrderSelect(ticket[i],SELECT_BY_TICKET);
               OrderModify(ticket[i],OrderOpenPrice(),EntryPrice,OrderTakeProfit(),0,CLR_NONE);
            }

            StopLossAdjust=true;
         }
      }
   return(0);
}

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