Here is the code for Expert Advisor which uses this indicator TrendToTrend_open
code below
Question - why does my Expert Advisor set this indicator with a close price?
//--- входные параметрыinputint LongTrend=14; // Период LongTrendinputint ShortTrend=7; // Период ShortTrendinputint EA_Magic=0; // Magic Number советникаinputdouble Lot=0.02; // Количество лотовinputdouble STR= 0.14;
inputdouble TR= 0.1;
inputdouble TP= 0.55;
//--- глобальные переменныеint TrendToTrend;
int TrendToTrendOpen;
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//--- достаточно ли количество баров для работыif(Bars(_Symbol,_Period)<60) // общее количество баров на графике меньше 60?
{
Alert("На графике меньше 60 баров, советник не будет работать!!");
return(-1);
}
TrendToTrend=iCustom(_Symbol,0,"TrendToTrend",LongTrend,ShortTrend);
TrendToTrendOpen=iCustom(_Symbol,0,"TrendToTrend_open",LongTrend,ShortTrend);
if(TrendToTrend<0||TrendToTrendOpen<0)
{
Alert("Ошибка при создании индикаторов - номер ошибки: ",GetLastError(),"!!");
return(-1);
}
return(0);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//--- освобождаем хэндлы индикаторовIndicatorRelease(TrendToTrend);
IndicatorRelease(TrendToTrendOpen);
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
staticdatetime Old_Time;
datetime New_Time[1];
bool IsNewBar=false;
// копируем время текущего бара в элемент New_Time[0]int copied=CopyTime(_Symbol,_Period,0,1,New_Time);
if(copied>0) // ok, успешно скопировано
{
if(Old_Time!=New_Time[0]) // если старое время не равно
{
IsNewBar=true; // новый барif(MQL5InfoInteger(MQL5_DEBUGGING)) Print("Новый бар",New_Time[0],"старый бар",Old_Time);
Old_Time=New_Time[0]; // сохраняем время бара
}
}
else
{
Alert("Ошибка копирования времени, номер ошибки =",GetLastError());
ResetLastError();
return;
}
//--- советник должен проверять условия совершения новой торговой операции только при новом бареif(IsNewBar==false)
{
return;
}
//--- Имеем ли мы достаточное количество баров на графике для работыint Mybars=Bars(_Symbol,_Period);
if(Mybars<60) // если общее количество баров меньше 60
{
Alert("На графике менее 60 баров, советник работать не будет!!");
return;
}
return;
}
Can you please point me in the direction of the answer to your question?
I have an EA with two strategies that open trades on different principles. It has a common position as the end result.
A bit later, I need to understand how each strategy has contributed to the position. So, which strategy (or two) opened the position.
How do I do it?
Thank you!
If your EA has the ability to disable one of the strategies and you can change the magic number in the settings. Then you should add two EAs in your account and disable one of the strategies in each of them and set different magic numbers for positions and then use magic numbers in the history to track which one gives more profit or loss.
Kino: If the EA has the ability to disable one of the strategies and you can change the magic number in the settings. Then put two EAs on the account and disable one of the strategies in each of them and assign different magic numbers for positions, and then trace in the history what gives more plus or minus by magic numbers.
Thanks for the reply. I made through static variables that change their value if the strategy position is open (on closing and stop loss the values also change). In general this works fine, but I understand that after restarting the EA it will lose its orders.
int BarsAmountPassed(datetime open_time)
{
datetime time_array[];
int n;
Print("inpupt time=",TimeToString(open_time));
CopyTime(_Symbol,_Period,open_time,TimeCurrent(),time_array);
n=ArraySize(time_array);
Print("number of elements in array=",n);
return(n);
}
Calling like this for example:
int bars;
bars=BarsAmountPassed(1365198000);
Print(__FUNCTION__+": Баров прошло с этого времени ",bars);
It is strange, if I change the function type to short or double, it returns the calculated value (it turns out to be 4 in this example). But with int 0.
Here is the code for Expert Advisor which uses this indicator TrendToTrend_open
code below
Question - why does my Expert Advisor set this indicator with a close price?
Hello!
Can you please point me in the direction of the answer to your question?
I have an EA with two strategies that open trades on different principles. It has a common position as the end result.
A bit later, I need to understand how each strategy has contributed to the position. So, which strategy (or two) opened the position.
How do I do it?
Thank you!
Hello!
Can you please point me in the direction of the answer to your question?
I have an EA with two strategies that open trades on different principles. It has a common position as the end result.
A bit later, I need to understand how each strategy has contributed to the position. So, which strategy (or two) opened the position.
How do I do it?
Thank you!
If the EA has the ability to disable one of the strategies and you can change the magic number in the settings. Then put two EAs on the account and disable one of the strategies in each of them and assign different magic numbers for positions, and then trace in the history what gives more plus or minus by magic numbers.
Thanks for the reply. I made through static variables that change their value if the strategy position is open (on closing and stop loss the values also change). In general this works fine, but I understand that after restarting the EA it will lose its orders.
Why isn't the money ticking?
thanks, buddy... i'll keep that in mind.
I've got computers in the basement, ...., mining the pots... let's do something.
I don't understand why the function returns 0:
Calling like this for example:
n writes correct, but returns 0.I don't understand why the function returns 0:
Calling it like this for example:
n writes correct, but returns 0.