Question for connoisseurs - page 12

 
rid писал(а) >>

I'm not really an expert on this.

But the assumption is that if after the 1st signal you 'hang' the flag, then let it hang.

Even if the 1st signal is already exhausted!

Then the 2nd signal will give a signal to open without any problem.

If I understood the question correctly...

But the flag is a variable, as I understand it, and with a new tick the program will see the initial or newly calculated flag value. Maybe I misunderstand what a flag is?

 
MQLBankir >> :

But a flag is a variable, as I understand it, and with a new tick the program will see the initial or calculated value of the flag from the new data. Maybe I misunderstand what a flag is?

A flag is a boolean constant which has a value true or false, with a numeric representation of 1 or 0 respectively.

If the condition of the 1st signal (like crossing 2 wheels) then the flag is set to true, if the crossing has not yet occurred flag remains false! For your task... it would look something like this :

bool signal1=true;

int start()

if (signal1==false) {return();}

signal1 ......... tra la get signal

if (signal1 ==true) //the first signal appears

{

signal2 .............. tra la receiving signal

signal1=false;

}

something like that should happen )))

oh, as I was writing, it was already defined below)

 
MQLBankir >> :

But a flag is a variable, as I understand it, and with a new tick the program will see the initial or calculated value of the flag from the new data. Maybe I misunderstand what a flag is?

I can add, that globally declared variables save their values.

>> until they are forcibly changed or the program is closed.

 

The protection of the flag is done as follows:

int flag;
int start()
{
 // функция принятия решения и установки флага
 if( flag==1)
  { flag=0;
   // код защищенный от запуска флагом   
  } 
return(0);
}
By the way
// функция принятия решения и установки флага

can be anywhere, depending on the author's idea, the sequence of actions changes.

 
Urain писал(а) >>

The protection of the flag is done as follows:

by the way

can be anywhere, depending on the author's idea, and it changes the sequence of actions.

>>Thank you all, seems to have figured it out))

 

Good evening. Trouble has come down from somewhere.

An advisor with a martingale.

10 steps. At each step the position has a different magician.

At the beginning everything was working fine. For several days.

However, all of a sudden it did not work at all!

The very first position opens and immediately, on the next bar, it closes!

It is unclear why.


And it goes on and on. Opens and closes.

It just started today. All of a sudden !

Here's the closing block :

 //жжжжжжжжжжжж  Закрытие позиций жжжжжжжжжжжжжжжжжжжжжжж
 //(используются ф-и И.Кима
if ( NumberOfPositions(NULL,OP_BUY, -1)>0) {//если есть открытые позиции
// если цена открытия первой позиции меньше текущей цены на тейкпрофит - закрываем её 
if ( ( PriceOpenLastPos(NULL, OP_BUY, Magic  )+ TakeProfit_Buy*Point)<=Bid  && PriceOpenLastPos(NULL, OP_BUY, Magic  )>0)  ClosePositions(NULL, OP_BUY, Magic );

// если цена открытия второй  позиции меньше текущей цены на тейкпрофит - закрываем её 
if ( ( PriceOpenLastPos(NULL, OP_BUY, Magic_2)+ TakeProfit_Buy*Point)<=Bid  && PriceOpenLastPos(NULL, OP_BUY, Magic_2)>0) ClosePositions(NULL, OP_BUY, Magic_2);

 // если цена открытия след.  позиции меньше текущей цены на тейкпрофит - закрываем всё открытые позиции  
if ( ( PriceOpenLastPos(NULL, OP_BUY, Magic_3)+ TakeProfit_Buy*Point)<=Bid  && PriceOpenLastPos(NULL, OP_BUY, Magic_3)>0) ClosePosFirstProfit(NULL, OP_BUY, -1);
if ( ( PriceOpenLastPos(NULL, OP_BUY, Magic_4)+ TakeProfit_Buy*Point)<=Bid  && PriceOpenLastPos(NULL, OP_BUY, Magic_4)>0) ClosePosFirstProfit(NULL, OP_BUY, -1);    
if ( ( PriceOpenLastPos(NULL, OP_BUY, Magic_5)+ TakeProfit_Buy*Point)<=Bid  && PriceOpenLastPos(NULL, OP_BUY, Magic_5)>0) ClosePosFirstProfit(NULL, OP_BUY, -1);   
if ( ( PriceOpenLastPos(NULL, OP_BUY, Magic_6)+ TakeProfit_Buy*Point)<=Bid  && PriceOpenLastPos(NULL, OP_BUY, Magic_6)>0) ClosePosFirstProfit(NULL, OP_BUY, -1);    
if ( ( PriceOpenLastPos(NULL, OP_BUY, Magic_7)+ TakeProfit_Buy*Point)<=Bid  && PriceOpenLastPos(NULL, OP_BUY, Magic_7)>0) ClosePosFirstProfit(NULL, OP_BUY, -1);   
if ( ( PriceOpenLastPos(NULL, OP_BUY, Magic_8)+ TakeProfit_Buy*Point)<=Bid  && PriceOpenLastPos(NULL, OP_BUY, Magic_8)>0) ClosePosFirstProfit(NULL, OP_BUY, -1);    
if ( ( PriceOpenLastPos(NULL, OP_BUY, Magic_9)+ TakeProfit_Buy*Point)<=Bid  && PriceOpenLastPos(NULL, OP_BUY, Magic_9)>0) ClosePosFirstProfit(NULL, OP_BUY, -1);
if ( ( PriceOpenLastPos(NULL, OP_BUY, Magic_10)+ TakeProfit_Buy*Point)<=Bid&& PriceOpenLastPos(NULL, OP_BUY, Magic_10)>0) ClosePosFirstProfit(NULL, OP_BUY, -1);  

 } 

