Here's a breakdown of what the trading script does, explained without technical jargon:
This script is designed to automatically place buy or sell orders in the trading market based on a set of rules.
-
Initialization and Memory:
- The script starts by remembering the most recent market bar it analyzed. This helps it avoid re-analyzing the same data repeatedly.
-
Order Management:
- The script first checks if there are any existing open orders. If there aren't any, it proceeds to look for opportunities to open new ones.
-
Opportunity Identification (Entry Logic):
-
Position Calculation:
- The script calculates a number (
OPEN_POS()
) to determine possible entries. - It looks at the high, low, and closing prices of the most recent market bar.
- It calculates the relative position of the close to the high and low.
- If the closing price is relatively high, it returns 1, suggesting a possible buy. If relatively low, it returns -1, suggesting a possible sell.
- The script calculates a number (
-
VSA Consideration (Optional):
- The script optionally uses a Volume Spread Analysis (
vsa()
) function to refine entry consideration. - The
vsa()
function looks at recent market volatility by calculating the difference between values of Average True Range over different timeframes, multiplied by input weights. - If VSA is enabled (
mod_vsa = true
), the script needsvsa()
to return a positive value for a buy or a negative value for a sell.
- The script optionally uses a Volume Spread Analysis (
-
Time Restriction:
- The script has certain hours of the day where it will not place trades. This is controlled by the
hh
,hn
,hb
,hc
, andn
parameters.
- The script has certain hours of the day where it will not place trades. This is controlled by the
-
-
Order Placement:
- If the calculated position suggests a buy (
OPEN_POS() > 0
), and the VSA, if enabled, confirms, and the current hour is not restricted, the script places a buy order. - If the calculated position suggests a sell (
OPEN_POS() < 0
), and the VSA, if enabled, confirms, and the current hour is not restricted, the script places a sell order.
- If the calculated position suggests a buy (
-
Order Parameters:
- Lot Size: The script uses a specified
lots
size for each order. - Stop Loss: It sets a
stop_loss
to automatically close the order if the market moves against the trade by a certain amount. - Take Profit: It sets a
take_profit
to automatically close the order and secure profits if the market moves in the trade's favor by a certain amount. - Magic Number: It assigns a unique "magic number" to each trade so the script can identify and manage its own trades separately from any other trading activity. Buy orders use the
MAGIC
number, while sell orders useMAGIC+1
.
- Lot Size: The script uses a specified
int MAGIC = 1234;
extern double lots =0.1;
extern double hh = 4;
extern double hn = 4;
extern double hb = 4;
extern double hc = 4;
extern double n = 4;
extern double p = 65;
extern double stop_loss = 1000; //100 for 4 Digits
extern double take_profit = 700; //70
extern bool mod_vsa = false;
extern int v1 = 100;
extern int v2 = 100;
extern int v3 = 100;
extern int v4 = 100;
extern int p2 = 10;
int last_bar = 0;
int start(){
if (last_bar == Bars) return(0);
last_bar = Bars;
if (OrdersTotal() <= 0 ){
if( OPEN_POS()>0&&(!mod_vsa || vsa()>0)
&& Hour()!=hh&& Hour()!=hn&& Hour()!=hb&& Hour()!=hc&& Hour()!=hb+n&& Hour()!=hc+n)OrderSend(Symbol(), OP_BUY, lots ,Ask, 3, Ask - stop_loss * Point, Bid + take_profit * Point, WindowExpertName(), MAGIC, 0, Blue);
if( OPEN_POS()<0 &&(!mod_vsa || vsa()<0)
&& Hour()!=hh&& Hour()!=hn&& Hour()!=hb&& Hour()!=hc&& Hour()!=hb+n&& Hour()!=hc+n)OrderSend(Symbol(), OP_SELL, lots ,Bid, 3, Bid + stop_loss * Point, Ask - take_profit * Point, WindowExpertName(), MAGIC+1, 0, Red);
}
return(0);
}
double OPEN_POS()
{
double L = iLow(NULL, 0, 1);
double H = iHigh(NULL, 0, 1);
double C = iClose(NULL, 0, 1);
if( ((H-C) / (H-L+0.00001))*100 > p ) { return(1); }
if( ((C-L) / (H-L+0.00001))*100 > p ) { return(-1);}
return(0);
}
double vsa() {
double w1 = v1 - 50;
double w2 = v2 - 50;
double w3 = v3 - 50;
double w4 = v4 - 50;
double a1 = (iATR(NULL,60,1,p2 *1) - iATR(NULL,60,1,p2 *2));
double a2 = (iATR(NULL,60,1,p2 *2) - iATR(NULL,60,1,p2 *3));
double a3 = (iATR(NULL,60,1,p2 *3) - iATR(NULL,60,1,p2 *4));
double a4 = (iATR(NULL,60,1,p2 *4) - iATR(NULL,60,1,p2 *5));
return(w1 * a1 + w2 * a2 + w3 * a3 + w4 * a4);
}
Comments