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

 

Hello programming guru

Can you please tell me how to draw a rectangle filled with the background colour in the upper left corner with a small indentation (for aesthetics) on top of the chart and under the text displayed by the expert?

Thanks in advance

 
if(!trend)
      {

      (if ((Close[i] - Open[i]) >= i_sizeOfSequentialCorrectionBar * pt)     // Если бар соответствует требуемым признакам..
          cnt++;                                                                     // .. прибавим 1 к счётчику

      if (Close[i] < Open[i])                                                        // Если бар, не соответствует основному признаку..
          cnt = 0;   
      }
      else
      {
      ...
      }
 
Guys, where can you download a library of sound notifications. i.e. to play a voice like "Buy position closed at takeprofit". so it can be played in PlaySound("Buy_close_tp.wav");
 
YOUNGA:

it's the same... To describe it too, just for a different situation.
 
You can either drive or drive by car! If you pass the trend variable as a numerical value, you can multiply the difference by +1 or -1 for example (I wouldn't do that)
 
CYBOPOB:

Isn't that it?

Artem, don't mind writing the code, will you? Or give me that thing you got in your hand and I'll end this misery...

Nah, live a little longer... :) Let's break your code in private, in order not to litter the forum.
 
tCynik:

Question about the operation of the tester: Afterrunning a test, you change the parameters (dates, currency pair, timeframe), re-run the test - it runs, but when it is over the information in the tabs like "chart" and "report" does not change at all - everything remains from the previous test. The saved report also turns out to be old. What is the reason and how to fix it? Maybe there is some function to reset the results?

I've read the manual, articles, searched the forum - I haven't encountered any mentions of such a problem...


It shouldn't be like this, maybe you have "Optimisation" checked?
 
Sepulca:

This shouldn't be the case, maybe you have "Optimise" ticked?


Oh, that seems to be the case: when running a new test I didn't notice that optimisation was on, thought it wasn't critical. Slightly strange interface solution...

But it's working now, thank you very much!

 
TarasBY:
I haven't dug deep into logic, but something tells me there are some unnecessary calculations. A year and a half ago I was solving the same problem with quotes gathering and forming M1 candlesticks with clear cut at the beginning of the astronomical minute.
If you will be interested, you may take a look at some moments of pure optimization of your code (file). Really, if we seriously talk about optimization, you need to measure the code's runtime. ;)


Now I'm trying a different way entirely from scratch.

Question for Vadim on the mapping. So, uh... Started from scratch. We take the original ticking TF:

int start()
  {  
//----
if(flag == true)
  {
  if(tick.time.local == true)
    {
    time = TimeLocal();
    }
    else{
    time = TimeCurrent();
    }
  if(t < time)
    { 
         t = time; 
    }
    else{ 
         t ++;
    }   

  if(FileSeek(hand1e, fpos, SEEK_SET) == false)
           { 
           error = GetLastError();
           Print("out: error(",error,"): ",ErrorDescription(error));
           flag = false;
           return;
           }
           else{
           bid = MarketInfo(symbol, MODE_BID);
           ask = MarketInfo(symbol, MODE_ASK);
           
                FileWriteInteger(hand1e,    t,   LONG_VALUE);            
                FileWriteDouble (hand1e,  bid, DOUBLE_VALUE);          
                FileWriteDouble (hand1e,  bid, DOUBLE_VALUE);            
                FileWriteDouble (hand1e,  ask, DOUBLE_VALUE);    
                FileWriteDouble (hand1e,  ask, DOUBLE_VALUE);                            
                FileWriteDouble (hand1e, time, DOUBLE_VALUE);                   
      FileFlush       (hand1e);  

      fpos = FileTell (hand1e);
      
      if(tick.chart.update == true)
        {
                  hwnd = WindowHandle(sn, 1);
        if(PostMessageA(hwnd, WM_COMMAND, 0x822c, 0) == false)
          {
          hwnd = 0;
          return;
          }
          PostMessageA(hwnd, MT4InternalMsg, 2, 1);             
          }                  
      } 
  }
//----
   return(0);
  }

In principle, there is a very simple logic: We catch a bidask, form RateInfo, but we put time to Volume and model Time. Now, without worrying about how to simulate Time, we remove simulation completely and do it by standard TOLHCV and before it we put "if more than 0 seconds have passed since last call of start()". If it was less in another branch of the same condition, edit High-Low and increment Volume. In essence it is the same as described above but with cycle completely removed, i.e. we obtain second TF "with gaps" (with missing seconds):

int start(){  
//----
        if(flag){
                bid = MarketInfo(symbol, MODE_BID);
                ask = MarketInfo(symbol, MODE_ASK);
                   
                if(FileSeek(hFile, fpos, SEEK_SET) == false){ 
                        error = GetLastError();
                        Print("out: error(",error,"): ",ErrorDescription(error));
                        flag = false;
                        return;
                }else{
                        if(time==TimeCurrent()){
                                if(bid<bid_prev){
                                        FileSeek(hFile, fpos-32, SEEK_SET);
                                        FileWriteDouble (hFile,  bid, DOUBLE_VALUE);
                                        FileFlush       (hFile);
                                }
                                if(bid<bid_prev){
                                        FileSeek(hFile, fpos-24, SEEK_SET);
                                        FileWriteDouble (hFile,  bid, DOUBLE_VALUE);
                                        FileFlush       (hFile);
                                }
                                vol++;
                                FileSeek(hFile, fpos-8, SEEK_SET);
                                FileWriteDouble (hFile,  vol, DOUBLE_VALUE);
                                FileFlush       (hFile);
                                bid_prev=bid; ask_prev=ask;
                        }else{
                                time=TimeCurrent();
                                vol=1;
                                if(bid<bid_prev){close=bid; open=ask;
                                }else{close=ask; open=bid;}
                                ask_prev=ask; bid_prev=bid;
                                
                                FileWriteInteger(hFile,  time,  LONG_VALUE);
                                FileWriteDouble (hFile,  open, DOUBLE_VALUE);
                                FileWriteDouble (hFile,  bid, DOUBLE_VALUE);
                                FileWriteDouble (hFile,  ask, DOUBLE_VALUE);
                                FileWriteDouble (hFile,  close, DOUBLE_VALUE);
                                FileWriteDouble (hFile,  vol, DOUBLE_VALUE);
                                FileFlush       (hFile);
                                fpos = FileTell (hFile);
                        }
                        if(tick.chart.update == true){
                                hwnd = WindowHandle(sn, 1);
                                if(PostMessageA(hwnd, WM_COMMAND, 0x822c, 0) == false){
                                        hwnd = 0;
                                        return;
                                }
                                PostMessageA(hwnd, MT4InternalMsg, 2, 1);             
                        }            
                } 
        }
   return(0);
}

Also left the bullish-bearish grading completely off. Worth the gamble? Let's check, put GetTickCount() with shrinking to this variant and to the initial one from the owner, run them simultaneously on one chart, look at the log:

16:14:56 Сек.тф с проп. AUDUSD,M1: 0
16:14:56 Тик.тф AUDUSD,M1: 0
16:14:56 Сек.тф с проп. AUDUSD,M1: 0
16:14:56 Тик.тф AUDUSD,M1: 0
16:14:56 Сек.тф с проп. AUDUSD,M1: 0
16:14:57 Тик.тф AUDUSD,M1: 0
16:14:57 Сек.тф с проп. AUDUSD,M1: 0
16:14:58 Тик.тф AUDUSD,M1: 0
16:14:58 Сек.тф с проп. AUDUSD,M1: 0
16:14:58 Тик.тф AUDUSD,M1: 0
16:14:58 Сек.тф с проп. AUDUSD,M1: 0
16:14:58 Тик.тф AUDUSD,M1: 0
16:14:58 Сек.тф с проп. AUDUSD,M1: 0
16:15:00 Тик.тф AUDUSD,M1: 0
16:15:00 Сек.тф с проп. AUDUSD,M1: 0
16:15:00 Тик.тф AUDUSD,M1: 0
16:15:00 Сек.тф с проп. AUDUSD,M1: 0
16:15:04 Тик.тф AUDUSD,M1: 0
16:15:04 Сек.тф с проп. AUDUSD,M1: 0
16:15:04 Тик.тф AUDUSD,M1: 0
16:15:04 Сек.тф с проп. AUDUSD,M1: 0
16:15:05 Тик.тф AUDUSD,M1: 0
16:15:05 Сек.тф с проп. AUDUSD,M1: 0
16:15:05 Тик.тф AUDUSD,M1: 0
16:15:05 Сек.тф с проп. AUDUSD,M1: 0
16:15:05 Тик.тф AUDUSD,M1: 0
16:15:05 Сек.тф с проп. AUDUSD,M1: 0
16:15:06 Тик.тф AUDUSD,M1: 0
16:15:06 Сек.тф с проп. AUDUSD,M1: 0
16:15:07 Тик.тф AUDUSD,M1: 0
16:15:07 Сек.тф с проп. AUDUSD,M1: 0
16:15:08 Тик.тф AUDUSD,M1: 0
16:15:08 Сек.тф с проп. AUDUSD,M1: 0
16:15:08 Тик.тф AUDUSD,M1: 0
16:15:08 Сек.тф с проп. AUDUSD,M1: 0
16:15:09 Тик.тф AUDUSD,M1: 0
16:15:09 Сек.тф с проп. AUDUSD,M1: 0
16:15:09 Тик.тф AUDUSD,M1: 0
16:15:09 Сек.тф с проп. AUDUSD,M1: 0
16:15:09 Тик.тф AUDUSD,M1: 16
16:15:09 Сек.тф с проп. AUDUSD,M1: 0
16:15:10 Тик.тф AUDUSD,M1: 0
16:15:10 Сек.тф с проп. AUDUSD,M1: 16
16:15:11 Тик.тф AUDUSD,M1: 0
16:15:11 Сек.тф с проп. AUDUSD,M1: 0
16:15:11 Тик.тф AUDUSD,M1: 0
16:15:11 Сек.тф с проп. AUDUSD,M1: 0
16:15:12 Тик.тф AUDUSD,M1: 0
16:15:12 Сек.тф с проп. AUDUSD,M1: 15
 

as expected. Tick - original, seconds with gaps - modified. Now form an auxiliary array before time=TimeCurrent():

Δt=TimeCurrent()-time;
Σ=Σ+Δt;
ArrayResize(ind, Σ);
for(; i<Σ; i++) ind[i]=iBars(sn, 1);
GlobalVariableSet("final", i);
time=TimeCurrent();

This is in the code of the seconds tf. For the EA that will be hovering on the secondtf itself, the values of TOLHCV x seconds ago can then be obtained as ind[GlobalVariableGet("final")]-ind[GlobalVariableGet("final")-x]+1, if of course this array is somehow passed. So, let's use mapping:

//в шапке
#import "SharedMemoryMT4.dll"
        int MemoryCreate(int nArea, string sPrefixArea, int hFileUser, int nIndex, string sName, int nSize);
        bool MemoryWriteInt(int nArea, string sPrefixArea, int nIndex, string sName, int nStartByte, int nValue);
        bool MemoryCloseHandle(int nArea, string sPrefixArea, int hMemory);
#import
//в инит
hMapping=MemoryCreate(1, "", NULL, -1, "ind", 60*GlobalVariableGet("ADXBars"));
//в деинит
MemoryCloseHandle(1, "", hMapping);
//в старт вместо 
for(; i<Σ; i++) MemoryWriteInt(1, "", -1, "ind", i, iBars(sn, 1));//ind[i]=iBars(sn, 1);

We write a test script that will hover over the seconds and read theTOLHCV values x seconds ago (not the candlesticks):

#property show_inputs
#import "SharedMemoryMT4.dll"
   int MemoryOpen(int nArea, string sPrefixArea, int nIndex, string sName);
   int MemoryReadInt(int nArea, string sPrefixArea, int nIndex, string sName, int nStartByte);
#import
extern int x;//сколько секунд назад с данного момента прикрепления смотрим значения TOLHCV

int init()
  {
   MemoryOpen(1, "", -1, "ind");
   return(0);
  }
int start()
  {
   //MemoryReadInt(1, "", -1, "ind", i) это ind[i], GlobalVariableGet("final") это последний элемент в массиве, а ф-ла выглядит так: n=ind[final]-ind[final-x]+1
   int n=MemoryReadInt(1, "", -1, "ind", GlobalVariableGet("final"))-MemoryReadInt(1, "", -1, "ind", GlobalVariableGet("final")-x)+1;
   Alert(TimeToStr(TimeCurrent(),TIME_SECONDS), ": Time=", TimeToStr(Time[n], TIME_SECONDS), ", Open=", Open[n], ", High=", High[n], ", Low=", Low[n], ", Close=", Close[n], ", Volume=", Volume[n]);
   return(0);
  }

We run the seconds timeframe. On initialization, a window will be displayed

Ошибка в методе "Utils::Memory::Mapping::Create()".
В файловом отображении ""
не выделена память при отсутствии дескриптора пользовательского файла.

There are 58.572 times in the log

10:45:42 SandyEw7-2.4 EURUSD,M1: function 'MemoryWriteInt' call from dll 'SharedMemoryMT4.dll' critical error c0000005 at 02CA05A3.
...
10:48:43 SandyEw7-2.4 EURUSD,M1: function 'MemoryWriteInt' call from dll 'SharedMemoryMT4.dll' critical error c0000005 at 02CA05A3.

and at deinitialization it shows a window

В методе "MT4::Memory::SearchIndexOrHandle()" не установлен параметр для поиска в области памяти терминала.

Well deinitializatsii it later, I put the script - alert once. I override MemoryCreate and MemoryCloseHandle, nothing appears (the script keeps the alert), the log

10:54:55 PrintForSec sec_EURUSD,M1 inputs: x=8; 
10:54:56 PrintForSec sec_EURUSD,M1: initialized
10:54:56 PrintForSec sec_EURUSD,M1: Alert: 09:55:05: Time=00:00:00, Open=0, High=0, Low=0, Close=0, Volume=0

10:55:36 PrintForSec sec_EURUSD,M1 inputs: x=2; 
10:55:37 PrintForSec sec_EURUSD,M1: initialized
10:55:38 PrintForSec sec_EURUSD,M1: Alert: 09:55:46: Time=00:00:00, Open=0, High=0, Low=0, Close=0, Volume=0

- and that's it. So, logically speaking, I'm using calls in wrong order or declaring them incorrectly. My operating system is WinXP. Vadim, at least tell me which direction to go.

Reason: