UpDn-Alexander Piechotta
Download scriptThis automated trading script is designed to manage and execute trades on the MetaTrader platform by monitoring specific market momentum indicators. It operates by analyzing the relationship between current and previous market power data to determine entry signals and manage existing positions.
Core Trading Logic
Market Analysis and Entry Signals The script continuously monitors a "Bulls Power" indicator, which measures the strength of buying pressure in the market. It compares the strength of the previous time period against the current one to identify potential trends:
- Sell Opportunities: If the momentum shows a decline (where the previous power was higher than the current power) and the current power remains positive, the script identifies a potential downward move. When no other trades are active, it automatically opens a "Sell" position with a predefined profit target.
- Buy Opportunities: If the market power drops into negative territory, indicating significant selling pressure, the script interprets this as a signal to prepare for a reversal or a low-point entry. In this scenario, when no other trades are active, it automatically opens a "Buy" position.
Trade Management and Profit Protection Once a trade is active, the script actively monitors the price movement to protect gains through a trailing mechanism:
- Trailing for Buy Positions: For active "Buy" orders, the script tracks how much the price has moved in your favor. If the market price rises beyond a specific threshold above your entry price, the script is designed to close the position, effectively locking in profits.
- Trailing for Sell Positions: Conversely, for active "Sell" orders, the script monitors downward movement. If the price drops sufficiently below your entry price, the script triggers a closure of that position to secure the gains.
Operational Parameters
The system is governed by several user-defined settings that dictate its behavior:
- Volume Control: Defines the size of the trade (Lots) executed at each signal.
- Profit Targets: Sets the specific distance from the entry price at which a profit is realized.
- Dynamic Movement: The trailing thresholds determine how much "room" the market has to move in your favor before the script decides to exit the trade.
In summary, this script automates the transition from analysis to execution by reacting to shifts in bullish/bearish momentum, while simultaneously managing active trades to capture profit as price movement evolves.
//+------------------------------------------------------------------+
extern double TakeProfit = 7;
extern double Lots = 0.1;
extern double TrailingStop = 5;
extern double StopLoss = 30;
int start()
{
double pos1pre=0;
double pos2cur=0;
int cnt=0;
int mode=0;
double openpozprice=0;
pos1pre = iBullsPower(NULL,0,13,PRICE_WEIGHTED,1);
pos2cur = iBullsPower(NULL,0,13,PRICE_WEIGHTED,0);
//Comment("??????? ??????? ",pos2cur,"Previous pos", pos1pre );
if (pos1pre >pos2cur) {
//????????? ??????? ???????
for (cnt=1; cnt<OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if( OrderSymbol()==Symbol() && OrderType()==OP_BUY )
{
if (Bid>(OrderOpenPrice()+TrailingStop*Point))
{
OrderClose(OrderTicket(),OrderLots(),Bid,5,Violet);
return(0);
}
}
}
}
if (pos2cur<0)
//????????? ???????? ???????
{
for (cnt=1; cnt<OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if( OrderSymbol()==Symbol() && OrderType()==OP_SELL )
{
if (Ask< (OrderOpenPrice()-TrailingStop*Point))
{
OrderClose(OrderTicket(),OrderLots(),Ask,5,Violet);
return(0);
} }
}
}
if (OrdersTotal() < 1 )
{
Print("pos1pre = "+pos1pre+" pos2cur ="+pos2cur);
if (pos1pre>pos2cur && pos2cur>0) {
int ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"",0,0,Gold);
return(0);
}
// ????????? ?? ??????????? ?????? ? ??????? ??????? (BUY)
if (pos2cur<0) {
// print("K = "+K+" S ="+S);
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"",0,0,Gold);
return(0);
}
}
}
Profitability Reports
Expected payoff
Average expected payoff across the available backtests for each symbol.
Comments