[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 251

 
Ibiss >> :

How to correctly program an exit at a reverse crossing of the main and signal lines ? because signals come in short intervals of time... and orders are not closed where they should in the condition...

this question has been bugging me for a long time! HELP!

Here is the exit condition:


I am no ace but

if(OrderMagicNumber()!= MAGICMA || OrderSymbol()!=Symbol()) continue;

if (OMN does not equal OMN or OS does not equal OS) {then go on}


but it means that the order does not belong to the Expert Advisor

try

if(OrderMagicNumber()!= MAGICMA || OrderSymbol()!=Symbol()) break;
 
Ibiss >> :

How to correctly program an exit at a reverse crossing of the main and signal lines ? because signals come in short intervals of time... and orders are not closed where they should in the condition...

this question has been bugging me for a long time! PLEASE!

Here is the exit condition:


Snachala narusyj sebe blok shemy svoego algorutma, chtob tu vuzyalno vudel chto tu doesh y po kakum yslovuyam y tebya zakruvayutsya orders, a vse eto delo perevestu v kod eto yge delo tehnuku - ya tak dymayu.

 

Gentlemen, could you tell me if there is anything ready to display comments on the chart for each order. I.e. arrow on a chart and next to it a comment with a reason. I want it to be drawn in tester :)

Thank you.

 
AndBar >> :

Snachala narusyj sebe blok shemy svoego algorithm, chtob tu vuzyalno vudel chto tu doaesh y po kakum yslovuyam y tebya zakruvayutsya orders, a vse eto delo perevestu v kod eto yge delo tehnuku - ya tak dymayu.


Hey man can you speak like this or like this :) >> I'm breaking my eyes. :)
 

costy, it didn't help, but thank you !

maybe who knows how to make the crossing and back crossing to open and close opposite orders!??

this needs some magic...ahhh...

You see how many different purchases and sales there should be? and there are only a couple of pieces...

how can i fix this problem?

who doesn't mind looking at the code! please!

It's all in the code of the EA, not in the indicator... I think...

and the drawdowns are like... you can't wish for 96%... who cares :)

it should be like this:


Files:
itrend.mq4  5 kb
 

Anyway, I decided to redo the EA after reading about global variables, and eureka!!!

and there was also a problem with the ticks...

trades open at all crossovers, but one big BUT...they open inbig stacks...

people, how do i fix this problem? have mercy)))

here's a screenshot:


"It's not for the faint of heart."

Files:
ggftest.mq4  3 kb
 
Ibiss >> :

costy, it didn't help, but thank you !

Can anyone know how to make opposite orders open and close at crossing and back crossing!??

this needs some magic...ahhh...

You see how many different purchases and sales there should be? and there are only a couple of pieces...

how can this bug be fixed?

who doesn't mind looking at the code! please!

It's all in the code of the EA, not in the indicator... I think...

and the drawdowns are like... you can't wish for 96%... who cares :)

this is the way it should be:



The easiest way:

At each tick we initialise 4 indicator variables. Two for the red line and two for the green. And two trading signal variables, respectively.

In this case, the code should look like this:

// ------ Пользовательские переменные -------------------
extern bool CloseObr=true;// закрывать ли противоположный ордер при возникновении торгового сигнала
// ---------- Вспомогательные переменные ------------
double Green_1, Green_2, Red_1, Red_2;// значения индикатора на первой и второй свечках
bool SigBuy, SigSell;// торговые сигналы
int TICKET;

int start(){
  Green_1=iCustom(****);// зелёная на первой свече
  Green_2=iCustom(****);// зелёная на второй свече
  Red_1=iCustom(****);// красная на первой свече
  Red_2=iCustom(****);// красная на второй свече
  
  // ------- формируем торговые сигналы -------------
  
  SigBuy=false;
  SigSell=false;
  
  if( Green_2<= Red_2 && Green_1> Red_1){// зелёная пересекает красную снизу вверх
    SigBuy=true;
  }
  if( Green_2>= Red_2 && Green_1< Red_1){// зелёная пересекает красную сверху вниз
    SigSell=true;
  }
  
  // ------ Сигналы сформированы. Торгуем ------------------
  if( SigBuy){
    if( CloseObr){
      // то удаляем все Sell-ордера
    }
    // --- противоположные удалены. Открываем позу
    ......
    TICKET=OrderSend( тут пишем параметры установки лонга);
  }
  if( SigSell){
    if( CloseObr){
      // то удаляем все Buy-ордера
    }
    // --- противоположные удалены. Открываем позу
    ......
    TICKET=OrderSend( тут пишем параметры установки шорта);
  }
}
Generally speaking, this is how the EA should work. It may not be the most perfect version of the code set, but it illustrates the logic of its construction well.
 

drknn, thanks for the idea and for the code)!


do you happen to know how to deal with a crowd of orders?)

 
Ibiss >> :

Anyway, I decided to redo the EA after reading about global variables, and eureka!!!

and there was also a problem with the ticks...

trades open at all crossovers, but one big BUT...they open in big stacks...

people, how do i fix this problem? have mercy)))

here's a screenshot:


">> it's not for the faint of heart.



Well then you can do it like this:

// ------ Пользовательские переменные -------------------
extern bool CloseObr=true;// закрывать ли противоположный ордер при возникновении торгового сигнала
extern int MAGIC=0;// у ордеров открытых вручную магик = 0
// ---------- Вспомогательные переменные ------------
double Green_1, Green_2, Red_1, Red_2;// значения индикатора на первой и второй свечках
bool SigBuy, SigSell;// торговые сигналы
int TICKET;

int start(){
  Green_1=iCustom(****);// зелёная на первой свече
  Green_2=iCustom(****);// зелёная на второй свече
  Red_1=iCustom(****);// красная на первой свече
  Red_2=iCustom(****);// красная на второй свече
  
  // ------- формируем торговые сигналы -------------
  
  SigBuy=false;
  SigSell=false;
  
  if( Green_2<= Red_2 && Green_1> Red_1){// зелёная пересекает красную снизу вверх
    SigBuy=true;
  }
  if( Green_2>= Red_2 && Green_1< Red_1){// зелёная пересекает красную сверху вниз
    SigSell=true;
  }
  
  // ------ Сигналы сформированы. Торгуем ------------------
  if( SigBuy && SchBuy( MAGIC)==0){
    if( CloseObr && SchSell( MAGIC)>0){
      // то удаляем все Sell-ордера
    }
    // --- противоположные удалены. Открываем позу
    ......
    TICKET=OrderSend( тут пишем параметры установки лонга);
  }
  if( SigSell && SchSell( MAGIC)==0){
    if( CloseObr && SchBuy( MAGIC)>0){
      // то удаляем все Buy-ордера
    }
    // --- противоположные удалены. Открываем позу
    ......
    TICKET=OrderSend( тут пишем параметры установки шорта);
  }
return(0);
}
// --------- Пользовательские подпрограммы -----------------

// ==========================================================================================================================
// ************************* Счётчики ордеров *******************************************************************************
// ==========================================================================================================================


//=========== SchBuy()  ===============================
//  Функция возвращает количество Buy-ордеров
//   SchBuy      - счётчик Buy ордеров
//-----------------------------------------------------------
int SchBuy(int MAGIC){
  string SMB=Symbol();
  int SchBuy=0;
  int i;
  for ( i=OrdersTotal()-1; i>=0; i--) {
    if (!OrderSelect( i, SELECT_BY_POS, MODE_TRADES)) { WriteError( i);}
    else {
      if(OrderSymbol()!= SMB || OrderMagicNumber()!= MAGIC){ continue;}
      if(OrderType()==OP_BUY){ 
        SchBuy++;
      }  
    }
  }
  return( SchBuy);
}                  
//==================================================================================================


//=========== SchSell()  ===============================
//  Функция возвращает количество Sell-ордеров
//  SchSell  - счётчик Sell ордеров
//-----------------------------------------------------------
int SchSell(int MAGIC){
  string SMB=Symbol();
  int SchSell=0;
  int i;
  for ( i=OrdersTotal()-1; i>=0; i--){
    if (!OrderSelect( i, SELECT_BY_POS, MODE_TRADES)) { WriteError( i);}
    else {
      if(OrderSymbol()!= SMB || OrderMagicNumber()!= MAGIC){ continue;} 
      if(OrderType()==OP_SELL){
        SchSell++;
      }
    }
  }
 return( SchSell);     
}                  
//==================================================================================================
 
Bond >> :

Gentlemen, could you tell me if there is anything ready to display comments on the chart for each order. I.e. arrow on the chart and next to it a comment with the reason. I want it to be drawn in the tester.)

>> Thank you.


If you want it to be drawn even in the tester, you will have to do the programming code manually.

In this case, it is better to set the arrows in functions OrderSend() and OrderClose().

The comment can be printed in various ways. As for the ready-made ones, I can say that this is quite a specific task - it is unlikely that one can find a ready-made code.

I posted my script here in MQL4 that displays the trading history on charts. My idea was later modified by other programmers. I just had arrows and lines showing order open/close points. Later, comments to orders and indication of execution prices appeared in other programmers' scripts. This may be good to find here.