Индикаторы: Прогнозирующий индикатор WmiFor 3.0 (ядро DTW) - страница 5

 
А вы думали что будет грааль ? Этот индикатор неординарная идея, к тому же сложно реализуемая, за что автору ещё раз спасибо.
 

step_up777, мне совершенно непонятно ваше негодование в комментах. На этом сайте програмисты MQL4 делятся своим опытом и выкладывают свои наработки в общее пользование. По существу, вам дарят исходники индикаторов и советников, с которыми вы можете делать все, что угодно. Если удастся заработать на готовом советнике - это хорошо. Если натолкнет на свою идею и вы напишете другой советник на базе выложенного - тоже хорошо. Вас никто с этого сайта не обманывал и ничего вам не гарантировал. Тем более, что это просто индикатор. Параметры его подберите сами, придумайте торговую стратегию.

И еще странно, что меняющийся на каждом баре прогноз (в определенные моменты рынка) вас удивляет. Может, это говорит о неопределенности ситуации? Пробовали торговать, если цель не меняется N баров?

 
wmlab:

step_up777, мне совершенно непонятно ваше негодование в комментах. На этом сайте програмисты MQL4 делятся своим опытом и выкладывают свои наработки в общее пользование. По существу, вам дарят исходники индикаторов и советников, с которыми вы можете делать все, что угодно. Если удастся заработать на готовом советнике - это хорошо. Если натолкнет на свою идею и вы напишете другой советник на базе выложенного - тоже хорошо. Вас никто с этого сайта не обманывал и ничего вам не гарантировал. Тем более, что это просто индикатор. Параметры его подберите сами, придумайте торговую стратегию.

И еще странно, что меняющийся на каждом баре прогноз (в определенные моменты рынка) вас удивляет. Может, это говорит о неопределенности ситуации? Пробовали торговать, если цель не меняется N баров?


Я полностью Вас поодерживаю, Вы молодец!!! И не важно будет ли давать профит или нет Индикатор, но попытка не пытка, я тоже в свою очередь попытался сделать советника по нему,так как тема показалась мне интересной.

Респект. 10 поставил. Спасибо.

 
wmlab: Пробовали торговать, если цель не меняется N баров?

Пока смотрю его на Фунте - Н4. стабильность прогноза смотрю только по направлению. Увеличение числа N особого улучшения не приносит. Я думаю это актуально на малых ТФ. Их еще не смотрел.
 
wmlab:
Я рекомендую открываться по прогнозу, а закрываться по факту - трейлинг выручает.


Вот трейлинг вносит приличные коррективы. Конечно нужна хорошая история, пока у меня нет возможности ее загрузить.

Я сделал своего рода динамический трейлинг в процентах от разности ТП-СЛ. Размер шага пересчитавается перед каждой новой модификацией от предыдущего СЛ конкретного ордера. Тем самым чем ближе мы идем к ТП, тем "шустрее" подтягивается стоп.

 

Из остальных новоротов сделал МИН-ТП и МИН-СЛ, сделал МИН отношение ТП/СЛ. Сделал проверку на "достоверность" ТП и СЛ, так как в коде всё-таки есть ошибка и иногда получаем или СЛ>2 (Евра и Фунт) или ТП=0.00001, ловить саму ошибку лень, потому просто сделал ограничение и проверку.

Работу по сигналам ограничил следующим образом - БАЙ открываем только когда нет СЕЛЛ и наоборот.

При возникновении следующего прогноза БАЙ при уже открытых БАЙ входим только если все остальные БАЙ уже в безубытке по тралу. Аналогично с СЕЛЛ.

По самой логике индикатора - исправил ошибку о которой писал тут ранее и исключил использование параметра MaxAgeInDays. Я полагаю что искать более верно по всей истории.

З.Ы. В принципе после этих доработок на стандартных настройках по Еве и Фунту работает в плюс на 4Н. Но надо еще думать и тестировать на хорошей истории.

З.З.Ы. А вообще, думаю что использовать этот индикатор (советник) более логично на низковолатильных парах и производных, например EURGPB, EURCAD, NZDUSD, AUDCAD и аналогичных. На мажерах сейчас слишком много помех...

 
yis:
Может выложите своего советника?
 

#property copyright ""
#property link ""


#include <stdlib.mqh>
#include <stderror.mqh>

