#include <stdlib.mqh>
extern int MagicNumber = 2222;
extern bool AccountIsMini = false; // Change to true if trading mini account
extern bool MoneyManagement = false; // Change to false to shutdown money management controls.
extern double TradeSizePercent = 5; // Change to whatever percent of equity you wish to risk.
extern double Lots = 3; // standard lot size.
extern double MaxLots = 100;
extern int FastMA_Mode = 0; //0=sma, 1=ema, 2=smma, 3=lwma, 4=LSMA
extern int FastMA_Period = 2;
extern int FastMA_Shift = 0;
extern int FastMA_AppliedPrice = 0; // 0=close, 1=open, 2=high, 3=low, 4=median((h+l/2)), 5=typical((h+l+c)/3), 6=weighted((h+l+c+c)/4)
extern int SlowMA_Mode = 0; //0=sma, 1=ema, 2=smma, 3=lwma, 4=LSMA
extern int SlowMA_Period = 5;
extern int SlowMA_Shift = 0;
extern int SlowMA_AppliedPrice = 0; // 0=close, 1=open, 2=high, 3=low, 4=median((h+l/2)), 5=typical((h+l+c)/3), 6=weighted((h+l+c+c)/4)
extern int Fast_SlowSpreadEntry = 11; // How many pips separation between MAs for signal
extern int Fast_SlowSpreadExit=0; // How many pips separation between MAs for signal
extern int SignalCandle=1;
extern double StopLoss = 250; // Maximum pips willing to lose per position.
extern bool UseTrailingStop = true;
extern int TrailingStopType = 3; // Type 1 moves stop immediately, Type 2 waits til value of TS is reached
extern double TrailingStop = 40; // Change to whatever number of pips you wish to trail your position with.
extern double FirstMove = 20; // Type 3 first level pip gain
extern double FirstStopLoss = 15; // Move Stop to Breakeven
extern double SecondMove = 30; // Type 3 second level pip gain
extern double SecondStopLoss = 20; // Move stop to lock is profit
extern double ThirdMove = 40; // type 3 third level pip gain
extern double TrailingStop3 = 20; // Move stop and trail from there
extern int TakeProfit = 0; // Maximum profit level achieved.
extern double Margincutoff = 800; // Expert will stop trading if equity level decreases to that level.
extern int Slippage = 10; // Possible fix for not getting closed
string setup;
double lotMM;
int TradesInThisSymbol;
int init()
{
// код доступен только после оплаты
}
int deinit()
{
}
double LSMA(int Rperiod,int prMode, int TimeFrame, int mshift)
{
int i;
double sum, price;
int length;
double lengthvar;
double tmp;
double wt;
length = Rperiod;
sum = 0;
for(i = length; i >= 1 ; i--)
{
lengthvar = length + 1;
lengthvar /= 3;
tmp = 0;
switch (prMode)
{
case 0: price = iClose(NULL,TimeFrame,length-i+mshift);break;
case 1: price = iOpen(NULL,TimeFrame,length-i+mshift);break;
case 2: price = iHigh(NULL,TimeFrame,length-i+mshift);break;
case 3: price = iLow(NULL,TimeFrame,length-i+mshift);break;
case 4: price = (iHigh(NULL,TimeFrame,length-i+mshift) + iLow(NULL,TimeFrame,length-i+mshift))/2;break;
case 5: price = (iHigh(NULL,TimeFrame,length-i+mshift) + iLow(NULL,TimeFrame,length-i+mshift) + iClose(NULL,TimeFrame,length-i+mshift))/3;break;
case 6: price = (iHigh(NULL,TimeFrame,length-i+mshift) + iLow(NULL,TimeFrame,length-i+mshift) + iClose(NULL,TimeFrame,length-i+mshift) + iClose(NULL,TimeFrame,length-i+mshift))/4;break;
}
tmp = ( i - lengthvar)*price;
sum+=tmp;
}
wt = sum*6/(length*(length+1));
return(wt);
}
bool CheckExitCondition(string TradeType)
{
bool YesClose;
double fMA, sMA;
YesClose = false;
if (FastMA_Mode == 4)
{
fMA = LSMA(FastMA_Period,FastMA_AppliedPrice,0,SignalCandle);
}
else
{
fMA = iMA(NULL, 0, FastMA_Period, FastMA_Shift, FastMA_Mode, FastMA_AppliedPrice, SignalCandle);
}
if (SlowMA_Mode == 4)
{
sMA = LSMA(SlowMA_Period,SlowMA_AppliedPrice,0,SignalCandle);
}
else
{
sMA = iMA(NULL, 0, SlowMA_Period, SlowMA_Shift, SlowMA_Mode, SlowMA_AppliedPrice, SignalCandle);
}
if (TradeType == "BUY" && fMA - sMA < Fast_SlowSpreadExit*Point) YesClose = true;
if (TradeType == "SELL" && fMA - sMA > Fast_SlowSpreadExit*Point) YesClose = true;
return (YesClose);
}
bool CheckEntryCondition(string TradeType)
{
bool YesTrade;
double fMA, sMA;
YesTrade = false;
if (FastMA_Mode == 4)
{
fMA = LSMA(FastMA_Period,FastMA_AppliedPrice,0,SignalCandle);
}
else
{
fMA = iMA(NULL, 0, FastMA_Period, FastMA_Shift, FastMA_Mode, FastMA_AppliedPrice, SignalCandle);
}
if (SlowMA_Mode == 4)
{
sMA = LSMA(SlowMA_Period,SlowMA_AppliedPrice,0,SignalCandle);
}
else
{
sMA = iMA(NULL, 0, SlowMA_Period, SlowMA_Shift, SlowMA_Mode, SlowMA_AppliedPrice, SignalCandle);
}
if (TradeType == "BUY" && fMA - sMA > Fast_SlowSpreadExit*Point) YesTrade = true;
if (TradeType == "SELL" && fMA - sMA < Fast_SlowSpreadExit*Point ) YesTrade = true;
return (YesTrade);
}
int start()
{
// код доступен только после оплаты
}
void OpenBuyOrder()
{
int err,ticket;
double myStopLoss = 0, myTakeProfit = 0;
myStopLoss = 0;
if ( StopLoss > 0 ) myStopLoss = Ask - StopLoss * Point ;
myTakeProfit = 0;
if (TakeProfit>0) myTakeProfit = Ask + TakeProfit * Point;
ticket=OrderSend(Symbol(),OP_BUY,lotMM,Ask,Slippage,myStopLoss,myTakeProfit,setup,MagicNumber,0,Green);
if(ticket<=0)
{
err = GetLastError();
Print("Error opening BUY order [" + setup + "]: (" + err + ") " + ErrorDescription(err));
}
}
void OpenSellOrder()
{
int err, ticket;
double myStopLoss = 0, myTakeProfit = 0;
myStopLoss = 0;
if ( StopLoss > 0 ) myStopLoss = Bid + StopLoss * Point;
myTakeProfit = 0;
if (TakeProfit > 0) myTakeProfit = Bid - TakeProfit * Point;
ticket=OrderSend(Symbol(),OP_SELL,lotMM,Bid,Slippage,myStopLoss,myTakeProfit,setup,MagicNumber,0,Red);
if(ticket<=0)
{
err = GetLastError();
Print("Error opening Sell order [" + setup + "]: (" + err + ") " + ErrorDescription(err));
}
}
int CheckOpenPositions()
{
int cnt, NumPositions;
int NumBuyTrades, NumSellTrades; // Number of buy and sell trades in this symbol
NumBuyTrades = 0;
NumSellTrades = 0;
for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSeleПоказано первые 50% кода (символов: 9268)
Введите ваш email и нажмите кнопку, чтобы перейти к оплате.