Author: Copyright © 2006, Yury V. Reshetov. ICQ: 282715499
Price Data Components
Series array that contains the lowest prices of each barSeries array that contains open prices of each barSeries array that contains close prices for each barSeries array that contains the highest prices of each bar
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
Pipsover
ÿþ//+------------------------------------------------------------------+

//|                            Pipsover(barabashkakvn's edition).mq5 |

//|                              Copyright © 2006, Yury V. Reshetov. |

//|                                       http://betaexpert.narod.ru |

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

#property copyright "Copyright © 2006, Yury V. Reshetov. ICQ: 282715499"

#property link      "http://betaexpert.narod.ru"

#property version   "1.001"

#include <Trade\PositionInfo.mqh>

#include <Trade\Trade.mqh>

#include <Trade\SymbolInfo.mqh>  

CPositionInfo  m_position;                   // trade position object

CTrade         m_trade;                      // trading object

CSymbolInfo    m_symbol;                     // symbol info object

//--- input parameters

input double      m_lots      = 0.1;         // 1J5<K

input ushort      m_stoploss  = 65;          // C1KB:8

input ushort      m_takeprofit= 100;         // @81K;L

input double      m_openlevel = 100;         // @545;L=K9 C@>25=L 7=0G5=8O 8=48:0B>@0 '09:8=0 4;O >B:@KB8O ?>78F88

input double      m_closelevel= 125;         // @545;L=K9 C@>25=L 7=0G5=8O 8=48:0B>@0 '09:8=0 4;O ;>:8@>20=8O ?>78F88

//---

static datetime   prevtime          = 0;     // @5<O ?>A;54=53> 10@0

ulong             m_magic           = 888;   // magic number

double            m_adjusted_point  = 0.0;   // tuning for 3 or 5 digits

int               handle_iMA;                // variable for storing the handle of the iMA indicator 

int               handle_iChaikin;           // variable for storing the handle of the iChaikin indicator  

ENUM_ACCOUNT_MARGIN_MODE m_margin_mode;

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

//| Expert initialization function                                   |

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

int OnInit()

  {

   SetMarginMode();

   if(!IsHedging())

     {

      Print("Hedging only!");

      return(INIT_FAILED);

     }

//---

   m_symbol.Name(Symbol());                  // sets symbol name

   if(!RefreshRates())

     {

      Print("Error RefreshRates. Bid=",DoubleToString(m_symbol.Bid(),Digits()),

            ", Ask=",DoubleToString(m_symbol.Ask(),Digits()));

      return(INIT_FAILED);

     }

   m_symbol.Refresh();

   m_trade.SetExpertMagicNumber(m_magic);    // sets magic number

//--- tuning for 3 or 5 digits

   int digits_adjust=1;

   if(m_symbol.Digits()==3 || m_symbol.Digits()==5)

      digits_adjust=10;

   m_adjusted_point=m_symbol.Point()*digits_adjust;



//--- create handle of the indicator iMA

   handle_iMA=iMA(m_symbol.Name(),Period(),20,0,MODE_SMA,PRICE_CLOSE);

//--- if the handle is not created 

   if(handle_iMA==INVALID_HANDLE)

     {

      //--- tell about the failure and output the error code 

      PrintFormat("Failed to create handle of the iMA indicator for the symbol %s/%s, error code %d",

                  m_symbol.Name(),

                  EnumToString(Period()),

                  GetLastError());

      //--- the indicator is stopped early 

      return(INIT_FAILED);

     }

//--- create handle of the indicator iChaikin

   handle_iChaikin=iChaikin(m_symbol.Name(),Period(),3,10,MODE_EMA,VOLUME_TICK);

//--- if the handle is not created 

   if(handle_iChaikin==INVALID_HANDLE)

     {

      //--- tell about the failure and output the error code 

      PrintFormat("Failed to create handle of the iChaikin indicator for the symbol %s/%s, error code %d",

                  m_symbol.Name(),

                  EnumToString(Period()),

                  GetLastError());

      //--- the indicator is stopped early 

      return(INIT_FAILED);

     }

//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

//--- 645<, :>340 AD>@<8@C5BAO =>2K9 10@

   if(iTime(m_symbol.Name(),Period(),0)==prevtime)

      return;

   prevtime=iTime(m_symbol.Name(),Period(),0);



   double ma=iMAGet(0);                   // 20 ?5@8>4=K9 <C28=3

   double ch=iChaikinGet(1);              // 7=0G5=85 8=48:0B>@0 '09:8=0 =0 10@5 !1



   int total=0;

   for(int i=PositionsTotal()-1;i>=0;i--) // returns the number of open positions

      if(m_position.SelectByIndex(i))

         if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic)

            total++;



   if(!RefreshRates())

      return;



   if(total<1) // =5B >B:@KBKE ?>78F89

     {

      //--- 5A;8 7=0G5=85 8=48:0B>@0 '09:8=0 70H:0;8;> 8 =0G0;AO ?>B5=F80;L=K9 @072>@>B

      //--- A2>53> @>40 ?5@5?@>40==>ABL

      //--- ?>:C?05<

      if(iClose(m_symbol.Name(),Period(),1)>iOpen(m_symbol.Name(),Period(),1) && iLow(m_symbol.Name(),Period(),1)<ma && ch<-m_openlevel)

        {

         double level_price=m_symbol.Ask();

         double level_sl=m_symbol.Ask()-m_stoploss*m_adjusted_point;

         double level_tp=m_symbol.Ask()+m_takeprofit*m_adjusted_point;

         m_trade.Buy(m_lots,NULL,level_price,level_sl,level_tp,"Pipsover");

         return;

        }

      //--- 5A;8 7=0G5=85 8=48:0B>@0 '09:8=0 70H:0;8;> 8 =0G0;AO ?>B5=F80;L=K9 @072>@>B

      //--- A2>53> @>40 ?5@5:C?;5==>ABL

      //--- ?@>405<

      if(iClose(m_symbol.Name(),Period(),1)<iOpen(m_symbol.Name(),Period(),1) && iHigh(m_symbol.Name(),Period(),1)>ma && ch>m_openlevel)

        {

         double level_price=m_symbol.Bid();

         double level_sl=m_symbol.Bid()+m_stoploss*m_adjusted_point;

         double level_tp=m_symbol.Bid()-m_takeprofit*m_adjusted_point;

         m_trade.Sell(m_lots,NULL,level_price,level_sl,level_tp,"Pipsover");

         return;

        }

     }

   else

     {

      //--- 5ABL >B:@KBK5 ?>78F88. >65B 1KBL ?>@0 ?>4AB@0E>20BLAO?



      //--- 5A;8 >B:@KB> 1>;55 >4=>9 ?>78F88 - 2KE>48<

      if(total>1)

         return;



      //--- 5A;8 >B:@KB0 2A53> >4=0 ?>78F8O

      if(m_position.SelectByIndex(0))

        {

         //--- ?>E>65 =0 >B:0B, 70;>:8@C5< 4;8==CN ?>78F8N

         if(m_position.PositionType()==POSITION_TYPE_BUY && 

            iClose(m_symbol.Name(),Period(),1)<iOpen(m_symbol.Name(),Period(),1) && iHigh(m_symbol.Name(),Period(),1)>ma && ch>m_closelevel)

           {

            double level_price=m_symbol.Bid();

            double level_sl=m_symbol.Ask()+m_stoploss*m_adjusted_point;

            double level_tp=m_symbol.Ask()-m_takeprofit*m_adjusted_point;

            m_trade.Sell(m_lots,NULL,level_price,level_sl,level_tp,"Pipsover");

            return;

           }



         //--- ?>E>65 =0 >B:0B, 70;>:8@C5< :>@>B:C ?>78F8N

         if(m_position.PositionType()==POSITION_TYPE_SELL && 

            iClose(m_symbol.Name(),Period(),1)>iOpen(m_symbol.Name(),Period(),1) && iLow(m_symbol.Name(),Period(),1)<ma && ch<-m_closelevel)

           {

            double level_price=m_symbol.Ask();

            double level_sl=m_symbol.Bid()-m_stoploss*m_adjusted_point;

            double level_tp=m_symbol.Bid()+m_takeprofit*m_adjusted_point;

            m_trade.Buy(m_lots,NULL,level_price,level_sl,level_tp,"Pipsover");

            return;

           }

        }

     }

//--- 2>B 8 A:07:5 728745F

   return;

  }

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

//| Refreshes the symbol quotes data                                 |

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

bool RefreshRates()

  {

//--- refresh rates

   if(!m_symbol.RefreshRates())

      return(false);

//--- protection against the return value of "zero"

   if(m_symbol.Ask()==0 || m_symbol.Bid()==0)

      return(false);

//---

   return(true);

  }

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

//| Get value of buffers for the iMA                                 |

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

double iMAGet(const int index)

  {

   double MA[1];

//--- reset error code 

   ResetLastError();

//--- fill a part of the iMABuffer array with values from the indicator buffer that has 0 index 

   if(CopyBuffer(handle_iMA,0,index,1,MA)<0)

     {

      //--- if the copying fails, tell the error code 

      PrintFormat("Failed to copy data from the iMA indicator, error code %d",GetLastError());

      //--- quit with zero result - it means that the indicator is considered as not calculated 

      return(0.0);

     }

   return(MA[0]);

  }

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

//| Get value of buffers for the iChaikin                            |

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

double iChaikinGet(const int index)

  {

   double Chaikin[1];

//--- reset error code 

   ResetLastError();

//--- fill a part of the iChaikin array with values from the indicator buffer that has 0 index 

   if(CopyBuffer(handle_iChaikin,0,index,1,Chaikin)<0)

     {

      //--- if the copying fails, tell the error code 

      PrintFormat("Failed to copy data from the iChaikin indicator, error code %d",GetLastError());

      //--- quit with zero result - it means that the indicator is considered as not calculated 

      return(0.0);

     }

   return(Chaikin[0]);

  }

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

//|                                                                  |

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

void SetMarginMode(void)

  {

   m_margin_mode=(ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE);

  }

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

//|                                                                  |

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

bool IsHedging(void)

  {

   return(m_margin_mode==ACCOUNT_MARGIN_MODE_RETAIL_HEDGING);

  }

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

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