1-2-3_forcodebase_v01.mq4
Похожие материалы по тегам
Сообщите нам, если считаете, что материал размещён без разрешения.
Сообщить о материале
Обращение по товару «1-2-3_forcodebase_v01.mq4» отправится на рассмотрение. Укажите контакт для ответа и опишите причину.
О программе
Советник для MetaTrader 4, реализующий торговую стратегию на основе анализа ценовых паттернов. Он определяет образование ценовых структур путём поиска впадин и пиков на свечных данных, а затем подтверждает сигналы с помощью индикатора MACD. Для оценки относительной длины трендов используются два пользовательских индикатора (RelDownTrLen и RelUpTrLen).
Советник поддерживает как длинные, так и короткие позиции с настраиваемыми параметрами тейк-профита, объёма, трейлинг-стопа и соотношения трендов. При выполнении условий на покупку открывается BUY-ордер с расчётными уровнями стоп-лосса и тейк-профита. Логика для продажи работает по зеркальному принципу.
Функция start() управляет текущими позициями, корректируя стоп-лосс при срабатывании трейлинг-стопа. Перед открытием нового ордера проверяется свободная маржа на счёте. Функции CloseLongCondition и CloseShortCondition возвращают false, поэтому позиции закрываются только через трейлинг-стоп или вручную.
Настройки программы
| Настройка | Описание |
|---|---|
| TakeProfit | Тейк-профит — Уровень тейк-профита в пунктах |
| Lots | Объём лота — Объём лота для открытия позиции |
| TrailingStop | Трейлинг-стоп — Расстояние трейлинг-стопа в пунктах |
| TrendRatio | Соотношение трендов — Минимальное соотношение длины текущего тренда к предыдущему для подтверждения сигнала |
Поиск по коду файла
/*
This expert implements the method described on page
This is not a canonical imlementation. This is just a try.
I run the expert on the H1-graph of EURJPY with positive but not
excellent results. The expert has one "disatvantage", I mean rare trades.
*/
extern double TakeProfit = 60;
extern double Lots = 0.5;
extern double TrailingStop = 30;
extern double TrendRatio = 4;
double dStopLoss=0, dTakeProfit=0;
int MagicNumber=12301;
bool BuyCondition()
{
bool Condition=false;
int Point1Index, Point2Index, Point3Index;
double CurrentLevel=Ask, Point1Level, Point2Level, Point3Level;
double DownTrLen,UpTrLen;
double MacdCurrent, MacdPrevious;
double SignalCurrent, SignalPrevious;
bool MacdSignalsToBuy;
Point3Index=FindFirstValley(CurrentLevel, -10000,1,100);
if(Point3Index==-1)
return(false);
else
Point3Level=MathMin(Open[Point3Index],Close[Point3Index]);
Point2Index=FindFirstPeak(CurrentLevel, Point3Level, Point3Index+1, 100);
if(Point2Index==-1)
return(false);
else
Point2Level=MathMax(Open[Point2Index],Close[Point2Index]);
Point1Index=FindFirstValley(Point2Level, -10000,Point2Index+1,100);
if(Point1Index==-1)
return(false);
else
Point1Level=MathMin(Open[Point1Index],Close[Point1Index]);
if(CurrentLevel-Point2Level>5*Point)
return(false);//Too far from the potential entry level.
MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
MacdSignalsToBuy=((MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious) ||
(MacdCurrent>0 && MacdPrevious<0)) &&
iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,Point3Index)>0;
if(!MacdSignalsToBuy)
return(false);
DownTrLen=iCustom(NULL, 0, "RelDownTrLen_forCodeBase_v01", 100, Point1Index, true, 0, 0);
UpTrLen=iCustom(NULL, 0, "RelUpTrLen_forCodeBase_v01", Point1Index, 1, true, 0, 0);
Condition=DownTrLen/(UpTrLen+0.001)>TrendRatio && //The down trend was longer enough.
(Point2Level-Point3Level)/Point>13;//Potential stop loss far enough.
if(Condition)
{
dStopLoss=Point3Level-Point;
dTakeProfit=CurrentLevel+(Point2Level-Point3Level);
}
return(Condition);
}
bool SellCondition()
{
bool Condition=false;
int Point1Index, Point2Index, Point3Index;
double CurrentLevel=Bid, Point1Level, Point2Level, Point3Level;
double DownTrLen,UpTrLen;
double MacdCurrent, MacdPrevious;
double SignalCurrent, SignalPrevious;
bool MacdSignalsToSell;
Point3Index=FindFirstPeak(10000, CurrentLevel,1,100);
if(Point3Index==-1)
return(false);
else
Point3Level=MathMax(Open[Point3Index],Close[Point3Index]);
Point2Index=FindFirstValley(Point3Level, CurrentLevel, Point3Index+1, 100);
if(Point2Index==-1)
return(false);
else
Point2Level=MathMin(Open[Point2Index],Close[Point2Index]);
Point1Index=FindFirstPeak(10000, Point2Level,Point2Index+1,100);
if(Point1Index==-1)
return(false);
else
Point1Level=MathMax(Open[Point1Index],Close[Point1Index]);
if(MathAbs(CurrentLevel-Point2Level)>5*Point)
return(false);////Too far from the potential entry level.
MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
MacdSignalsToSell=((MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious) ||
(MacdCurrent<0 && MacdPrevious>0)) &&
iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,Point3Index)<0;
if(!MacdSignalsToSell)
return(false);
DownTrLen=iCustom(NULL, 0, "RelDownTrLen_forCodeBase_v01", 100, Point1Index, true, 0, 0);
UpTrLen=iCustom(NULL, 0, "RelUpTrLen_forCodeBase_v01", Point1Index, 1, true, 0, 0);
Condition=UpTrLen/(DownTrLen+0.001)>TrendRatio && //The up trend was longer enough.
MathAbs(Point2Level-Point3Level)/Point>13;////Potential stop loss far enough.
if(Condition)
{
dStopLoss=Point3Level+Point;
dTakeProfit=CurrentLevel-MathAbs(Point2Level-Point3Level);
}
return(Condition);
}
bool CloseLongCondition()
{
bool Condition=false;
return(Condition);
}
bool CloseShortCondition()
{
bool Condition=false;
return(Condition);
}
int FindFirstValley(double MaxLevel, double MinLevПоказано первые 50% кода (символов: 6872)
Открыть по тарифу
Купите тариф с пакетом открытий или войдите, если тариф уже есть. Открытый файл останется в вашем кабинете навсегда.
Разовая покупка файла
На этой странице откроется полный исходный код файла вместо ознакомительного фрагмента.
Зачем нужен email? После подтверждения оплаты файл сохранится в кабинете на этот email. Если аккаунта ещё нет, мы создадим его и пришлём ссылку для задания пароля. Если аккаунт уже есть, покупка добавится в него. Укажите адрес, к которому у вас есть доступ.
Чтобы оформить заказ, введите email и перейдите к оплате.