[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 131

 

I've reworked a piece of code about what I asked yesterday. Everything is now as it should be. Below are 3 functions to show what is used to get the original signal, as this is just the beginning of what I'm writing.

//+-------------------------------------------------------------------------------------+
//| Открытие позиций                                                                    |
//+-------------------------------------------------------------------------------------+
bool Trade(int signal)
{
   double fastMa = iMA(NULL,i_TF,i_fastMaPeriod,0,MODE_EMA,MODE_CLOSE,0);
   double slowMa = iMA(NULL,i_TF,i_slowMaPeriod,0,MODE_EMA,MODE_CLOSE,0);
   
   DeletePendingOrders();
   
   if (signal == SIGNAL_BUY)
       if (!OpenBuy(fastMa, slowMa))
          return(false);
   
   if (signal == SIGNAL_SELL)
       if (!OpenSell(fastMa, slowMa))
          return(false);
       
   return (true);
}
//+-------------------------------------------------------------------------------------+
//| Получаем общий сигнал на открытие позиции                                           |
//+-------------------------------------------------------------------------------------+
int GetSignal()
{
   // Получаем значения машек для дальнейших рассчётов
   double fastMa = iMA(NULL,i_TF,i_fastMaPeriod,0,MODE_EMA,MODE_CLOSE,0);
   double slowMa = iMA(NULL,i_TF,i_slowMaPeriod,0,MODE_EMA,MODE_CLOSE,0);
 //  double filtrMa = iMA(NULL,i_TF,i_filtrMaPeriod,0,MODE_SMA,MODE_CLOSE,0);
   
   if (FindOrders() > 0)                                 // Если есть открытые ордера, то..
       return (SIGNAL_NO);                               //..ничего не делаем
   
   if (GetStateMa(fastMa, slowMa/*, filtrMa*/) == MA_DIRECT_TO_UP)      // Если машки указывают вверх
       if ( (MathAbs(High[0] - fastMa) <= 0.1 * pt ) || ( MathAbs(Low[0] - fastMa) <= 0.1 * pt) )     // Цена вблизи 0.1пп от fastMa
           return(SIGNAL_BUY);      // Функция возвращает сигнал покупки
       
 //  if (GetStateMa(fastMa, slowMa/*, filtrMa*/) == MA_DIRECT_TO_DOWN)
   //    return(SIGNAL_SELL);
   
   return (SIGNAL_NO);
}

Here's the buy function:

//+-------------------------------------------------------------------------------------+
//| Открытие длинной позиции                                                            |
//+-------------------------------------------------------------------------------------+
bool OpenBuy(double fastMa, double slowMa)
{
   int ticket = -1;
   
//   if ( (MathAbs(High[0] - fastMa) <= 0.1 * pt ) || ( MathAbs(Low[0] - fastMa) <= 0.1 * pt) )
   {
       if ((fastMa + i_thresholdFromMa * pt) > Ask)            // Проверка что цена открытия выше Ask, т.к. у нас вход отложенником
      Print("fastMa = ", DoubleToStr(fastMa,Digits));
      Print("i_thresholdFromMa = ", DoubleToStr(i_thresholdFromMa * pt,Digits));
       ticket = OrderSend(Symbol(), OP_BUYSTOP, 0.1, ND(fastMa + i_thresholdFromMa * pt), 3, 0, 0, NULL, i_magic, 0);
      Print("OrderOpenPrice() = ", DoubleToStr(OrderOpenPrice(),Digits));
   }
      if (ticket > 0 && OrderSelect(ticket, SELECT_BY_TICKET == true))
 
   return (true);
}

Here is the line:

ticket = OrderSend(Symbol(), OP_BUYSTOP, 0.1, ND(fastMa + i_thresholdFromMa * pt), 3, 0, 0, NULL, i_magic, 0);

we have a position opening atND(fastMa + i_thresholdFromMa * pt) price, but opens not there at all. Why?

I've been struggling for 2 days now, I don't know what to do. In the code, everything is the same. I haven't written any checks for real, I'm writing them for tester now.

Here is a screenshot, for example,

A joint

On the chart you can see that the price is not higher than fastMa (red), and lower in general. But in the code, it is clearly stated condition that the pending order should be at the price:

ND(fastMa + i_thresholdFromMa * pt)

What's the catch, professionals? I don't know what to do anymore...

 

Hello.I have written an indicator based on the indicator, the original Signal-Signal indicator shows its values on all previous bars when attached to the chart (it is applied to all bars, starting from bar [1]), but the indicator created from it (it is applied to bar [0]) shows its values only when attached to the chart, its values are correct but on previous bars "empty", please tell me how to fix it.

My code:

#property indicator_separate_window
#property indicator_minimum -7
#property indicator_maximum 7
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 DarkOrange
#property indicator_width1  2
#property indicator_width2  2
#property indicator_level1 0.0
//--- buffers
double UpMapBuffer[];
double DnMapBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,UpMapBuffer);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,DnMapBuffer);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    int vb;   // внутренний бар
    int i;

    for(i=1;i<Bars-34-1;i++)                                               
     {
      double AO_Sig_Sig_1 = iCustom(NULL,0,"Signal-Signal",0,i);                           
      double AO_Sig_Sig_2 = iCustom(NULL,0,"Signal-Signal",0,i+1);
      
      if((High[i]<=High[i+1])&&(Low[i]>=Low[i+1])&&(AO_Sig_Sig_1==AO_Sig_Sig_2))  vb++;
            
      if((AO_Sig_Sig_1!=AO_Sig_Sig_2)||(i>3+vb)) break;                                                                
     }
         
    i=i*(AO_Sig_Sig_1); 
            
    if(MathAbs(i)>3+vb) i=0;                  

    if(i>0)            
     {
      UpMapBuffer[0]=i;
     }
    else
     {
      UpMapBuffer[0]=0;
     } 
         
    if(i<0)         
     {
      DnMapBuffer[0]=i;
     }
    else
     {
      DnMapBuffer[0]=0;
     }          
                      
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