Maybe someone will see the inaccuracy or error ? (by prices of opened positions)

 

rid писал(а) >>

It is not clear why.

Will anyone suddenly see any inaccuracy or error?

The problem is probably not with this code, but with opening positions or calculating TakeProfit_Buy. It is more likely that it is the latter.

If it plays in the tester, Print should help.

 

I do not calculate TakeProfit_Buy - I just set it in external parameters.

extern int       TakeProfit_Buy=21;

In the tester - the same crap.But in places. At first, all is normal.

And then this shit appears. And not always.

I'll have to insert a comment or a print...

Besides. I have never tried to use this kind of magic when I was a rookie, but I have never forgotten.

 

I think I've got it wrong. And, of course, not at all where I was originally looking.

Apart from the above closure, I also have this one:

//----------------------- Закрытие позиций по текй профиту ----------------------------------

if ( NumberOfPositions(NULL,OP_BUY, -1)>0) {// если есть открытые позиции
// если очередная  позиция закрылась по тейкпрофиту , то закрываем
// все остальные позиции  
if ( isCloseLastPosByTake(NULL, OP_BUY, Magic_3 ))  { ClosePosFirstProfit(NULL, OP_BUY, -1);}
if ( isCloseLastPosByTake(NULL, OP_BUY, Magic_4 ))  { ClosePosFirstProfit(NULL, OP_BUY, -1);}    
if ( isCloseLastPosByTake(NULL, OP_BUY, Magic_5 ))  { ClosePosFirstProfit(NULL, OP_BUY, -1);}   
if ( isCloseLastPosByTake(NULL, OP_BUY, Magic_6 ))  { ClosePosFirstProfit(NULL, OP_BUY, -1);}    
if ( isCloseLastPosByTake(NULL, OP_BUY, Magic_7 ))  { ClosePosFirstProfit(NULL, OP_BUY, -1);}   
if ( isCloseLastPosByTake(NULL, OP_BUY, Magic_8 ))  { ClosePosFirstProfit(NULL, OP_BUY, -1);}    
if ( isCloseLastPosByTake(NULL, OP_BUY, Magic_9 ))  { ClosePosFirstProfit(NULL, OP_BUY, -1);}
if ( isCloseLastPosByTake(NULL, OP_BUY, Magic_10))  { ClosePosFirstProfit(NULL, OP_BUY, -1);} 
                                           }

It turns out that the function flag
isCloseLastPosByTake( )//если поза закрылась по тейку - возвращает единицу
after its execution equals 1, but after all other positions have been closed it still equals 1 !And of course, when the next first position with magic number = magic number is opened - it is immediately closed !

It's just not clear why this error didn't show up for two days ?

//--------------------------------------------------------------

Also. Can you advise me, - How can I make this block work correctly after all ?

In other words, how to reset function isCloseLastPosByTake() after closing all positions?

 
rid >> :

In other words, how do I reset the isCloseLastPosByTake() function after all positions have been closed?

As far as I understand, the opening time of a position closed on profit should be longer than that of the remaining small orders, add this condition and everything will be cool.

Reason: