Questions from Beginners MQL5 MT5 MetaTrader 5 - page 112

 
How do I get credits or how do I deposit them?
 

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?

//--- входные параметры
input int LongTrend=14; // Период LongTrend
input int ShortTrend=7; // Период ShortTrend
input int EA_Magic=0;   // Magic Number советника
input double Lot=0.02; // Количество лотов
input double STR= 0.14;
input double TR= 0.1;
input double TP= 0.55;

//--- глобальные переменные

int TrendToTrend;
int TrendToTrendOpen;

//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
  {
  //--- достаточно ли количество баров для работы
   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 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- освобождаем хэндлы индикаторов
   IndicatorRelease(TrendToTrend);
   IndicatorRelease(TrendToTrendOpen);
   }
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
  {
   static datetime 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; 
}
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы - Документация по MQL5
 

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!

 
sanderz:

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 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.

Документация по MQL5: Основы языка / Переменные / Статические переменные
Документация по MQL5: Основы языка / Переменные / Статические переменные
  • www.mql5.com
Основы языка / Переменные / Статические переменные - Документация по MQL5
 
Why isn't the money ticking?
Files:
965pp1ixr4.png  2000 kb
 
sneak:
Why isn't the money ticking?
The calculation update isn't frequent. Once a day maybe.
 

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:

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);
n writes correct, but returns 0.
 
tor4en:

I don't understand why the function returns 0:

Calling it like this for example:

n writes correct, but returns 0.
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.