extern int uniqueGridMagic = 11111; // Magic number of the trades. must be unique to identify
extern double Lots = 0.1; //
extern double GridSize = 6; // pips between orders - grid or mesh size
extern double GridSteps = 12; // total number of orders to place
extern double TakeProfit = 12 ; // number of ticks to take profit. normally is = grid size but u can override
extern double StopLoss = 0; // if u want to add a stop loss. normal grids dont use stop losses
extern int trailStop = 0; // will trail if > 0
extern double UpdateInterval = 1; // update orders every x minutes
extern bool wantLongs = true; // do we want long positions
extern bool wantShorts = true; // do we want short positions
extern bool wantBreakout = true; // do we want longs above price, shorts below price
extern bool wantCounter = true; // do we want longs below price, shorts above price
extern bool limitEMA = true; // do we want longs above ema only, shorts below ema only
extern int EMAperiod = 34; // the length of the EMA.. was previously fixed at 34
extern double GridMaxOpen = 0; // maximum number of open positions : implemented in v1.92
extern bool UseMACD = true; // if true, will use macd >0 for longs only, macd <0 for shorts only
extern bool UseOsMA = false; // if true, will use OSMA > 0 for longs only, OSMA <0 for shorts only. used in same way as MACD.
extern bool CloseOpenPositions = false;// if UseMACD, do we also close open positions with a loss?
extern bool doHouseKeeping = true; // this will remove long orders below the 34 ema and vv if limitEMA flag is true
extern double keepOpenTimeLimit = 0; // in hours - if > 0, all open orders or positions will be closed after this period. fractions are permitted
extern int emaFast = 12; // parameters for MACD and OSMA
extern int emaSlow = 26; // parameters for MACD and OSMA
extern int signalPeriod = 9; // parameters for MACD and OSMA
extern int timeFrame = 0; // parameters for MACD and OSMA
extern int minFromPrice = 0; // minimum distance from price to place trades.
string GridName = "Grid"; // identifies the grid. allows for several co-existing grids - old variable.. shold not use any more
double LastUpdate = 0; // counter used to note time of last update
int init()
{
// код доступен только после оплаты
}
bool IsPosition(double atRate, double inRange, bool checkLongs )
{
int totalorders = OrdersTotal();
for(int i=0;i<totalorders;i++) // scan all orders and positions...
{
OrderSelect(i, SELECT_BY_POS);
if ( OrderSymbol()==Symbol() && ( (OrderMagicNumber() == uniqueGridMagic) || (OrderComment() == GridName)) ) // only look if mygrid and symbol...
{ int type = OrderType();
if (MathAbs( OrderOpenPrice() - atRate ) < (inRange*0.9)) // dont look for exact price but price proximity (less than gridsize) - added 0.9 because of floating point errors
{ if ( ( checkLongs && ( type == OP_BUY || type == OP_BUYLIMIT || type == OP_BUYSTOP ) ) || (!checkLongs && ( type == OP_SELL || type == OP_SELLLIMIT || type == OP_SELLSTOP ) ) )
{
return(true);
}
}
}
}
return(false);
}
void DeleteAfter( double xHours ) // delete pending orders or open positions after x hours
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if ( OrderSymbol()==Symbol() && ( (OrderMagicNumber() == uniqueGridMagic) || (OrderComment() == GridName)) ) // only look if mygrid and symbol...
{
if (( MathAbs(iTime(Symbol(),5,0)-OrderOpenTime()) >= xHours*60*60 ) && (iTime(Symbol(),5,0)>0))
{ bool result = false;
if ( OrderType() == OP_BUY ) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
if ( OrderType() == OP_SELL ) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
if ( OrderType() > 1 ) result = OrderDelete( OrderTicket() );
}
}
} // proc DeleteAfter()
void CloseAllPendingOrders( )
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--) // scan all orders and positions...
{
OrderSelect(i, SELECT_BY_POS);
if ( OrderSymbol()==Symbol() && ( (OrderMagicNumber() == uniqueGridMagic) || (OrderComment() == GridName)) ) // only look if mygrid and symbol...
{
if ( OrderType() > 1 ) bool result = OrderDelete( OrderTicket() );
}
}
return;
}
void ClosePendingOrdersAndPositions()
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
bool result = false;
if ( OrderSymbol()==Symbol() && ( (OrderMagicNumber() == uniqueGridMagic) || (OrderComment() == GridName)) ) // only look if mygrid and symbol...
{
if ( OrderType() == OP_BUY ) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
if ( OrderType() == OP_SELL ) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
if ( OrderType() > 1 ) result = OrderDelete( OrderTicket() );
}
}
return;
}
void CloseOrdersfromEMA( double theEMAValue )
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--) // scan all orders and positions...
{
OrderSelect(i, SELECT_BY_POS);
if ( OrderSymbol()==Symbol() && ( (OrderMagicNumber() == uniqueGridMagic) || (OrderComment() == GridName)) ) // only look if mygrid and symbol...
{
int type = OrderType();
bool result = false;
if ( type == OP_BUYLIMIT && OrderOpenPrice() <= theEMAValue ) result = OrderDelete( OrderTicket() );
if ( type == OP_BUYSTOP && OrderOpenPrice() <= theEMAValue ) result = OrderDelete( OrderTicket() );
if ( type == OP_SELLLIMIT && OrderOpenPrice() >= theEMAValue ) result = OrderDelete( OrderTicket() );
if ( type == OP_SELLSTOP && OrderOpenPПоказано первые 50% кода (символов: 9168)
Введите ваш email и нажмите кнопку, чтобы перейти к оплате.