Victor, I think you should put a pause on Asc + distance, and in the condition specify the ratio of Asc and Mashka, then it will be what you want. Try it!

 
hoz:


You can see on the chart that the price is not above fastMa (the red wristband), but below it altogether. But in the code, the condition is explicitly stated that the pause should be at the price:

What's the catch, professionals? I don't know what to do anymore...

Maybe at the time when the order was placed the MA was lower than what is now drawn. Try to take MAA values not from the 0th bar but from the 1st one.
 
borilunad:

Victor, I think you should put a pause on Asc + distance, and in the condition specify the ratio of Asc and Mashka, then it will be what you want. Try it!


Boris, That's what I did:

//+-------------------------------------------------------------------------------------+
//| Получаем общий сигнал на открытие позиции                                           |
//+-------------------------------------------------------------------------------------+
int GetSignal()
{
   // Получаем значения машек для дальнейших рассчётов
   double fastMa = iMA(NULL,i_TF,i_fastMaPeriod,0,MODE_EMA,MODE_CLOSE,0);
   double slowMa = iMA(NULL,i_TF,i_slowMaPeriod,0,MODE_EMA,MODE_CLOSE,0);
 //  double filtrMa = iMA(NULL,i_TF,i_filtrMaPeriod,0,MODE_SMA,MODE_CLOSE,0);
   
   if (FindOrders() > 0)                                 // Если есть открытые ордера, то..
       return (SIGNAL_NO);                               //..ничего не делаем
   
   if (GetStateMa(fastMa, slowMa/*, filtrMa*/) == MA_DIRECT_TO_UP)      // Если машки указывают вверх
      // if ( (MathAbs(High[0] - fastMa) <= 0.1 * pt ) || ( MathAbs(Low[0] - fastMa) <= 0.1 * pt) )     // Цена вблизи 0.1пп от fastMa
       if ( (MathAbs(Ask - fastMa) <= 0.1 * pt ) || ( MathAbs(Ask - fastMa) <= 0.1 * pt) )
           return(SIGNAL_BUY);      // Функция возвращает сигнал покупки
       
 //  if (GetStateMa(fastMa, slowMa/*, filtrMa*/) == MA_DIRECT_TO_DOWN)
   //    return(SIGNAL_SELL);
   
   return (SIGNAL_NO);
}

And here is the position opening:

//+-------------------------------------------------------------------------------------+
//| Открытие длинной позиции                                                            |
//+-------------------------------------------------------------------------------------+
bool OpenBuy(double fastMa, double slowMa)
{
   int ticket = -1;
   
       if ((fastMa + i_thresholdFromMa * pt) > Ask)            // Проверка что цена открытия выше Ask, т.к. у нас вход отложенником
      Print("fastMa = ", DoubleToStr(fastMa,Digits));
      Print("i_thresholdFromMa = ", DoubleToStr(i_thresholdFromMa * pt,Digits));
       ticket = OrderSend(Symbol(), OP_BUYSTOP, 0.1, ND(fastMa + i_thresholdFromMa * pt), 3, 0, 0, NULL, i_magic, 0);
      Print("OrderOpenPrice() = ", DoubleToStr(OrderOpenPrice(),Digits));
      
      if (ticket > 0 && OrderSelect(ticket, SELECT_BY_TICKET == true))
 
   return (true);
}

Everything seems to be correct. But it is still there.

Sepulca:
Perhaps at the time the order was placed, the MAHA was lower than what is now drawn. Try to take the MA values from the 1st bar instead of the 0th.


Tried it, no difference. I put it back... What matters to me is what's happening at this point in time, not what happened before.

Here is a screenshot (if the value received from the machine is not 0, but 1) :

Where is the logic?

 

Victor, that's why I write conditions at the start, so I can see everything, so it's easier to find logical errors, especially when there is not yet enough knowledge and experience, which I will count myself among for a long time to come. Professionals easily manipulate functions, files and libraries, and have probably forgotten how they gradually mastered all this wisdom. But we cannot learn the theory without practice, and much more depends on the character of each person.

 
hoz:


Boris, that's what I did:

And here is the opening of the position:

Everything seems to be right. But it's still there.


Tried it, no difference. I went back... What matters to me is what's happening at this point in time, not what happened before.

Here is a screenshot (if the value received from the machine is not 0, but 1) :

Finally, tell me exactly what you want to do... For example: MA such-and-such is going up and it is above MA such-and-such and the price is above/below MA such-and-such and if it is true, then put such-and-such a pending order at such-and-such a distance. I will give you a rough algorithm. Because it's difficult to direct you in the right direction, when your code fragments are torn out of context. And the problem is for the fifth grade (exaggerated).


As for the highlighted: work on open prices, then you won't see the MACs redrawing on the zero bar

 
artmedia70:

... it's hard to point you in the right direction...

IMHO, not difficult, but very easy to "direct" or send, for comrade is too zealous in his fight against sachets and shelves, not bothering to study the textbook and documentation. :-)

 
Roman.:

IMHO, not difficult, but very easy to "direct" or send, for the comrade is too zealous in the fight against sachets and shelves, not bothering to study the textbook and documentation. :-)

Man, there are virtually no pitfalls ... There are no miracles.
So a man has surrounded himself with these stones and moves them, moves them.
 
Sepulca:


Thank you very much. exactly what is needed)
Reason: