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

 
palomnik:

//-----------------------------------------------------------------------------+
//Kim Respect and respect !!! |
//+----------------------------------------------------------------------------+

This was undoubtedly the most stressful part of the code))))

Okay. I don't understand a thing. I got the second TF up and running. Everything should be running like clockwork. But it doesn't. No, it's working, but it's not as expected. Checked it a thousand times. I do not see any syntactic or algorithmic errors myself. Let me try to explain. I'm attaching the full code. So:

Δtime=TimeCurrent()-time;//перестраховка на случай, если TimeCurrent() во время выполнения цикла изменится
switch(Δtime){
  case 0 ://если секунда не прошла
    AccumulatorOfTicks(false);//заносим в массив-накопитель
    break;
  case 1 ://если прошла ОДНА секунда после последнего тика
    WriteBar();//по предыдущему тику рисуем свечу
    AccumulatorOfTicks(true);//и ловим текущий тик
    break;
  default://если прошло НЕСКОЛЬКО секунд после последнего тика
    WriteBar();//по предыдущему тику рисуем свечу
    Δtime--; time++;//уменьшаем разницу на единицу, т.к. свечу уже нарисовали
    while(Δtime!=0) WriteDash();//и рисуем прочерки по кол-ву пропущ. сек. минус один
    AccumulatorOfTicks(true);//ловим текущий тик
}

In the beginning of start() I put a handler for the number of seconds passed since the last start(). Repeated sections were moved to user-defined functions. The new value time=TimeCurrent() is assigned there, in user functions.

void AccumulatorOfTicks(bool AtFirst){
        if (AtFirst){
                ArrayResize(bid, 1);//урезаем использованные массивы
                ArrayResize(ask, 1);
                i=0;//обнуляем счётчик тиков в секунду
                time=TimeCurrent();//приводим счётчик времени к текущему
        }else{
                ArrayResize(bid, i+1);
                ArrayResize(ask, i+1);
                i++;
        }
        bid[i]=MarketInfo(symbol, MODE_BID);
        ask[i]=MarketInfo(symbol, MODE_ASK);
        if (bid[i]==ask[i]) Alert("from accumulator: bid=ask");
}

The function works in two modes: in the first branch, AtFirst=true, it only catches a tick and pre-zeroes the array-storage, while in the second branch, AtFirst=false, it works exactly as a tick store. That is, we either zero out and truncate the drive and catch the bid-ask in a zero cell, or lengthen the drive and catch the bid-ask. Alert was set only for debugging purpose. I will describe the condition of zeroing of the accumulator further on.

void WriteBar(){
        if(FileSeek(hand1e, fpos, SEEK_SET) == false){//перемещаем указатель на новую позицию, которую мы запомнили в FileTell
                //проверяем, переместилось-не переместилось, это я убрал, т.к. к вопросу не относится.
        }else{
                FileWriteInteger(hand1e,  time,   LONG_VALUE);//TimeCurrent()
                FileWriteDouble (hand1e,  bid[0], DOUBLE_VALUE);//Open[]
                FileWriteDouble (hand1e,  bid[ArrayMaximum(bid)], DOUBLE_VALUE);//High[]
                FileWriteDouble (hand1e,  ask[ArrayMinimum(ask)], DOUBLE_VALUE);//Low[]
                FileWriteDouble (hand1e,  ask[ArraySize(ask)-1], DOUBLE_VALUE);//Close[]
                FileWriteDouble (hand1e,  ArraySize(ask), DOUBLE_VALUE);//Volume[]
                FileFlush       (hand1e);
                fpos = FileTell (hand1e);//запоминаем позицию записи в файле
                if(ArraySize(ask)==2) Alert(StringConcatenate(TimeToStr(TimeCurrent(), TIME_SECONDS), " - volume = ", ArraySize(ask)));
                if(bid[0]==ask[ArraySize(ask)-1]) Alert(StringConcatenate(TimeToStr(TimeCurrent(), TIME_SECONDS), " - bid=ask, Ticks = ", ArraySize(ask)));
                /*Необходимое пояснение. Хотя код рассчитан в т.ч. на тени свечей (т.е. независимыми от Open и Close
                 High и Low), в реальности их на чарте не будет, т.к. в секунде максимум 2 тика, три тика в секунде
                я ещё не встречал. Поэтому в массиве из двух элементов (т.е. двух тиков)
                один будет максимумом, другой минимумом, - и невольно совпадать с Open и Close.*/
        }
}

The function of 'drawing' the candle (adding a candle to .hst opened in the autonomous chart). Similarly - I put alerts for debugging. The first alert signals at two caught ticks in one second (array size is equal to two, and in idea the volume should be equal to two), while the second one signals at bit equal to ack in the caught tick (similar alert in drive: but they work non-synchronously for some reason), and the volume of candlestick. This is all in theory, in fact, when entered into file (by alert), for example, two (or 0x00 00 00 00 00 00 00 40, double 2.0) it somehow still turns out to be one (0x00 00 00 00 00 00 F0 3F, double 1.0 in BigEndian format). I usually override that alert in the drive, it beeps often, I work with these two.

void WriteDash(){
        if(FileSeek(hand1e, fpos, SEEK_SET) == false){//перемещаем указатель на новую позицию, которую мы запомнили в FileTell
                //аналогично убрал, т.к. к вопросу не относится.
        }else{//ставим прочерк на Close[0]
                Δtime--; time++;
                FileWriteInteger(hand1e,  time,   LONG_VALUE);//TimeCurrent()
                FileWriteDouble (hand1e,  ask[ArraySize(ask)-1], DOUBLE_VALUE);//Open[]
                FileWriteDouble (hand1e,  ask[ArraySize(ask)-1], DOUBLE_VALUE);//High[]
                FileWriteDouble (hand1e,  ask[ArraySize(ask)-1], DOUBLE_VALUE);//Low[]
                FileWriteDouble (hand1e,  ask[ArraySize(ask)-1], DOUBLE_VALUE);//Close[]
                FileWriteDouble (hand1e,  0, DOUBLE_VALUE);//Volume[]
                FileFlush       (hand1e);
                fpos = FileTell (hand1e);//запоминаем позицию записи в файле
        }
}

The function "draws" a dash in case there was no tick in what second. It works according to the following algorithm:

Δtime=0: catch (copy) ticks.

Δtime=1: Draw a candlestick on the tick that was caught before, then catch the tick (with a preliminarily zeroed accumulator).

Δtime>1: Draw a candle on the tick caught before, draw dashes on the Close[0] line in the amount ofΔtime-1, catch a tick (with preliminarily zeroed accumulator). In all cases the accumulator should be zeroed when a candle is already drawn on it and it means that the accumulator is not needed anymore. This happens whenΔtime>0.

Let's run it through:

With the arrow I have drawn the moments where the bid is supposedly equal to the asc and the volume should be supposedly equal to one. I did not capture the bottom with volumes, you can't see anything there anyway, it's shallow. But they are all level, i.e. either zero or one, none goes up to two (although the alert is signalling). Two ticks per second - still at a mouse hover ironically shows volume = 1, and the bid is equal to asku also ironically shows volume = 0. Why? I understand that somewhere is an error, but most likely I do not notice the error, or look in the wrong place. I am attaching the code, I've commented out my part of the code well, checked indents everywhere, removed inluders, just selected functions to be used, so that it would compile faster. The only one remark - it doesn't work offline, i.e. with TimeLocal, unlike original tick collector, because I've written in if(tickTimeLocal==true) there from the scratch (as I didn't need it much). I tried to translate it into Expert Advisor following Taras' advice - candlesticks are not shown in autonomous chart (but current quote's line is moving well).

Files:
fif.ta.mq4  18 kb
 
artmedia70:

your slippers.

You should get a spoiler from the administration. I've started noticing that uncommented footwear doesn't become less footwear for some reason))
 

Hello

Here's a question. Let's say today is Monday. I need to know the closing price on Friday. I need to know the closing price on Friday.

iClose(NULL, Period_D1, 1)
I asked this question because I see the Saturday and Sunday bars in the Strategy Tester. I have not traded on these days. Above written line is the closing price on Friday or Sunday?
 
gince:

Hello

Here's a question. Let's say today is Monday. I need to know the closing price on Friday. Can I write

I got this question because in the Strategy Tester I see bars on Saturday and Sunday. I did not trade on those days. Above written line gives the closing price on Friday or Sunday?

Give me Friday's price! If the server closes no later than 24.00 on Friday and starts no earlier than 0.00 after Sunday!

