Weekend evening - page 9

 
Aleksey Panfilov:

There are six handles from one indicator on three timeframes.

And the offset of the value to be taken, is already laid down. I copied from them one value at a time.

I got confused by using three handles of one indicator on three timeframes and copying the possible offset interval from them.

If you need to get an indicator value from more than one bar at a time, you should copy the values into an array. Using iATR as an example:

//+------------------------------------------------------------------+
//| Get value of buffers for the iATR                                |
//+------------------------------------------------------------------+
double iATRGet(const int index)
  {
   double ATR[1];
//--- reset error code 
   ResetLastError();
//--- fill a part of the iATR array with values from the indicator buffer that has 0 index 
   if(CopyBuffer(handle_iATR,0,index,1,ATR)<0)
     {
      //--- if the copying fails, tell the error code 
      PrintFormat("Failed to copy data from the iATR indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated 
      return(0.0);
     }
   return(ATR[0]);
  }
//+------------------------------------------------------------------+
//| Get value of buffers for the iATR in the array                   |
//+------------------------------------------------------------------+
bool iATRGetArray(const int start_pos,const int count,double &arr_buffer[])
  {
   bool result=true;
   if(!ArrayIsDynamic(arr_buffer))
     {
      Print("This a no dynamic array!");
      return(false);
     }
   ArrayFree(arr_buffer);
   int       buffer_num=0;          // indicator buffer number 
//--- reset error code 
   ResetLastError();
//--- fill a part of the iATRBuffer array with values from the indicator buffer that has 0 index 
   int copied=CopyBuffer(handle_iATR,buffer_num,start_pos,count,arr_buffer);
   if(copied!=count)
     {
      //--- if the copying fails, tell the error code 
      PrintFormat("Failed to copy data from the iATR indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated 
      return(false);
     }
//---
   return(result);
  }
 
Vladimir Karputov:

If you want to receive an indicator value from more than one bar at a time, you need to copy the values into an array. Using iATR as an example:

Yes, it seems it was a mistake to leave the arrays I copied to as dynamic. :(

Will check.

 
Aleksey Panfilov:

Yes, it seems to have been a mistake to leave the arrays I copied to as dynamic arrays. :(

I'll check.

I copy only to dynamic arrays! And, before copying, forcibly makeArrayFree. I had problems with static arrays. Since then, only dynamic ones.

 
Vladimir Karputov:

I only copy to dynamic arrays! And before copying, I forceArrayFree. There were problems with static arrays. Since then, only dynamic ones.

Got it. The error is not here.

Here is the Expert Advisor that did not go.

Files:
 
Aleksey Panfilov:

Got it. The mistake is not here.

Here's the expert that didn't go.

ERROR: are you copying ONE value or TWO?

   //---  Используя функцию CopyBuffer, мы копируем по 1 последних новых значения индикаторов в динамические массивы

   if(CopyBuffer(Handle_4P72_L0_1,0,0,200,line1_L0)<0  // || CopyBuffer(Handle_4P72_L0_2,0,0,1,line2_L0)<0   || CopyBuffer(SMA_Handle_00,0,0,1,SMA_L0)<0
   || CopyBuffer(Handle_4P72_L1_1,0,0,200,line1_L1)<0  // || CopyBuffer(Handle_4P72_L1_2,0,0,1,line2_L1)<0   || CopyBuffer(SMA_Handle_01,0,0,1,SMA_L1)<0
   || CopyBuffer(Handle_4P72_L2_1,0,0,200,line1_L2)<0  // || CopyBuffer(Handle_4P72_L2_2,0,0,1,line2_L2)<0   || CopyBuffer(SMA_Handle_02,0,0,1,SMA_L2)<0
   ||  CopyTime(_Symbol,_Period,0,1,New_Time)<0)
 
Vladimir Karputov:

ERROR: are you copying ONE value or TWO?

In this EA (it is different in date) I have tried three handels and two hundred values.

 

If you are ready to make robots for MT5, I can begin to give you ideas. I simulate conditions in TS-Lab, but I would like to trade them on MT5 in auto-mode.

If there are no problems with the test, I will describe the trading logic. The first will probably be this one.

 
Vladimir Karputov:

I'll start with small portions.

As soon as there are"Seconds before closing the signal candle" seconds before the current candle closes, we calculate the average size of"Number of candles for calculating the average candle size" candles. If the current candle exceeds the average size by"Current candle: excess body size, percents" - we open a position with the volume"Lots" and place a pending limit order with the volume"Lots" *"Multiplication factor" from the opening price at the distance of"Pending limit level: percent of the height of the current candle" in percent of the signal candle height.

Is this correct?


I need time to remember what I made there :) I'm getting a cold because of the draughts. It's both angry and funny: to catch a fever in summer and catch a cold :)

 
Vladimir Karputov:

It takes time to remember what I've been up to :) And then, as if on purpose, there are draughts and the result is a cold. It's both funny and angry: to catch a fever and catch a cold in the summer :)

Feel better.

 
Vladimir Karputov:

I only copy to dynamic arrays! And before copying, I forceArrayFree. There were problems with static arrays. Since then, only dynamic ones.

Oh, come on... I don't have a problem with static ones either. It depends on what we're talking about, though. In the indices, yes, dynamic ones are better, if there is no desire to manage the buffer and catch errors. But in owls there is no difference, in fact.

Reason: