#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 BrokerIsIBFX = false;
extern string m1="Set mini and micro to false for standard account";
extern bool AccountIsMini = false;
extern bool AccountIsMicro = false;
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;
extern string st8 = "-- Money Management --";
extern bool UseMoneyManagement = true;
extern bool UseStopLossMM = true;
extern bool UseFreeMargin = true;
extern double Risk = 5;
extern int maxPipsLoss=100; //max pips loss possible if you don't use a stopploss
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)
{
if (UseStopLossMM) lot = GetSLMMLots();
else lot = GetMMLots();
}
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 GetSLMMLots()
{
double lot=Lots;
if (StopLoss!=0) maxPipsLoss=StopLoss;
if (UseFreeMargin == true)
lot = NormalizeDouble((Risk/100)*AccountFreeMargin()/(maxPipsLoss*MarketInfo(Symbol(),MODE_TICKVALUE)),2);
else
lot = NormalizeDouble((Risk/100)*AccountBalance()/(maxPipsLoss*MarketInfo(Symbol(),MODE_TICKVALUE)),2);
Print("next SL >"+(lot * MarketInfo(Symbol(),MODE_TICKVALUE)*(StopLoss+((Ask-Bid)*2))));
Print("MarketInfo(Symbol(),MODE_TICKVALUE) "+MarketInfo(Symbol(),MODE_TICKVALUE));
return(lot);
}
double GetMMLots()
{
double lot=Lots;
if (UseFreeMargin == true)
lot = NormalizeDouble((Risk)*AccountFreeMargin()/MarketInfo(Symbol(),MODE_LOTSIZE),2);
else
lot = NormalizeDouble((Risk)*AccountBalance()/MarketInfo(Symbol(),MODE_LOTSIZE),2);
Print("Lotsize >"+MarketInfo(Symbol(),MODE_LOTSIZE));
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
{Показано первые 50% кода (символов: 8322)
Введите ваш email и нажмите кнопку, чтобы перейти к оплате.