Use the DailyPivotPoints indicator!

 

Nah, I don't understand it at all. Clearly already writing

                switch(ArraySize(ask)){
                 case 0: FileWriteDouble(hand1e,  0.0, DOUBLE_VALUE); Alert(StringConcatenate(TimeToStr(TimeCurrent(), TIME_SECONDS), " 0")); break;
                 case 1: FileWriteDouble(hand1e,  1.0, DOUBLE_VALUE); Alert(StringConcatenate(TimeToStr(TimeCurrent(), TIME_SECONDS), " 1")); break;
                 case 2: FileWriteDouble(hand1e,  2.0, DOUBLE_VALUE); Alert(StringConcatenate(TimeToStr(TimeCurrent(), TIME_SECONDS), " 2")); break;
                 default: Alert("!!!!! - ", ArraySize(ask));
                }

At the alerts equal to 2, I take the indicator off the minutes, I drag the mouse over the candlestick... Volume=1.

Looked RateInfo in hst through FileInsight (like debugger), I think maybe there int, but not double in Volume - no, same-double...

 

Good evening.

Thanks for the reply to my question))

Please tell me if I open a Buy order like this OrderSend (Symbol(),OP_BUY,Lot,Ask,3,0,0, "Buy",0,0,Green);

If it is a sell orderOrderSend (Symbol(),OP_SELL,Lot,Ask,3,0,0, "Sell",0,0,Red);


is the difference blue or does it need to change the red colour as well? i.e. where OP_BUY is the Bid price

where OP_SELL has the Ask price

I also wanted to check if my order hasn't changed and I didn't want to change it, so why is it OK in the Strategy Tester, but in the REAL "Error when opening order 129" - please, help!

 
ed3sss:

Good evening.

Thank you for answering my question))

Please tell me if I open a Buy order like this OrderSend (Symbol(),OP_BUY,Lot,Ask,3,0,0, "Buy",0,0,Green);

If it is a sell orderOrderSend (Symbol(),OP_SELL,Lot,Ask,3,0,0, "Sell",0,0,Red);

is the difference blue or does it need to change the red colour as well? i.e. where OP_BUY is the Bid price

where OP_SELL has the Ask price

I also wanted to check if my order hasn't changed and I didn't want to change it, so why all went well in the Strategy Tester and in the Demo, but I got an error of 129 when I tried to open it in the REAL Market?

If you open Buy, on Asc, if Sell on Bid! And close the other way round!
 
ed3sss:

Good evening.

Thank you for answering my question))

Can you tell me if I open a Buy order like this OrderSend (Symbol(),OP_BUY,Lot,Ask,3,0,0, "Buy",0,0,Green);

If it is a sell orderOrderSend (Symbol(),OP_SELL,Lot,Ask,3,0,0, "Sell",0,0,Red);

...
On Buy:
OrderSend (Symbol(),OP_BUY,Lot,Ask,3,0,0,"Покупка",0,0,Green);

Sell:

OrderSend (Symbol(),OP_SELL,Lot,Bid,3,0,0,"Продажа",0,0,Red);

I recommend updating quotes before sending an order:

RefreshRates();
OrderSend (...);
And note that your slipage =3, for 4-digit quotes will be =3 pips and for 5-digit quotes it will calculate as 0.3 pips. So if your EA is going to work with 5-digit quotes, then set slipage = 30.
 
gyfto:

Nah, I don't understand it at all. Obviously I'm already writing

At the alerts equal to 2, I take the indicator off the minutes, I drag the mouse over the candlestick... Volume=1.

Looked RateInfo in hst through FileInsight (like debugger), I think maybe there int, but not double in Volume - no, same-double...

Looked at your code.... You got it all too confused))))

I don't quite understand, why we need to accumulate ticks, because it is enough to store in memory (or even not to store, because the current bar must be written in HST - otherwise the chart won't be updated) parameters of the current bar - six numbers TOHLCV, and to update them as needed at tick receipt, and to make bar cutoff at specified condition(TimeCurrent()-O>1).

Try to rework the code this way, it will be reduced by 8 times, I guarantee it (I've checked it:)

 
I tried to check one indicator, I put the numbers on the chart but they don't change, I'll try to put it in another way, I need the attached indicator to fix the price as a cross that stands on a zigzag or alert or print but it freezes on the connection.
Files:
Reason: