#include <stdlib.mqh>
extern string Expert_Name = "LSMA_Daily";
extern int LSMAShortPeriod=7;
extern int LSMALongPeriod=16;
extern string mm = "---Money Management---";
extern double Lots=1.0;
extern double MaxLots = 100;
extern bool UseMoneyManagement = true; // Change to false to shutdown money management controls.
extern bool BrokerIsIBFX = false;
extern string m1="Set mini and micro to false for standard account";
extern bool AccountIsMini = false;
extern bool AccountIsMicro = false;
extern string fm="UseFreeMargin = false to use Account Balance";
extern bool UseFreeMargin = true;
extern double TradeSizePercent = 10; // Change to whatever percent of equity you wish to risk.
extern bool BrokerPermitsFractionalLots = true;
extern string st6 = "--Profit Controls--";
extern double StopLoss=0;
extern double TakeProfit=0;
extern int Slippage=3;
int MagicNumber=0;
string setup;
int TradesInThisSymbol = 0;
double mLots=0;
datetime timeprev = 0;
int init()
{
// код доступен только после оплаты
}
int deinit()
{
return(0);
}
double LSMADaily(int Rperiod, int shift)
{
int i;
double sum;
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;
tmp = ( i - lengthvar)*iClose(NULL,1440,length-i+shift);
sum+=tmp;
}
wt = sum*6/(length*(length+1));
return(wt);
}
bool CheckExitCondition(int TradeType)
{
bool YesClose;
double L_Fast,L_Slow;
YesClose = false;
L_Fast=LSMADaily(LSMAShortPeriod,1);
L_Slow=LSMADaily(LSMALongPeriod,1);
if (TradeType == OP_BUY)
{
if (L_Fast < L_Slow) YesClose = true;
}
if (TradeType == OP_SELL)
{
if (L_Fast > L_Slow) YesClose = true;
}
return (YesClose);
}
bool CheckEntryCondition(int TradeType)
{
bool YesTrade;
double L_Fast,L_Slow;
L_Fast=LSMADaily(LSMAShortPeriod,1);
L_Slow=LSMADaily(LSMALongPeriod,1);
YesTrade = false;
if (TradeType == OP_BUY)
{
if ( L_Fast > L_Slow) YesTrade = true;
}
if (TradeType == OP_SELL)
{
if ( L_Fast < L_Slow) YesTrade = true;
}
return (YesTrade);
}
int start()
{
// код доступен только после оплаты
}
double GetLots()
{
double lot;
if(UseMoneyManagement == true)
{
lot = LotsOptimized();
}
else
{
lot = Lots;
}
if (AccountIsMicro == true)
{
if (lot < 0.01) lot = 0.01;
if (lot > MaxLots) lot = MaxLots * 100;
if (BrokerIsIBFX == true) lot = lot * 10;
return(lot);
}
if(AccountIsMini == true)
{
if (lot < 0.1) lot = 0.1;
if (lot > MaxLots) lot = MaxLots;
if (BrokerIsIBFX == true) lot = lot * 10;
return(lot);
}
if( BrokerPermitsFractionalLots == false)
{
if (lot >= 1.0) lot = MathFloor(lot); else lot = 1.0;
}
if (lot > MaxLots) lot = MaxLots;
return(lot);
}
double LotsOptimized()
{
double lot=Lots;
if (UseFreeMargin == true)
lot=NormalizeDouble(MathFloor(AccountFreeMargin()*TradeSizePercent/10000)/10,1);
else
lot=NormalizeDouble(MathFloor(AccountBalance()*TradeSizePercent/10000)/10,1);
if(AccountIsMini == true)
{
lot = MathFloor(lot*10)/10;
}
return(lot);
}
int OpenBuyOrder(double mLots, double mStopLoss, double mTakeProfit, int mSlippage, string mComment, int mMagic, color mColor)
{
int err,ticket;
double myPrice, myStopLoss = 0, myTakeProfit = 0;
RefreshRates();
myStopLoss = StopLong(Bid,mStopLoss);
myTakeProfit = TakeLong(Bid,mTakeProfit);
if (Digits > 0)
{
myPrice = NormalizeDouble( Ask, Digits);
myStopLoss = NormalizeDouble( myStopLoss, Digits);
myTakeProfit = NormalizeDouble( myTakeProfit, Digits);
}
ticket=OrderSend(Symbol(),OP_BUY,mLots,myPrice,mSlippage,myStopLoss,myTakeProfit,mComment,mMagic,0,mColor);
if (ticket > 0)
{
if (OrderSelect( ticket,SELECT_BY_TICKET, MODE_TRADES) )
{
Print("BUY order opened : ", OrderOpenPrice( ));
}
}
else
{
err = GetLastError();
if(err==0)
{
return(ticket);
}
else
{
if(err==4 || err==137 ||err==146 || err==136) //Busy errors
{
Sleep(5000);
}
else //normal error
{
Print("Error opening BUY order [" + setup + "]: (" + err + ") " + ErrorDescription(err));
}
}
}
return(ticket);
}
void OpenSellOrder(dПоказано первые 50% кода (символов: 7750)
Введите ваш email и нажмите кнопку, чтобы перейти к оплате.