newgrid_2009_11_15_floating_center_thorup
Download scriptThis automated trading script is designed to manage a "grid" trading strategy. Instead of predicting the direction of the market in a single movement, it creates a structured web of potential entry points based on historical price data to capture fluctuations over time.
Core Logic Overview
1. Market Range Analysis The script begins by looking back at a specific number of days (default is 90) to identify the highest and lowest prices reached. It then calculates the exact midpoint of this range. This "Mid-point" serves as the anchor for the entire strategy.
2. The Grid System From that midpoint, the script projects a series of price levels (a grid) both above and below the center.
- Grid Separation: You can define how far apart these horizontal lines are.
- Max Trades: The script limits how many total positions it will hold at once to manage risk.
3. Trade Execution The script constantly monitors the current market price. When the price touches one of the predetermined grid lines:
- It identifies if the price is hitting a "Buy" line or a "Sell" line.
- It opens a position only if it hasn't already reached the maximum allowed trades.
- Take Profit: As soon as a trade is opened, the script automatically attaches a fixed profit target (Take Profit) based on a specific point distance.
4. Dynamic Lot Sizing (Money Management) Depending on your settings, the script can handle your trade sizes in two ways:
- Fixed Lots: It always trades the same amount for every position.
- Optimized Lots: It looks at your account balance and divides it by a "Balance Factor" to determine how much of your capital to risk on each trade. This ensures that as your account grows, your trade sizes grow proportionally.
5. Risk Protection (Equity Stop) The script includes a safety mechanism regarding your account's equity. If the ratio of your current account value to your balance exceeds a certain percentage, the script is designed to close all open positions immediately to protect your capital from excessive fluctuations.
6. User Interface (On-Screen Information) While the script is running, it provides a real-time text display on your trading screen. This informs you of:
- The price boundaries of your current grid.
- The specific price level the market is currently approaching.
- The distance between each grid line in pips.
- A calculation of your potential total risk in dollars based on the current grid layout.
#property copyright "Expert for tests"
extern int MagicNumber = 100001;
extern double Lots = 0.1 ;
extern bool MM=false;
extern double Balancefactor=4650;
extern bool microlots=false;
extern int max_trades = 30 ;
extern int grid_lines = 30 ;
extern double grid_separation = 0.005 ;
extern double TP_absolute = 0.005 ;
extern double AccountEquityPercent=100.01;
extern bool FIFO=false;
extern int LookBackDays = 90;
extern int slip = 3 ;
extern double pipvalue=0.1;
int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init() {
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
GlobalVariableDel("next_level_"+Symbol());
GlobalVariableDel("test_next_level__"+Symbol());
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start() {
int Entertradebuy =0 ;
int Entertradesell =0 ;
double next_level_,test_next_level_,i ;
double Ticket1, Ticket2;
double pips_risked=0,money_risked=0;
int iOrders=0;
double RangeMid_center=RangeMid();
if(IsTesting()==true)
{
if(OrdersTotal()<max_trades)
{
for (i = 1; i<grid_lines; i++)
{
if (Ask <= (RangeMid_center - grid_separation*i)+0.0001 && Ask >= (RangeMid_center - grid_separation*i)-0.0001)
{
Entertradebuy=1 ;
}
if (Bid <= (RangeMid_center + grid_separation*i)+0.0001 && Bid >= (RangeMid_center + grid_separation*i)-0.0001)
{
Entertradesell=1 ;
}
}
}
iOrders = OrdersTotal()-1;
for (i = iOrders; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (((OrderOpenPrice() <= Ask+0.0003 && OrderOpenPrice() >= Ask-0.0003) || (OrderOpenPrice() <= Bid+0.0003 && OrderOpenPrice() >= Bid-0.0003))&&OrderMagicNumber()==MagicNumber)
{
Entertradebuy=0 ;
Entertradesell=0 ;
}
}
if(FIFO==false&&MM==false)
{
if(Entertradebuy==1)
{
Ticket1 = OrderSend(Symbol(), OP_BUY, Lots, Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;
}
if(Entertradesell==1)
{
Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
}
for(i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL&&OrderMagicNumber()==MagicNumber&&OrderTakeProfit()==0)
{
if(OrderType()==OP_BUY)
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()+TP_absolute,0,CLR_NONE);
}
else
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()-TP_absolute,0,CLR_NONE);
}
}
}
for (i = 1; i<grid_lines; i++)
{
if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
if(RangeMid_center + grid_separation*i - Bid < grid_separation)
GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
}
next_level_=GlobalVariableGet("test_next_level_"+Symbol()) ;
for (i = 1; i<grid_lines-1; i++)
{
pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
money_risked = (pips_risked*100000*Lots)/2 ;
}
if(OrdersTotal() < max_trades)
Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
"closest grid line to enter trade is ", test_next_level_ , "\n",
"distance between grid lines is ", grid_separation*10000, " pips", "\n",
"number of grid lines is ", grid_lines, "\n",
"maximum number of trades is ", max_trades, "\n",
"TP is ", TP_absolute, "\n",
"---------------------------------------------------", "\n",
"You are risking a potential ", money_risked, "USD") ;
if(OrdersTotal() >= max_trades)
Comment("I am full, I have ", max_trades, " positions opened");
return(0);
}
if(FIFO==false&&MM==true)
{
if(Entertradebuy==1)
{
Ticket1 = OrderSend(Symbol(), OP_BUY, LotsOptimized(), Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;
}
if(Entertradesell==1)
{
Ticket2 = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
}
for(i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL&&OrderMagicNumber()==MagicNumber&&OrderTakeProfit()==0)
{
if(OrderType()==OP_BUY)
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()+TP_absolute,0,CLR_NONE);
}
else
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()-TP_absolute,0,CLR_NONE);
}
}
}
for (i = 1; i<grid_lines; i++)
{
if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
if(RangeMid_center + grid_separation*i - Bid < grid_separation)
GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
}
next_level_=GlobalVariableGet("test_next_level_"+Symbol()) ;
for (i = 1; i<grid_lines-1; i++)
{
pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
money_risked = (pips_risked*100000*LotsOptimized())/2 ;
}
if(OrdersTotal() < max_trades)
Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
"closest grid line to enter trade is ", test_next_level_ , "\n",
"distance between grid lines is ", grid_separation*10000, " pips", "\n",
"number of grid lines is ", grid_lines, "\n",
"maximum number of trades is ", max_trades, "\n",
"TP is ", TP_absolute, "\n",
"---------------------------------------------------", "\n",
"You are risking a potential ", money_risked, "USD") ;
if(OrdersTotal() >= max_trades)
Comment("I am full, I have ", max_trades, " positions opened");
return(0);
}
if(FIFO==true&&MM==false)
{
if(Entertradebuy==1)
{
Ticket1 = OrderSend(Symbol(), OP_BUY, Lots, Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;
}
if(Entertradesell==1)
{
Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
}
for (i = 1; i<grid_lines; i++)
{
if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
if(RangeMid_center + grid_separation*i - Bid < grid_separation)
GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
}
next_level_=GlobalVariableGet("test_next_level_"+Symbol()) ;
for (i = 1; i<grid_lines-1; i++)
{
pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
money_risked = (pips_risked*100000*Lots)/2 ;
}
if(OrdersTotal() < max_trades)
Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
"closest grid line to enter trade is ", test_next_level_ , "\n",
"distance between grid lines is ", grid_separation*10000, " pips", "\n",
"number of grid lines is ", grid_lines, "\n",
"maximum number of trades is ", max_trades, "\n",
"AccountEquityPercent is ", AccountEquity()/AccountBalance()*100, "\n",
"---------------------------------------------------", "\n",
"You are risking a potential ", money_risked, "USD") ;
if(OrdersTotal() >= max_trades)
Comment("I am full, I have ", max_trades, " positions opened");
if(AccountEquity()/AccountBalance()*100>=AccountEquityPercent)
{
for(i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
if(OrderType() == OP_BUY)
{
OrderClose(OrderTicket(),OrderLots(),Bid,slip,Yellow);
}
else
{
OrderClose(OrderTicket(),OrderLots(),Ask,slip,Yellow);
}
}
i--;
}
}
return(0);
}
if(FIFO==true&&MM==true)
{
if(Entertradebuy==1)
{
Ticket1 = OrderSend(Symbol(), OP_BUY, LotsOptimized(), Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;
}
if(Entertradesell==1)
{
Ticket2 = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
}
for (i = 1; i<grid_lines; i++)
{
if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
if(RangeMid_center + grid_separation*i - Bid < grid_separation)
GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
}
next_level_=GlobalVariableGet("test_next_level_"+Symbol()) ;
for (i = 1; i<grid_lines-1; i++)
{
pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
money_risked = (pips_risked*100000*LotsOptimized())/2 ;
}
if(OrdersTotal() < max_trades)
Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
"closest grid line to enter trade is ", test_next_level_ , "\n",
"distance between grid lines is ", grid_separation*10000, " pips", "\n",
"number of grid lines is ", grid_lines, "\n",
"maximum number of trades is ", max_trades, "\n",
"AccountEquityPercent is ", AccountEquity()/AccountBalance()*100, "\n",
"---------------------------------------------------", "\n",
"You are risking a potential ", money_risked, "USD") ;
if(OrdersTotal() >= max_trades)
Comment("I am full, I have ", max_trades, " positions opened");
if(AccountEquity()/AccountBalance()*100>=AccountEquityPercent)
{
for(i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
if(OrderType() == OP_BUY)
{
OrderClose(OrderTicket(),OrderLots(),Bid,slip,Yellow);
}
else
{
OrderClose(OrderTicket(),OrderLots(),Ask,slip,Yellow);
}
}
i--;
}
}
return(0);
}
}
else
{
if(OrdersTotal()<max_trades)
{
for (i = 1; i<grid_lines; i++)
{
if (Ask == RangeMid_center - grid_separation*i)
{
Entertradebuy=1 ;
}
if (Bid == RangeMid_center + grid_separation*i)
{
Entertradesell=1 ;
}
}
}
iOrders = OrdersTotal()-1;
for (i = iOrders; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if ((OrderOpenPrice() == Ask || OrderOpenPrice() == Bid)&&OrderMagicNumber()==MagicNumber)
{
Entertradebuy=0 ;
Entertradesell=0 ;
}
}
if(FIFO==false&&MM==false)
{
if(Entertradebuy==1)
{
Ticket1 = OrderSend(Symbol(), OP_BUY, Lots, Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;
}
if(Entertradesell==1)
{
Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
}
for(i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL&&OrderMagicNumber()==MagicNumber&&OrderTakeProfit()==0)
{
if(OrderType()==OP_BUY)
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()+TP_absolute,0,CLR_NONE);
}
else
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()-TP_absolute,0,CLR_NONE);
}
}
}
for (i = 1; i<grid_lines; i++)
{
if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
GlobalVariableSet("next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
if(RangeMid_center + grid_separation*i - Bid < grid_separation)
GlobalVariableSet("next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
}
next_level_=GlobalVariableGet("next_level_"+Symbol()) ;
for (i = 1; i<grid_lines-1; i++)
{
pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
money_risked = (pips_risked*100000*Lots)/2 ;
}
if(OrdersTotal() < max_trades)
Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
"closest grid line to enter trade is ", next_level_ , "\n",
"distance between grid lines is ", grid_separation*10000, " pips", "\n",
"number of grid lines is ", grid_lines, "\n",
"maximum number of trades is ", max_trades, "\n",
"TP is ", TP_absolute, "\n",
"---------------------------------------------------", "\n",
"You are risking a potential ", money_risked, "USD") ;
if(OrdersTotal() >= max_trades)
Comment("I am full, I have ", max_trades, " positions opened");
return(0);
}
if(FIFO==false&&MM==true)
{
if(Entertradebuy==1)
{
Ticket1 = OrderSend(Symbol(), OP_BUY, LotsOptimized(), Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;
}
if(Entertradesell==1)
{
Ticket2 = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
}
for(i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL&&OrderMagicNumber()==MagicNumber&&OrderTakeProfit()==0)
{
if(OrderType()==OP_BUY)
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()+TP_absolute,0,CLR_NONE);
}
else
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()-TP_absolute,0,CLR_NONE);
}
}
}
for (i = 1; i<grid_lines; i++)
{
if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
GlobalVariableSet("next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
if(RangeMid_center + grid_separation*i - Bid < grid_separation)
GlobalVariableSet("next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
}
next_level_=GlobalVariableGet("next_level_"+Symbol()) ;
for (i = 1; i<grid_lines-1; i++)
{
pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
money_risked = (pips_risked*100000*LotsOptimized())/2 ;
}
if(OrdersTotal() < max_trades)
Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
"closest grid line to enter trade is ", next_level_ , "\n",
"distance between grid lines is ", grid_separation*10000, " pips", "\n",
"number of grid lines is ", grid_lines, "\n",
"maximum number of trades is ", max_trades, "\n",
"TP is ", TP_absolute, "\n",
"---------------------------------------------------", "\n",
"You are risking a potential ", money_risked, "USD") ;
if(OrdersTotal() >= max_trades)
Comment("I am full, I have ", max_trades, " positions opened");
return(0);
}
if(FIFO==true&&MM==false)
{
if(Entertradebuy==1)
{
Ticket1 = OrderSend(Symbol(), OP_BUY, Lots, Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;
}
if(Entertradesell==1)
{
Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
}
for (i = 1; i<grid_lines; i++)
{
if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
GlobalVariableSet("next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
if(RangeMid_center + grid_separation*i - Bid < grid_separation)
GlobalVariableSet("next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
}
next_level_=GlobalVariableGet("next_level_"+Symbol()) ;
for (i = 1; i<grid_lines-1; i++)
{
pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
money_risked = (pips_risked*100000*Lots)/2 ;
}
if(OrdersTotal() < max_trades)
Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
"closest grid line to enter trade is ", next_level_ , "\n",
"distance between grid lines is ", grid_separation*10000, " pips", "\n",
"number of grid lines is ", grid_lines, "\n",
"maximum number of trades is ", max_trades, "\n",
"AccountEquityPercent is ", AccountEquity()/AccountBalance()*100, "\n",
"---------------------------------------------------", "\n",
"You are risking a potential ", money_risked, "USD") ;
if(OrdersTotal() >= max_trades)
Comment("I am full, I have ", max_trades, " positions opened");
if(AccountEquity()/AccountBalance()*100>=AccountEquityPercent)
{
for(i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
if(OrderType() == OP_BUY)
{
OrderClose(OrderTicket(),OrderLots(),Bid,slip,Yellow);
}
else
{
OrderClose(OrderTicket(),OrderLots(),Ask,slip,Yellow);
}
}
i--;
}
}
return(0);
}
if(FIFO==true&&MM==true)
{
if(Entertradebuy==1)
{
Ticket1 = OrderSend(Symbol(), OP_BUY, LotsOptimized(), Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;
}
if(Entertradesell==1)
{
Ticket2 = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
}
for (i = 1; i<grid_lines; i++)
{
if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
GlobalVariableSet("next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
if(RangeMid_center + grid_separation*i - Bid < grid_separation)
GlobalVariableSet("next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
}
next_level_=GlobalVariableGet("next_level_"+Symbol()) ;
for (i = 1; i<grid_lines-1; i++)
{
pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
money_risked = (pips_risked*100000*LotsOptimized())/2 ;
}
if(OrdersTotal() < max_trades)
Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
"closest grid line to enter trade is ", next_level_ , "\n",
"distance between grid lines is ", grid_separation*10000, " pips", "\n",
"number of grid lines is ", grid_lines, "\n",
"maximum number of trades is ", max_trades, "\n",
"AccountEquityPercent is ", AccountEquity()/AccountBalance()*100, "\n",
"---------------------------------------------------", "\n",
"You are risking a potential ", money_risked, "USD") ;
if(OrdersTotal() >= max_trades)
Comment("I am full, I have ", max_trades, " positions opened");
if(AccountEquity()/AccountBalance()*100>=AccountEquityPercent)
{
for(i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
if(OrderType() == OP_BUY)
{
OrderClose(OrderTicket(),OrderLots(),Bid,slip,Yellow);
}
else
{
OrderClose(OrderTicket(),OrderLots(),Ask,slip,Yellow);
}
}
i--;
}
}
return(0);
}
}
}
double LotsOptimized()
{
double lot = Lots;
if(microlots==true)
{
lot = NormalizeDouble(MathFloor(AccountBalance()/Balancefactor)*0.01-0.005,2);
if(lot < 0.01) lot = 0.01;
return(lot);
}
else
{
lot = NormalizeDouble(MathFloor(AccountBalance()/Balancefactor)*0.01-0.05, 1);
if(lot < 0.1) lot = 0.1;
return(lot);
}
}
double RangeMid()
{
double rangemid = 0;
double lowest = 100000;
lowest = iLow(Symbol(), PERIOD_D1, 0);
for (int i = 0; i <= LookBackDays; i++)
{
if (iLow(Symbol(), PERIOD_D1, i) < lowest) lowest = iLow(Symbol(), PERIOD_D1, i);
}
double highest = 0;
highest = iHigh(Symbol(), PERIOD_D1, 0);
for (i = 1; i <= LookBackDays; i++)
{
if (iHigh(Symbol(), PERIOD_D1, i) > highest) highest = iHigh(Symbol(), PERIOD_D1, i);
}
rangemid = (highest + lowest) / 2.0;
rangemid = NormalizeDouble(rangemid, Digits);
return(rangemid);
}
//+------------------------------------------------------------------+
Profitability Reports
Expected payoff
Average expected payoff across the available backtests for each symbol.
Comments