PairsTrading

TopicStarter

Moderator
Apr 15, 2024
10,076
4
38

Introduction​

So, you've decided to dive into the world of PairsTrading, huh? Well, good for you. While some are singing praises, others are scratching their heads. And that's precisely why you're here – to get a no-nonsense guide on setting up and using this trading robot.

Installation and Setup​

Let's cut to the chase. Here's how you get this robot up and running:

  • Download the EA: Head over to the official website PairsTrading Robot to download the EA.
  • Install on MetaTrader 5: Copy the downloaded file to your ‘Experts’ folder. You can find this through File → Open Data Folder → MQL5 → Experts.
  • Attach to Chart: Open a chart (preferably one with a pair you want to trade), and drag the EA from the Navigator window onto the chart.
  • Configure Settings: This is where the fun begins. Set your lot size, risk management parameters, and pairs to trade. Don't get too ambitious with the lot size; you're not Warren Buffet.
  • Activate: Click 'OK' and sit back. Or, if you're like me, watch it like a hawk.

Experience Using PairsTrading​

So far so good… It is going well so far! – , [USER=mbrand0307]. Good for you guys. But let's keep it real. This robot won't turn you into a millionaire overnight. It's a tool, not a magic wand. My experience? It did reasonably well when I tested it, but I'd always keep an eye on it. [USER=zhuomi] seemed happy but for you non-Chinese speakers, don't bother with his QQ group. Meanwhile, [USER=nerojack] couldn't get it to work and never got a response from support. Not surprising in this industry.

[HEADING=2]Tips for Improving Performance[/HEADING]
Want to squeeze every bit of efficiency out of this robot? Try this:

[LIST]
[*][B]Keep It Updated:[/B] The developers may release updates. Keep your version current.
[*][B]Backtest:[/B] Run as many backtests as you can in different market conditions. Knowledge is power, after all.
[*][B]Diversify:[/B] Use it on multiple pairs, but don’t go overboard. Diversification is key.
[*][B]Risk Management:[/B] Keep your risk low. Greed never ends well – as [USER=asarov16] so wisely pointed out.
[*][B]Regular Check-ins:[/B] Don't just set and forget. The market is unpredictable; regular check-ins can save you from unexpected losses.
[/LIST]

[HEADING=2]Source Code for PairsTrading[/HEADING]
Ah, the source code. This is where things get interesting. The original source code of the PairsTrading algorithm sold on MQL5 is not disclosed. However, we can create a version based on the description available. If you're a coding enthusiast and want to play around with it, feel free to ask questions on easytradingforum.com.

Just to clarify, the EASY Trading Team does not sell the PairsTrading robot. We've merely created a code based on its description.

[CODE]mql5
//+------------------------------------------------------------------+
//| PairsTrading.mq5 |
//| Copyright 2024, Forex Robot EASY Team |
//| https://forexroboteasy.com/ |
//+------------------------------------------------------------------+
#property strict
#include <Trade\Trade.mqh>
#include <Charts\ChartObjects\ChartObjectsTxtControls.mqh>

//+------------------------------------------------------------------+
//| Global Variables and Objects |
//+------------------------------------------------------------------+
CTrade trade; // Trading object
input string Pair1 = EURUSD; // First currency pair
input string Pair2 = GBPUSD; // Second currency pair
input double LotSize = 0.1; // Default lot size
input int TimeFrame = PERIOD_H1; // Default timeframe
input double RiskPercentage = 2.0; // Risk percentage
input bool UseStopLoss = true; // Enable stop loss
input double StopLoss = 100.0; // Stop loss in points
input bool UseTakeProfit = true; // Enable take profit
input double TakeProfit = 100.0; // Take profit in points
input int BacktestPeriod = 12; // Backtest period in months
input bool EnableNotifications = false; // Enable notifications

//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Ensure proper symbol is selected
if(!CheckSymbols(Pair1) || !CheckSymbols(Pair2))
{
Print(One or both currency pairs are invalid.);
return(INIT_FAILED);
}
// Initialize chart
CreateDashboard();

// Initialize backtesting if applicable
InitializeBacktesting();

// Provide feedback
Print(PairsTrading initialized successfully.);

return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Clear dashboard elements if necessary
ClearDashboard();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// Fetch market data
double price1 = SymbolInfoDouble(Pair1, SYMBOL_BID);
double price2 = SymbolInfoDouble(Pair2, SYMBOL_BID);

// Display prices
ObjectSetDouble(0, PricePair1, OBJPROP_TEXT, StringFormat(PAIR1: %.5f, price1));
ObjectSetDouble(0, PricePair2, OBJPROP_TEXT, StringFormat(PAIR2: %.5f, price2));

// Execute trading strategies
ExecuteStrategies(price1, price2);
}
//+------------------------------------------------------------------+
//| Trade Execution Functions |
//+------------------------------------------------------------------+
void ExecuteStrategies(double price1, double price2)
{
// Sample trading logic
if(price1 > price2)
{
// Example: Buy Pair1 and Sell Pair2
PlaceOrder(Pair1, ORDER_TYPE_BUY);
PlaceOrder(Pair2, ORDER_TYPE_SELL);
}
else
{
// Example: Sell Pair1 and Buy Pair2
PlaceOrder(Pair1, ORDER_TYPE_SELL);
PlaceOrder(Pair2, ORDER_TYPE_BUY);
}
}
//+------------------------------------------------------------------+
//| Place Order Function |
//+------------------------------------------------------------------+
void PlaceOrder(string pair, ENUM_ORDER_TYPE order_type)
{
double stop_loss = 0.0;
double take_profit = 0.0;

if(UseStopLoss)
stop_loss = (order_type == ORDER_TYPE_BUY) ? StopLoss*Point() : -StopLoss*Point();

if(UseTakeProfit)
take_profit = (order_type == ORDER_TYPE_BUY) ? TakeProfit*Point() : -TakeProfit*Point();

// Place order with appropriate parameters
trade.SetExpertMagicNumber(123456);
if(order_type == ORDER_TYPE_BUY)
trade.Buy(LotSize, pair, 0.0, stop_loss, take_profit);
else
trade.Sell(LotSize, pair, 0.0, stop_loss, take_profit);
}
//+------------------------------------------------------------------+
//| Symbol Checking Function |
//+------------------------------------------------------------------+
bool CheckSymbols(string symbol)
{
if(SymbolSelect(symbol, true))
return(true);
else
{
Print(Symbol not found: , symbol);
return(false);
}
}
//+------------------------------------------------------------------+
//| Dashboard Functions |
//+------------------------------------------------------------------+
void CreateDashboard()
{
// Example: Create text on chart for displaying information
ObjectCreate(0, PricePair1, OBJ_TEXT, 0, 0, 0);
ObjectCreate(0, PricePair2, OBJ_TEXT, 0, 0, 0);

// Set text properties
ObjectSetInteger(0, PricePair1, OBJPROP_COLOR, clrLime);
ObjectSetInteger(0, PricePair2, OBJPROP_COLOR, clrLime);

ObjectSetDouble(0, PricePair1, OBJPROP_CORNER, CORNER_LEFT_UPPER);
ObjectSetDouble(0, PricePair2, OBJPROP_CORNER, CORNER_LEFT_UPPER);

ObjectSetDouble(0, PricePair1, OBJPROP_XDISTANCE, 10);
ObjectSetDouble(0, PricePair2, OBJPROP_XDISTANCE, 10);

ObjectSetDouble(0, PricePair1, OBJPROP_YDISTANCE, 20);
ObjectSetDouble(0, PricePair2, OBJPROP_YDISTANCE, 40);
}
//+------------------------------------------------------------------+
//| Clear Dashboard |
//+------------------------------------------------------------------+
void ClearDashboard()
{
ObjectDelete(0, PricePair1);
ObjectDelete(0, PricePair2);
}
//+------------------------------------------------------------------+
//| Initialization for Backtesting |
//+------------------------------------------------------------------+
void InitializeBacktesting()
{
// Logic for setting up backtesting parameters
}
//+------------------------------------------------------------------+
//| Custom Functions for Risk Management |
//+------------------------------------------------------------------+
double CalculateRisk(double balance, double risk_percent)
{
return(balance * (risk_percent / 100));
}
//+------------------------------------------------------------------+
[/CODE]

[HEADING=2]Download PairsTrading Robot from EASY Trading[/HEADING]
Ready to take the plunge? Navigate to the [URL=https://forexroboteasy.com/trading-robot/pairstrading/]PairsTrading Robot[/URL] and get your hands on it. If you have any questions about the code, drop them in the forum. We’re always here to help, albeit with a raised eyebrow and a smirk.

Happy trading. Or at least, try not to lose too much.