[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 463

 

Hi all!

Can you tell me how to teach the Expert Advisor to remember that there was a fact of opening an order (after closing the order). Global logical variables are suitable, but only for one instrument. If I have more than one symbol in one terminal, the variables will change and will not work as expected.

 
demlin:

Hi all!

Can you tell me how to teach the Expert Advisor to remember that there was a fact of opening an order (after closing the order). Global logical variables are suitable, but only for one instrument. If I have more than one symbol in one terminal, the variables will change and will not work as expected.


So each tool has its own global variable.)
 
tol64:

So each tool has its own global variable.)
It makes sense, then how do I get the program to generate the names? I don't want to manually cram 60 variables into the code)))
 

Hi all!

I'm having difficulties... I've been working on this, I've been trying to open a short order on EUR/USD for a long time, I've been trying to open a short once before the MA and the close of the previous candle was below the MA, but the order didn't open, I've been working in the tester now and the order opened like a nice guy,

Where is the error in the code - I do not understand, I have specifically inserted the condition, if the order has not opened - try to open it 10 times, but it does not seem to help, please help a beginner ...

void CheckForOpensell()
  {
   double maopensell;
   int    ticketsell=0;


//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//---- get Moving Average 
   maopensell=iMA(NULL,TF,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//---- sell conditions
   if(Open[1]>maopensell && Close[1]<maopensell)
   for (int it=1; it<=10; it++)
    {
      while (!IsTradeAllowed()) Sleep(5000); 
      RefreshRates();
      ticketsell=OrderSend(Symbol(),OP_SELL,LotsOptimizedsell(),Bid,3,0,0," MA Sell M"+TF,MAGICMA,0,Red);
      if(ticketsell>0)
         {
          OrderModify (ticketsell,OrderOpenPrice(),Bid+StopLoss*Point,Bid-TakeProfit*Point,0,Gold);
          return;  
         }
      
      else
       {
        int err=GetLastError();
        if (err==128 || err==142 || err==143 || err==144) 
         {
           Sleep(2000);
           Print("Error(",err,") opening position: ",ErrorDescription(err),", try ",it);
           continue;
         }
        if (err==146) while (IsTradeContextBusy()) Sleep(2000);
        Print("Error(",err,") opening position: ",ErrorDescription(err),", try ",it);
        if (err==2 || err==64 || err==65 || err==4110 || err==4111) break;
        Sleep(2000);
       }
      
     }
  }
 
Abylhat:

Hi all!

I'm having difficulties... I've been working with the EA on the chart 24 hours a day, today on EUR/USD I had a condition to open a short, (previous candle's open was higher than MA, and its close was lower than MA), but the order didn't open, I've tried to open this section in the tester, the order opened like a nice one,

If the order hasn't opened, I tried to open it 10 times, but it didn't help, please help a beginner ...


It is very possible that the problem is in this area

 if(Volume[0]>1) return;

Signals with such a condition may be skipped. But in the tester they will work for sure.

There is no tick skipping in the tester

 
Vinin:


It is very possible that the problem is in this section

Signals with this condition may be missed. But they will definitely work in the tester.

No tick skipping in the tester


Thank you, could you tell me how to set the condition differently?
 
Abylhat:

Thank you, could you tell me how to set the condition differently?

int start(){
   static int prevtime=0;
   if (Time[0]==prevtime) return(0);
   prevtime=Time[0];

//
   return(0);
}
You can use TimeCurrent() instead of Time[0]
 
demlin:

Hi all!

Can you tell me how to teach an Expert Advisor to remember that there was an order open (after the order was closed). Global logical variables are suitable, but only for one instrument. If there are several symbols in one terminal, the variables will change and will not work as expected.

So, does the Expert Advisor trade several symbols at once?

If he/she trades only one instrument, the Magic number of Expert Advisor can be added to the name of the global variable.

 
rlx:

Does the Expert Advisor trade more than one instrument at a time?

If it only trades one, the Magic number of the Expert Advisor can be added to the global variable name.

The Expert Advisor trades several instruments at the same time
 
Vinin:

You can use TimeCurrent() instead of Time[0]

thanks, I will apply and test....