Here's a breakdown of what the MetaTrader script does, explained in a way that's easy to understand, without getting into programming jargon.
This script is designed to automatically place and manage trades in the Forex market using a strategy called "scalping," which aims to profit from small price changes. It operates based on the day's high and low prices.
Here's a step-by-step explanation:
-
Setting the Stage (Initialization):
- The script starts by reading some settings you can adjust, like how far away from the day's high and low it should place orders, how much risk (stop loss) to use, and how much of your money to trade with (lot size). It also sets up special conditions called trailing stops that automatically adjust to lock in profits.
-
Order Placement Time:
- The script determines a specific time of day (either 9:00 AM or 12:00 PM, depending on the currency pair) when it will consider placing its initial orders.
-
Checking Existing Orders:
- Before placing any new orders, the script checks to see if you already have open trades or pending orders for the specific currency pair it's working with.
-
Finding the Day's High and Low:
- If it's the right time and no orders are already in place, the script looks back over the past day to find the highest and lowest prices reached.
-
Placing Initial Orders:
- Based on the day's high and low, the script places two pending orders:
- A "buy stop" order, which is an order to buy if the price goes above the day's high by a specified amount.
- A "sell stop" order, which is an order to sell if the price goes below the day's low by a specified amount.
- These orders are placed with a built-in stop-loss, which limits how much money you could lose if the trade goes the wrong way.
- Based on the day's high and low, the script places two pending orders:
-
Order Management:
- The script actively manages the trades.
- If one of the pending orders is triggered (meaning the price reached the level to buy or sell), the script cancels the opposite pending order.
- It also activates a "break-even" feature, which moves the stop-loss to the entry price once the trade is a certain amount in profit, so you can't lose money on the trade.
- It may also use a "trailing stop", automatically adjusting the stop loss to follow the price movement to protect growing profits
- The script actively manages the trades.
-
Reversal Mechanism:
- As an optional twist, if a trade hits its stop-loss, the script can immediately place a new pending order in the opposite direction, hoping to profit from a potential price reversal.
-
Cleanup:
- Finally, if the main trade is closed (either by hitting the take-profit or stop-loss), the script removes any pending reversal orders that are still in place.
In simple terms, this script tries to automatically trade based on daily price ranges, aiming for small profits while managing risk with stop-losses and trailing stops.
Price Data Components
Orders Execution
3
Views
0
Downloads
0
Favorites
Profitability Reports
2557.00 %
Total Trades
10
Won Trades
5
Lost trades
5
Win Rate
50.00 %
Expected payoff
85.99
Gross Profit
894.90
Gross Loss
-35.00
Total Net Profit
859.90
-100%
-50%
0%
50%
100%
Scalping by day channel v1[1].02
//+------------------------------------------------------------------+
//| Scalping by day channel.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//---- input parameters
extern int Order_Point=10; // Íà êàêîì ðàññòîÿíèè âûñòàâëÿòü îðäåðà îò äíåâíûõ ìàõ/ìèí
extern int SL_Point=50; // Âåëè÷èíà ñòîï-ëîñcà
extern int TS1_Point=10; // ×åðåç ñêîëüêî ïóíêòîâ ïðèáûëè ïåðåíîñòèòü ñòîï-ëîññ â áåçóáûòî÷íîñòü
extern int TS2_Point=15; // Âåëè÷èíà òðåéëèí-ñòîïà
extern double Lots=0.1; // Îòêðûâàòüñÿ ëîòîì
extern double TurnLots=0.2; // Âåëè÷èíà ñòîïà-ïåðåâîðîòà
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int total, cnt, OpenOrder, DefOrder, pos;
double max, min, SL;
datetime time;
//----
// Óñòàíàâëèâàåì âðåìÿ âûñòàâëåíèÿ îðäåðîâ äëÿ ðàçëè÷íûõ âàëþòíûõ ïàð
if(Symbol()=="USDCAD")
time=StrToTime("12:00");
else
time=StrToTime("09:00");
// Ñ÷èòàåì êîëè÷åñòâî îòêðûòûõ è îòëîæåííûõ îðäåðîâ ïî òåêóùåìó èíñòðóìåíòó
total=OrdersTotal();
OpenOrder=0;
DefOrder=0;
for(cnt=0;cnt<total;cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY || OrderType()==OP_SELL)
OpenOrder++; // êîëè÷åñòâî îòêðûòûõ îðäåðîâ
else
DefOrder++; // êîëè÷åñòâî çàêðûòûõ îðäåðîâ
}
}
// Ïðîâåðÿåì íå ïîðà ëè óñòàíàâëèâàòü îòëîæåííûå îðäåðà
if(TimeHour(CurTime())==TimeHour(time) && TimeMinute(CurTime())<5 && OpenOrder==0 && DefOrder==0)
{
total=24*60/Period()+1;
max=High[0];
min=Low[0];
for(pos=0; pos<total; pos++)
{
if (TimeDayOfYear(Time[pos])==TimeDayOfYear(CurTime()))
{
if(High[pos]>max)
max=High[pos]; // Äíåâíîé ýêñòðåìóì
if(Low[pos]<min)
min=Low[pos]; // Äíåâíîé ýêñòðåìóì
}
}
OrderSend(Symbol(),OP_BUYSTOP,Lots,max+Order_Point*Point,3,max-(SL_Point-Order_Point)*Point,0,"BUY Scalping",16384,0,CLR_NONE);
OrderSend(Symbol(),OP_SELLSTOP,Lots,min-Order_Point*Point,3,min+(SL_Point-Order_Point)*Point,0,"SELL Scalping",16384,0,CLR_NONE);
}
//  ñëó÷àå îòêðûòèÿ îðäåðà óäàëÿåì ïðîòèâîïîëîæíûé îðäåð
// à òàê æå òðåéëèì ïðîôèò íà áåçóáûòî÷íîñòü
if(OpenOrder==1 && DefOrder==1)
{
total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true && OrderSymbol()==Symbol() && OrderMagicNumber()==16384)
{
// Óñòàíîâêà ñòîï ëîñà â áåçóáûòî÷íîñòü
if(OrderType()==OP_BUY && (Bid-OrderOpenPrice())>(TS1_Point*Point) && OrderStopLoss()<OrderOpenPrice())
OrderModify(OrderTicket(),0,OrderOpenPrice()+1*Point,0,0,CLR_NONE);
if(OrderType()==OP_SELL && (OrderOpenPrice()-Ask)>(TS1_Point*Point) && OrderStopLoss()>OrderOpenPrice())
OrderModify(OrderTicket(),0,OrderOpenPrice()-1*Point,0,0,CLR_NONE);
// Òðåéëèíã îòêðûòûõ ïîçèöèé
if(OrderType()==OP_BUY && (Bid-OrderStopLoss())>(TS2_Point*Point) && OrderStopLoss()>OrderOpenPrice())
OrderModify(OrderTicket(),0,Bid-TS2_Point*Point,0,0,CLR_NONE);
if(OrderType()==OP_SELL && (OrderStopLoss()-Ask)>(TS2_Point*Point) && OrderStopLoss()<OrderOpenPrice())
OrderModify(OrderTicket(),0,Ask+TS2_Point*Point,0,0,CLR_NONE);
// Óäàëåíèå ïðîòèâîïîëîæíûõ îðäåðîâ
if(OrderType()==OP_BUYSTOP && OrderLots()==Lots)
{
OrderDelete(OrderTicket());
DefOrder--;
}
if(OrderType()==OP_SELLSTOP && OrderLots()==Lots)
{
OrderDelete(OrderTicket());
DefOrder--;
}
}
}
}
//Âûñòàâëÿåì îòêðûòèå ñòîïîì-ïåðåâîðîòîì
if(OpenOrder==1 && DefOrder==0)
{
total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true && OrderSymbol()==Symbol() && OrderMagicNumber()==16384)
{
if(OrderType()==OP_BUY && OrderLots()==Lots)
{
SL=OrderStopLoss();
OrderSend(Symbol(),OP_SELLSTOP,TurnLots,SL,3,SL+SL_Point*Point,0,"TurnSELL Scalping",16384,0,CLR_NONE);
}
if(OrderType()==OP_SELL && OrderLots()==Lots)
{
SL=OrderStopLoss();
OrderSend(Symbol(),OP_BUYSTOP,TurnLots,SL,3,SL-SL_Point*Point,0,"TurnBUY Scalping",16384,0,CLR_NONE);
}
}
}
}
//  ñëó÷àå çàêðûòèÿ îñíîâíîé ïîçèöèè óäàëÿåì ñòîï ïåðåâîðîòîì
if(OpenOrder==0 && DefOrder==1)
{
total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true && OrderSymbol()==Symbol() && OrderMagicNumber()==16384 && OrderLots()==TurnLots)
OrderDelete(OrderTicket());
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
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
---