TimeBasedEAMOD 2

Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reached
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 2
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff 3.00
Gross Profit 6.00
Gross Loss 0.00
Total Net Profit 6.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
100.00 %
Total Trades 2
Won Trades 1
Lost trades 1
Win Rate 0.50 %
Expected payoff 0.00
Gross Profit 3.00
Gross Loss -3.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
TimeBasedEAMOD 2
//+------------------------------------------------------------------+
//|                                                  TimeBasedEA.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
//changed by:       "forex4capital@yahoo.ca"

// Time frame: M5 and higher

extern int     MagicNumber = 20080122;
extern int  Take_Profit  = 30;
extern int  Stop_Loss    = 30;
extern double  Lots        = 0.1;
extern string Remark1="Time to open trades";
extern int     StartHour   = 09;      // Open Trade time
extern int     Gap         =  20;
extern string Remark2="Time to close Pending trades";
extern int     CloseHour = 12;        //Time to close Pending trades
extern bool    OpenBuy     = true;
extern bool    OpenSell    = true;
extern int     NumBuys     = 1;
extern int     NumSells    = 1;
extern int     Slippage    = 4;
datetime TimeStamp=0;
bool Buy=false,Sell=false;
double TakeProfit,StopLoss;
double OpenOrderPrice;
//+------------------------------------------------------------------+
//|                        S T A R T                                 |
//+------------------------------------------------------------------+
int start()
  {
   int cnt, ticket, total;
   int ct;
//-------------------------------------+
   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }
//-------------------------------------+
   if(Take_Profit<10)
     {
      Print("TakeProfit less than 10");
      return(0);  // check TakeProfit
     }
//-------------------------------------+
//ClosePending = (Hour() == CloseHour);
   ct = Hour();
   total=OrdersTotal();
   if(total<1) 
     {
      // no opened orders identified
      if(AccountFreeMargin()<(1*Lots))
        {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);  
        }
      // check for long position (BUY) possibility
      
      if(ct == StartHour && OpenBuy)
      //if(ct == StartHour && High[1]<Open[0] && OpenBuy)
        {
         for ( cnt = 0; cnt < NumBuys; cnt++)
        {
            OpenOrderPrice=Ask+Gap*Point;
            if(Stop_Loss>0)
               {StopLoss=OpenOrderPrice-Stop_Loss*Point;}
               else
               {StopLoss=0;}
            if(Take_Profit>0)
               {TakeProfit=OpenOrderPrice+Take_Profit*Point;}
               else
               {TakeProfit=0;}
//           ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Bid-StopLoss*Point,Ask+TakeProfit*Point,"",MagicNumber,0,Blue);
           ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,OpenOrderPrice,Slippage,StopLoss,TakeProfit,"",MagicNumber,CloseHour,Blue);
           if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
           else Print("Error opening BUY order : ",GetLastError()); 
         }
         return(0); 
        }
      // check for short position (SELL) possibility
         if(ct == StartHour && OpenSell)
      //if(ct == StartHour && Low[1]>Open[0] && OpenSell)
        {
         for ( cnt = 0; cnt < NumSells; cnt++)
         {
            OpenOrderPrice=Bid-Gap*Point;
            if(Stop_Loss>0)
               {StopLoss=OpenOrderPrice+Stop_Loss*Point;}
               else
               {StopLoss=0;}
            if(Take_Profit>0)
               {TakeProfit=OpenOrderPrice-Take_Profit*Point;}
               else
               {TakeProfit=0;}
//            ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Ask+StopLoss*Point,Bid-TakeProfit*Point,"",MagicNumber,0,Red);
            ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,OpenOrderPrice,Slippage,StopLoss,TakeProfit,"",MagicNumber,CloseHour,Red);
            if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
           else Print("Error opening SELL order : ",GetLastError());
         } 
         return(0); 
        }
     }
   return(0);
  }
// the end.

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