195 lines
21 KiB
MQL5
195 lines
21 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Two_Symbols_iRSI_EA.mq5 |
|
|
//| Copyright © 2020, Vladimir Karputov |
|
|
//| https://www.mql5.com/ru/market/product/43516 |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright © 2020, Vladimir Karputov"
|
|
#property link "https://www.mql5.com/ru/market/product/43516"
|
|
#property version "1.004"
|
|
//---
|
|
#include "Two Symbols iRSI EA Class.mqh"
|
|
#include <Arrays\ArrayObj.mqh>
|
|
CArrayObj m_array_obj; // CArrayObj object
|
|
//--- input parameters
|
|
input group "Strategy parameters"
|
|
input double InpProfitTarget = 15; // Profit target, in deposit money
|
|
input double InpMaximumLoss = -45; // Maximum loss, in deposit money
|
|
input group "Symdol 0 parameters"
|
|
input ushort InpStopLoss_0 = 15; // 0: Stop Loss, in pips (1.00045-1.00055=1 pips)
|
|
input ushort InpTakeProfit_0 = 46; // 0: Take Profit, in pips (1.00045-1.00055=1 pips)
|
|
input ushort InpTrailingFrequency_0 = 10; // 0: Trailing, in seconds (< "10" -> only on a new bar)
|
|
input ushort InpSignalsFrequency_0 = 9; // 0: Search signals, in seconds (< "10" -> only on a new bar)
|
|
input ushort InpTrailingStop_0 = 25; // 0: Trailing Stop (min distance from price to Stop Loss, in pips
|
|
input ushort InpTrailingStep_0 = 5; // 0: Trailing Step, in pips (1.00045-1.00055=1 pips)
|
|
input ENUM_LOT_OR_RISK InpLotOrRisk_0 = risk; // 0: Money management: Lot OR Risk
|
|
input double InpVolumeLotOrRisk_0 = 3.0; // 0: The value for "Money management"
|
|
input ENUM_TRADE_MODE InpTradeMode_0 = buy_sell; // 0: Trade mode:
|
|
input string Inp_RSI_symbol_0 = "EURUSD"; // 0: RSI symbol
|
|
input int Inp_RSI_ma_period_0 = 14; // 0: RSI averaging period
|
|
input ENUM_APPLIED_PRICE Inp_RSI_applied_price_0 = PRICE_CLOSE; // 0: RSI type of price
|
|
input uchar InpMaxPositions_0 = 5; // 0: Maximum positions
|
|
input group "Symdol 1 parameters"
|
|
input ushort InpStopLoss_1 = 15; // 1: Stop Loss, in pips (1.00045-1.00055=1 pips)
|
|
input ushort InpTakeProfit_1 = 46; // 1: Take Profit, in pips (1.00045-1.00055=1 pips)
|
|
input ushort InpTrailingFrequency_1 = 10; // 1: Trailing, in seconds (< "10" -> only on a new bar)
|
|
input ushort InpSignalsFrequency_1 = 9; // 1: Search signals, in seconds (< "10" -> only on a new bar)
|
|
input ushort InpTrailingStop_1 = 25; // 1: Trailing Stop (min distance from price to Stop Loss, in pips
|
|
input ushort InpTrailingStep_1 = 5; // 1: Trailing Step, in pips (1.00045-1.00055=1 pips)
|
|
input ENUM_LOT_OR_RISK InpLotOrRisk_1 = risk; // 1: Money management: Lot OR Risk
|
|
input double InpVolumeLotOrRisk_1 = 3.0; // 1: The value for "Money management"
|
|
input ENUM_TRADE_MODE InpTradeMode_1 = buy_sell; // 1: Trade mode:
|
|
input string Inp_RSI_symbol_1 = "USDCAD"; // 1: RSI symbol
|
|
input int Inp_RSI_ma_period_1 = 14; // 1: RSI averaging period
|
|
input ENUM_APPLIED_PRICE Inp_RSI_applied_price_1 = PRICE_CLOSE; // 1: RSI type of price
|
|
input uchar InpMaxPositions_1 = 5; // 1: Maximum positions
|
|
input group "Symdol 0 and Symbol 1 parameters"
|
|
input ulong InpDeviation = 10; // Deviation, in points (1.00045-1.00055=10 points)
|
|
input bool InpOnlyOne = false; // Only one positions
|
|
input bool InpReverse = false; // Reverse
|
|
input bool InpCloseOpposite = false; // Close opposite
|
|
input bool InpPrintLog = false; // Print log
|
|
input ulong InpMagic = 591064158; // Magic number
|
|
//+------------------------------------------------------------------+
|
|
//| Expert initialization function |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
//---
|
|
CTradingEngine31 *multi_0=new CTradingEngine31;
|
|
if(multi_0==NULL)
|
|
{
|
|
Print("Object CTradingEngine31 create error");
|
|
return(INIT_FAILED);
|
|
}
|
|
m_array_obj.Add(multi_0);
|
|
int init_0=multi_0.OnInit(
|
|
InpStopLoss_0, // Stop Loss, in pips (1.00045-1.00055=1 pips)
|
|
InpTakeProfit_0, // Take Profit, in pips (1.00045-1.00055=1 pips)
|
|
InpTrailingFrequency_0, // Trailing, in seconds (< "10" -> only on a new bar)
|
|
InpSignalsFrequency_0, // Search signals, in seconds (< "10" -> only on a new bar)
|
|
InpTrailingStop_0, // Trailing Stop (min distance from price to Stop Loss, in pips
|
|
InpTrailingStep_0, // Trailing Step, in pips (1.00045-1.00055=1 pips)
|
|
InpLotOrRisk_0, // Money management: Lot OR Risk
|
|
InpVolumeLotOrRisk_0, // The value for "Money management"
|
|
InpTradeMode_0, // Trade mode:
|
|
Inp_RSI_symbol_0, // RSI symbol
|
|
Inp_RSI_ma_period_0, // RSI averaging period
|
|
Inp_RSI_applied_price_0, // RSI type of price
|
|
InpMaxPositions_0, // Maximum positions
|
|
InpDeviation, // Deviation, in points (1.00045-1.00055=10 points)
|
|
InpOnlyOne, // Only one positions
|
|
InpReverse, // Reverse
|
|
InpCloseOpposite, // Close opposite
|
|
InpPrintLog, // Print log
|
|
InpMagic // Magic number
|
|
);
|
|
if(init_0!=INIT_SUCCEEDED)
|
|
return(init_0);
|
|
|
|
CTradingEngine31 *multi_1=new CTradingEngine31;
|
|
if(multi_1==NULL)
|
|
{
|
|
Print("Object CTradingEngine31 create error");
|
|
return(INIT_FAILED);
|
|
}
|
|
m_array_obj.Add(multi_1);
|
|
int init_1=multi_1.OnInit(
|
|
InpStopLoss_1, // Stop Loss, in pips (1.00045-1.00055=1 pips)
|
|
InpTakeProfit_1, // Take Profit, in pips (1.00045-1.00055=1 pips)
|
|
InpTrailingFrequency_1, // Trailing, in seconds (< "10" -> only on a new bar)
|
|
InpSignalsFrequency_1, // Search signals, in seconds (< "10" -> only on a new bar)
|
|
InpTrailingStop_1, // Trailing Stop (min distance from price to Stop Loss, in pips
|
|
InpTrailingStep_1, // Trailing Step, in pips (1.00045-1.00055=1 pips)
|
|
InpLotOrRisk_1, // Money management: Lot OR Risk
|
|
InpVolumeLotOrRisk_1, // The value for "Money management"
|
|
InpTradeMode_1, // Trade mode:
|
|
Inp_RSI_symbol_1, // RSI symbol
|
|
Inp_RSI_ma_period_1, // RSI averaging period
|
|
Inp_RSI_applied_price_1, // RSI type of price
|
|
InpMaxPositions_1, // Maximum positions
|
|
InpDeviation, // Deviation, in points (1.00045-1.00055=10 points)
|
|
InpOnlyOne, // Only one positions
|
|
InpReverse, // Reverse
|
|
InpCloseOpposite, // Close opposite
|
|
InpPrintLog, // Print log
|
|
InpMagic // Magic number
|
|
);
|
|
if(init_1!=INIT_SUCCEEDED)
|
|
return(init_1);
|
|
//---
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert deinitialization function |
|
|
//+------------------------------------------------------------------+
|
|
void OnDeinit(const int reason)
|
|
{
|
|
//---
|
|
for(int i=0; i<m_array_obj.Total(); i++)
|
|
{
|
|
CTradingEngine31 *multi=m_array_obj.At(i);
|
|
if(multi==NULL)
|
|
{
|
|
//--- Error reading from array
|
|
Print("Object CMultiGrid create error");
|
|
return;
|
|
}
|
|
multi.OnDeinit(reason);
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert tick function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTick()
|
|
{
|
|
double profit_all=0;
|
|
//---
|
|
for(int i=0; i<m_array_obj.Total(); i++)
|
|
{
|
|
CTradingEngine31 *multi=m_array_obj.At(i);
|
|
if(multi==NULL)
|
|
{
|
|
//--- Error reading from array
|
|
Print("Object CMultiGrid create error");
|
|
return;
|
|
}
|
|
multi.OnTick();
|
|
profit_all+=multi.ProfitAllPositions();
|
|
}
|
|
//--- close all
|
|
if(profit_all>=InpProfitTarget || profit_all<=InpMaximumLoss)
|
|
{
|
|
for(int i=0; i<m_array_obj.Total(); i++)
|
|
{
|
|
CTradingEngine31 *multi=m_array_obj.At(i);
|
|
if(multi==NULL)
|
|
{
|
|
//--- Error reading from array
|
|
Print("Object CMultiGrid create error");
|
|
return;
|
|
}
|
|
multi.CloseAllPositions(true);
|
|
}
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| TradeTransaction function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTradeTransaction(const MqlTradeTransaction &trans,
|
|
const MqlTradeRequest &request,
|
|
const MqlTradeResult &result)
|
|
{
|
|
//---
|
|
for(int i=0; i<m_array_obj.Total(); i++)
|
|
{
|
|
CTradingEngine31 *multi=m_array_obj.At(i);
|
|
if(multi==NULL)
|
|
{
|
|
//--- Error reading from array
|
|
Print("Object CMultiiMATrend create error");
|
|
return;
|
|
}
|
|
multi.OnTradeTransaction(trans,request,result);
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|