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

 

Hi

I am wanting to run multiple accounts on my VPS. Each account with it's own EA running. When I switch accounts, my EA opens on the account i login to. I need it to continue running on the original account. How do I stop this from happening.  

Thanking you in advance

Aldo

 
@Aldo Errico #:I am wanting to run multiple accounts on my VPS. Each account with it's own EA running. When I switch accounts, my EA opens on the account i login to. I need it to continue running on the original account. How do I stop this from happening.  

A MetaQuotes virtual host can only host one trade account at a time, so you will need multiple virtual hosts ...

If using 3rd party VPS, then a single MetaTrader desktop terminal can only run one trade account at a time. So you will need to run multiple terminals (maximum of 32).

 

Hello everyone.

I started to study MQL4 last week with the intention of making something similar to the Magic Keys device.

Reading the MQL4 manual raised some questions and I was wondering if someone could help me to solve them.

I wonder if it would be possible to create a macro so I can select the rectangle tool and draw in the chart.I would like to

be able to activate/select some of the tools that have no shortcut in the mt4 plataform from a macro pad.

Is that possible? If so, could you tell me what do I need to learn or focuss my attention on?


Thank you.

 
Hello Support and all,



I've found problem of no any alert sounds from MT4 after update as build 1408.

I've confirmed all setting for sounds are Enable (Option-->Events-->Enable for all).

I've confirmed MT4 teminal for 2 brokers with 1408 update have the same problem,

while MT4 teminal for other 2 brokers with 1380 update are still have sounds alert as usual.



I hope the support will see this post very soon.

Anyway, I'm not sure if this forum is the best way to feedback this problem, please suggest if it not.



Thank you very much

SaltedPN

 

Good day everyone, 

I am experiencing some problem which I find difficult to explain and hence difficult to find a working solution from the Codebase and forums. I have an indicator which runs well when back testing but when I place it on a live chart, it shows/draws bogus arrows. If I recompile the code while the indicator is placed on a live chart, the bogus arrows become even more. I am thinking that somewhere in the code I have to delete old data from buffers/arrays or set them to empty values, but I don't know how to do that because I don't understand what is causing the bogus arrows.  

Please see image below:  Bogus arrows


The code is below, I have excluded the unnecessary if conditions which in the end only set bool variables to either true or false.

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_plots   6

// For the 10% RRT ratio signal
#property indicator_color1  DarkTurquoise
#property indicator_type1   DRAW_ARROW
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

#property indicator_color2  Orange
#property indicator_type2   DRAW_ARROW
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

// For the 20% RRT ratio signal
#property indicator_color3  Red
#property indicator_type3   DRAW_ARROW
#property indicator_style3  STYLE_SOLID
#property indicator_width3  3

#property indicator_color4  Green
#property indicator_type4   DRAW_ARROW
#property indicator_style4  STYLE_SOLID
#property indicator_width4  3

// For the b1 formation setup
#property indicator_color5  DarkTurquoise
#property indicator_type5   DRAW_ARROW
#property indicator_style5  STYLE_SOLID
#property indicator_width5  1

#property indicator_color6  Orange
#property indicator_type6   DRAW_ARROW
#property indicator_style6  STYLE_SOLID
#property indicator_width6  1


//----- Indicator buffers -----

// For the 10% RRT ratio signal
double upArrow[];
double downArrow[];

// For the 20% RRT ratio signal
double upArrow2[];
double downArrow2[];

// For the b1 formation setup
double upArrow3[];
double downArrow3[];


// The below flags are initially set to false and become true when conditions are met
bool MconditionBuy = false;
bool MconditionSell = false;

bool MconditionBuy2 = false;
bool MconditionSell2 = false;

bool MconditionBuy3 = false;
bool MconditionSell3 = false;

bool UseAlerts = true; // Use Alerts
// bool UseEmailAlerts = false; // Use Email Alerts (configure SMTP parameters in Tools->Options->Emails)
bool Push=false; //Enable Push Notification

int prev_calc; // To hold value of previously calculatd and make it accessible 
               // outside the for loop (accessible in the Alerts function)

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
   IndicatorSetString(INDICATOR_SHORTNAME,"RRT");

   PlotIndexSetInteger(0,PLOT_ARROW,233);
   PlotIndexSetInteger(1,PLOT_ARROW,234);
   PlotIndexSetInteger(2,PLOT_ARROW,217);
   PlotIndexSetInteger(3,PLOT_ARROW,218);
   PlotIndexSetInteger(4,PLOT_ARROW,221);
   PlotIndexSetInteger(5,PLOT_ARROW,222);

   SetIndexBuffer(0,upArrow);
   SetIndexBuffer(1,downArrow);
   SetIndexBuffer(2,upArrow2);
   SetIndexBuffer(3,downArrow2);
   SetIndexBuffer(4,upArrow3);
   SetIndexBuffer(5,downArrow3);

  }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectsDeleteAll(0,0,OBJ_ARROW);
   ObjectsDeleteAll(0,0,OBJ_TEXT);
   Comment("");
   
   //--- Clearing the buffers
   ArrayFree(upArrow);
   ArrayFree(downArrow);
   ArrayFree(upArrow2);
   ArrayFree(downArrow2);
   ArrayFree(upArrow3);
   ArrayFree(downArrow3);

  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &Time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

   //--- Return value of prev_calculated for next call
   int total, limit;
  
      if (prev_calculated == 0) // i.e The indicator is running for the first time
     {
       total = rates_total - 1; // leave at least 1 candle to the right to avoid array out of range
       limit = 20; // This is the limit of candles / bars to count backwards, i.e. the lookback and zero is
                   // the last candle / bar on the left of the chart.
       prev_calc = 0; // Make the value of previously calculated available in the Alerts function
     }
     
      else if (rates_total - prev_calculated <= 0) // i.e The indicator is not running for the first time but is on same candle
                                                   // total is zero and the for loop will not run
     {
       total = rates_total - prev_calculated; // total is/has zero
       limit = 0; 
       prev_calc = prev_calculated;
     }     

      else  
     {
        total = rates_total-2;
        limit = prev_calculated-2;     
        prev_calc = prev_calculated; 
     }  

   for(int i = total; i > limit; i--)
     {
          if (conditions_Sell_met)  MconditionSell = true;
          if (conditions_Sell2_met) MconditionSell2 = true;
          if (conditions_Buy_met) MconditionBuy = true;
          if (conditions_Buy2_met) MconditionBuy2 = true;
          if (conditions_Sell3_met) MconditionSell3 = true;
          if (conditions_Buy3_met) MconditionBuy3 = true;


   //------------------- Buy conditions ---------------------------
   
   if(MconditionBuy) 
     {
      upArrow[i]=low[i];
      SendAlert(signalText);
      MconditionBuy = false; // reset the market condition and wait for new conditions to arrive - to prevent repetitions    
     }
    
   if(MconditionBuy2) 
     {
      upArrow2[i]=low[i];
      SendAlert(signalText);
      MconditionBuy2 = false; // reset the market condition and wait for new conditions to arrive - to prevent repetitions
     }
     
   if(MconditionBuy3) 
     {
      upArrow3[i]=low[i];
      SendAlert(signalText);
      MconditionBuy3 = false; 
     }


   //------------------- Sell conditions ---------------------------
   if(MconditionSell) 
     {
      downArrow[i]=high[i];
      SendAlert(signalText);
      MconditionSell = false; 
     }
     
   if(MconditionSell2) 
     {
      downArrow2[i]=high[i];
      SendAlert(signalText);
      MconditionSell2 = false;
     }

   if(MconditionSell3) 
     {
      downArrow3[i]=high[i];
      SendAlert(signalText);
      MconditionSell3 = false; 
     }
      
   }

   //--- Return value for the next call
   return(rates_total);
  }

//+------------------------------------------------------------------+
void SendAlert(string signal)
{
   if (UseAlerts && prev_calc != 0) // prev_calc is to avoid making alerts when the indicator is 
                                    // calculating historical data (backwards), alerts should only
                                    // be made going forward and not for past patterns.
      {
        Alert(signal);
        PlaySound("alert.wav");      
      }
   
 //  if (UseEmailAlerts)
 //     SendMail(signal);

   if(Push)
     { 
       SendNotification(signal);               
     } 
}
//+------------------------------------------------------------------+

Your assistance in explaining why the bogus arrows appear and showing me how to get rid of them is much appreciated.

 
ITM7 #:

Good day everyone, 

I am experiencing some problem which I find difficult to explain and hence difficult to find a working solution from the Codebase and forums. I have an indicator which runs well when back testing but when I place it on a live chart, it shows/draws bogus arrows. If I recompile the code while the indicator is placed on a live chart, the bogus arrows become even more. I am thinking that somewhere in the code I have to delete old data from buffers/arrays or set them to empty values, but I don't know how to do that because I don't understand what is causing the bogus arrows.  

Please see image below: 


The code is below, I have excluded the unnecessary if conditions which in the end only set bool variables to either true or false.

Your assistance in explaining why the bogus arrows appear and showing me how to get rid of them is much appreciated.

I found the solution, and now I see how simple it was. Before the indicator runs, clean all buffers. Since you would like to do this only once, clean the buffers at the instance the indicator is first dropped on the chart, and that would be when prev_calculated is zero. See code below: 

      if (prev_calculated == 0) // i.e The indicator is running for the first time
     {
       total = rates_total - 1; // leave at least 1 candle to the right to avoid array out of range
       limit = 20; // This is the limit of candles / bars to count backwards, i.e. the lookback and zero is
                   // the last candle / bar on the left of the chart.
       prev_calc = 0; // Make the value of previously calculated available in the Alerts function
     
     
           // Clean / delete old buffer values to avoid bogus arrows
           // This is done once only when prev_calculated is zero, i.e when u first drop the indicator
            for(int i = total; i > limit; i--)
              {
                 upArrow[i] = EMPTY_VALUE;
                 downArrow[i] = EMPTY_VALUE;
                 upArrow2[i] = EMPTY_VALUE;
                 downArrow2[i] = EMPTY_VALUE;
                 upArrow3[i] = EMPTY_VALUE;
                 downArrow3[i] = EMPTY_VALUE;
              
              }
     }
Reason: