Here's a breakdown of what the MetaTrader script does, explained in plain language for someone who isn't a programmer:
This script is an automated trading program (sometimes called an "Expert Advisor" or EA) for the MetaTrader platform. It's designed to automatically open and close trades based on the readings from a specific technical indicator called the MACD (Moving Average Convergence Divergence). The goal of the script is to automatically execute buy orders according to a particular strategy that it is coded to implement.
Here's how it works step-by-step:
-
Initial Setup & Checks:
- The script starts by defining a key setting: "Lots." This represents the size of the trades it will make (e.g., 0.3 standard lots).
- Before doing anything else, it checks if the trading chart has enough data (at least 100 bars/periods). If not, it stops because it needs sufficient historical data to work correctly.
- It retrieves the current and previous two values of the MACD indicator. It gets these values using specific settings (periods 6, 18, 1) and applies them to the closing price.
-
Trading Logic (Buy Orders Only):
- The script checks if there are currently any open orders in the market. If there aren't any open orders, it proceeds.
- It then checks if the account has enough free margin (available money) to place a trade of the specified "Lots" size. If not, it stops because it can't afford to trade.
- The core logic is in the BUY order placement: The script checks specific conditions based on the MACD values from the current period, the previous period, and the period before that.
- Specifically, it checks if the two previous MACD values are between 0 and 0.06. It also checks if the second most recent MACD value is greater than the most recent previous MACD value which in turn is less than the current MACD value.
- If all these MACD conditions are met, the script places a BUY order.
- If the order is successfully placed, it prints a message. If there's an error placing the order, it prints an error message.
- The Buy order is placed at the current Ask price (the price you'd pay to buy). The script also sets a Take Profit level (at Ask + 40 * Point, which depends on the specific instrument). The Stop Loss is set to 0.
In essence, this script monitors the MACD indicator and, when it sees a specific pattern in the indicator's recent values, it automatically places a buy order, provided certain account conditions are met.
//+------------------------------------------------------------------------+
//| MACD edited with new magic period.mq4 |
//| periode yg dimodifikasi didapat dengan kecerdasan buatan tingkat dasar|
//| period number is taken from book of soros, global crisis of capitalizm |
//| any better performance please contact with pm |
//+------------------------------------------------------------------------+
extern double Lots = 0.3;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double MacdCurrent, MacdPrevious, MacdPrevious2, SignalCurrent;
double SignalPrevious, MaCurrent, MaPrevious;
int cnt, ticket, total, a, s, d, f;
// initial data checks
// cek data
// it is important to make sure that the expert works with a normal
// memastikan EA bekerja dengan normal
// chart and the user did not make any mistakes setting external
// tidak ada kesalahan user ataupun chart
// variables (Lots, StopLoss, TakeProfit,
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
// memastikan grafik lebih dari 100 bar
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
// sederhanakan kode untuk percepat running-to simplify the coding and speed up access
// data dipindahkan ke internal variabel-data are put into internal variables
MacdCurrent=iMACD(NULL,0,6,18,1,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,6,18,1,PRICE_CLOSE,MODE_MAIN,1);
MacdPrevious2=iMACD(NULL,0,6,18,1,PRICE_CLOSE,MODE_MAIN,2);
//-------------------------------------------------------------------------------
// if we use artificial neural network
// the best combination of period for each technical indicator
// will created instantly without significant consecutive loss
// i am still work on it
// always hope some one to help our team in jakarta...... :-)
// anything better the period that we have now are welcome
//-------------------------------------------------------------------------------
// periode didapat dari kutipan soros pada bukunya
// global crisis of capitalizm
// time periode are got from soros's book
total=OrdersTotal();
if(total<1)
{
// no opened orders identified
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
//-----------------------------------------------------------------penting
// check for long position (BUY) possibility
//-----------------------------------------------------------------penting
//if(MacdCurrent>0 && MacdCurrent<0.2&& MacdPrevious>0&& MacdPrevious<0.2&& MacdPrevious2>MacdPrevious<MacdCurrent)
if(MacdPrevious2>0 && MacdPrevious2<0.06 && MacdPrevious2>MacdPrevious<MacdCurrent)
//OP_BUY,Lots,Ask,3,Ask - 200*Point,Ask + 200*Point,"macd sample",16384,0,Green);
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+40*Point,"macd sample",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
//-----------------------------------------------------------------penting
}}// the end-tamat
Comments