SymbolInfoTick() doubt - page 3

 

I've read the entire thread and I can't find this.


This code print a line with ask, bid, volume ...., on log for every tick. I need to get the volume grouped by prices the candle has run.


For example if the low is 1.001 and the high is 1.009, I need to print, when every candle closes, the ask and bid volume for 1.001, 1.002, 1.003 ... and so on.


Thank you

 
israelhernando: I've read the entire thread and I can't find this. This code print a line with ask, bid, volume ...., on log for every tick. I need to get the volume grouped by prices the candle has run. For example if the low is 1.001 and the high is 1.009, I need to print, when every candle closes, the ask and bid volume for 1.001, 1.002, 1.003 ... and so on.

Then do as you have described:

  1. Either collect the tick data (SymbolTickInfo) in real time over a candle into an array, or copy all the tick data (CopyTicksRange) for a candle once it closes.
  2. Sort the tick data in the array by price.
  3. Group by each price and sum the volume by price grouping.
You can reverse the order of steps 2 and 3 or combine them, depending on how you go about processing the tick data volume.
     

    thank you for the response.

    The SymbolTickInfo, doesn't give me the correct info, if I compare with a real indicator.

    I've tried with this

    MqlTick tick_struct;
    
       if (SymbolInfoTick(Symbol(), tick_struct))
       {
           Print("" + DoubleToString(tick_struct.bid, 5)
             + "\t" + DoubleToString(tick_struct.ask, 5)
             + "\t" + DoubleToString(tick_struct.last, 5)
             + "\t" + tick_struct.volume_real 
             + "\t" + tick_struct.volume
             + "\t" + tick_struct.time
             + "\t" + tick_struct.flags
          );
       }
    


    And the CopyTicksRange function, throws and  4401 error .... (I don't know how get the last candle only)


       MqlTick m_tick[];
       
       int res= CopyTicksRange(Symbol(),m_tick,COPY_TICKS_ALL);
       if (res<0)
          int error = GetLastError();
    
     
    israelhernando: The SymbolTickInfo, doesn't give me the correct info, if I compare with a real indicator (yucluster for example). I've tried with this. And the CopyTicksRange function, throws and  4401 error .... (I don't know how get the last candle only)
    1. "doesn't give me the correct info" has no meaning for us. We cannot read your mind. Show us the printed output and explain why you think it is wrong.
    2. For "CopyTicksRange", set a start and end time, equivalent to the opening and closing time of the candle you wish to analyse.
     

    With this code:

       MqlTick tick_struct;
    
       if (SymbolInfoTick(Symbol(), tick_struct))
       {
           Print("" + tick_struct.bid
             + "\t" + tick_struct.ask
             + "\t" + tick_struct.last
             + "\t" + tick_struct.volume_real 
             + "\t" + tick_struct.volume
             + "\t" + tick_struct.time
             + "\t" + tick_struct.flags
          );
       }
    

    I get this. 


    Bid/Ask/Last/Volume_Real/Volume/Time/Flags
    1873.7 1873.8 1873.8 1.0 1 2021.06.03 17:41:34 6
    1873.7 1873.8 1873.8 1.0 1 2021.06.03 17:41:34 6
    1873.8 1873.9 1873.8 3.0 3 2021.06.03 17:41:34 6
    1873.8 1873.9 1873.8 3.0 3 2021.06.03 17:41:34 6
    1873.8 1873.9 1873.8 3.0 3 2021.06.03 17:41:34 6
    1873.8 1874.0 1873.9 1.0 1 2021.06.03 17:41:37 4
    1873.8 1874.0 1873.9 1.0 1 2021.06.03 17:41:37 4
    1873.8 1874.0 1873.9 1.0 1 2021.06.03 17:41:37 4
    1873.8 1874.0 1873.9 1.0 1 2021.06.03 17:41:37 4
    1873.9 1874.0 1873.9 1.0 1 2021.06.03 17:41:37 2
    1873.8 1874.0 1873.9 1.0 1 2021.06.03 17:41:37 2
    1873.9 1874.0 1873.9 1.0 1 2021.06.03 17:41:38 2
    1873.8 1873.9 1873.9 1.0 1 2021.06.03 17:41:40 6
    1873.8 1873.9 1873.9 1.0 1 2021.06.03 17:41:40 6
    1873.8 1873.9 1873.9 1.0 1 2021.06.03 17:41:40 6
    1873.8 1873.9 1873.9 1.0 1 2021.06.03 17:41:40 6
    1873.8 1873.9 1873.9 1.0 1 2021.06.03 17:41:40 6
    1873.8 1873.9 1873.9 1.0 1 2021.06.03 17:41:40 6
    1873.9 1874.0 1873.9 1.0 1 2021.06.03 17:41:40 6
    1873.9 1874.0 1873.9 1.0 1 2021.06.03 17:41:40 6
    1873.9 1874.0 1874.0 2.0 2 2021.06.03 17:41:41 56
    1873.9 1874.0 1874.0 1.0 1 2021.06.03 17:41:46 56
    1873.9 1874.0 1874.0 1.0 1 2021.06.03 17:41:46 56
    1873.9 1874.0 1874.0 1.0 1 2021.06.03 17:41:51 56
    1873.9 1874.0 1873.9 1.0 1 2021.06.03 17:41:53 88

    1873.9 1874.0 1874.0 1.0 1 2021.06.03 17:41:57 56

    Then I group by price (ask/bid or last) and I sum the volumes (the volume and volume_real are the same)


    The problem is, I don't know if the data I get with my function is the real data of future. I'm using a futures broker.


    Thank you very much

     
    israelhernando: With this code:I get this. Then I group by price (ask/bid or last) and I sum the volumes (the volume and volume_real are the same) The I compare with "..." indicator and the values I get aren't the same. The problem is, I don't know if the data I get with my function is the real data of future. I'm using a futures broker, the same I using "..." indicator.

    Sorry, but I have no idea of how that "..." indicator works, and we are not allowed to discuss Market products on the forum.

     

    OK, I've updated my last post.


    The problem is, Is the correct way to obtain the buy and sell volume? Is there another way?


    Thank you

     
    israelhernando: OK, I've updated my last post. The problem is, Is the correct way to obtain the buy and sell volume? Is there another way? Thank you

    Both ways I have mentioned are valid! But the CopyTicks method will be the most accurate, because OnTick can miss out on tick events if they happen very quickly before the function returns.

    There is also the possibility to analyse the data via the Order Book which holds information on a volume in a different way. Maybe the "..." indicator was using the Order Book data instead of the Tick data.

    However, I have no experience with the Order Book, so maybe someone else can comment on that.

     

    ok, one question more


    with CopyTicks  how can I set a begin and end date, with the last 30 days, for example. I don't know how convert date to milliseconds.


    Thanks

     
    israelhernando: ok, one question more with CopyTicks  how can I set a begin and end date, with the last 30 days, for example. I don't know how convert date to milliseconds. Thanks

    Why did you not read the documentation or hit the F1 key in MetaEditor. The answer is right there in the parameter list - "from_sc" and "to_msc" where ( milliseconds = seconds * 1000 )!

    CopyTicksRange

    The function receives ticks in the MqlTick format within the specified date range to ticks_array. Indexing goes from the past to the present meaning that a tick with the index 0 is the oldest one in the array. For tick analysis, check the flags field, which shows what exactly has changed.

    int  CopyTicksRange(
       const string     symbol_name,           // symbol name
       MqlTick&         ticks_array[],         // tick receiving array
       uint             flags=COPY_TICKS_ALL,  // flag that defines the type of the ticks that are received
       ulong            from_msc=0,            // date, starting from which ticks are requested
       ulong            to_msc=0               // date, up to which ticks are requested
       );


    from_msc

    [in]   The date, from which you want to request ticks. In milliseconds since 1970.01.01. If the from_msc parameter is not specified, ticks from the beginning of the history are sent. Ticks with the time >= from_msc are sent.

    to_msc

    [in]   The date, up to which you want to request ticks. In milliseconds since 01.01.1970. Ticks with the time <= to_msc are sent. If the to_msc parameter is not specified, all ticks up to the end of the history are sent.

    Reason: