Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1174

 

I want the EA to close open positions when the price crosses the MA.

Please advise how to implement this.

Thank you

 
RichLux:

I want the EA to close open positions when the price crosses the MA.

Please advise how to implement this.

Thank you

void CheckForClose_MA()
  {
   double MA=iMA(NULL,0,ma_period,ma_shift,MODE_SMMA,PRICE_MEDIAN,0);

   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
        //---- check order type 
      if(OrderType()==OP_BUY)
        {
         if(Low[1]>=MA) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
         break;
        }
     }
//----


doubleiMA(
stringsymbol,// symbol name
inttimeframe,// timeframe
intma_period,// period
intma_shift,// shift average
intma_method,// averaging method
intapplied_price,//price type
intshift// shift
);

 

How to know what parameters have been sent to the Expert Advisor through iCustom. I receive an incorrect value from the buffer specified in iCustom, I want to check if the data has "reached" the indicator after iCustom has been called.

How can I debug at all?

 
Александр:

There is a function.


Each function call will change variable ХХ, and I need ХХ to be external (by the logic I want), but each function call started with ХХ being 0 and accordingly return(ХХ) will return its value. I.e . I don't understand how to make the variable XX external and the function could be called "autonomously", in isolation. Exactly by means of MQ4. Thank you!


I've read it several times, but still don't understand what you're looking for.

Maybe this:

double XX = 0;


double x()
{
   double rez = XX;
   XX++;
   return rez;
}
 
How can I tell if all bars are loaded on the chart?
It is necessary to call the recalculation of the indicator only when it is fully loaded.

The condition
if(time[0] > TimeCurrent() - 60 * ChartPeriod())
does not help to solve the problem.
 

memorise and check the total number of bars, if the value does not "go up" within a few seconds, then "here we go".

and then recalculate again if

rates_total-prev_calculated > 1
 
Koldun Zloy:

I've read it several times, but still don't understand what you want.

Maybe it is:

There is a function (it is an indicator in my EA, I need it and it is not disputed, this an indicator and it starts working (counting down) from a new peak). The indicator has several parameters that change all the time. Since I want to avoid loop, I make these parameters external (for the function external) in order not to lose their values. And in any new function call, I see only the change of the indicator value. But I want to have a new "instance " of the indicator from a new peak, while the old "instance" continues working and changing values. I want to achieve this using the standard methods of MQ4, because I know very little about classes, structures and other inheritance. Thank you!
 
Александр:
I have a function (it's an indicator in my Expert Advisor, I need it and it's not challenged, this the turkey and it starts running (counting down) from a new peak). I have an indicator with several parameters which change all the time. Since I want to avoid a cycle, I make these parameters external (for the function external) in order not to lose their values. And in any new function call, I see only the change of the indicator value. But I want to have a new "instance " of the indicator from a new peak, while the old "instance" continues working and changing values. I want to achieve this using the standard methods of MQ4, because I know very little about classes, structures and other inheritance. Thank you!

Didn't help.

You should probably learn the language so you don't get confused about the terms at least.

Don't think everyone understands what you call an external variable, what "call a function autonomously" means.

And what does a loop have to do with it, which you don't want to use, again, for reasons only you understand.

Well, I don't hope to understand you.


 
//+------------------------------------------------------------------+
//|           Проверка нажатия клавиш на клавиатуре                  |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   if(id==CHARTEVENT_KEYDOWN)
     {
     Alert(lparam);
     }
   }

Can you tell me how to check the combination, e.g. Shift+A !

 
//+------------------------------------------------------------------+
//|           Проверка нажатия клавиш на клавиатуре                  |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   if(id==CHARTEVENT_KEYDOWN)
     {
      ///Alert(lparam);
      switch(int(lparam))
        {
         case 101:if(Paint5==1) Paint5=2; else Paint5=1;
         bar0=0;
         start(); 
         break;
         case 100:if(Paint4==1) Paint4=2; else Paint4=1;
         bar0=0;
         start(); 
         break;
        }
     }
  }
//+------------------------------------------------------------------+

Or rather this code, how do the key combinations work?

Reason: