اقتباس:
//================================================== ==========================================
//
//
//
//
//
//================================================== ==========================================
extern int MA1_Period=3; // دهًèîن 1-é جہ
extern int MA2_Period=13; // دهًèîن 2-é جہ
extern int MA1_Method=0; // جهٍîن âû÷èٌëهيèے جہ1 (SMA=0,EMA=1,SMMA=2,LWMA=3)
extern int MA2_Method=3; // جهٍîن âû÷èٌëهيèے جہ2 (SMA=0,EMA=1,SMMA=2,LWMA=3)
extern int MA1_Price=0; // جهٍîن âû÷èٌëهيèے ِهيû جہ1
extern int MA2_Price=4; // جهٍîن âû÷èٌëهيèے ِهيû جہ2
extern int MA1_Shift=0; // آًهىهييîé ٌنâèم جہ1
extern int MA2_Shift=0; // آًهىهييîé ٌنâèم جہ2
extern double Lot = 0.1;
extern bool Autoclose=false;
extern int Takeprofit=50;
extern int Stoploss=50;
extern int Trailing=50; // شèêٌèًîâàييûé ëîٍ
extern int slippage = 0;
extern int migic=1458877; // خٍêëîيهيèه ِهيû نëے ًûيî÷يûُ îًنهًîâ
int New_Bar; // 0/1 شàêٍ îلًàçîâàيèے يîâîمî لàًà
int Time_0; // آًهىے يà÷àëà يîâîمî لàًà
int PosOpen; // حàïًàâëهيèه ïهًهٌه÷هيèے
int PosClose; // حàïًàâëهيèه ïهًهٌه÷هيèے
int total; // تîëè÷هٌٍâî îٍêًûٍûُ îًنهًîâ
double MA1_0; // زهêَùهه çيà÷هيèه 1-é جہ (ًîçîâ)
double MA1_1; // دًهنûنَùهه çيà÷هيèه 1-é جہ (ًîçîâ)
double MA2_0; // زهêَùهه çيà÷هيèه 2-é جہ (مîëَلàے)
double MA2_1; // دًهنûنَùهه çيà÷هيèه 2-é جہ (مîëَلàے)
int orderBuy; // 1 = ôàêٍ يàëèèے îًنهًà Buy
int orderSell; // 1 = ôàêٍ يàëèèے îًنهًà Sell
//================================================== ==========================================
int init()
{
}
//================================================== ==========================================
int start()
{
orderBuy=0;
orderSell=0;
double price;
int openOrders=0;
int total=OrdersTotal();
Trailingstop(migic);
if (Autoclose==true ) {
Takeprofit=2000;
Stoploss=2000;
}
if(Takeprofit<10 ){
Alert("Take profit is too small");
Alert("error");
return(0);
} // خلùهه êîëè÷هٌٍâî îًنهًîâ
for(int i=total-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) // آûلèًàهى îًنهً
{
if(OrderType()==OP_BUY) // إٌëè ٌٍîèٍ îًنهً يà ïîêَïêَ
{
orderBuy=1;
if(CrossPositionClose()==1&&Autoclose==true) // اàêًûâهى îًنهً, هٌëè َنîâëهٍâîًےهٍ
{ // ٌَëîâè CrossPositionClose()=1
price=MarketInfo(Symbol(),MODE_BID);
OrderClose(OrderTicket(),OrderLots(),price,slippag e,CLR_NONE);
}
}
if(OrderType()==OP_SELL) // إٌëè ٌٍîèٍ îًنهً يà ïîêَïêَ
{
orderSell=1;
if(CrossPositionClose()==2&&Autoclose==true ) // اàêًûâهى îًنهً, هٌëè َنîâëهٍâîًےهٍ
{ // ٌَëîâè CrossPositionClose()=2
price=MarketInfo(Symbol(),MODE_ASK);
OrderClose(OrderTicket(),OrderLots(),price,slippag e,CLR_NONE);
}
}
}
}
New_Bar=0; // ؤëے يà÷àëà îليَëèىٌے
if (Time_0 != Time[0]) // إٌëè َوه نًَمîه âًهىے يà÷àëà لàًà
{
New_Bar= 1; // ہ âîٍ è يîâûé لàً
Time_0 = Time[0]; // اàïîىيèى âًهىے يà÷àëà يîâîمî لàًà
}
MA1_0=iMA(NULL,0, MA1_Period, MA1_Shift,MAMethod(MA1_Method), MAPrice(MA1_Price), 0); // زهêَùهه çيà÷هيèه 1-é جہ
MA1_1=iMA(NULL,0, MA1_Period, MA1_Shift,MAMethod(MA1_Method), MAPrice(MA1_Price), 1); // دًهنûنَùهه çيà÷هيèه 1-é جہ
MA2_0=iMA(NULL,0, MA2_Period, MA2_Shift,MAMethod(MA2_Method), MAPrice(MA2_Price), 0); // زهêَùهه çيà÷هيèه 2-é جہ
MA2_1=iMA(NULL,0, MA2_Period, MA2_Shift,MAMethod(MA2_Method), MAPrice(MA2_Price), 1); // دًهنûنَùهه çيà÷هيèه 2-é جہ
if (CrossPositionOpen()==1 && New_Bar==1) // ؤâèوهيèه ٌيèçَ ââهًُ = îٍêً. Buy
{
OpenBuy();
}
if (CrossPositionOpen()==2 && New_Bar==1) // ؤâèوهيèه ٌâهًَُ âيèç = îٍêً. Sell
{
OpenSell();
}
return;
}
//================================================== ==========================================
int CrossPositionOpen()
{
PosOpen=0; // آîٍ منه ٌîلàêà çàًûٍà!!:)
if ((MA1_1<=MA2_0 && MA1_0>MA2_0) || (MA1_1<MA2_0 && MA1_0>=MA2_0)) // دهًهٌه÷هيèه ٌيèçَ ââهًُ
{
PosOpen=1;
}
if ((MA1_1>=MA2_0 && MA1_0<MA2_0) || (MA1_1>MA2_0 && MA1_0<=MA2_0)) // دهًهٌه÷هيèه ٌâهًَُ âيèç
{
PosOpen=2;
}
return(PosOpen); // آîçâًàùàهى يàïًàâëهيèه ïهًهٌه÷هي.
}
//================================================== ==========================================
int CrossPositionClose()
{
PosClose=0; // آîٍ منه ٌîلàêà çàًûٍà!!:)
if ((MA1_1>=MA2_0 && MA1_0<MA2_0) || (MA1_1>MA2_0 && MA1_0<=MA2_0)) // دهًهٌه÷هيèه ٌâهًَُ âيèç {
{
PosClose=1;
}
if ((MA1_1<=MA2_0 && MA1_0>MA2_0) || (MA1_1<MA2_0 && MA1_0>=MA2_0)) // دهًهٌه÷هيèه ٌيèçَ ââهًُ
{
PosClose=2;
}
return(PosClose); // آîçâًàùàهى يàïًàâëهيèه ïهًهٌه÷هي.
}
//================================================== ==========================================
int OpenBuy()
{
if (total==1)
{
OrderSelect(0, SELECT_BY_POS,MODE_TRADES); // آûنهëèى îًنهً
if (OrderType()==OP_BUY) return; // إٌëè îي buy, ٍî يه îٍêًûâàهىٌے
}
OrderSend(Symbol(),OP_BUY, Lot, Ask, slippage, Ask-Stoploss*Point,Ask+Takeprofit*Point, "Buy: MA_cross_Method_PriceMode", migic, 0, CLR_NONE);// خٍêًûâàهىٌے
return;
}
//================================================== ==========================================
int OpenSell()
{
if (total==1)
{
OrderSelect(0, SELECT_BY_POS,MODE_TRADES); // آûنهëèى îًنهً
if (OrderType()==OP_SELL) return; // إٌëè îي sell, ٍî يه îٍêًûâàهىٌے
}
OrderSend(Symbol(),OP_SELL, Lot, Bid, slippage, Bid+Stoploss*Point, Bid-Takeprofit*Point, "Sell: MA_cross_Method_PriceMode", migic, 0, CLR_NONE);
return;
}
//================================================== ==========================================
int MAMethod(int MA_Method)
{
switch(MA_Method)
{
case 0: return(0); // آîçâًàùàهٍ MODE_SMA=0
case 1: return(1); // آîçâًàùàهٍ MODE_EMA=1
case 2: return(2); // آîçâًàùàهٍ MODE_SMMA=2
case 3: return(3); // آîçâًàùàهٍ MODE_LWMA=3
}
}
//================================================== ==========================================
int MAPrice(int MA_Price)
{
switch(MA_Price)
{
case 0: return(PRICE_CLOSE); // آîçâًàùàهٍ PRICE_CLOSE=0
case 1: return(PRICE_OPEN); // آîçâًàùàهٍ PRICE_OPEN=1
case 2: return(PRICE_HIGH); // آîçâًàùàهٍ PRICE_HIGH=2
case 3: return(PRICE_LOW); // آîçâًàùàهٍ PRICE_LOW=3
case 4: return(PRICE_MEDIAN); // آîçâًàùàهٍ PRICE_MEDIAN=4
case 5: return(PRICE_TYPICAL); // آîçâًàùàهٍ PRICE_TYPICAL=5
case 6: return(PRICE_WEIGHTED); // آîçâًàùàهٍ PRICE_WEIGHTED=6
}
}
//================================================== ==========================================
void Trailingstop(int Magicnumber)
{
for(int p=0;p<OrdersTotal();p++)
{
OrderSelect(p, SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_SELL && OrderSymbol()==Symbol()&& OrderMagicNumber()==Magicnumber)
{
if ( (OrderOpenPrice() - Ask) > (Point * Trailing)&& (OrderStopLoss() > (Ask + Point * Trailing) || (OrderStopLoss() == 0)))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Poi nt*Trailing,OrderTakeProfit(),0,Yellow);
}
}
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==Magicnumber)
{
if( Bid - OrderOpenPrice() > Point * Trailing&& OrderStopLoss() < Bid - Point * Trailing)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*Trailing,OrderTakeProfit(),0,Yellow);
}
}
}
return(0);
}