Antitrend_EURUSD1H

Author: Copyright © 2020, ASNIK
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 reachedChecks for the total of closed orders
Indicators Used
Relative strength index
0 Views
0 Downloads
0 Favorites
Antitrend_EURUSD1H
ÿþ//+------------------------------------------------------------------+

//|                                           Antitrend_EURUSD1H.mq4 |

//|                                          Copyright © 2020, ASNIK |

//|                                         http://www.digital01.rut |

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



#property copyright "Copyright © 2020, ASNIK"

#property link      "http://digital01.ru"

#define MAGICMA  20200425

#property strict

extern double    Lots= 0;

extern double    TRisk = 3; //3  - max = 6  

extern int       Profit = 155 ;  // take profit

extern int       Loss = 277 ; // stop loss 

extern double    MinRSI = 36; // Level RSI mHB

extern double    MaxRSI = 63; // Level RSI max

extern int       PeriodRSI = 8; // Period RSI

extern int       Hd = 820; // Hight bar

extern int       BigDelta = 1111; // delta different bars





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

//| Calculate optimal lot size                                       |

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

double LotsOptimized()

  {

   double Lot;

   if(Lots != 0)

      Lot =Lots;

   else

      if(AccountFreeMargin() < 100)

         Lot=MathCeil(AccountFreeMargin()*0.125/10*TRisk)/100;//      0.01

      else

         if(AccountFreeMargin() < 1000)

            Lot=MathCeil(AccountFreeMargin()*0.125/100*TRisk)/10;//   0.1

         else

            Lot=MathCeil(AccountFreeMargin()*0.125/1000*TRisk);  //   1

   return(Lot);

  }



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

//| Calculate open positions                                         |

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

int CalculateCurrentOrders(string symbol)

  {

   int buys=0,sells=0;

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

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)

         break;

      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)

        {

         if(OrderType()==OP_BUY)

            buys++;

         if(OrderType()==OP_SELL)

            sells++;

        }

     }

   if(buys>0)

      return(buys);

   else

      return(-sells);

  }

//+------------------------------------------------------------------+!!!!!!! !!!! !!! !!!! !!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!

//| Check for open order conditions                                  |!!!!!!! !  ! !!! !!!  ! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

//+------------------------------------------------------------------+!!!!!!! !!!! !   !!!! ! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

void CheckForOpen()

  {

   double RSICurrent, RSIPrev;

   int    res;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

   RSICurrent=iRSI(NULL,0,PeriodRSI,PRICE_WEIGHTED,0);

   if((High[iHighest(NULL,PERIOD_H1,MODE_HIGH,12,0)] - Low[iLowest(NULL,PERIOD_H1,MODE_LOW,12,0)]) < 1800 *Point

      && (High[iHighest(NULL,PERIOD_H1,MODE_HIGH,2,2)] - Low[iLowest(NULL,PERIOD_H1,MODE_LOW,2,0)]) < 1300 *Point)

     {

      if((High[1] - Ask)  > Hd * Point)

        {

         if(MathAbs(High[1]- Close[1]) > 25 * Point && RSICurrent > MinRSI)

           {

            res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,1,Ask-Loss*Point,Ask+Profit*Point," Hd  ",MAGICMA,0,Blue);

            return;

           }

        }

      if((Bid - Low[1])  > Hd * Point)

        {

         if(MathAbs(Open[1]- Close[1]) > 100 *Point && RSICurrent < MaxRSI)

            res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,1,Bid+Loss*Point,Bid-Profit*Point," Hd ",MAGICMA,0,Red);

        }



      ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

      if((High[iHighest(NULL,PERIOD_H1,MODE_HIGH,12,0)] - Low[iLowest(NULL,PERIOD_H1,MODE_LOW,12,0)]) > BigDelta *Point)

        {

         RSICurrent=iRSI(NULL,0,PeriodRSI,PRICE_WEIGHTED,0);

         RSIPrev=iRSI(NULL,0,PeriodRSI,PRICE_WEIGHTED,1);

         if(RSIPrev < (RSICurrent - 2) && RSIPrev < 12)

            res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,1,Ask-Loss*Point*3,Ask+Profit*Point*2," BigDelta up ",MAGICMA,0,Blue);

         if(RSIPrev > (RSICurrent + 2) && RSIPrev > 88)

            res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,1,Bid+Loss*Point*3,Bid-Profit*Point*2," BigDelta down ",MAGICMA,0,Red);

        }

     }



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  }



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

//| expert initialization function                                   |

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

int init()

  {

   return(0);

  }

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

//| expert deinitialization function                                 |

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

int deinit()

  {

   return(0);

  }

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

//| expert start function                                            |

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

void start()

  {

   if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)==true && (TimeCurrent() - OrderCloseTime())< 120)

      return;

   if(Bars<100 || IsTradeAllowed()==false)

      return;

   if(DayOfWeek()==0 || DayOfWeek()==6)

      return;

   if(CalculateCurrentOrders(Symbol())==0)

      CheckForOpen();

  }

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

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