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

 
-Aleks-:

Are you sure you looked at the last code you posted? If so, I need a rest... thank you.
Trace the"c" variable.
 
Artyom Trishkin:
Trace the"c" variable.

Yes, thank you! I see - but can't quite make sense of this code yet - will be experimenting!

Victor Nikolaev- thanks for your help!

 

Good day all!

Please tell me if you can change the value of MAJIC NUMBER in an order which has already been closed and appears in the list of closed orders.

I.e., change the value of MAJIC NUMBER after the order is closed.

If it is possible, then which function should be used to change it. I did not find such a function in Kim's work.

Thank you.
 
ANDREY:

Good day all!

Please tell me if you can change the value of MAJIC NUMBER in an order which has already been closed and appears in the list of closed orders.

I.e., change the value of MAJIC NUMBER after the order is closed.

If it is possible, then which function should be used to change it. I did not find such a function in Kim's work.

Thank you.

You cannot. And why do you need it at all - maybe there is another solution to the problem?
 
-Aleks-:

You can't. Why would you want to do that in the first place - is there another solution to the problem?

Thanks for the tip.

While I was waiting for an answer, something came to mind. If it doesn't work, I'll write down what I need.

Can you give me a hint?

if(OrderSelect (Ht-1,SELECT_BY_POS, MODE_HISTORY)) // if LAST order
if ( OrderType ()==OP_SELL)// SEL

X = OrderProfit( );// store the TakeProfit value

if (OrderSelect (Ht-1,SELECT_BY_POS, MODE_HISTORY)) // if LAST order
if ( OrderType ()==OP_SELL)// SEL

if(X < 0)// and if this Sell was closed at the stop

OPEN ANOTHER ORDER

QUESTION

How to code an addendum to these conditions.

Not only the last order, but also the next-to-last and last-to-last orders should be closed at stop

and only then

TO OPEN ONE MORE ORDER.

Thank you.



 
geratdc:I have made the recommended changes to the code in Notepad for now. Please check if I corrected the code correctly?

I've had a look at it. Corrected it. In the tester for 3 months this is the result

The drawdown is big.

 
Can you please tell me how to find the numbers of the last 5 crossings in the current day
 
missha32: To find the number of bars crossed by a Mach number of let's say 5 last crossings for the current day

If at 4am - not many bars yet for today. On H4 there are only 6 bars in a day. you need to set the number of bars to search for or the number of crossovers.

//+-------------------------------------------------------+
//| Подсчет пересечений MA                    PROBA_MA.mq4|
//+-------------------------------------------------------+
#property strict

extern int Баров = 500;  // Баров для подсчета пересечений МА
extern int MA_1  =10;
extern int MA_2  =100;

void OnStart()
{
  int Бар, Счетчик;
  double MA_1_Предыдущая, MA_2_Предыдущая,
         MA_1_Следующая,  MA_2_Следующая;

  ObjectsDeleteAll(); // Удалить вертикальные линии

  for(Счетчик=0, Бар=0; Бар<Баров; Бар++) // Начинаем с послнего бара
  {
    MA_1_Предыдущая = iMA(_Symbol,0,MA_1,0,MODE_EMA,PRICE_CLOSE,Бар+1);
    MA_1_Следующая  = iMA(_Symbol,0,MA_1,0,MODE_EMA,PRICE_CLOSE,Бар);
    MA_2_Предыдущая = iMA(_Symbol,0,MA_2,0,MODE_EMA,PRICE_CLOSE,Бар+1);
    MA_2_Следующая  = iMA(_Symbol,0,MA_2,0,MODE_EMA,PRICE_CLOSE,Бар);

    if((MA_1_Предыдущая>=MA_2_Предыдущая && MA_1_Следующая<=MA_2_Следующая) ||
       (MA_1_Предыдущая<=MA_2_Предыдущая && MA_1_Следующая>=MA_2_Следующая))
    {
      Счетчик++;
      Alert(Счетчик, "  Бар = ", Бар, "  T = ",Time[Бар]);

      // Создать вертикальную линию
      ObjectCreate( (string)Счетчик+"_"+(string)Бар,OBJ_VLINE,0,Time[Бар],0);

      if(Счетчик == 5) break;  // 5 линий есть - выход
    }
  }
}

distances large = trend

 

Can you give me a hint?

if(OrderSelect (Ht-1,SELECT_BY_POS, MODE_HISTORY)) // if LAST order
if ( OrderType ()==OP_SELL)// SEL

X = OrderProfit( );// store the TakeProfit value

if (OrderSelect (Ht-1,SELECT_BY_POS, MODE_HISTORY)) // if LAST order
if ( OrderType ()==OP_SELL)// SEL

if(X < 0)// and if this Sell was closed at the stop

OPEN ANOTHER ORDER

QUESTION

How to code an addendum to these conditions.

Not only the last order, but also the next-to-last and last-to-last orders should be closed at stop

and only then

TO OPEN ONE MORE ORDER.

Thank you.
 

I need some kind of indicator to change the indicator, I want to draw a line from high to low on the hour chart every 24 hours, and get the data on the length of the line and the slope and be able to work with these data in the code, I'm not a great expert on mql4 if I write from scratch, big problem?

I've got a two-coordinate stretched line, no matter how I turned it around it's just a mess, please help me, maybe I should not have messed with it.

#property indicator_chart_window
//---- input parameters
extern int   CountDays     =22;
extern int   GMT           =0;
extern color pivot         =Gold;
extern color day           =Yellow;
extern color metka         =MidnightBlue;

//---- indicator buffers
double range[];
double ny_close[];
double low[];
double high[];
datetime time1;
datetime time2;
datetime ny_time[];

int shift, num;
int ny_shift[];
datetime prevDay=0;
bool fTime;
// ----
void ObjDel()
{
   if (ObjectsTotal() > 0)
   for (num=0;num<=CountDays;num++)
   {
   ObjectDelete("PPw["+num+"]");   
          
   }
   ObjectDelete("mPw");           
}
// ----
void PlotLine(string name,double value,double value1,double line_color,double style)
{
   double valueN=NormalizeDouble(value,Digits);
   double valueN1=NormalizeDouble(value1,Digits);
   bool res = ObjectCreate(name,OBJ_TREND,0,time1,valueN,time2,valueN1);
   ObjectSet(name, OBJPROP_WIDTH, 1);
   ObjectSet(name, OBJPROP_STYLE, style);
   ObjectSet(name, OBJPROP_RAY, false);
   ObjectSet(name, OBJPROP_BACK, true);
   ObjectSet(name, OBJPROP_COLOR, line_color);
} 
//***********
void PlotVLine(string name,double tm,double line_color)
{
   bool res = ObjectCreate(name,OBJ_VLINE,0,tm,0);
   ObjectSet(name, OBJPROP_WIDTH, 0);
   ObjectSet(name, OBJPROP_STYLE, 2);
   ObjectSet(name, OBJPROP_COLOR, line_color);
} 
//***********
void PlotPrice(string name, double value, double line_color)
{
    double valueN=NormalizeDouble(value,Digits);
    bool res = ObjectCreate(name, OBJ_ARROW, 0, time2,valueN);
    ObjectSet(name, OBJPROP_COLOR, line_color);
    ObjectSet(name, OBJPROP_WIDTH, 1);
    ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
}       
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   fTime = true;
   IndicatorBuffers(2);
   SetIndexBuffer(0,range);
   SetIndexBuffer(1,ny_close);
   return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+   
int deinit()
{
   ObjDel();
   Comment("");
   return(0);
}
//+------------------------------------------------------------------+
//| LNX_Pivots_v3.1                                                    |
//+------------------------------------------------------------------+
int start()
{
   int i;
   double P;
  
   datetime cDay = iTime(NULL,PERIOD_D1,0) + (GMT-Period()/60.0)*3600;
   if (cDay != prevDay || fTime)  
   {
   ObjDel();
   ArrayResize(ny_time,CountDays+1);
   ArrayResize(ny_shift,CountDays+1);
   ArrayResize(high,CountDays+1);
   ArrayResize(low,CountDays+1); 
   ArrayResize(range,CountDays+1);    
      for (shift=0;shift<=CountDays;shift++)
      {
      ny_time[shift]  = iTime(NULL,PERIOD_D1,shift) + (GMT-Period()/60.0)*3600;
      ny_shift[shift] = iBarShift(NULL,0,ny_time[shift]);
      ny_close[shift] = iClose(NULL,0,ny_shift[shift]);        
      }
     
 for (shift=0;shift<=CountDays-1;shift++)
      {
      int length = ny_shift[shift+1]-ny_shift[shift];
   
      high[shift] = High[iHighest(NULL,0,MODE_HIGH,length,ny_shift[shift])];
      low[shift]  = Low[iLowest(NULL,0,MODE_LOW,length,ny_shift[shift])];
      range[shift] = high[shift] - low[shift]; 
      }
  
  for (shift=0;shift<=CountDays-1;shift++)
      {
  
           
      P  = (ny_close[shift]+high[shift]+low[shift])/3;
      

      time1 = ny_time[shift]+Period()*60;    
         
         if (shift==0) 
         {
         time2 = ny_time[shift] + 24*3600+Period()*60 ;
         PlotVLine("pV0",time2,day);
         PlotPrice("mPw",P,metka);
                 
         }
         else
         time2 = ny_time[shift-1]+Period()*60;
         PlotVLine("pV["+shift+"]",time1,day);
            
      int pstyle=0;
   PlotLine("PPw["+shift+"]",P,P,pivot,pstyle); // *********две координаты*******

}
   fTime = false;
   prevDay = cDay;
   }           
   return(0);
}
//+------------------------------------------------------------------+
Reason: