Understanding the RobotPowerM5_meta4V12 (RobotBB) Trading Strategy
This document provides a detailed explanation of the logic behind the RobotPowerM5_meta4V12
trading strategy, designed for MetaTrader's MQL scripting language. This strategy is intended for use on 5-minute charts and focuses on automated trading with specific rules for buying and selling.
Overview
The RobotPowerM5_meta4V12 strategy automates trading decisions based on market indicators. It primarily uses two indicators to determine whether to buy or sell: the Bulls Power and Bears Power, which are part of a set known as "Bollinger Bands." The strategy aims to capitalize on short-term price movements by executing trades with predefined profit targets and managing risks using trailing stops.
Key Parameters
- Chart Type: Designed for 5-minute charts.
- Currency Pair Preference: GBP pairs are recommended due to their liquidity and volatility characteristics.
- Lot Size: Determines the volume of currency traded, set at 1.0 lots by default.
- Trailing Stop: Used to lock in profits as a trade moves favorably; set to 15 pips.
- Take Profit: The maximum profit target for each trade, recommended not to exceed 150 pips.
- Stop Loss: Set at 45 pips but is generally discouraged from being used actively due to the strategy's reliance on trailing stops.
Logic and Functionality
Initialization and Setup
-
Initial Checks:
- The strategy begins by ensuring there are enough historical data points (bars) for analysis. A minimum of 200 bars is required.
- If insufficient data is available, the strategy will not execute any trades and notifies the user.
-
Indicator Calculation:
- The Bulls Power and Bears Power indicators are calculated to assess market momentum and trend strength over a specified period (
BullBearPeriod
).
- The Bulls Power and Bears Power indicators are calculated to assess market momentum and trend strength over a specified period (
Trading Signals
-
Buying Signal:
- A buying signal is generated when the sum of Bulls Power and Bears Power is greater than zero. This indicates upward momentum in the market.
-
Selling Signal:
- Conversely, a selling signal occurs when this sum is less than zero, suggesting downward pressure or bearish momentum.
Trade Management
-
Existing Trades:
- The strategy reviews all open trades to apply trailing stops dynamically. This helps protect gains by adjusting the stop level as prices move favorably.
-
New Orders:
- If a buying signal is detected and no active selling or closing conditions are met, the strategy places a buy order with a calculated take profit and trailing stop.
- Similarly, if a selling signal is present without conflicting conditions, a sell order is executed.
Alerts
- The strategy provides real-time alerts through both print statements and notifications whenever a trade decision (buy/sell) is made. This ensures the user is informed of all automated actions taken by the system.
Conclusion
The RobotPowerM5_meta4V12 strategy leverages market indicators to automate trading decisions on 5-minute charts, primarily focusing on GBP currency pairs. By using Bulls and Bears Power for signal generation and managing trades with trailing stops, it aims to maximize profitability while minimizing risk. The strategy emphasizes dynamic trade management and provides alerts to keep the trader informed of all activities.
Profitability Reports
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| RobotPowerM5_meta4V12 (RobotBB).mq4 |
//| Copyright © 2005, Company |
//| http://www.funds.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005"
#property link "http://www.funds.com"
// A reliable expert, use it on 5 min charts (GBP is best) with
// 150/pips profit limit.
// No worries, check the results.
extern int BullBearPeriod=5;
extern double lots = 1.0;
extern double trailingStop = 15; // trail stop in points
extern double takeProfit = 150; // recomended no more than 150
extern double stopLoss = 45; // do not use s/l
extern double slippage = 3;
// EA identifier. Allows for several co-existing EA with different values.
extern string nameEA = "Soultrading";
//----
double bull, bear;
double realTP, realSL, b, s, sl, tp;
bool isBuying = false, isSelling = false, isClosing = false;
int cnt, ticket;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
//----
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
//----
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
// Check for invalid bars and takeprofit
if(Bars < 200)
{
Print("Not enough bars for this strategy - ", nameEA);
return(-1);
}
// Calculate indicators' value
calculateIndicators();
// Control open trades
int totalOrders = OrdersTotal();
int numPos = 0;
// scan all orders and positions...
for(cnt = 0; cnt < totalOrders; cnt++)
{
// the next line will check for ONLY market trades, not entry orders
OrderSelect(cnt, SELECT_BY_POS);
// only look for this symbol, and only orders from this EA
if(OrderSymbol() == Symbol() && OrderType() <= OP_SELL )
{
numPos++;
// Check for close signal for bought trade
if(OrderType() == OP_BUY)
{
// Check trailing stop
if(trailingStop > 0)
{
if(Bid - OrderOpenPrice() > trailingStop*Point)
{
if(OrderStopLoss() < (Bid - trailingStop*Point))
OrderModify(OrderTicket(), OrderOpenPrice(),
Bid - trailingStop*Point, OrderTakeProfit(), 0, Blue);
}
}
}
else
// Check sold trade for close signal
{
// Control trailing stop
if(trailingStop > 0)
{
if(OrderOpenPrice() - Ask > trailingStop*Point)
{
if(OrderStopLoss() == 0 || OrderStopLoss() > Ask + trailingStop*Point)
OrderModify(OrderTicket(), OrderOpenPrice(),
Ask + trailingStop*Point, OrderTakeProfit(), 0, Red);
}
}
}
}
}
// If there is no open trade for this pair and this EA
if(numPos < 1)
{
if(AccountFreeMargin() < 1000*lots)
{
Print("Not enough money to trade ", lots, " lots. Strategy:", nameEA);
return(0);
}
// Check for BUY entry signal
if(isBuying && !isSelling && !isClosing)
{
sl = Ask - stopLoss * Point;
tp = Bid + takeProfit * Point;
OrderSend(Symbol(), OP_BUY, lots, Ask, slippage, sl, tp, nameEA + CurTime(),
0, 0, Green);
Comment(sl);
if(ticket < 0)
Print("OrderSend (", nameEA, ") failed with error #", GetLastError());
prtAlert("Day Trading: Buying");
}
// Check for SELL entry signal
if(isSelling && !isBuying && !isClosing)
{
sl = Bid + stopLoss * Point;
tp = Ask - takeProfit * Point;
OrderSend(Symbol(), OP_SELL, lots, Bid, slippage, sl, tp, nameEA + CurTime(),
0, 0, Red);
if(ticket < 0)
Print("OrderSend (", nameEA, ") failed with error #", GetLastError());
prtAlert("Day Trading: Selling");
}
}
return(0);
}
//+------------------------------------------------------------------+
//| Calculate indicators' value |
//+------------------------------------------------------------------+
void calculateIndicators()
{
bull = iBullsPower(NULL, 0, BullBearPeriod, PRICE_CLOSE, 1);
bear = iBearsPower(NULL, 0, BullBearPeriod, PRICE_CLOSE, 1);
Comment("bull+bear= ", bull + bear);
//sarCurrent = iSAR(NULL,0,0.02,0.2,0); // Parabolic Sar Current
//sarPrevious = iSAR(NULL,0,0.02,0.2,1); // Parabolic Sar Previuos
//momCurrent = iMomentum(NULL,0,14,PRICE_OPEN,0); // Momentum Current
// momPrevious = iMomentum(NULL,0,14,PRICE_OPEN,1); // Momentum Previous
b = 1 * Point + iATR(NULL, 0, 5, 1)*1.5;
s = 1 * Point + iATR(NULL, 0, 5, 1)*1.5;
// Check for BUY, SELL, and CLOSE signal
// isBuying = (sarCurrent <= Ask && sarPrevious>sarCurrent && momCurrent < 100 &&
// macdHistCurrent < macdSignalCurrent && stochHistCurrent < 35);
// isSelling = (sarCurrent >= Bid && sarPrevious < sarCurrent && momCurrent > 100 &&
// macdHistCurrent > macdSignalCurrent && stochHistCurrent > 60);
isBuying = (bull+bear > 0);
isSelling = (bull+bear < 0);
isClosing = false;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void prtAlert(string str = "")
{
Print(str);
Alert(str);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---