void Trade_BUY(int mn,int num,double factor1,double factor2,int sl)
void Trade_SELL(int mn,int num,double factor1,double factor2,int sl)
double Out(int n,double l1,double l2)
double lot(int R)
lm=iMA(NULL,0,n,0,MODE_LWMA,PRICE_CLOSE,1),
sm=iMA(NULL,0,n,0, MODE_SMA,PRICE_CLOSE,1);
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//oooooooooooooooooooooooooooooooooooooooooooooooooooo
if (Time[0] == prevtime) return(0);
prevtime = Time[0];
if (!IsTradeAllowed()) {
prevtime=Time[1]; MathSrand(TimeCurrent());Sleep(30000 + MathRand());
}
//oooooooooooooooooooooooooooooooooooooooooooooooooooo
if( In_BUY)Trade_BUY ( Magic_BUY, Count_buy,w_price,w_trend, SL_buy);
if(In_SELL)Trade_SELL(Magic_SELL,Count_sell,m_price,m_trend,SL_sell);
//oooooooooooooooooooooooooooooooooooooooooooooooooooo
return(0);
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
void Trade_BUY(int mn,int num,double factor1,double factor2,int sl) {
int total=OrdersTotal();
for (int i = 0; i < total; i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderMagicNumber() == mn) { return(0);
}
}
//ooooooooooooooooooooooooooooooooooooooooooooooooooo
ticket = -1;
double target=Out(num,factor1,factor2);
if (target>(Bid+15*x*Point) && IsTradeAllowed()) {
ticket= OrderSend(Symbol(), OP_BUY,lot(Risk_buy),Ask,5,Bid-x*sl*Point,target,DoubleToStr(mn,0),mn,0,Blue);
RefreshRates();
if ( ticket < 0) { Sleep(30000); prevtime = Time[1]; }
} //-- Exit ---
return(0); }
What it wants >>> Trade_BUY(int mn,int num,double factor1,double factor2,int sl)
What we're giving it >>> Trade_BUY( Magic_BUY, Count_buy,w_price,w_trend, SL_buy)
Trade_BUY(123,24,0.18,0.18,62)
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
double Out(int n,double l1,double l2) { double t[120],
s[120],
lm=iMA(NULL,0,n,0,MODE_LWMA,PRICE_CLOSE,1),
sm=iMA(NULL,0,n,0, MODE_SMA,PRICE_CLOSE,1);
//ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
t[n]=(6*lm-6*sm)/(n-1);s[n]=4*sm-3*lm-t[n];
for (int k = n-1; k>0; k--) {
s[k]=l1*Close[k]+(1-l1)*(s[k+1]+t[k+1]);
t[k]=l2*(s[k]-s[k+1])+(1-l2)*t[k+1];
}//--end--for-
return (NormalizeDouble(s[1]+t[1],MarketInfo(Symbol(),MODE_DIGITS)));}
t[24]=(6*lm-6*sm)/(24-1);
s[24]=4*sm-3*lm-t[24];
for (int k = 23; k>0; k--)
{
s[k] = 0.18 * Close[k] + (1 - 0.18) * (s[k+1]+t[k+1]);
t[k] = 0.18 * (s[k] - s[k+1]) + (1 - 0.18) * t[k+1];
}
return (NormalizeDouble(s[1] + t[1],MarketInfo(Symbol(),MODE_DIGITS)));
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
double lot(int R) { double minlot = MarketInfo(Symbol(), MODE_MINLOT);
int o = MathAbs(MathLog(minlot) *0.4343) + 0.5;
double lot = minlot;
//ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
lot = NormalizeDouble(AccountFreeMargin() * 0.00001*R, o);//---
if (AccountFreeMargin() < lot * MarketInfo(Symbol(), MODE_MARGINREQUIRED)) {
lot = NormalizeDouble(AccountFreeMargin() / MarketInfo(Symbol(), MODE_MARGINREQUIRED), o);
}
//ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
if(lot < minlot) lot = minlot;
double maxlot =MarketInfo(Symbol(), MODE_MAXLOT);
if(lot > maxlot) lot = maxlot;
return(lot); }
lot = NormalizeDouble(AccountFreeMargin() * 0.00001 * R, o);
if(lot < minlot) lot = minlot;
if (target > (Bid + 15 * x * Point) && IsTradeAllowed())
ticket = OrderSend(Symbol(), //Whatever symbol is on the same chart as the EA
OP_BUY, //Buying position
lot(Risk_buy), //This is a function call that resolves to a minimum number of lots while Risk_buy is set to 0
Ask, //We're buying, so we have to go with what the market is asking.
5, //I guess we're going to allow 5 pips slippage
Bid-x*62*Point, //Stop loss. x will be either 1 or 10 depending on if the broker is four or five digits.
target, // At least we know it's more than 15 pips!
DoubleToStr(mn,0), //Comments will quote the magic number as a string.
mn, //The magic number = 123
0, //No order expiration
Blue); //We want a blue arrow on the chart showing where this order was filled