// Внешние переменные
extern string s11="------Параметры управления размером лота--------";
extern double Lot_Size=0.1;
extern bool MM=true; // ММ Switch
extern double MMRisk=0.02;
extern string s12="------Параметры ММ--------";
extern int Minimum_StopLoss=40;
extern int Minimum_TakeProfit=20;
extern int Trail_SL_TP_percent=5;
extern int TP_SL_Dif=10;
extern int magic=12345;
extern int Slipage=2;
extern string s13="------Параметры настройки WmiFor--------";
extern int N_bars=3;
extern int metod = 0; //0-Close; 1-Open; 2-High; 3-Low; 4-(O+C)/2; 5- (H+L)/2; 6- (Hi+Lo+Cl)/3; 7 - (Hi+Lo+Cl+Cl)/4;
extern int OffsetInBars = 1; // Смещение исходного образца в барах (для проверки надежности прогноза) [1..]
extern int PastInBars = 12; // Размер образца в барах, который ищется на истории [3..]
extern int VarShiftInBars = 4; // Смещение паттерна в барах плюс-минус [0..]
extern int ForecastInBars = 4; // На сколько баров вперед делать прогноз [1..]
extern double MaxVarInPercents = 95; // Максимальное расхождение с лучшим вариантом в процентах [0..100]
extern int MaxAlts = 10; // Максимальное число найденных паттернов [1..]

// Глобальные переменные
string IndicatorName = "WmiFor_EA";
bool ShowPastAverage = true; // Показывать ли среднюю истории
bool ShowForecastAverage = true; // Показывать ли прогноз средней
bool ShowBestPattern = false; // Показывать ли максимально близкий образец (вместо средней)
bool ShowTip = true; // Показывать ли торговый совет
bool Debug = true;
datetime OffsetStart, OffsetEnd;
bool IsRedraw;
datetime LastRedraw;
double PastAverage[1000000];
double ForecastCloudHigh[1000000];
double ForecastCloudLow[1000000];
double ForecastCloudAverage[1000000];
double ForecastBestPatternOpen[1000000];
double ForecastBestPatternClose[1000000];
double ForecastBestPatternHigh[1000000];
double ForecastBestPatternLow[1000000];
double SL,TP;
int signal,TP_SL_Dif_temp,MSL,MTP;
int Dig,n_tick;
int orders,buy_orders,sell_orders,sell_stop,buy_stop,sell_lim,buy_lim;
double last_sell_sl,last_sell_tp,last_buy_sl,last_buy_tp,MA,pt;
int Error=300;
int dg, st, sp;
int bars_b,bars_s;
bool BU_buy,BU_sell;
//+------------------------------------------------------------------+
//| Инициализация |
//+------------------------------------------------------------------+

int init()
{ bars_s=0;
bars_b=0;
SL=0.0;
TP=0.0;
signal=0;
if (MarketInfo(Symbol(),MODE_MINLOT)==0.1)Dig=1;
if (MarketInfo(Symbol(),MODE_MINLOT)==0.01)Dig=2;
if (MarketInfo(Symbol(),MODE_DIGITS)==5 || MarketInfo(Symbol(),MODE_DIGITS)==3)
{Minimum_StopLoss=Minimum_StopLoss*10;
Minimum_TakeProfit=Minimum_TakeProfit*10;
Slipage=Slipage*10;
Error=Error*10;
}
Orders_count();
if (OffsetInBars < 1)
{
OffsetInBars = 1;
}

if (PastInBars < 3)
{
PastInBars = 3;
}

if (ForecastInBars < 1)
{
ForecastInBars = 1;
}

if (VarShiftInBars < 0)
{
VarShiftInBars = 0;
}


IsRedraw = true;

return (0);
}

//+------------------------------------------------------------------+
//| Деинициализация |
//+------------------------------------------------------------------+

int deinit()
{
return (0);
}

//+------------------------------------------------------------------+
//| Работа индикатора |
//+------------------------------------------------------------------+

int start()
{
int counted_bars = IndicatorCounted();
if(Trail_SL_TP_percent>0)Trailing();


if (IsRedraw)
{ ReCalculate();
RefreshRates();
Orders_count();
Lot_Size = MoneyManagement(MM,MMRisk);
RefreshRates();
MSL=NormalizeDouble(MathAbs(SL-(Ask+Bid)/2)/Point,0);
MTP=NormalizeDouble(MathAbs(TP-(Ask+Bid)/2)/Point,0);
TP_SL_Dif_temp=NormalizeDouble(MTP/MSL*100,0);
if(signal==1)
{bars_b=bars_b+1;bars_s=0;}
if(signal==-1)
{bars_s=bars_s+1;bars_b=0;}

Orders_count();
if(bars_b>=N_bars && MTP<Error && MSL<Error && sell_orders<=0 && (buy_orders==0 || BU_buy==true) && signal==1 && TP_SL_Dif_temp>=TP_SL_Dif && Minimum_StopLoss<=MSL && Minimum_TakeProfit<=MTP && SL<Bid && TP>Ask && SL!=last_buy_sl && TP!=last_buy_tp)
{n_tick=OrderSend(Symbol(),OP_BUY,NormalizeDouble(Lot_Size,Dig),NormalizeDouble(Ask,Digits),Slipage,0,0,DoubleToStr(NormalizeDouble(TP,Digits),Digits),magic,0,Blue);
if(OrderSelect(n_tick, SELECT_BY_TICKET))
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(SL,Digits),NormalizeDouble(TP,Digits),0,Gray);
last_buy_sl=NormalizeDouble(SL,Digits);
last_buy_tp=NormalizeDouble(TP,Digits);
}
if(bars_s>=N_bars && MTP<Error && MSL<Error && (sell_orders==0 || BU_sell==true) && buy_orders<=0 && signal==-1 && TP_SL_Dif_temp>=TP_SL_Dif && Minimum_StopLoss<=MSL && Minimum_TakeProfit<=MTP && SL>Ask && TP<Bid && SL!=last_sell_sl && TP!=last_sell_tp)
{n_tick=OrderSend(Symbol(),OP_SELL,NormalizeDouble(Lot_Size,Dig),NormalizeDouble(Bid,Digits),Slipage,0,0,DoubleToStr(NormalizeDouble(TP,Digits),Digits),magic,0,Red);
if(OrderSelect(n_tick, SELECT_BY_TICKET))
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(SL,Digits),NormalizeDouble(TP,Digits),0,Gray);
last_sell_sl=NormalizeDouble(SL,Digits);
last_sell_tp=NormalizeDouble(TP,Digits);
}

}
if (IsNewBar())
{
OffsetStart = iTime(NULL, 0, OffsetInBars + PastInBars - 1);
OffsetEnd = iTime(NULL, 0, OffsetInBars);

IsRedraw = true;
LastRedraw = TimeCurrent();
}

