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

 
hoz:

At the moment the task is as follows: fastMa has crossed slowMa upwards... so we are looking for where to buy. Then we wait until the price i.e. Ask (since we consider buying) reaches fastMa ( well, I guess there will be no exact value, we need +- some deviation, and this is changed by i_thresholdFromMa) and as soon as the price reaches fastMa +- i_thresholdFromMa the Expert Advisor should set BUYSTOP at (fastMa + buyHear * pt).

What I have come up with does not work in one terminal and does not always work in another one. Something is wrong in general.

The last variant of the buyHear function here:

Here are the input parameters:

Errors can be seen on the screenshot (in OrderSend() the price is fed above the red wand, and the order as seen on the screenshot is below....):

Been away for a few days... I'm wondering - do the same parameters have the wands thrown onto the chart as the wands used in the calculations? Maybe that's where the dog is buried?

(I still had no time to delve into the code and take it apart).

I would make a function, for example:

//-----------------------------------------------------------------------------+
double ma(int MAperiod, int MAmethod, int MAshift) {return (iMA(Symbol(), Period(), MAperiod, 0, MAmethod, PRICE_OPEN,MAshift));}
//-----------------------------------------------------------------------------+

and call it to get the parameters

 

Hello, could you please advise! An indicator signal to buy has triggered, I open an order only after confirming the next two candles upwards.

 
Top2n:

Hello, could you please advise! An indicator signal to buy has triggered, I open an order only after confirming the next two candles upwards.


So check that the last two candles up and the condition to open an order two bars ago at the same time.
 
Roger:

So check that the last two candlesticks up and the condition to open an order two bars back at the same time.

how do I do it?

 if (bay_min == true) сработал сигнал на покупку ждем подтверждение
  
 if (Open[1]<Close[1] && Open[2]<Close[2] )
   
 if (Bars(2).............


And if so, the signal is triggered wait for confirmation, only after a bar up or down 2 bars.

We need it to remember the bar on the signal, the bar after the signal, compare them if the two are ascending or descending, then .....

 
Top2n:

how do I do it?


If the signal worked, we wait for confirmation, but after the bar goes up or down.

It should remember the bar on the signal, the bar after the signal, compare them if the two are ascending or descending, then .....

Show how you got bay_min.
 
Top2n:

how do I do it?


If the signal worked, we wait for confirmation, but after the bar goes up or down.

It should remember the bar on the signal, the bar after the signal, compare them if the two are ascending or descending, then .....



if (bay_min == true)   datetime T=Time[0] //сработал сигнал на покупку запоминаем время  бара

if(iBarShift(NULL,0,T)==2) //по времени, сигнал был на 2 баре
   {   
  if (Open[1]<Close[1] && Open[2]<Close[2] )   //и эти бары бичьи 
     { 
    // что-то делаем
     }
   }
   
// я думаю, как-то так.
 
Question for Expert Advisors

I am writing a simple Expert Advisor and run into a lot of problems.

The condition is

I remember the close price of the current bar and enter it into the variable Startprice if the previous 4th bar was in the sliding bar.


If the condition is satisfied, then draw an icon showing the close price of the bar, i.e., Startprice.

What I have got is that the icon is drawn, but only once, while I need it every time.

The close price of the bar does not coincide with the Startprice price at 0.00001 why and how do I fix it?

Tried rounding and trimming to 5 digits did not help(

In the log using the print I call the value Startprice, shows the number only up to 4 digits and less.

How to achieve the same accuracy as in the data window of the terminal?

This decimal point problem also applies to the slider itself. If you call its values via print, you can't get more than 4 digits in the log.



#property copyright "Zuly"


 extern int MA_Period = 50; //периуд Ма
extern int MA_Method =MODE_SMA;     //Метод усреднения скользящего среднего. Может быть любым из значений методов скользящего среднего (Moving Average):
                              //*MODE_SMA 
                              
 extern int Maximum_History = 0;         //Ограничение истории для расчетов, если 0 то расчет всей истории
 
   
    
   //начало кода советника
int start()


{      
    double MA4;                                // Значение МА на 4 баре 
    
    double Startprice;
    
   { 
   MA4=iMA(NULL,0,MA_Period,0,MA_Method,PRICE_CLOSE,4); 
 
   
                       if  (Low[4]< MA4 && MA4 < High[4]) //условия если 4-я свеча лежит в скользящей
  
  {    
  
   Startprice=Close[0];
  
    //   Startprice=NormalizeDouble(Close[0],5); // пробуем округлить до 5-го знака, не помогло 
 
    //  Startprice=MathFloor(Close[0]*100000)/100000; // пробуем обрезать до 5-го знака не помогло
      
  
  
     
      //Print (Startprice); // распечатаем Startprice
     
      
   datetime TmR1=Time[0]; // запоминаем время текущего бара? 

   

   
       ObjectCreate("Rep1",OBJ_ARROW, 0, TmR1, Startprice); // создаем обьект 
      ObjectSet("Rep1", OBJPROP_COLOR, White); // устанавливаем обьект на график
       ObjectSet("Rep1", OBJPROP_ARROWCODE,71); 
      
     return(0); 
 
 
 
}} }    
   
test parameters and time
 
Use DoubleToStr(number, Digits) to output. Instead of Digits, you can write the accuracy you want. Add to the icon name the time of the bar at which you are setting the icon.
 
artmedia70:
Use DoubleToStr(number, Digits) for output. Instead of Digits you can write the accuracy you want. Add to the icon name the time of the bar at which you are setting the icon.


if so

Startprice=DoubleToStr(Close[0],5);

it's not working, it's blaming '=' - incompatible types C:\fortest\experts\sve.mq4 (34, 14)

How do I write it correctly?

Thanks for the reply, I've been struggling with this for a week )

 
artmedia70:
Use DoubleToStr(number, Digits). You can write the precision you want instead of Digits. Add the bar time to the name of the icon where you are setting the icon.

but for the output, I understand that the printer only prints 4 or less digits.

then if Print (DoubleToStr(Startprice,5)); // print Startprice

it gives out 5.

But here's how to add the time of the bar.

This line does not add the time of the bar?

  datetime TmR1=Time[0];