King EA _001

Author: opensurce
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 Closes Orders by itself
Indicators Used
Relative strength index
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
9.00 %
Total Trades 58
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -15.57
Gross Profit 90.00
Gross Loss -993.00
Total Net Profit -903.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
11.00 %
Total Trades 60
Won Trades 21
Lost trades 39
Win Rate 0.35 %
Expected payoff -14.25
Gross Profit 105.00
Gross Loss -960.00
Total Net Profit -855.00
-100%
-50%
0%
50%
100%
King EA _001
//+------------------------------------------------------------------+
//|                                                     King EA .mq4 |
//|                                                        opensurce |
//|                                                      www.tsd.com |
//+------------------------------------------------------------------+
#property copyright "opensurce"
#property link      "www.tsd.com"




extern int       Magic         = 1110;
extern double    Lots          = 1.0;
extern int       SL            = 25;
extern int       TP            = 5;
extern int       Start         = 21;
extern int       End           = 6;
extern double    RSI_BUY       = 30;
extern double    RSI_SELL      = 70;
extern int       RSI_PERIOD    = 10;
extern int       RSI_TF        = 1;
extern bool      MM            = false;
extern int       LotsPercent   = 10;
extern int    MaxOpenTime_BUY  = 10;
extern int    MaxOpenTime_SELL = 10;
/////////////////////////////////////////
int       MaxLot        = 100;
double    MinLot        = 0.01;
double    RSI_BUY_Zera  = 40;
double    RSI_SELL_Zera = 60;
bool      Compra        = true;
bool      Venda         = true;

int    i,tmp,ordtotal,closeprice,cnt,total;

//+------------------------------------------------------------------+

int isMgNum(int magic)
{
 ordtotal = OrdersTotal();
for ( i = 0; i < ordtotal; i++)
   {
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   if ((OrderMagicNumber() == magic) && (OrderSymbol() == Symbol())) return(1);
   }
}

//+------------------------------------------------------------------+

int init()
{
return(0);
}

//+------------------------------------------------------------------+

int deinit()
{
return(0);
}

//+------------------------------------------------------------------+

int start()
{

//+------------------------------------------------------------------+
//|Easy Money Management                                             |
//+------------------------------------------------------------------+
double free;
tmp = (TimeCurrent()-OrderOpenTime())/36000.0;

if (AccountFreeMargin() < free * 150.0) return(0);

if (MM)
   {
   if (LotsPercent > 0)
      Lots = NormalizeDouble(MathCeil(AccountFreeMargin() / 1000.0 * LotsPercent) / 10.0,1);
         else
      Lots = Lots;
   }
   
   if (Lots < MinLot) Lots = MinLot;
   if (Lots > MaxLot) Lots = MaxLot;
   
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+   

double IN;

double RSI_1   = iRSI(NULL, RSI_TF, RSI_PERIOD, PRICE_CLOSE, 0);
double RSI_2   = iRSI(NULL, RSI_TF, RSI_PERIOD, PRICE_CLOSE, 1);

Comment("Trading hours: ",Start," to ",End,"\n","Trading is disabled");
if ((Start < End) && ((TimeHour(TimeCurrent()) < Start ) || (TimeHour(TimeCurrent()) >= End))) return(0);
else
if ((Start > End) && ((TimeHour(TimeCurrent()) < Start ) && (TimeHour(TimeCurrent()) >= End))) return(0);
else
Comment("Trading hours: ",Start," to ",End,"\n","Trading is enabled");

IN = NormalizeDouble(AccountFreeMargin() / 2500,2);

if ((isMgNum(Magic) == 0) && (RSI_1 < RSI_BUY)&& (RSI_1< RSI_2))
   {
   if (Compra)
   OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask - SL * Point, Ask + TP * Point,0,Magic,0,Blue);
   Compra = false;
   Venda = true;
  }
 
  if(MaxOpenTime_BUY>0)
  {
    for(cnt=0;cnt>OrdersTotal();cnt++)
    {
      if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      {
         if (((NormalizeDouble(tmp,8)-MaxOpenTime_BUY)>=0))
        {     
          RefreshRates();
          if (OrderType()==OP_BUY)
            closeprice=Bid;
          if (OrderClose(OrderTicket(),OrderLots(),closeprice,10,Yellow))
          {
            Print("CloseLong(),OrderSelect():",OrderTicket());
            OrderPrint();
          }
          else 
            Print("Error close Long order :",GetLastError());        
        } 
      }
      else 
        Print("TimeOver",GetLastError());
    } 
    }



if ((isMgNum(Magic) == 0) && (RSI_1 > RSI_SELL)&& (RSI_1> RSI_2))
   {
   if (Venda)
   OrderSend(Symbol(),OP_SELL,Lots,Bid,0,Bid + SL * Point,Bid - TP * Point,0,Magic,0,Red);
   Venda = false;
   Compra = true;
   }
  
  if(MaxOpenTime_SELL>0)
  {
    for(cnt=0;cnt<OrdersTotal();cnt++)
    {
      if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      {
         if (((NormalizeDouble(tmp,8)-MaxOpenTime_SELL)>=0))
        {     
          RefreshRates();
          if (OrderType()==OP_SELL)
            closeprice=Ask;          
          if (OrderClose(OrderTicket(),OrderLots(),closeprice,10,Yellow))
          {
            Print("CloseShort(),OrderSelect():",OrderTicket());
            OrderPrint();
          }
          else 
            Print("Error close Sell order :",GetLastError());        
        } 
      }
      else 
        Print("TimeOver",GetLastError());
    } 
  }     
   
   
if ( ( RSI_1 < RSI_SELL_Zera ) && ( RSI_1 > RSI_BUY_Zera ))
   {
   Venda = true;
   Compra = true;
}
}

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