return (0);
}

//+------------------------------------------------------------------+
//| Появился новый бар? |
//+------------------------------------------------------------------+

bool IsNewBar()
{
static datetime prevTime = 0;

datetime currentTime = iTime(NULL, 0, 0);
if (prevTime == currentTime)
{
return (false);
}

prevTime = currentTime;
return (true);
}

//+------------------------------------------------------------------+
//| DTW |
//+------------------------------------------------------------------+

double Distance(double value1, double value2)
{
double value = MathAbs(value1 - value2);
return (value);
}

double DTWDistance(double s[], double t[])
{
int slenght = ArraySize(s);
int tlenght = ArraySize(t);
double dtw[1000][1000];
int i, j;

dtw[0, 0] = 0.0;
for (j = 1; j <= tlenght; j++)
{
dtw[0, j] = 1000000.0;
}

for (i = 1; i <= slenght; i++)
{
dtw[i, 0] = 1000000.0;
}

for (i = 1; i <= slenght; i++)
{
for (j = 1; j <= tlenght; j++)
{
dtw[i, j] = Distance(s[i], t[j]) + MathMin(dtw[i - 1, j], MathMin(dtw[i, j - 1], dtw[i - 1, j - 1]));
}
}

return (dtw[slenght, tlenght]);
}

//+------------------------------------------------------------------+
//| Пересчет |
//+------------------------------------------------------------------+

