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

 
Pacman:


As far as I understand I need to redo it like this:

Same problem again. When I run the Expert Advisor, it immediately opens an SELL order.

Can you please explain why?

Replace:

  double L_1= iCustom(NULL,0,"Go_go",K,0,0);  //Линия минимума
  double L_2= iCustom(NULL,0,"Go_go",K,1,0);  //Линия максимума 

To:

  double L_1= Low[iLowest (NULL, 0, MODE_LOW, K, 1)];;    //Значение минимума
  double L_2= High[iHighest (NULL, 0, MODE_HIGH, K, 1)];;  //Значение максимума 

And why an SELL order opens (in your version) (based on what I said earlier), find the answer yourself!!!

 

I set flags for the direction of the trade. Condition: If it falls in one zone between the lines, then buy and do not sell, if in another zone, then do not buy and sell. I regulate this process with horizontal lines.

extern bool    Покупать  = false;
extern bool    Продавать = false; 


   if ( pcb < Ask && Ask < pl )       // Если Аск цены попал в зону между Уровнем и КлозеБай,
    {                             
     Покупать = false;                // останавливаем покупку
     Продавать = true;
    }
   if ( pl < Bid && Bid < pcs )       // Если Бид цены попал в зону между Уровнем и КлозеСелл,
    {                            
     Продавать = false;               // останавливаем продажи (контрольный флаг)
     Покупать = true;
    }
   if ( pl < Bid && Bid < pb )        // Если Бид цены попал в зону между Уровнем и Покупкой,
    {                                 // начинаем покупать
     Покупать = true;
    }
   if ( pl > Ask && Ask > ps )        // Если Аск цены попал в зону между Уровнем и Продажей,
    {                                 // начинаем продавать
     Продавать = true;             
    }

Before that I ask for the prices of the exposed lines. And after that a block of placing or closing orders - depending on the flag.

The code is trivially simple. But... - Question...

When this design starts working, the buy and sell values turn out to be unpredictable (chaotic). Why does this happen? Because there are clear conditions for the "if" function and "end" and "more/less" operators.

That is, the program behaves according to its own reasons: it either buys, sells or does nothing, regardless of what is written in the values of the variables.


How and what do I need to write to make the conditions work and, most importantly, to make them work? What am I doing wrong and what am I not taking into account? (I think I have mentioned everything I need in the function conditions).


There is also another issue in this topic: when variables change depending on the conditions, their values in Expert Advisor settings (when accessing them via F7) will be the same as they were set by the user. That's why it's impossible to see the current state of these variables. How can we make it so that we can see what their values are at the moment?

 
Dimka-novitsek:
Good morning! Condition doesn't work

I've already looked at the ife string, looked at it, looked at it, looked at it.... There must be some reason, I may be confused and not see something simple and elementary, it happens.

I looked in the morning. I went out. I came back and looked again. It's easier now, ifs, more, less... I don't get it at all.



And this is under my start.


p.s. It's all part of this strategy condition

EMA - period 10 crosses from top to bottom EMA - period 200 , CCI crosses 0.100 or 100 from top to bottom; Candle closes or is below LMA - period 100


Put a parenthesis to show how and what is done

if( CCI_50S>100&&CCI_50<100 ||CCI_50S>0&&CCI_50<0|| CCI_50S>-100&&CCI_50<-100 )CCInapravlenie=true;
 
Chiripaha:

I set flags for the direction of the trade. Condition: If it falls in one zone between the lines, then buy and do not sell, if in another zone, then do not buy and sell. I regulate this process with horizontal lines.

Before that I ask for the prices of the exposed lines. And after that a block of placing or closing orders - depending on the flag.

The code is trivially simple. But... - Question...

When this design starts working, the buy and sell values turn out to be unpredictable (chaotic). Why does this happen? Because there are clear conditions for the "if" function and "end" and "over/under" operators.

That is, the program behaves according to its own reasons: it either buys or sells, or does nothing regardless of what is written in the values of the variables.

How and what do I need to write to make the conditions work and, most importantly, to make them work? What am I doing wrong and what am I not taking into account? (I think I have mentioned everything I need in the function conditions).

There is also another issue in this topic: when variables change depending on the conditions, their values in Expert Advisor settings (when accessing them via F7) will be the same as they were set by the user. That's why it's impossible to see the current state of these variables. How do I make it so that I can see what their values are at the moment?

Start by grouping the conditions together:

    extern bool    Покупать  = false;
    extern bool    Продавать = false; 

    if (pl > Ask) {if (Ask > psb || Ask > ps) Продавать = true;}
    else {if (pl < Bid) if (Bid < pcs || Bid < pb) Покупать = true;}
Maybe this way it will be easier to understand! (I didn't get into the meaning of the code itself).
 

At first glance, it's probably about the variables, not the conditions. I would start by outputting the variables with alerts, as the code itself looks NORMAL !!!

Alert(" pcb " , pcb ); Alert(" pl " , pl ); Alert(" pb " , pb );

 

how do I change the data format when writing to a file?

it writes in unreadable fonts :(

 
TarasBY:

Replace:

For:

And why the SELL order opens (in your variant) (based on what I said earlier) find the answer MYSELF!!!


It turns out that there is no need to call parameters from the indicator. Everything can be registered directly in the Expert Advisor.

I will analyze my error.

I rewrote my indicator with iLowest and iHighest functions, is this code correct or can it be truncated?

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red

extern int Quant_Bars = 5; //количество баров

//--- buffers
double Line_1[];     //объявление массивов под..
double Line_2[];     //..буферы индикаторов

int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);    //стиль линии
   SetIndexBuffer(0,Line_1);                    //назнач. массива буферу
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);    //стиль линии
   SetIndexBuffer(1,Line_2);                    //назнач. массива буферу
//----
   return(0);                                      
  }

int start()
  {                        
   double Minimum;
   double Maximum;
   int k;
   
   Maximum= High[iHighest(NULL,0,MODE_HIGH,Quant_Bars,1)];
   Minimum= Low[iLowest(NULL,0,MODE_LOW,Quant_Bars,1)];
   
   for(k=1; k<=Quant_Bars; k++)
      {
       Line_1[k]= Minimum;
       Line_2[k]= Maximum;
      }
    return(0);
    }
               
 
Now... My brother's here, the eldest... The brackets are probably just clogging up. Now
 
Dimka-novitsek:

At first glance, it's probably about the variables, not the conditions. I would start by outputting the variables with alerts, as the code itself looks NORMAL !!!

Alert(" pcb " , pcb ); Alert(" pl " , pl ); Alert(" pb " , pb );


I already did it - all variables are correct: both prices and parameters are set.
 
TarasBY:

Start by grouping the conditions together:

Maybe this way it will be easier to understand! (I didn't get into the meaning of the code itself).


If you set it that way, it will be a different matter - if below the line, then... And I need when it falls between specific lines - in the area of those lines.