[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 642

 
gordeef:

I'm careful with reversals and corrections as it is. But concerning the trend exhaustion I am interested in it too, I wandered through the forum and looked at CodeBase, but did not meet any indices on this topic. It will be interesting to read your results. I have another question, they sent me an EA that controls my losses and profits, like in the picture it should work, but the question is, it has a 15 point profit and the price may go even higher, if I increase the profit on one trade, it may break the general calculations and operation of the EA?
I think the answer to this question may be in the guts of my Expert Advisor... Maybe it will be answered by one of the much more experienced comrades... I think their answer will be more valid from their experience - I am just a beginner... :)
 
artmedia70:

OK. Thank you, Victor. So far it's working correctly. So far, because I haven't followed it for a long time, but NEVER had it output Trend Up for me before. It is now:


I knew there was always a more powerful sorcerer-wizard for one sorcerer-wannabe... :)

It's all in jest, of course, but... Victor, I want to not just blindly copy the right solution, and to find out and understand where the dog is hidden, what is the essence of the problem and this incomprehensible to me code behavior?


Problems with logic. No more than that. Try drawing block diagrams. It helps
 

Another question came up: at first I was doing a number of lines, but then I realised that one of them would be superfluous and it would be more appropriate to put it in brackets in the numeric percentage form, so I removed it and put it next to the one where there was just the right place for it:

That's how it was at first:


And this is how it is now:


I'm haunted by echoes of past events... When the EA is launched for the first time, before a new tick arrives, it always displays what it was originally... Although it hasn't been in the code for a long time. Where do the ghosts come from???

 
artmedia70:

I have another question: at first I was doing N number of lines, but then I realised that one of them would be superfluous and it would be more appropriate to put it in brackets in the numeric percentage form, so I removed it and put it next to the one where there was just room for it:

That's how it was at first:


And this is how it is now:


I'm haunted by echoes of past events... When the EA is launched for the first time, before a new tick arrives, it always displays what it was originally... Although it hasn't been in the code for a long time. Where do the ghosts come from???





You have to look at the code. Take the logic apart.
 
Vinin:

Logical problems. Nothing more. Try drawing block diagrams. Helps

:):) Thank you... Eh... I've already got such a 'tartan' spread on my floor... Mamma mia! There doesn't seem to be much logic in the three lines. It turns out that when you check: if the 1st, then do it, if you don't do the 1st, of course the 2nd comes next. If the 2nd one fails, the 3rd one follows...

No... It's like this: If it's the 1st, then it's like this... Otherwise, if 2nd, we do so-c, otherwise, if not the 1st and not the 2nd, we do the 3rd and if not the 1st, not the 2nd and not the 3rd, then we look for errors in logic...

Oh... I'm completely confused myself... Well, Victor, your addition behaves correctly, and now I'll try to understand why I need one more else operator which seems to be in that place where this "otherwise" occurs anyway, after I've racked my brain...

Thanks for the advice.

 
Vinin:

You have to look at the code. To sort out the logic.

There's hardly any logic to it - the simple output of lines in order one after the other...

/--------------------------------------------------------------- 1 --
// Функция вывода на экран графических сообщений.
//--------------------------------------------------------------- 2 --
  int Informations()
  {
   int   Win_ind;                     // Номер окна индикатора
   int   x,y;
   
   trH4     =Trend_PSAR(NULL,240);  // Четырёхчасовой тренд
   trH1     =Trend_PSAR(NULL,60);   // Часовой тренд
   trM30    =Trend_PSAR(NULL,30);   // Получасовой тренд
   trM15    =Trend_PSAR(NULL,15);   // 15-ти минутный тренд

//--------------------------------------------------------------- 3 --
   Win_ind= WindowFind("Info");        // Ищем номер окна индикатора
   if (Win_ind<0)return;               // Если такого окна нет, уходим
//--------------------------------------------------------------- 4 --
   x =10; y =17;
   ObjectCreate("Equ",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("Equ",OBJPROP_XDISTANCE,x);
   ObjectSet("Equ",OBJPROP_YDISTANCE,y);
   ObjectSetText("Equ",    "Свободные средства",9,"Tahoma",Gold);
   
   ObjectCreate("EquVal",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("EquVal",OBJPROP_XDISTANCE,x*23);
   ObjectSet("EquVal",OBJPROP_YDISTANCE,y);
   ObjectSetText("EquVal",DoubleToStr(Equ_NEW,2),9,"Tahoma",Yellow);
//--------------------------------------------------------------------   
   ObjectCreate("Prof",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("Prof",OBJPROP_XDISTANCE,x);
   ObjectSet("Prof",OBJPROP_YDISTANCE,y*2);
   ObjectSetText("Prof",   "Уровень фиксации прибыли (      %)",9,"Tahoma",Gold);
   
   ObjectCreate("ProfVal",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("ProfVal",OBJPROP_XDISTANCE,x*23);
   ObjectSet("ProfVal",OBJPROP_YDISTANCE,y*2);
   ObjectSetText("ProfVal", DoubleToStr(Equ_OLD+EquPerc,2),9,"Tahoma",Yellow);
//--------------------------------------------------------------------    
   ObjectCreate("Perc",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("Perc",OBJPROP_XDISTANCE,x*18);
   ObjectSet("Perc",OBJPROP_YDISTANCE,y*2);
   ObjectSetText("Perc", DoubleToStr(PercentEquityForClose,1),9,"Tahoma",Yellow);
   
//--------------------------------------------------------------------   
   ObjectCreate("Tral",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("Tral",OBJPROP_XDISTANCE,x);
   ObjectSet("Tral",OBJPROP_YDISTANCE,y*3);
   ObjectSetText("Tral",   "Уровень включения трала",9,"Tahoma",Gold);
   
   ObjectCreate("TralVal",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("TralVal",OBJPROP_XDISTANCE,x*23);
   ObjectSet("TralVal",OBJPROP_YDISTANCE,y*3);
   ObjectSetText("TralVal", DoubleToStr(Equ_OLD-EquPerc,2),9,"Tahoma",Yellow);
//--------------------------------------------------------------------   
   ObjectCreate("Wloss",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("Wloss",OBJPROP_XDISTANCE,x);
   ObjectSet("Wloss",OBJPROP_YDISTANCE,y*4);
   ObjectSetText("Wloss",  "Порог выставления безубытка",9,"Tahoma",Gold);
   
   ObjectCreate("WlossVal",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("WlossVal",OBJPROP_XDISTANCE,x*23);
   ObjectSet("WlossVal",OBJPROP_YDISTANCE,y*4);
   ObjectSetText("WlossVal", DoubleToStr(LevelProfit,0),9,"Tahoma",Yellow);
//--------------------------------------------------------------------   
   ObjectCreate("WlossPP",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("WlossPP",OBJPROP_XDISTANCE,x);
   ObjectSet("WlossPP",OBJPROP_YDISTANCE,y*5);
   ObjectSetText("WlossPP","Размер безубытка в пунктах",9,"Tahoma",Gold);
   
   ObjectCreate("WlossPPVal",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("WlossPPVal",OBJPROP_XDISTANCE,x*23);
   ObjectSet("WlossPPVal",OBJPROP_YDISTANCE,y*5);
   ObjectSetText("WlossPPVal",DoubleToStr(LevelWLoss,0),9,"Tahoma",Yellow);
//--------------------------------------------------------------------   
   ObjectCreate("ATR",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("ATR",OBJPROP_XDISTANCE,x);
   ObjectSet("ATR",OBJPROP_YDISTANCE,y*6);
   ObjectSetText("ATR",    "Волатильность рынка",9,"Tahoma",Gold);
   
   ObjectCreate("ATRVal",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("ATRVal",OBJPROP_XDISTANCE,x*23);
   ObjectSet("ATRVal",OBJPROP_YDISTANCE,y*6);
   ObjectSetText("ATRVal", DoubleToStr(VolATR,0),9,"Tahoma",Yellow);
//--------------------------------------------------------------------   
   ObjectCreate("TP",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("TP",OBJPROP_XDISTANCE,x);
   ObjectSet("TP",OBJPROP_YDISTANCE,y*7);
   ObjectSetText("TP",     "Размер Take Profit",9,"Tahoma",Gold);
   
   ObjectCreate("TPVal",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("TPVal",OBJPROP_XDISTANCE,x*23);
   ObjectSet("TPVal",OBJPROP_YDISTANCE,y*7);
   ObjectSetText("TPVal", DoubleToStr(TPatr,0),9,"Tahoma",Yellow);
//--------------------------------------------------------------------   
   ObjectCreate("trH4",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("trH4",OBJPROP_XDISTANCE,x);
   ObjectSet("trH4",OBJPROP_YDISTANCE,y*9);
   
   ObjectCreate("ArrowH4",OBJ_LABEL,Win_ind,0,0,0,0);
   ObjectSet("ArrowH4",OBJPROP_XDISTANCE,x*8);
   ObjectSet("ArrowH4",OBJPROP_YDISTANCE,y*9);

   if (trH4==1)
      {
         ObjectSetText("trH4","Тренд H4",9,"Tahoma",Lime);
         ObjectSetText("ArrowH4",CharToStr(241),10,"Wingdings",Lime);
//         ObjectSetText("ArrowH4",DoubleToStr(trH4,0),9,"Tahoma",Lime);
      }
   else if (trH4==-1)
      {
         ObjectSetText("trH4","Тренд H4",9,"Tahoma",OrangeRed);
         ObjectSetText("ArrowH4",CharToStr(242),10,"Wingdings",OrangeRed);
//         ObjectSetText("ArrowH4",DoubleToStr(trH4,0),9,"Tahoma",OrangeRed);
      }
   else
      {
         ObjectSetText("trH4","Тренд H4",9,"Tahoma",LightGray);
         ObjectSetText("ArrowH4",CharToStr(240),10,"Wingdings",LightGray);
//         ObjectSetText("ArrowH4",DoubleToStr(trH4,0),9,"Tahoma",LightGray);
      }
//--------------------------------------------------------------------   
   ObjectCreate("trH1",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("trH1",OBJPROP_XDISTANCE,x*10);
   ObjectSet("trH1",OBJPROP_YDISTANCE,y*9);
   
   ObjectCreate("ArrowH1",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("ArrowH1",OBJPROP_XDISTANCE,x*17);
   ObjectSet("ArrowH1",OBJPROP_YDISTANCE,y*9);
   
   if (trH1==1)
      {
         ObjectSetText("trH1","Тренд H1",9,"Tahoma",Lime);
         ObjectSetText("ArrowH1",CharToStr(241),10,"Wingdings",Lime);
//         ObjectSetText("ArrowH1",DoubleToStr(trH1,0),9,"Tahoma",Lime);
      }
   else if (trH1==-1)
      {
         ObjectSetText("trH1","Тренд H1",9,"Tahoma",OrangeRed);
         ObjectSetText("ArrowH1",CharToStr(242),10,"Wingdings",OrangeRed);
//         ObjectSetText("ArrowH1",DoubleToStr(trH1,0),9,"Tahoma",OrangeRed);
      }
   else
      {
         ObjectSetText("trH1","Тренд H1",9,"Tahoma",LightGray);
         ObjectSetText("ArrowH1",CharToStr(240),10,"Wingdings",LightGray);
//         ObjectSetText("ArrowH1",DoubleToStr(trH1,0),9,"Tahoma",LightGray);
      }
//--------------------------------------------------------------------   
   ObjectCreate("trM30",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("trM30",OBJPROP_XDISTANCE,x);
   ObjectSet("trM30",OBJPROP_YDISTANCE,y*10);
   
   ObjectCreate("ArrowM30",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("ArrowM30",OBJPROP_XDISTANCE,x*8);
   ObjectSet("ArrowM30",OBJPROP_YDISTANCE,y*10);
   
   if (trM30==1)
      {
         ObjectSetText("trM30","Тренд M30",9,"Tahoma",Lime);
         ObjectSetText("ArrowM30",CharToStr(241),10,"Wingdings",Lime);
//         ObjectSetText("ArrowM30",DoubleToStr(trM30,0),9,"Tahoma",Lime);
      }
   else if (trM30==-1)
      {
         ObjectSetText("trM30","Тренд M30",9,"Tahoma",OrangeRed);
         ObjectSetText("ArrowM30",CharToStr(242),10,"Wingdings",OrangeRed);
//         ObjectSetText("ArrowM30",DoubleToStr(trM30,0),9,"Tahoma",OrangeRed);
      }
   else
      {
         ObjectSetText("trM30","Тренд M30",9,"Tahoma",LightGray);
         ObjectSetText("ArrowM30",CharToStr(240),10,"Wingdings",LightGray);
//         ObjectSetText("ArrowM30",DoubleToStr(trM30,0),9,"Tahoma",LightGray);
      }
//--------------------------------------------------------------------   
   ObjectCreate("trM15",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("trM15",OBJPROP_XDISTANCE,x*10);
   ObjectSet("trM15",OBJPROP_YDISTANCE,y*10);
   
   ObjectCreate("ArrowM15",OBJ_LABEL,1,0,0,0,0);
   ObjectSet("ArrowM15",OBJPROP_XDISTANCE,x*17);
   ObjectSet("ArrowM15",OBJPROP_YDISTANCE,y*10);
   
   if (trM15==1)
      {
         ObjectSetText("trM15","Тренд M15",9,"Tahoma",Lime);
         ObjectSetText("ArrowM15",CharToStr(241),10,"Wingdings",Lime);
//         ObjectSetText("ArrowM15",DoubleToStr(trM15,0),9,"Tahoma",Lime);
      }
   else if (trM15==-1)
      {
         ObjectSetText("trM15","Тренд M15",9,"Tahoma",OrangeRed);
         ObjectSetText("ArrowM15",CharToStr(242),10,"Wingdings",OrangeRed);
//         ObjectSetText("ArrowM15",DoubleToStr(trM15,0),9,"Tahoma",OrangeRed);
      }
   else if (trM15==0)
      {
         ObjectSetText("trM15","Тренд M15",9,"Tahoma",OrangeRed);
         ObjectSetText("ArrowM15",CharToStr(240),10,"Wingdings",LightGray);
//         ObjectSetText("ArrowM15",DoubleToStr(trM15,0),9,"Tahoma",OrangeRed);
      }
/*
   else
      {
         ObjectSetText("trM15","Хрен вам",9,"Tahoma",LightGray);
//         ObjectSetText("ArrowM15",CharToStr(240),10,"Wingdings",LightGray);
         ObjectSetText("ArrowM15",DoubleToStr(trM15,0),9,"Tahoma",LightGray);
      }
*/
//--------------------------------------------------------------------   
   

//--------------------------------------------------------------------   
   WindowRedraw();                      // Перерисовываем все объекты
   return;
  }
//--------------------------------------------------------------- 9 --
 

People, please share the ready, working (not glitchy) templates of Expert Advisor, so that it is only possible to change the trading strategy, with the possibility to close the open position to the opposite one if necessary (reversal, but so that Buy/Sell in the condition is not through else, but with the possibility to separately prescribe the conditions:

if condition to buy
{
Opn_B=true; // Open Buy crit.
Cls_S=true; // Close Sell crit. Sell
}
if condition to sell
{
Opn_S=true; // Criterion open Sell
Cls_B=true; // Criterion closed Buy Buy criterion
} ), or TP/SL to close the position.

I am losing my head, I am struggling with this for a month. I cannot move trading strategies from Omega to MT, some kind of buffers/ schmuffers, farfetched arrays, and blocks of accountancy, opening/closing and error accountancy in an EA.

Thanks in advance to everyone who responded.

 
Craft:

People, please share the ready, working templates of an EA, so that you can only change the trading strategy, with the ability to close an open position on the opposite side (reversal), or by TP/SL, if necessary.

I'm going around my head with order accounting, opening/closing blocks, and error accounting.

I will give you the answer, because I have been "sweating" over it for a long time - only when testing strategies and quickly changing them, you can leave orders out of the game, and shelve the orders and errors too. Just copy what he has in the textbook and let them be. Work only with Trade() and Criterion(), if you are following Sergei Kovalev's tutorial. Criterion() - to find entry points for your strategies, Trade() - to open/close positions. Working with them and changing them is enough to test strategies. And then, once you are good at programming, you will get to your own functions, because you will understand what all this is for and how it all works...
 
artmedia70:
I will answer, because I've been struggling with it myself for a long time - just for testing strategies and changing them quickly, you can leave order accounting out of the equation, and put error accounting on the shelf too. Just copy what he has in the textbook and let them be. Work only with Trade() and Criterion(), if you are following Sergei Kovalev's tutorial. Criterion() - to find entry points for your strategies, Trade() - to open/close positions. Working with them and changing them is enough to test strategies. And then, having mastered programming, you will get to your own functions, because you will get an understanding of what all this is for and how it all works...

Thanks, I have everything tested, I want to try trading via MT to really count orders and open/closed positions with balance corrections if necessary.
 
Vinin:

You have to look at the code. Take the logic apart.

The code for the emptiest indicator... where there's also nothing...

 
#property indicator_separate_window
#property indicator_minimum 1
#property indicator_maximum 10
 
bool initFinished=false;
// добавляем переменную, которая будет запоминать состояние инициализации.
// false - инициализации еще не было
// true - была
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{

   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   ObjectsDeleteAll();
   // удаляем все объекты
   
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   if(initFinished==false)
   {
      IndicatorShortName("Info");
 
      int winID=WindowFind("Info");
   
      if(winID<0)
      {
         // если номер подокна равен -1, то возникла ошибка
         Print("Чёт не могу твоего окошечка найти, пошел я отсюдова");
         return(0);
      }  
//------------------------ Тут можно рисовать ------------------------- 
 
// ----------------------- Но не нужно... ----------------

//------------------------------------------------------------------------- 
      WindowRedraw();      
            
      initFinished=true;
     
   }
   
   return(0);
}