Trading Strategy Logic Overview (FMW_1)
This document provides a non-technical explanation of the automated trading logic contained within the FMW_1 script. The script is designed to autonomously monitor market conditions, manage risk, and execute trades based on specific technical indicators.
1. Trade Management and Protection
The script includes several mechanisms to manage active trades and protect capital:
- Trailing Stop: If enabled, the script will automatically move the "Stop Loss" (the price at which a trade closes if it goes against you) as the market moves in your favor. This helps lock in profits while allowing the trade room to continue growing.
- Position Monitoring: The script actively scans open trades. It ensures that it only manages orders related to the specific currency pair or asset currently being viewed on the chart.
2. Automated Risk Management
The script features a dynamic lot-sizing system designed to protect your account balance:
- Percentage-Based Sizing: If "Risk Management" is active, the script calculates the number of units (lots) to trade based on a percentage of your available free margin and leverage. This means it attempts to adjust your position size automatically based on how much money is currently available in your account.
- Safety Boundaries: Regardless of the calculations, the script enforces "hard limits" on trade sizes. It ensures that no single trade is smaller than the minimum allowed by the broker or larger than a pre-defined maximum limit.
3. Entry Strategy Logic (How it decides to Buy or Sell)
The script uses three distinct types of technical analysis to decide when to enter a trade:
- Moving Averages (Trend Filter): It compares two "Exponential Moving Averages" (EMA). These are smoothed lines that represent the average price over different periods. By comparing a fast-moving average against a slower-moving average, the script determines the current direction of the trend.
- Williams Percentile Range (Momentum): This indicator is used to identify whether the market is "overbought" (too high) or "oversold" (too low). It helps the script avoid entering trades at prices that are moving too fast in one direction without a chance to correct.
- Fractals: While calculated in the background, these help identify structural highs and lows in price action.
Execution Rules:
- To Sell (Short): The script looks for a specific "bearish" alignment where the fast moving average is above the slow moving average AND the momentum indicator suggests there is room for the price to drop. When both conditions are met, it places a Sell order.
- To Buy (Long): The script looks for a "bullish" alignment where the fast moving average is below the slow moving average AND the momentum indicator suggests the price is sufficiently low. When both conditions are met, it places a Buy order.
4. Trade Execution Details
When the entry conditions are met, the script automatically calculates:
- Take Profit: The target price where the trade will automatically close to secure gains.
- Stop Loss: The safety price where the trade will close to prevent further losses.
- Execution: It sends the order to the market instantly using the calculated lot size and price coordinates.
//+------------------------------------------------------------------+
//| FMW_1.mq4 |
//| * |
//| * |
//+------------------------------------------------------------------+
#property copyright "FMW_1"
#property link "fraktalis@gmail.com"
//---- input parameters
extern double Lots=0.2;
extern bool RiskManagement=true;
extern double RiskPercent=20;
extern int StopLose=0;
extern int TakeProfit=12;
extern int TrailingStop=0;
extern int WPRSell=10;
extern int WPRBuy=90;
extern int S=80; // EMA
extern int B=40; // EMA
int start()
{
double SL,TP;
int Total=0;
for(int cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol())
{
Total++;
if(OrderType()==OP_BUY)
{
if(TrailingStop>0
&& Bid-OrderOpenPrice()>Point*TrailingStop
&& OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0);
return(0);
}
}
if(OrderType()==OP_SELL)
{
if(TrailingStop>0
&& OrderOpenPrice()-Ask>Point*TrailingStop
&& (OrderStopLoss()>Ask+Point*TrailingStop || OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0);
return(0);
}
}
}
}
if(OrdersTotal()==1)return(0);
if(RiskManagement)
{
if(RiskPercent<0.1||RiskPercent>100)
{
Comment("Invalid Risk Value.");
return(0);
}
else
{
Lots=MathFloor((AccountFreeMargin()*AccountLeverage()*RiskPercent*Point*100)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*
MarketInfo(Symbol(),MODE_MINLOT)))*MarketInfo(Symbol(),MODE_MINLOT);
}
}
if(Lots<0.01)Lots=0.01;//My min lots
if(Lots>100)Lots=100;//My max lots
if(RiskManagement==false){Lots=Lots;}
double SellMA=iMA(NULL,0,S,0,MODE_EMA,PRICE_OPEN,1);
double BuyMA=iMA(NULL,0,B,0,MODE_EMA,PRICE_OPEN,1);
double hight=iFractals(NULL,0,MODE_UPPER,3);
double low=iFractals(NULL,0,MODE_LOWER,3);
double R=iWPR(NULL,0,21,1);
if(SellMA>BuyMA && R>-WPRSell)
{
if (TakeProfit>0) TP=Bid-TakeProfit*Point;
if (StopLose>0) SL=Bid+StopLose*Point;
OrderSend(Symbol(),OP_SELL,Lots,Bid,2,SL,TP,NULL,0,0);
return(0);
}
if(SellMA<BuyMA && R<-WPRBuy)
{
if (TakeProfit>0) TP=Ask+TakeProfit*Point;
if (StopLose>0) SL=Ask-StopLose*Point;
OrderSend(Symbol(),OP_BUY,Lots,Ask,2,SL,TP,NULL,0,0);
return(0);
}
return(0);
}
//+------------------------------------------------------------------+
Comments