void ReCalculate()
{
datetime currentTime = TimeCurrent();
if ((currentTime - LastRedraw) < 1)
{
return;
}

LastRedraw = currentTime;
IsRedraw = false;

if (Bars < 100)
{
return;
}

int handleLog;
if (Debug)
{
handleLog = FileOpen(IndicatorName + ".log", FILE_WRITE);
if (handleLog < 1)
{
Print ("handleLog = ", handleLog, ", error = ", GetLastError());
}
}

datetime xtime = iTime(NULL, 0, OffsetInBars);
datetime minDate = xtime - (1 * 60 * 60 * 24);
int baseHour = TimeHour(xtime);
int baseMinute = TimeMinute(xtime);
double x[];
ArrayResize(x, PastInBars);
double x0;
if(metod<=0 || metod>7)
x0 = iClose(NULL, 0, OffsetInBars);
if(metod==1)
x0 = iOpen(NULL, 0, OffsetInBars);
if(metod==2)
x0 = iHigh(NULL, 0, OffsetInBars);
if(metod==3)
x0 = iLow(NULL, 0, OffsetInBars);
if(metod==4)
x0 = (iOpen(NULL, 0, OffsetInBars)+iClose(NULL, 0, OffsetInBars))/2;
if(metod==5)
x0 = (iHigh(NULL, 0, OffsetInBars)+iLow(NULL, 0, OffsetInBars))/2;
if(metod==6)
x0 = (iHigh(NULL, 0, OffsetInBars)+iLow(NULL, 0, OffsetInBars)+iClose(NULL, 0, OffsetInBars))/3;
if(metod==7)
x0 = (iHigh(NULL, 0, OffsetInBars)+iLow(NULL, 0, OffsetInBars)+iClose(NULL, 0, OffsetInBars)+iClose(NULL, 0, OffsetInBars))/4;

if (Debug)
{
FileWrite(handleLog, "xtime", TimeToStr(xtime));
FileWrite(handleLog, "minDate", TimeToStr(minDate));
FileWrite(handleLog, "baseHour", baseHour);
FileWrite(handleLog, "baseMinute", baseMinute);
FileWrite(handleLog, "x0", x0);
}

for (int indexBar = OffsetInBars; indexBar < (OffsetInBars + PastInBars); indexBar++)
{
if(metod<=0 || metod>7)
x[indexBar - OffsetInBars] = x0 - iClose(NULL, 0, indexBar);
if(metod==0)
x[indexBar - OffsetInBars] = x0 - iOpen(NULL, 0, indexBar);
if(metod==0)
x[indexBar - OffsetInBars] = x0 - iHigh(NULL, 0, indexBar);
if(metod==0)
x[indexBar - OffsetInBars] = x0 - iLow(NULL, 0, indexBar);
if(metod==0)
x[indexBar - OffsetInBars] = x0 - (iClose(NULL, 0, indexBar)+iOpen(NULL, 0, indexBar))/2;
if(metod==0)
x[indexBar - OffsetInBars] = x0 - (iHigh(NULL, 0, indexBar)+iLow(NULL, 0, indexBar))/2;
if(metod==0)
x[indexBar - OffsetInBars] = x0 - (iHigh(NULL, 0, indexBar)+iLow(NULL, 0, indexBar)+iClose(NULL, 0, indexBar))/3;
if(metod==0)
x[indexBar - OffsetInBars] = x0 - (iHigh(NULL, 0, indexBar)+iLow(NULL, 0, indexBar)+iClose(NULL, 0, indexBar)+iClose(NULL, 0, indexBar))/4;
if (Debug)
{
FileWrite(handleLog, "x", indexBar - OffsetInBars, x[indexBar - OffsetInBars]);
}
}

int foundAlts = 0;
int iAlt[];
ArrayResize(iAlt, MaxAlts);
double dAlt[];
ArrayResize(dAlt, MaxAlts);

int patternscount = 0;

for (int indexShift = ForecastInBars + OffsetInBars + 1; indexShift < Bars; indexShift++)
{
datetime ytimebase = iTime(NULL, 0, indexShift);


if ((indexShift + PastInBars + VarShiftInBars) >= Bars)
{
break;
}

int currentHour = TimeHour(ytimebase);
if (currentHour != baseHour)
{
continue;
}

int currentMinute = TimeMinute(ytimebase);
if (currentMinute != baseMinute)
{
continue;
}

int iAltSingle = 0;
double dAltSingle = 1000000.0;
double y[];
ArrayResize(y, PastInBars);

for (int indexVar = indexShift - VarShiftInBars; indexVar <= indexShift + VarShiftInBars; indexVar++)
{
patternscount++;
datetime ytime = iTime(NULL, 0, indexVar);
double y0;
if(metod<=0 || metod>7)
y0 = iClose(NULL, 0, indexVar);
if(metod==1)
y0 = iOpen(NULL, 0, indexVar);
if(metod==2)
y0 = iHigh(NULL, 0, indexVar);
if(metod==3)
y0 = iLow(NULL, 0, indexVar);
if(metod==4)
y0 = (iOpen(NULL, 0, indexVar)+iClose(NULL, 0, indexVar))/2;
if(metod==5)
y0 = (iHigh(NULL, 0, indexVar)+iLow(NULL, 0, indexVar))/2;
if(metod==6)
y0 = (iHigh(NULL, 0, indexVar)+iLow(NULL, 0, indexVar)+iClose(NULL, 0, indexVar))/3;
if(metod==7)
y0 = (iHigh(NULL, 0, indexVar)+iLow(NULL, 0, indexVar)+iClose(NULL, 0, indexVar)+iClose(NULL, 0, indexVar))/4;




for (indexBar = indexVar; indexBar < (indexVar + PastInBars); indexBar++)
{
if(metod<=0 || metod>7)
y[indexBar - indexVar] = y0 - iClose(NULL, 0, indexBar);
if(metod==1)
y[indexBar - indexVar] = y0 - iOpen(NULL, 0, indexBar);
if(metod==2)
y[indexBar - indexVar] = y0 - iHigh(NULL, 0, indexBar);
if(metod==3)
y[indexBar - indexVar] = y0 - iLow(NULL, 0, indexBar);
if(metod==4)
y[indexBar - indexVar] = y0 - (iOpen(NULL, 0, indexBar)+iClose(NULL, 0, indexBar))/2;
if(metod==5)
y[indexBar - indexVar] = y0 - (iHigh(NULL, 0, indexBar)+iLow(NULL, 0, indexBar))/2;
if(metod==6)
y[indexBar - indexVar] = y0 - (iHigh(NULL, 0, indexBar)+iLow(NULL, 0, indexBar)+iClose(NULL, 0, indexBar))/3;
if(metod==7)
y[indexBar - indexVar] = y0 - (iHigh(NULL, 0, indexBar)+iLow(NULL, 0, indexBar)+iClose(NULL, 0, indexBar)+iClose(NULL, 0, indexBar))/4;
}

double dtw = DTWDistance(x, y);
if (dtw < dAltSingle)
{
dAltSingle = dtw;
iAltSingle = indexVar;
}
}

if (Debug)
{
FileWrite(handleLog, "");
FileWrite(handleLog, "iAltSingle", iAltSingle);
FileWrite(handleLog, "dAltSingle", dAltSingle);
}

bool altAdded = false;
int j = 0;
for (j = 0; j < foundAlts; j++)
{
if (dAltSingle < dAlt[j])
{
if (foundAlts == MaxAlts)
{
foundAlts = MaxAlts - 1;
}

for (int m = foundAlts; m >= (j + 1); m--)
{
iAlt[m] = iAlt[m - 1];
dAlt[m] = dAlt[m - 1];
}

iAlt[j] = iAltSingle;
dAlt[j] = dAltSingle;
foundAlts++;
altAdded = true;
break;
}
}

if (!altAdded)
{
if (foundAlts < MaxAlts)
{
iAlt[j] = iAltSingle;
dAlt[j] = dAltSingle;
foundAlts++;
}
}
}

if (Debug)
{
FileWrite(handleLog, "");
FileWrite(handleLog, "foundAlts", foundAlts);
FileWrite(handleLog, "iAlt[0]", iAlt[0]);
FileWrite(handleLog, "dAlt[0]", dAlt[0]);
}

if (foundAlts > 1)
{
for (int a = 1; a < foundAlts; a++)
{
double sim = 100.0 - (((dAlt[a] - dAlt[0]) * 100.0) / dAlt[a]);
if (Debug)
{
FileWrite(handleLog, "a", a, "dAlt", dAlt[a], "sim", sim);
}

if (sim < MaxVarInPercents)
{
foundAlts = a;
break;
}
}
}

double xcbase, ycbase;
int altindex;
ArrayInitialize(PastAverage, EMPTY_VALUE);

if (ShowPastAverage && !ShowBestPattern)
{
if (Debug)
{
FileWrite(handleLog, "");
}

for (indexBar = ForecastInBars; indexBar < (PastInBars + ForecastInBars); indexBar++)
{ if(metod<=0 || metod>7)
PastAverage[indexBar] = iClose(NULL, 0, indexBar - ForecastInBars + OffsetInBars);
if(metod==1)
PastAverage[indexBar] = iOpen(NULL, 0, indexBar - ForecastInBars + OffsetInBars);
if(metod==2)
PastAverage[indexBar] = iHigh(NULL, 0, indexBar - ForecastInBars + OffsetInBars);
if(metod==3)
PastAverage[indexBar] = iLow(NULL, 0, indexBar - ForecastInBars + OffsetInBars);
if(metod==4)
PastAverage[indexBar] = (iOpen(NULL, 0, indexBar - ForecastInBars + OffsetInBars)+iClose(NULL, 0, indexBar - ForecastInBars + OffsetInBars))/2;
if(metod==5)
PastAverage[indexBar] = (iHigh(NULL, 0, indexBar - ForecastInBars + OffsetInBars)+iLow(NULL, 0, indexBar - ForecastInBars + OffsetInBars))/2;
if(metod==6)
PastAverage[indexBar] = (iHigh(NULL, 0, indexBar - ForecastInBars + OffsetInBars)+iLow(NULL, 0, indexBar - ForecastInBars + OffsetInBars)+iClose(NULL, 0, indexBar - ForecastInBars + OffsetInBars))/3;
if(metod==7)
PastAverage[indexBar] = (iHigh(NULL, 0, indexBar - ForecastInBars + OffsetInBars)+iLow(NULL, 0, indexBar - ForecastInBars + OffsetInBars)+iClose(NULL, 0, indexBar - ForecastInBars + OffsetInBars)+iClose(NULL, 0, indexBar - ForecastInBars + OffsetInBars))/4;




if (Debug)
{
FileWrite(handleLog, "PastBar", indexBar - ForecastInBars, PastAverage[indexBar]);
}
}
}

ArrayInitialize(ForecastCloudHigh, EMPTY_VALUE);
ArrayInitialize(ForecastCloudLow, EMPTY_VALUE);
ArrayInitialize(ForecastCloudAverage, EMPTY_VALUE);


double forecastCloudHigh[];
ArrayResize(forecastCloudHigh, ForecastInBars);
ArrayInitialize(forecastCloudHigh, -1000000.0);
double forecastCloudLow[];
ArrayResize(forecastCloudLow, ForecastInBars);
ArrayInitialize(forecastCloudLow, 1000000.0);
double forecastCloudAverage[];
ArrayResize(forecastCloudAverage, ForecastInBars);
ArrayInitialize(forecastCloudAverage, 0.0);

if(metod<=0 || metod>7)
xcbase = iClose(NULL, 0, OffsetInBars);
if(metod==1)
xcbase = iOpen(NULL, 0, OffsetInBars);
if(metod==2)
xcbase = iHigh(NULL, 0, OffsetInBars);
if(metod==3)
xcbase = iLow(NULL, 0, OffsetInBars);
if(metod==4)
xcbase = (iClose(NULL, 0, OffsetInBars)+iOpen(NULL, 0, OffsetInBars))/2;
if(metod==5)
xcbase = (iHigh(NULL, 0, OffsetInBars)+iLow(NULL, 0, OffsetInBars))/2;
if(metod==6)
xcbase = (iHigh(NULL, 0, OffsetInBars)+iLow(NULL, 0, OffsetInBars)+iClose(NULL, 0, OffsetInBars))/3;
if(metod==7)
xcbase = (iHigh(NULL, 0, OffsetInBars)+iLow(NULL, 0, OffsetInBars)+iClose(NULL, 0, OffsetInBars)+iClose(NULL, 0, OffsetInBars))/4;

for (indexBar = 0; indexBar < ForecastInBars; indexBar++)
{
for (a = 0; a < foundAlts; a++)
{
altindex = iAlt[a] - ForecastInBars + indexBar;
if(metod<=0 || metod>7)
ycbase = iClose(NULL, 0, iAlt[a]);
if(metod==1)
ycbase = iOpen(NULL, 0, iAlt[a]);
if(metod==2)
ycbase = iHigh(NULL, 0, iAlt[a]);
if(metod==3)
ycbase = iLow(NULL, 0, iAlt[a]);
if(metod==4)
ycbase = (iClose(NULL, 0, iAlt[a])+iOpen(NULL, 0, iAlt[a]))/2;
if(metod==5)
ycbase = (iHigh(NULL, 0, iAlt[a])+iLow(NULL, 0, iAlt[a]))/2;
if(metod==6)
ycbase = (iHigh(NULL, 0, iAlt[a])+iLow(NULL, 0, iAlt[a])+iClose(NULL, 0, iAlt[a]))/3;
if(metod==7)
ycbase = (iHigh(NULL, 0, iAlt[a])+iLow(NULL, 0, iAlt[a])+iClose(NULL, 0, iAlt[a])+iClose(NULL, 0, iAlt[a]))/4;

double yclose;
if(metod<=0 || metod>7)
yclose = xcbase + (iClose(NULL, 0, altindex) - ycbase);
if(metod==1)
yclose = xcbase + (iOpen(NULL, 0, altindex) - ycbase);
if(metod==2)
yclose = xcbase + (iHigh(NULL, 0, altindex) - ycbase);
if(metod==3)
yclose = xcbase + (iLow(NULL, 0, altindex) - ycbase);
if(metod==4)
yclose = xcbase + ((iClose(NULL, 0, altindex)+iOpen(NULL, 0, altindex))/2 - ycbase);
if(metod==5)
yclose = xcbase + ((iLow(NULL, 0, altindex)+iHigh(NULL, 0, altindex))/2 - ycbase);
if(metod==6)
yclose = xcbase + ((iLow(NULL, 0, altindex)+iHigh(NULL, 0, altindex)+iClose(NULL, 0, altindex))/3 - ycbase);
if(metod==7)
yclose = xcbase + ((iLow(NULL, 0, altindex)+iHigh(NULL, 0, altindex)+iClose(NULL, 0, altindex)+iClose(NULL, 0, altindex))/4 - ycbase);


if (yclose > forecastCloudHigh[indexBar])
{
forecastCloudHigh[indexBar] = yclose;
}

if (yclose < forecastCloudLow[indexBar])
{
forecastCloudLow[indexBar] = yclose;
}

forecastCloudAverage[indexBar] += yclose;
}

forecastCloudAverage[indexBar] /= foundAlts;

if (ShowForecastAverage && !ShowBestPattern)
{
if (foundAlts > 1)
{
ForecastCloudHigh[indexBar] = forecastCloudHigh[indexBar];
ForecastCloudLow[indexBar] = forecastCloudLow[indexBar];
}

ForecastCloudAverage[indexBar] = forecastCloudAverage[indexBar];
}
}

if (ShowForecastAverage && !ShowBestPattern)
{
if (foundAlts > 1)
{
ForecastCloudHigh[indexBar] = xcbase;
ForecastCloudLow[indexBar] = xcbase;
}

ForecastCloudAverage[indexBar] = xcbase;
}

ArrayInitialize(ForecastBestPatternOpen, EMPTY_VALUE);
ArrayInitialize(ForecastBestPatternClose, EMPTY_VALUE);
ArrayInitialize(ForecastBestPatternHigh, EMPTY_VALUE);
ArrayInitialize(ForecastBestPatternLow, EMPTY_VALUE);

if(metod<=0 || metod>7)
xcbase = iClose(NULL, 0, OffsetInBars);
if(metod==1)
xcbase = iOpen(NULL, 0, OffsetInBars);
if(metod==2)
xcbase = iHigh(NULL, 0, OffsetInBars);
if(metod==3)
xcbase = iLow(NULL, 0, OffsetInBars);
if(metod==4)
xcbase = (iOpen(NULL, 0, OffsetInBars)+iClose(NULL, 0, OffsetInBars))/2;
if(metod==5)
xcbase = (iHigh(NULL, 0, OffsetInBars)+iLow(NULL, 0, OffsetInBars))/2;
if(metod==6)
xcbase = (iHigh(NULL, 0, OffsetInBars)+iLow(NULL, 0, OffsetInBars)+iClose(NULL, 0, OffsetInBars))/3;
if(metod==7)
xcbase = (iHigh(NULL, 0, OffsetInBars)+iLow(NULL, 0, OffsetInBars)+iClose(NULL, 0, OffsetInBars)+iClose(NULL, 0, OffsetInBars))/4;

if (ShowBestPattern)
{
if(metod<=0 || metod>7)
ycbase = iClose(NULL, 0, iAlt[0]);
if(metod==1)
ycbase = iOpen(NULL, 0, iAlt[0]);
if(metod==2)
ycbase = iHigh(NULL, 0, iAlt[0]);
if(metod==3)
ycbase = iLow(NULL, 0, iAlt[0]);
if(metod==4)
ycbase = (iClose(NULL, 0, iAlt[0])+iOpen(NULL, 0, iAlt[0]))/2;
if(metod==5)
ycbase = (iHigh(NULL, 0, iAlt[0])+iLow(NULL, 0, iAlt[0]))/2;
if(metod==6)
ycbase = (iHigh(NULL, 0, iAlt[0])+iLow(NULL, 0, iAlt[0])+iClose(NULL, 0, iAlt[0]))/3;
if(metod==7)
ycbase = (iHigh(NULL, 0, iAlt[0])+iLow(NULL, 0, iAlt[0])+iClose(NULL, 0, iAlt[0])+iClose(NULL, 0, iAlt[0]))/4;

for (indexBar = 0; indexBar < (PastInBars + ForecastInBars - 1); indexBar++)
{
altindex = iAlt[0] - ForecastInBars + indexBar;
ForecastBestPatternOpen[indexBar] = xcbase + (iOpen(NULL, 0, altindex) - ycbase);
ForecastBestPatternClose[indexBar] = xcbase + (iClose(NULL, 0, altindex) - ycbase);
ForecastBestPatternHigh[indexBar] = xcbase + (iHigh(NULL, 0, altindex) - ycbase);
ForecastBestPatternLow[indexBar] = xcbase + (iLow(NULL, 0, altindex) - ycbase);
}
}

int opsignal = 0;
double ztp = 0.0, zsl = 0.0;
int digits = MarketInfo(Symbol(), MODE_DIGITS);
int spread = MarketInfo(Symbol(), MODE_SPREAD);
double point = MarketInfo(Symbol(), MODE_POINT);
int stoplevel = MarketInfo(Symbol(), MODE_STOPLEVEL);
if (stoplevel == 0.0)
{
// tester mode
stoplevel = spread * 2;
}

double forecastBuy = forecastCloudLow[ArrayMaximum(forecastCloudLow)];
double diffBuy = forecastBuy - xcbase;
double forecastSell = forecastCloudHigh[ArrayMinimum(forecastCloudHigh)];
double diffSell = xcbase - forecastSell;
if ((diffBuy > 0.0) && (diffSell < 0.0))
{
opsignal = 1;
ztp = forecastBuy;
zsl = xcbase - diffBuy;
}
else
{
if ((diffBuy < 0.0) && (diffSell > 0.0))
{
opsignal = -1;
ztp = forecastSell;
zsl = xcbase + diffSell;
}
else
{
if ((diffBuy > 0.0) && (diffSell > 0.0))
{
if (diffBuy > diffSell)
{
opsignal = 1;
ztp = forecastBuy;
zsl = xcbase - diffBuy;
}
else
{
opsignal = -1;
ztp = forecastSell;
zsl = xcbase + diffSell;
}
}
}
}

if (Debug)
{
FileWrite(handleLog, "");
FileWrite(handleLog, "forecastBuy", forecastBuy);
FileWrite(handleLog, "forecastSell", forecastSell);
FileWrite(handleLog, "diffBuy", diffBuy);
FileWrite(handleLog, "diffSell", diffSell);
FileWrite(handleLog, "opsignal", opsignal);
}

if (ShowTip)
{
if (opsignal == 0)
{
signal=0;
}
else
{
if (opsignal > 0)
{
if (ztp > (xcbase + (stoplevel * point)))
{
signal=1;
TP=ztp;
SL=zsl;
}
else
{
opsignal = 0;
signal=0;
TP=0;
SL=0;
}
}
else
{
if (ztp < (xcbase - (stoplevel * point)))
{
signal=-1;
TP=ztp;
SL=zsl;
}
else
{
opsignal = 0;
signal=0;
TP=0;
SL=0;
}
}
}
}
else
{
signal=0;
TP=0;
SL=0;
}

if (Debug)
{
FileClose(handleLog);
}
}
//+------------------------------------------------------------------+
void Orders_count()
{int cnt,ii;
cnt=OrdersTotal();
orders=0;
buy_orders=0;
sell_orders=0;
sell_stop=0;
buy_stop=0;
sell_lim=0;
buy_lim=0;
BU_buy=true;
BU_sell=true;
for (ii=0; ii<cnt; ii++)
{if (!OrderSelect(ii, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol()!=Symbol()) continue;
if (OrderMagicNumber()==magic)
{orders++;
if(OrderType()==OP_BUY){buy_orders++;if(OrderStopLoss()<OrderOpenPrice())BU_buy=false;}
if(OrderType()==OP_SELL){sell_orders++;if(OrderStopLoss()>OrderOpenPrice())BU_sell=false;}
if(OrderType()==OP_SELLSTOP)sell_stop++;
if(OrderType()==OP_BUYSTOP)buy_stop++;
if(OrderType()==OP_SELLLIMIT)sell_lim++;
if(OrderType()==OP_BUYLIMIT)buy_lim++;

}
}
}
//+------------------------------------------------------------------+
double MoneyManagement ( bool flag, double risk)
{
double Lotsi=Lot_Size;

if (MarketInfo(Symbol(),MODE_MINLOT)==0.1){
// if ( flag ) Lotsi=NormalizeDouble(MathPow((MathAbs(AccountFreeMargin())*risk/1000),0.5),1);
if ( flag ) Lotsi=NormalizeDouble(MathAbs(AccountFreeMargin()*risk/1000),1);
if (Lotsi<0.1) Lotsi=0.1;
}
if (MarketInfo(Symbol(),MODE_MINLOT)==0.01){
// if ( flag ) Lotsi=NormalizeDouble(MathPow((MathAbs(AccountFreeMargin())*risk/1000),0.5),2);
if ( flag ) Lotsi=NormalizeDouble(MathAbs(AccountFreeMargin()*risk/1000),2);
if (Lotsi<0.01) Lotsi=0.01;
}

if(Lot_Size<Lotsi)return(Lotsi);
if(Lot_Size>=Lotsi)return(Lot_Size);
}
//+------------------------------------------------------------------+
void Trailing(){
double SL_Sell,SL_Buy,TP_Buy,TP_Sell,trail_prc;
int cnt,ii;


RefreshRates();
cnt=OrdersTotal();
for (ii=0; ii<cnt; ii++) {
if (!OrderSelect(ii, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol()!=Symbol()) continue;
if (OrderMagicNumber()==magic)
{trail_prc=MathAbs(StrToDouble(OrderComment())-OrderStopLoss())*Trail_SL_TP_percent/100;
RefreshRates();
SL_Sell=NormalizeDouble(Ask+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point+trail_prc,Digits);
SL_Buy=NormalizeDouble(Bid-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point-trail_prc,Digits);
if(OrderType()==OP_BUY && OrderStopLoss()<NormalizeDouble(SL_Buy,Digits) && OrderOpenPrice()<NormalizeDouble(SL_Buy,Digits) && OrderStopLoss()!=0)
{if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(SL_Buy,Digits),OrderTakeProfit(),0,Blue))
Modify_Order(OrderTicket(),NormalizeDouble(SL_Buy,Digits),OrderTakeProfit(),1);
}
if(OrderType()==OP_SELL && OrderStopLoss()>NormalizeDouble(SL_Sell,Digits) && OrderOpenPrice()>NormalizeDouble(SL_Sell,Digits) && OrderStopLoss()!=0)
{if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(SL_Sell,Digits),OrderTakeProfit(),0,Red))
Modify_Order(OrderTicket(),NormalizeDouble(SL_Sell,Digits),OrderTakeProfit(),-1);
}
}
}
}
//+------------------------------------------------------------------+
void Modify_Order(int ticket, double Loss, double Profit, int type)
{ int error;
int cc;
error=99999;
cc=0;
if(OrderSelect(ticket, SELECT_BY_TICKET))
{while (error>1 && cc<5 && error!=130)
{if(type==1)OrderModify(ticket,OrderOpenPrice(),NormalizeDouble(Loss,Digits),NormalizeDouble(Profit,Digits),0,Blue);
if(type==-1)OrderModify(ticket,OrderOpenPrice(),NormalizeDouble(Loss,Digits),NormalizeDouble(Profit,Digits),0,Red);
error=GetLastError();
cc++;
Sleep(3000);
}
}
return(0);
}
//+------------------------------------------------------------------+

 
Sancho77:
yis:
Может выложите своего советника?

Выложил на изучение. Но использовать его в реальной торговле нельзя. Это только черновик для проверки.
 
yis:

Выложил на изучение. Но использовать его в реальной торговле нельзя. Это только черновик для проверки.

Спасибо, Илья! )
Причина обращения: