//---- input parameters
extern int period=240;
extern int coef=-1; // -1 внешний, 1 внутренний
extern int numbars=100;
//-- Подключаемые модули --
#include "Common.mq4"
//+----------------------------------------------------------------------------+
//| Формирует торговые сигналы. |
//+----------------------------------------------------------------------------+
void GetSignal()
{
// your code
static double PBuy = 0 , PSell = 0;
static int sl;
int total = OrdersTotal();
while (total > 0)
{
total--;
OrderSelect(total, SELECT_BY_POS);
int mn = OrderMagicNumber();
if (OrderSymbol()==Symbol() && mn == ExpertMagicNumberUp)
{
total++; break;
}
if (OrderSymbol()==Symbol() && mn == ExpertMagicNumberDn)
{
total++; total = - total; break;
}
}
if (PBuy > 0 && Bid >= PBuy && total <= 0)
{
Buy(); SellClose(); PBuy = 0; PSell = 0;
int level = MarketInfo(NULL, MODE_STOPLEVEL);
if (StopLoss < level) StopLoss = sl;
if (sl < level) sl = level;
if (TakeProfit < level) TakeProfit = sl * 2;
}
if (PSell > 0 && Bid <= PSell && total >= 0)
{
Sell(); BuyClose(); PBuy = 0; PSell = 0;
level = MarketInfo(NULL, MODE_STOPLEVEL);
if (StopLoss < level) StopLoss = sl;
if (sl < level) sl = level;
if (TakeProfit < level) TakeProfit = sl * 2;
}
if (Time[0] != iTime(NULL, period, 0)) return;
if (coef*iHigh(NULL, period, 1) > coef*iHigh(NULL, period, 2)) return;
if (coef*iLow(NULL, period, 1) < coef*iLow(NULL, period, 2)) return;
if (coef == -1)
{
if (MathAbs(Open[1]-Close[1])<MathAbs(Open[2]-Close[2])) return;
if (numbars > 1)
{
if (iLowest(NULL,period,MODE_LOW,numbars,1) != 1) return;
if (iHighest(NULL,period,MODE_HIGH,numbars,1)!=1) return;
}
}
if (coef == 1 && numbars > 1)return;
PBuy = iHigh(NULL, period, 1);
PSell = iLow(NULL, period, 1);
sl = Point*(PBuy - PSell);
//----
}