Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1660

 
MakarFX #:

1) Yes, these are the values of the number of "confirmation candles" .

2) No, it does not open on the first, only after a given number of "confirmation candles" .

3) Change the magik and put it on any pair

It is better to make the magik an external variable

1) Got it;

2) I will attach a screenshot in this post, it doesn't open on the first one, but if entry by 4 candles is in conditions, it will open on the 4th one, like in the screenshot. Of course, it is not the main thing. I just want to know how to fix it. But even if we leave it, what is "Init=true" responsible for? What is its essence?

3) And how to make a magik external variable? I just haven't touched magik and don't know how to do it:

#property copyright "Copyright 2021, DrMak."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//--- input parameters
#define MagicNumber  122122
extern string s1             = "Trading options";
extern double Lot            = 0.01;    // размер лота 0 - авт.расчет
extern double StopLoss       = 40;     // стоплосс
extern double TakeProfit     = 10;     // тейкпрофит
extern double TrailStop      = 21;     // уровень без убытка
extern int    Trailing       = 0;      // трейлинг стоп 1 вкл. 0 выкл.
extern int    Breakeven      = 0;      // перенос стоп лосса в без убыток
extern string s2             = "Day & Hour";
extern int    HrStart        = 0;      // время начала торговли
extern int    HrEnd          = 23;     // время окончания торговли
extern int    Monday         = 1;      // Понедельник 1 вкд. 0 выкл.
extern int    Tuesday        = 1;      // Вторник
extern int    Wednesday      = 1;      // Среда
extern int    Thursday       = 1;      // Четверг
extern int    Friday         = 1;      // Пятница
//+------------------------------------------------------------------+
// параметры индикаторов
int MovingPeriodLw        = 5;      
int MovingPeriodS1        = 75;
int MovingPeriodS2        = 85;
double StopLevel;
double TrailStep             = 3;      // шаг трейлинг стопа
bool OrderBuy = true, OrderSell = true, Order = false, Init = true;
int timeprev = 0, Slip = 3.0, Start, cnt=1;
datetime newbar=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if (Digits == 3 || Digits == 5) { // Пересчет для 5-ти знаков                                                    
      TakeProfit *= 10;
      TrailStop *= 10;
      TrailStep *= 10;
      StopLoss *=10;
      Slip *=10;
   } 
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL); 
   //---
   if(newbar!=Time[0])
     {
      if(CheckForOpen()!=Start)
        {Start=CheckForOpen(); cnt=1;}
      else
        {cnt+=1;}
      //---
      if(cnt==8)
        {
         // Открытие ордера по методу Пуриа
         if(CheckForOpen()==0) // Если сигнал для покупок 
           {
            if(OrderSend(Symbol(),OP_BUY,Lots(),Ask,Slip,Bid-StopLoss*Point,Ask+TakeProfit*Point,"",MagicNumber,0,Blue))
              {Print("BUY OK");}
              else {Print(GetLastError());}
           } 
         if(CheckForOpen()==1) // Если сигнал для продаж 
           {
            if(OrderSend(Symbol(),OP_SELL,Lots(),Bid,Slip,Ask+StopLoss*Point,Bid-TakeProfit*Point,"",MagicNumber,0,Red))
              {Print("SELL OK");}
              else {Print(GetLastError());}
           }
        }   
      newbar=Time[0];
     }
  }
Files:
 
MakarFX #:

Not bad!

 
artem artem #:

1) Got it;

2) I will attach a screenshot in this post, it does not open on the first candle, but if entry by 4 candles is in the conditions, it will open on the 4th, as in the screenshot. Of course, it is not the main thing. I just want to know how to fix it. But even if we leave it, what is "Init=true" for? What is its essence?

3) And how to make a magik external variable? It's just that I haven't touched magik anywhere near and don't know how to do it:

#define MagicNumber  122122

replace with

extern string MagicNumber = 122122;

"Init=true" can be removed.

About the first input, I'll think about it, but tomorrow)

 

artem artem #:

I would like to know how this can be removed.

Removed

Files:
artem.mq4  11 kb
 
MakarFX #:
// Мертвая строка

Good idea, well done, Makar!

 

Tell me what to do, I have an abnormal case:

Passage in the test shows 40 trades in the last six months. The balance is over $1000 in the account.

Running the same set for the whole year - only 8 trades. Remainder about 1000 dollars.

I am running it from the beginning of 2020, 3 months it trades - further 0 reaction.

I don't understand why it doesn't want to trade on a large period. It does not show any errors in the logbook.

 
artem artem #:

that one is good for fun in the tester.

and this one is for you, as a gift - to make money.

\\\\\\\\\\\\\\\\\\\\\\\\\\

I tested it and will see how it works tonight.

Screenshot 2021-10-10 054654

\\\\\\\\\\\\\\\\\\\\\\\\\\\

checked how it changes the pattern on all the charts - everything worked! -how the total profit reached the target.

Screenshot 2021-10-10 055232

Files:
artem_artem.mq4  26 kb
 

it is good to check in the tester - when you save the template with indicators, if you change the indicator settings - just press pause in the tester and adjust the indicators .

Screenshot 2021-10-10 063557

\\\\\\

chart template - for the expert above.

Files:
 
SanAlex #:

that one is good for fun in the tester.

and this one is for you, as a present, to make money.

Good morning to you all and good mood! I am intrigued. Please translateartem artem.mq4 code for MT5 if you have no problems with it. I want to see how it will "handle" rollovers on a real account.

Sincerely Vladimir.

 
MrBrooklin #:

Good morning everyone and good mood! I am intrigued. Please, if it's not difficult for you, translateartem artem.mq4 code for MT5. I want to see how it will "handle" the rollovers on a real account.

Sincerely, Vladimir.

Good Morning! Now I will create a signal indicator for mt5 out of these indicators

\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Here I made it - the rest is very simple - in Expert Advisor with its desires and its logic, trawl and everything else.

EURUSDH1

\\\\\\\\\\\\\\\\\\\\\\

In Expert Advisor you can set to open on a zero bar or on the first bar

Screenshot 2021-10-10 085616

Files:
Fx10_artem.mq5  20 kb
Reason: