[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 301

 
rustein:
Have searched the forum but haven't found a quick fix, help solve the problem with while in tester doesn't work, in real life it does.

Thank you.

If it hangs the tester, then it should. (Be sure to describe the exit from the loop).

Like this

    while(Result == -1)
    {
      if(TotalOpenOrders() < TotalOrders)
      {
        if(TrendDetection() == BULL)
        {
          Result = OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,NormalizeDouble(Ask,Digits)-(StopLoss*Point),NormalizeDouble(Ask,Digits)+(TakeProfit*Point),OrderComments,Magic,0,CLR_NONE); 
         if((IsTesting()||IsOptimization())&&Result == -1)break;
        }
 
drknn:


It's hard to say what your problem is. Take it as a rule in MQL4 that negative numbers in code should always be put in brackets. Sometimes errors may occur without brackets.

Although, in code lines starting with extern, taking negative values in brackets is not necessary. I don't know why it is so.

Thank you, but it doesn't work, can you suggest a construct to get rid of the loop if(IsTesting()==true || IsOptimization()==true)
 
rustein:
Thanks, but it doesn't work, can you suggest a construct to get rid of the loop if(IsTesting()==true || IsOptimization()==true)

 while(Result == -1)
    {
      if(TotalOpenOrders() < TotalOrders)
      {
        if(TrendDetection() == BULL)
        {
          Result = OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slippage,NormalizeDouble(Ask,Digits)-(StopLoss*Point),NormalizeDouble(Ask,Digits)+(TakeProfit*Point),OrderComments,Magic,0,CLR_NONE); 
         if((IsTesting()||IsOptimization())&&Result == -1)break;
        }

^^

 
drknn:
It doesn't need an alert - my understanding is that somewhere in the code the file is probably already open but not closed. That's probably why the file cannot be reopened and the alert window keeps popping up. Although, maybe I'm wrong - I'm not a member of telepath club :(
The situation is as follows: at a certain moment, the expert looks into the csv file and sees what command is there (buy, sell, close), this command is written to the file by EXCEL. The problem is at the moment, when expert will read the file, it can be opened by EXCEL, expert will give out an error and that's all, and I need it to go again and try until it reads the command.
I didn't know about while construct...
Please check if I wrote it correctly:
 
int init()
{
while(handle<1)
{ 
handle=FileOpen("firstfile.csv",FILE_CSV|FILE_READ|FILE_WRITE,'\t') 
} 

}

 
sanches83:

}

Yeah, why ask, you can test it with a "fight" )).
 
rustein:
Thanks, but it doesn't work, can you suggest a construct to get rid of the loop if(IsTesting()==true || IsOptimization()==true)


Try without a loop at all, say like this:

double  PR,SL,TP;
PR=NormalizeDouble(Ask,Digits);
SL=NormalizeDouble(PR-StopLoss*Point,Digits);
TP=NormalizeDouble(PR+TakeProfit*Point,Digits);
int Result=0;
Result = OrderSend(Symbol(),OP_BUY,Lots,PR,Slippage,SL,TP,OrderComments,Magic,0,CLR_NONE);
if(Result<=0){
        Print("Ошибка № ",GetLastError()," при открытии бай-ордера. PR = ",PR,"   SL = ",SL,"   TP = ",TP);
}

It would at least help to understand why the pose doesn't open.

 
costy_:

^^

Many Thanks :)

Thank you all, fixed it, it's working.

Many thanks for your help.

 
costy_:
Yes, why do we need to ask, we can check it by "fighting" )).


In general this is correct, but to make it work we need to initialize the variable before the loop

handle=0;

while(handle<1)
{
handle=FileOpen("firstfile.csv",FILE_CSV|FILE_READ|FILE_WRITE,'\t');
}

Well, it's just to be absolutely sure that code execution will enter the loop's body and not ignore it.

 
drknn:


Actually it is true but for it to work, the variable should be initialized before the loop

handle=0;

while(handle<1)
{
handle=FileOpen("firstfile.csv",FILE_CSV|FILE_READ|FILE_WRITE,'\t');
}

This is to make sure that code execution enters the loop body and does not ignore it.

Yeah, unfortunately I have to be like a fortune teller, create scripts with part of the code on the question, well or all the code and it will be easier for you to point out the error. (coffee grounds zakAchyVeTso).
 

Folks, help me out a little!!!

I am trying to write an EA using the morning channel strategy. The essence is this: at 6:01 on EURGBP pair we determine the channel of price movement from 0 o'clock till 6 am. We set two pending orders and if the triggered pending order is closed by a stopper, we open an order in the opposite direction. It is the second part of the strategy that does not work. I.e., if a stop has triggered, we cannot open an order in the opposite direction.
Files: