Pays Interest Multicurrency

Author: Copyright © 2019, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Pays Interest Multicurrency
ÿþ//+------------------------------------------------------------------+

//|                                  Pays Interest Multicurrency.mq5 |

//|                              Copyright © 2019, Vladimir Karputov |

//|                                           http://wmua.ru/slesar/ |

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

#property copyright "Copyright © 2019, Vladimir Karputov"

#property link      "http://wmua.ru/slesar/"

#property version   "1.000"

//---

#include <CTradingEngine3.mqh>

#include <Arrays\ArrayObj.mqh>

#include <Trade\SymbolInfo.mqh>

CArrayObj      m_array_obj;   // CArrayObj object

CSymbolInfo    m_temp_symbol; // symbol info object

//--- input parameters

input string   m_file_name="pays_interest.txt"; // File name, in \MQL5\Files\

//---

input ushort   InpStopLoss          = 15;          // Stop Loss, in pips (1.00045-1.00055=1 pips)

input ushort   InpTakeProfit        = 46;          // Take Profit, in pips (1.00045-1.00055=1 pips)

input ushort   InpTrailingFrequency = 9;           // Trailing, in seconds (< "10" -> only on a new bar)

input ushort   InpSignalsFrequency  = 9;           // Search signals, in seconds (< "10" -> only on a new bar)

input ushort   InpTrailingStop      = 0;           // Trailing Stop (min distance from price to Stop Loss, in pips

input ushort   InpTrailingStep      = 5;           // Trailing Step, in pips (1.00045-1.00055=1 pips)

input ENUM_LOT_OR_RISK InpLotOrRisk = risk;        // Money management: Lot OR Risk

input double   InpVolumeLotOrRisk   = 3.0;         // The value for "Money management"

//--- MA

input int                  Inp_MA_ma_period     = 12;          // MA: averaging period

input int                  Inp_MA_ma_shift      = 0;           // MA: horizontal shift

input ENUM_MA_METHOD       Inp_MA_ma_method     = MODE_SMA;    // MA: smoothing type

input ENUM_APPLIED_PRICE   Inp_MA_applied_price = PRICE_CLOSE; // MA: type of price

//---

input uchar    InpCurrentBar        = 0;           // Current Bar

input ushort   InpIndent            = 3;           // Indent, in pips (1.00045-1.00055=1 pips) 

//---

input bool     InpOnlyOne           = true;        // Only one positions 

input bool     InpReverse           = false;       // Reverse

input bool     InpCloseOpposite     = true;        // Close opposite

input bool     InpPrintLog          = false;       // Print log

input ulong    InpMagic             = 598595778;   // Magic number

//---

string array_symbols[];

ENUM_POSITION_TYPE array_pos_type[];

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

//| Expert initialization function                                   |

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

int OnInit()

  {

   string temp[7]=

     {

      "EURUSD",

      "AUDUSD",

      "USDJPY",

      "GBPUSD",

      "NZDUSD",

      "USDCAD",

      "AUDCAD"

     };

//---  

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

     {

      string read_symbol=temp[i];

      if(m_temp_symbol.Name(read_symbol)) // sets symbol name

         if(m_temp_symbol.RefreshRates())

            if(m_temp_symbol.Refresh())

              {

               double swap_long=m_temp_symbol.SwapLong();

               double swap_short=m_temp_symbol.SwapShort();

               if(swap_long>=swap_short && swap_long>0.0)

                 {

                  int size=ArraySize(array_symbols);

                  ArrayResize(array_symbols,size+1);

                  ArrayResize(array_pos_type,size+1);

                  array_symbols[size]=read_symbol;

                  array_pos_type[size]=POSITION_TYPE_BUY;

                 }

               else if(swap_short>=swap_long && swap_short>0.0)

                 {

                  int size=ArraySize(array_symbols);

                  ArrayResize(array_symbols,size+1);

                  ArrayResize(array_pos_type,size+1);

                  array_symbols[size]=read_symbol;

                  array_pos_type[size]=POSITION_TYPE_SELL;

                 }

              }

     }



   int size=ArraySize(array_symbols);

   if(size==0)

      return(INIT_FAILED);

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

     {

      CTradingEngine3 *multi=new CTradingEngine3;

      if(multi==NULL)

        {

         Print("Object CTradingEngine3 create error");

         return(INIT_FAILED);

        }

      m_array_obj.Add(multi);

      int init=multi.OnInit(

                            array_symbols[i],

                            InpStopLoss,            // Stop Loss, in pips (1.00045-1.00055=1 pips)

                            InpTakeProfit,          // Take Profit, in pips (1.00045-1.00055=1 pips)

                            InpTrailingFrequency,   // Trailing, in seconds (< "10" -> only on a new bar)

                            InpSignalsFrequency,    // Search signals, in seconds (< "10" -> only on a new bar)

                            InpTrailingStop,        // Trailing Stop (min distance from price to Stop Loss, in pips

                            InpTrailingStep,        // Trailing Step, in pips (1.00045-1.00055=1 pips)

                            InpLotOrRisk,           // Money management: Lot OR Risk

                            InpVolumeLotOrRisk,     // The value for "Money management"

                            Inp_MA_ma_period,       // MA: averaging period

                            Inp_MA_ma_shift,        // MA: horizontal shift

                            Inp_MA_ma_method,       // MA: smoothing type

                            Inp_MA_applied_price,   // MA: type of price

                            array_pos_type[i],// Position Type

                            InpCurrentBar,          // Current Bar

                            InpIndent,              // Indent, in pips (1.00045-1.00055=1 pips) 

                            InpOnlyOne,             // Only one positions 

                            InpCloseOpposite,       // Close opposite

                            InpPrintLog,            // Print log

                            InpMagic                // Magic number

                            );

      if(init!=INIT_SUCCEEDED)

         return(init);

     }

//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//---

   for(int i=0;i<m_array_obj.Total();i++)

     {

      CTradingEngine3 *multi=m_array_obj.At(i);

      if(multi==NULL)

        {

         //--- Error reading from array 

         Print("Object CMultiiMATrend create error");

         return;

        }

      multi.OnDeinit(reason);

     }

  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

//---

   for(int i=0;i<m_array_obj.Total();i++)

     {

      CTradingEngine3 *multi=m_array_obj.At(i);

      if(multi==NULL)

        {

         //--- Error reading from array 

         Print("Object CMultiiMATrend create error");

         return;

        }

      multi.OnTick();

     }

  }

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

//| TradeTransaction function                                        |

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

void OnTradeTransaction(const MqlTradeTransaction &trans,

                        const MqlTradeRequest &request,

                        const MqlTradeResult &result)

  {

//---

   for(int i=0;i<m_array_obj.Total();i++)

     {

      CTradingEngine3 *multi=m_array_obj.At(i);

      if(multi==NULL)

        {

         //--- Error reading from array 

         Print("Object CMultiiMATrend create error");

         return;

        }

      multi.OnTradeTransaction(trans,request,result);

     }

  }

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

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