Okay, here's a breakdown of what this MetaTrader script does, explained in a way that doesn't require any programming knowledge.
Overall Purpose
This script is designed to automatically trade on the Forex market. It's an "Expert Advisor" (EA), meaning it analyzes the market and opens/closes trades based on a predefined set of rules. The specific strategy it uses is based on something called "Stochastic Oscillators."
Core Idea: The "Ten Stochs Wave"
Imagine the script is watching ten different waves on a screen. Each wave represents a slightly different calculation of market momentum (the speed and strength of price changes). These waves are "Stochastic Oscillators". The script looks at where these waves are relative to certain high and low points.
- "Oversold" Condition (Buy Signal): If all ten waves are very low, it suggests the market might be "oversold." Think of it like a rubber band stretched too far; it's likely to snap back. The script might then decide to buy, betting the price will go up.
- "Overbought" Condition (Sell Signal): Conversely, if all ten waves are very high, the market might be "overbought." The rubber band is stretched too far in the other direction. The script might decide to sell, betting the price will go down.
Key Settings & Controls
The script has several settings that you, as a user, can adjust. Think of them as knobs and dials to customize how the robot trades. Here are some important ones:
- Stochastic Settings: There are settings to slightly adjust how the "waves" (Stochastic Oscillators) are calculated. This allows you to fine-tune the sensitivity of the trading strategy.
- Overbought/Oversold Levels: You can set the exact levels that the "waves" need to reach before the script considers the market overbought or oversold. Think of it like setting the threshold for how high or low the waves need to be.
- Lot Size: This determines how much money the script will risk on each trade. A higher lot size means potentially bigger profits (but also bigger losses).
- Money Management: The script can automatically adjust the lot size based on your account balance and a risk percentage you specify. This helps control risk.
- Stop Loss & Take Profit: These are safety nets for each trade.
- Stop Loss: If the price moves against the script's bet, the trade will automatically close when it reaches a certain loss level. This limits potential losses.
- Take Profit: If the price moves in favor of the script's bet, the trade will automatically close when it reaches a certain profit level. This secures profits.
- Trailing Stop: This is a more advanced stop loss. As the price moves in a favorable direction, the stop loss automatically adjusts upwards (for a buy) or downwards (for a sell) to lock in profits.
- Breakeven: This setting tells the script to move the stop loss to the trade's entry price once the trade has reached a certain profit level. This guarantees that the trade won't result in a loss.
- Reverse: a setting to make oposite calls
- Adding positions can be activated so the script will enter new trades if the rules are meet
- Maximum orders a setting to limit the number of operations that can be open
How It Works Step-by-Step
- Analysis: The script constantly watches the market, calculating the ten "Stochastic Oscillator" waves.
- Signal Check: It checks if all ten waves are above the "overbought" level or below the "oversold" level.
- Trade Decision:
- If the conditions are met, it decides whether to buy or sell (or do the reverse, depending on the "Reverse" setting).
- It also checks if it's allowed to open more positions ("Add Positions" setting) and if it's reached the maximum number of allowed open trades.
- Order Placement: If all conditions are right, the script sends an order to your broker to open a new trade with the specified lot size, stop loss, and take profit levels.
- Trade Management: The script continuously monitors open trades, adjusting the stop loss based on the "Trailing Stop" and "Breakeven" settings. It also checks if the stop loss or take profit levels have been reached, and if so, closes the trade.
- Closing Conditions: There are also optional conditions for closing trades based on alternative indicators and the use of real stop losses or take profits.
Important Considerations
- Risk: Forex trading involves risk. This script can lose money if the market moves against its trades.
- Customization: The effectiveness of the script depends heavily on the settings you choose. You'll need to experiment to find settings that work well for the specific currency pair and market conditions you're trading.
- Backtesting: Before using this script with real money, it's crucial to "backtest" it. This means running it on historical data to see how it would have performed in the past. This can give you an idea of its potential profitability and risk.
//+------------------------------------------------------------------+
//| Ten Stochs Wave EA.mq4 |
//| Copyright © 2008, TradingSytemForex |
//| http://www.tradingsystemforex.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, TradingSytemForex"
#property link "http://www.tradingsystemforex.com"
#define OrSt "Ten Stochs Wave EA"
extern string STO="---------------- Stochs";
extern double First_Stoch_KP=4;
extern double Stoch_HLevel=80;
extern double Stoch_LLevel=20;
extern string LM="---------------- Lot Management";
extern double Lots=0.1;
extern bool MM=false; //money management
extern double Risk=10; //risk in percentage
extern string TSTB="---------------- TP SL TS BE";
bool RealSL_Enabled=false;
int RealSL=5; //stop loss under 15 pîps
bool RealTP_Enabled=false;
int RealTP=10; //take profit under 10 pîps
extern int SL=0; //stop loss
extern int TP=0; //take profit
extern int TS=0; //trailing stop
extern int TS_Step=1; //trailing stop step
extern int BE=0; //breakeven
extern string EXT="---------------- Extras";
extern bool Reverse=false;
bool Add_Positions=false; //positions cumulated
int MaxOrders=100; //maximum number of orders
extern int Magic=0;
int Slip=3;static int TL=0;double MML=0;
// expert start function
int start(){int j=0,limit=1;double BV=0,SV=0;BV=0;SV=0;double STOM1,STOM2,STOM3,STOM4,STOM5,STOM6,STOM7,STOM8,STOM9,STOM10;
if(CntO(OP_BUY,Magic)>0) TL=1;if(CntO(OP_SELL,Magic)>0) TL=-1;for(int i=1;i<=limit;i++){
STOM1=iStochastic(NULL,0,First_Stoch_KP,3,3,MODE_SMA,0,MODE_MAIN,i);
STOM2=iStochastic(NULL,0,First_Stoch_KP+1,3,3,MODE_SMA,0,MODE_MAIN,i);
STOM3=iStochastic(NULL,0,First_Stoch_KP+2,3,3,MODE_SMA,0,MODE_MAIN,i);
STOM4=iStochastic(NULL,0,First_Stoch_KP+3,3,3,MODE_SMA,0,MODE_MAIN,i);
STOM5=iStochastic(NULL,0,First_Stoch_KP+4,3,3,MODE_SMA,0,MODE_MAIN,i);
STOM6=iStochastic(NULL,0,First_Stoch_KP+5,3,3,MODE_SMA,0,MODE_MAIN,i);
STOM7=iStochastic(NULL,0,First_Stoch_KP+6,3,3,MODE_SMA,0,MODE_MAIN,i);
STOM8=iStochastic(NULL,0,First_Stoch_KP+7,3,3,MODE_SMA,0,MODE_MAIN,i);
STOM9=iStochastic(NULL,0,First_Stoch_KP+8,3,3,MODE_SMA,0,MODE_MAIN,i);
STOM10=iStochastic(NULL,0,First_Stoch_KP+9,3,3,MODE_SMA,0,MODE_MAIN,i);
if(STOM1<Stoch_LLevel && STOM2<Stoch_LLevel && STOM3<Stoch_LLevel && STOM4<Stoch_LLevel && STOM5<Stoch_LLevel && STOM6<Stoch_LLevel && STOM7<Stoch_LLevel && STOM8<Stoch_LLevel && STOM9<Stoch_LLevel && STOM10<Stoch_LLevel){if(Reverse) BV=1; else SV=1; break;}
if(STOM1>Stoch_HLevel && STOM2>Stoch_HLevel && STOM3>Stoch_HLevel && STOM4>Stoch_HLevel && STOM5>Stoch_HLevel && STOM6>Stoch_HLevel && STOM7>Stoch_HLevel && STOM8>Stoch_HLevel && STOM9>Stoch_HLevel && STOM10>Stoch_HLevel){if(Reverse) SV=1; else BV=1; break;}}
// expert money management
if(MM){if(Risk<0.1 || Risk>100) {Comment("Invalid Risk Value."); return(0);}
else {MML=MathFloor((AccountFreeMargin() *AccountLeverage()*Risk*Point*100)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*MarketInfo(Symbol(),MODE_MINLOT )))*MarketInfo(Symbol(),MODE_MINLOT );}}
if(MM==false){MML=Lots;}
// expert init positions
int cnt=0,OP=0,OS=0,OB=0,CS=0,CB=0;OP=0;for(cnt=0; cnt<OrdersTotal();cnt++) {OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if((OrderType()==OP_SELL || OrderType()==OP_BUY) && OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)) OP=OP+1;}
if(OP>=1){OS=0; OB=0;}OB=0;OS=0;CB=0;CS=0;
// expert conditions to open position
if(SV>0){OS=1;OB=0;}if(BV>0){OB=1;OS=0;}
// expert conditions to close position
if((SV>0) || (RealSL_Enabled && (OrderOpenPrice()-Bid)/Point>=RealSL)||(RealTP_Enabled && (Ask-OrderOpenPrice())/Point>=RealTP)){CB=1;}
if((BV>0) || (RealSL_Enabled && (Ask-OrderOpenPrice())/Point>=RealSL)||(RealTP_Enabled && (OrderOpenPrice()-Bid)/Point>=RealTP)){CS=1;}
for(cnt=0;cnt<OrdersTotal();cnt++){OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)){if (CB==1){OrderClose(OrderTicket(),OrderLots(),Bid,Slip,Red); return(0);}}
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)){
if(CS==1){OrderClose(OrderTicket(),OrderLots(),Ask,Slip,Red);return(0);}}}double SLI=0,TPI=0;int TK=0;
// expert open position value
if((AddP() && Add_Positions && OP<=MaxOrders) || (OP==0 && !Add_Positions)) {
if(OS==1){if (TP==0) TPI=0; else TPI=Bid-TP*Point;if (SL==0) SLI=0; else SLI=Bid+SL*Point;TK=OrderSend(Symbol(),OP_SELL,MML,Bid,Slip,SLI,TPI,OrSt,Magic,0,Red);OS=0;return(0);}
if(OB==1){if(TP==0) TPI=0; else TPI=Ask+TP*Point;if(SL==0) SLI=0; else SLI=Ask-SL*Point;TK=OrderSend(Symbol(),OP_BUY,MML,Ask,Slip,SLI,TPI,OrSt,Magic,0,Lime);OB=0; return(0);}}
for(j=0;j<OrdersTotal();j++){if(OrderSelect(j,SELECT_BY_POS, MODE_TRADES)){if (OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)) {TrP();}}}return(0);}
// expert number of orders
int CntO(int Type,int Magic){int _CntO;_CntO=0;
for(int j=0;j<OrdersTotal();j++){OrderSelect(j, SELECT_BY_POS, MODE_TRADES);if(OrderSymbol()==Symbol()) {if((OrderType()==Type && (OrderMagicNumber()==Magic) || Magic==0)) _CntO++;}}return(_CntO);}
// expert trailing stop
void TrP(){double pb,pa,pp;pp=MarketInfo(OrderSymbol(),MODE_POINT);if (OrderType()==OP_BUY){pb=MarketInfo(OrderSymbol(),MODE_BID);
//expert breakeven
if(BE>0){if((pb-OrderOpenPrice())>BE*pp){if((OrderStopLoss()-OrderOpenPrice())<0){ModSL(OrderOpenPrice()+0*pp);}}}
if(TS>0){if((pb-OrderOpenPrice())>TS*pp){if(OrderStopLoss()<pb-(TS+TS_Step-1)*pp){ModSL(pb-TS*pp);return;}}}}
if(OrderType()==OP_SELL){pa=MarketInfo(OrderSymbol(),MODE_ASK);if(BE>0){if((OrderOpenPrice()-pa)>BE*pp){if((OrderOpenPrice()-OrderStopLoss())<0){ModSL(OrderOpenPrice()-0*pp);}}}
if (TS>0){if (OrderOpenPrice()-pa>TS*pp){if (OrderStopLoss()>pa+(TS+TS_Step-1)*pp || OrderStopLoss()==0){ModSL(pa+TS*pp);return;}}}}}
//expert stoploss
void ModSL(double ldSL){bool fm;fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSL,OrderTakeProfit(),0,CLR_NONE);}
//expert add positions function
bool AddP(){int _num=0; int _ot=0;
for (int j=0;j<OrdersTotal();j++){if(OrderSelect(j,SELECT_BY_POS)==true && OrderSymbol()==Symbol() && OrderType()<3 && ((OrderMagicNumber()==Magic) || Magic==0)) {
_num++;if(OrderOpenTime()>_ot) _ot=OrderOpenTime();}}
if(_num==0) return(true);if(_num>0 && ((Time[0]-_ot))>0) return(true);else return(false);}
Comments