[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 141

 
artmedia70:

IMHO - it is better to find your order and see if it is in the market or closed, and how it closed, at take, stop or manually. From here you should start dancing in different directions.

Then everything will be accurate. But global variables can be lost...


What do you mean by "lose variables"? Do you mean find it so that the EA checks this too?
 
Begemot7:
Please clarify what do you mean by lose variables, and find it in the sense of having the EA check that too?

In all EAs for real and demo trading, I do not store any important data on orders and positions in variables. The maximum I can write the data, which is necessary for the EA's logic, in the order comment. When I need to find out if there are positions, how many there are, if there are orders, closed positions, how they closed, I run a loop on market positions/orders or historical data, find the order I need and retrieve the information I need. This way, I don't store all important information in variables, as it can be lost during an unexpected computer shutdown. It can always be retrieved later. I tried to store it in global variables of terminal - it turned out that the information is not always saved there when computer crashes/hangs. And for me, constantly supervising writing there fresh information is too much trouble... I find it easier to find what I need at the moment I need it.
 
PapaYozh:

You can get the coordinates of the point on which the indicator has been dropped using the functions:

WindowXOnDropped()

WindowYOnDropped()

Price and time:

WindowPriceOnDropped()

WindowTimeOnDropped()


I'll try to build it in. An example would be similar...
 

I am facing a strange situation. Could you please tell me...

There are three self-written EAs. The strategy is the same, just different implementation, depending on the instrument. Pairs: EURUSD, EURGBP and USDJPY. I have a good working relationship with the first two, but the last one is not working. Broker is FX-Trend. My account is a mini one with the minimum lot 0.01 (it has been used so far for tests).

At the same time: Everything is OK on a demo account. When I run it in the tester, trades are opened on the same real account in the tester. But they do not during real trading. The order opening chart markers (and all other markers) are successfully placed. There is absolutely nothing in the logs.

It all runs on a VPS.


I think this is all the information. I would be grateful for any hints on what direction to dig.

 
Sepulca:

Better like this (in case the EA is restarted):



If there is only one order, we can do without it.


if(OrdersTotal()< 1)

{

}

......

 
artmedia70:
I do not store any important data on orders and positions in variables in all EAs for real and demo. The maximum I can write the data needed for the EA logic is in the order comment. When I need to find out if there are positions, how many there are, if there are orders, closed positions, how they closed, I run a loop on market positions/orders or historical data, find the order I need and retrieve the information I need. This way, I don't store all important information in variables, as it can be lost during an unexpected computer shutdown. It can always be retrieved later. I tried to store it in global variables of terminal - it turned out that the information is not always saved there when computer crashes/hangs. And for me, constantly supervising writing there fresh information is too much trouble... I find it easier to find what I need at the moment I need it.

That's right... ...to be extra reassured. The right thing is of course to go through all the orders. But this is a specific case. If we have lost GlobalVariables, we should leave this brokerage company. The GlobalVariables are stored not on your computer, but in the brokerage company up to three months if you leave them untouched. Or am I wrong?
 
Looks like I've figured it out for myself :). It is true what they say - the main thing is to formulate it. In general, when executing on the market, we set stop and take positions to zero. And then we set it properly. Maybe someone will find it useful...
 
Sepulca:
That's right... extra reassurance. The right thing to do, of course, is to go through all the orders. But this is a specific case. And if GlobalVariables are lost, we should leave this brokerage company.

What do you mean - does this brokerage company do this on purpose? I was told that MT4 is a terminal that can be easily controlled by broker and therefore probably a lot of cheating, who has heard about it?
 
Begemot7:

I mean does the DC do this on purpose? I was told that MT4 is a terminal that can easily be controlled by a broker and hence a lot of cheating is possible, who has heard of this?


I don't really understand. What's the point of DC destroying your global variables, unless of course you've built up a x...... bunch of them. Quote from the documentation:
"Global variables of the client terminal should not be mixed up with variables declared in the global scope of the MQL4 program. Global variables exist in the client terminal for 4 weeks since the last access, after which they are automatically deleted. An access to a global variable is not only setting of a new value but also reading of the global variable value.Global variables of the client terminal are accessible simultaneously from all MQL4 programs launched in the client terminal. "If you are working with 0.01 or 0.1 lot, nobody will oppress you, because it's a trifle.... But if you opened 100 lots on the real account, you'd better be ready to fight for your money.

 

Need help from the pros!!! Already racked my brain with this code... There are 4 buffers 2 of them work correctly (Buffer &buffer2), but the other 2 don't. When a certain condition occurs buffer is filled, when this value up for one and down for the second, buffers are removed (zeroed), but the remaining 2 buffers are still hanging in the chart. Can you tell me how to fix it?

      //--- Функция расчета буферов CountZZ(BuferUp,BuferDn,iPeriod,Dev,Step);
int CountZZ( double& ExtMapBuffer[], double& ExtMapBuffer1[], double& ExtMapBuffer2[], double& ExtMapBuffer3[], int ExtDepth, int ExtDeviation, int ExtBackstep )
{
   int    shift, back,lasthighpos,lastlowpos;
   double val,res;
   double curlow,curhigh,lasthigh,lastlow,lastlow1,lasthigh1;
   int count = iBars(pair,tf)-ExtDepth;

   for(shift=count; shift>=0; shift--)
     {
     //--- Расчитываем буфер BuferUp
      val = iLow(pair,tf,iLowest(pair,tf,MODE_LOW,ExtDepth,shift));
      if(val==lastlow) val=0.0;
      else
        {
         lastlow=val;
         if((iLow(pair,tf,shift)-val)>(ExtDeviation*Point)) val=0.0;
         else
           {
            for(back=1; back<=ExtBackstep; back++)
              {
               res=ExtMapBuffer[shift+back];
               if((res!=0)&&(res>val)) ExtMapBuffer[shift+back]=0.0;
              }
           }
        }
       
          ExtMapBuffer[shift]=val;
      //--------------------------------------------------------------------    
          
     //--- Расчитываем буфер BuferUp2
      if (ExtMapBuffer[shift]>0.0)
      {
             if(use.narrow.bands) val = MathMin(iClose(pair,tf,shift),iOpen(pair,tf,shift));
                else {val = MathMax(iClose(pair,tf,shift),iOpen(pair,tf,shift));
             val = MathMin(val,MathMin(iHigh(pair,tf,shift+1),iHigh(pair,tf,shift-1)));}
      if(ExtMapBuffer[shift+back]==0.0) ExtMapBuffer1[shift+back]=0.0;
      } 
          ExtMapBuffer1[shift]=val;
      //--------------------------------------------------------------------    
          
      //--- Расчитываем буфер BuferDn
      val=iHigh(pair,tf,iHighest(pair,tf,MODE_HIGH,ExtDepth,shift));
     
      if(val==lasthigh) val=0.0;
      else
        {
         lasthigh=val;
         if((val-iHigh(pair,tf,shift))>(ExtDeviation*Point)) val=0.0;
         else
           {
            for(back=1; back<=ExtBackstep; back++)
              {
               res=ExtMapBuffer2[shift+back];
               if((res!=0)&&(res<val)) ExtMapBuffer2[shift+back]=0.0;
              }
           }
        }
      ExtMapBuffer2[shift]=val;
      //-------------------------------------------------------------------
      
      //--- Расчитываем буфер BuferDn2
      if (ExtMapBuffer2[shift]>0.0)
      {
             if(use.narrow.bands) val = MathMax(iClose(pair,tf,shift),iOpen(pair,tf,shift));
                else {val = MathMin(iClose(pair,tf,shift),iOpen(pair,tf,shift));
             val = MathMax(val,MathMax(iLow(pair,tf,shift-1),iLow(pair,tf,shift+1)));}
      if(ExtMapBuffer2[shift+back]==0.0) ExtMapBuffer3[shift+back]=0.0;
      }
      ExtMapBuffer3[shift]=val;
      //-------------------------------------------------------------------
      
     }
           
   // Отсееваем ненужные значения
   lasthigh=-1; lasthighpos=-1;
   lastlow=-1;  lastlowpos=-1;

   for(shift=count; shift>=0; shift--)
     {
      curlow=ExtMapBuffer[shift];
      curhigh=ExtMapBuffer2[shift];
      if((curlow==0)&&(curhigh==0)) continue;
      //---
      if(curhigh!=0)
        {
         if(lasthigh>0)
           {
            if(lasthigh<curhigh) ExtMapBuffer2[lasthighpos]=0;
            else ExtMapBuffer2[shift]=0;
           }
         //---
         if(lasthigh<curhigh || lasthigh<0)
           {
            lasthigh=curhigh;
            lasthighpos=shift;
           }
         lastlow=-1;
        }
      //----
      if(curlow!=0)
        {
         if(lastlow>0)
           {
            if(lastlow>curlow) ExtMapBuffer[lastlowpos]=0;
            else ExtMapBuffer[shift]=0;
           }
         //---
         if((curlow<lastlow)||(lastlow<0))
           {
            lastlow=curlow;
            lastlowpos=shift;
           }
         lasthigh=-1;
        }
     }
 
   for(shift=iBars(pair,tf)-1; shift>=0; shift--)
   {
      if(shift>=count) ExtMapBuffer[shift]=0.0;
         else
         {
            res=ExtMapBuffer2[shift];
            if(res!=0.0) ExtMapBuffer2[shift]=res;
         }
   }
}

Reason: