Tick by milsec. Hard help please

 

Hi All,

This works really good attached to 1M chart.

It gives us the number of tick per min and then it calculates an average between 2 ticks in milliseconds.


Any one willing to change this to get the average fresher?

If we could get the average updated with a parameter in sec.

For example: Parameter = 30 (sec)

So it does the same calculation for the last 30 sec... and every second it refresh the data.


The point is to be alerted as soon as an average is :

< X milsec --> Price action on market.

> X milsex --> Low volatility on market.


Whatever your trading style is... it's good to know if market is as we required. (speed or low).


Please help me... I'm not skilled enough to write it down but I will understand if I see it : )




#property indicator_chart_window
//------------------------------
int j, start, cnt;
double ar;
string S;
//--------   
int init()
 {
   return(0);
 }
//+------------------------------------------------------------------+
int deinit()
 {
   Comment("");
   ObjectDelete("txt");  
   return(0);
 }
//+------------------------------------------------------------------+
int start()
 {
   if (Period() != 1)
    {
                Comment("Not a right Period!!! It should be M1");
                return(0);      
         }
   string t[60];  
   //==========
   if(Seconds() == 0)
    {
      cnt = 0;
      ar = 0;
    }
   for(j = 0; j <= 59; j++)
    {
      if(Minute() == j)
       {
         if(start == 0) start = GetTickCount();
         if(GetTickCount() - start > 0) 
          {
            cnt = cnt + 1;
            ar = ar + (GetTickCount() - start);
            start = 0;
          }
         if(cnt > 0)  t[j] = "Minute: " + DoubleToStr(j, 0) + "  Ticks #: "+  DoubleToStr(cnt, 0) + "    Avg= " + DoubleToStr(ar/cnt, 2) + " milliseconds" + "\n";  
       }
    }        
   //------
   Comment(t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9], t[10], t[11], t[12], t[13], t[14], t[15], t[16], t[17], t[18], t[19],
           t[20], t[21], t[22], t[23], t[24], t[25], t[26], t[27], t[28], t[29], t[30], t[31], t[32], t[33], t[34], t[35], t[36], t[37], t[38], t[39],
           t[40], t[41], t[42], t[43], t[44], t[45], t[46], t[47], t[48], t[49], t[50], t[51], t[52], t[53], t[54], t[55], t[56], t[57], t[58], t[59]);
   //------
   ObjectCreate("txt",OBJ_TEXT,0,TimeCurrent()- 60, Close[0] + 8 * Point);   
   ObjectSetText("txt", DoubleToStr(Minute(), 0), 16, "Times New Roman", Orange);
   ObjectMove("txt", 0, TimeCurrent()- 60, Close[0] + 8 * Point);
   //------
   return(0);
 }
//+------------------------------------------------------------------+


 
FrenchyTrader:

Hi All,

This works really good attached to 1M chart.

It gives us the number of tick per min and then it calculates an average between 2 ticks in milliseconds.

No, it doesn't . . . it takes no account of the tick you miss.
 

We don't miss any ticks as long as the EA is attcahed to the chart.

I may not understand what you are talking about?

 
And this is without taking into account, ticks that never reaches the platform/EA.
 

Ok... well even if some ticks are lost that we can consider as part of the process.

We can still count the "tick received" / min and calculate an average in milsec between thoses ticks. ?

 
FrenchyTrader:

Ok... well even if some ticks are lost that we can consider as part of the process.

We can still count the "tick received" / min and calculate an average in milsec between thoses ticks. ?

Working from the left to the right, the small red bar is the start of the ticks for a M5 bar, each red/lime bar is a missed tick, about 80% across to the right you will see another small red bar, that signifies the end of the ticks for the M5 bar, there are 25 missed ticks. When there is this many missed ticks how do you expect to get any meaningful measures ?

The tick chart at the bottom runs independently of the X axis time scale . . .

 

Thank you for the information, So here we have an exemple to talk about.

Let's say we are in a "normal" trading conditons... around 1 tick/sec.

So if my terminal is ignoring 25 ticks/5min => that's only 8% missed over 5 min. Honestly, I don't think any EA on MT4 are suffering from execution because Startfunction() is too slow to process so missing too much ticks to execute script.


Getting such an info (average millisec) should work even if we missed some ticks... Look at Calendar eco for a big news, then check average millisec. I don't know how many ticks we may missed...but suddenly there is enough to send an alert because average can be under 300 meaning more than 3 ticks/sec.


So the measure isn't 100% pure, I admit... but sufficient to alert as soon as price action occurs on market.


I hope you see my point... This should be an awesome indicator for any scalping EA... because then, if it has to open an order while we get a tight average we can:

increase/reduce lotsize

Increase/reduce tp

....


The code above works.. but it's not sufficient;

if a price action starts @ 10H01 : 45s... I will not be notified... because the average will include all ticks occured from the first second of minute1 and so the average is too much impacted from it.

Then minute 2: I need to wait X ticks, to have a reliable average.

=> So I can missed the info...or receiving it 1 min or 2 later... while this time market may have already jumps 15 to 20 pips.


So having counted the ticks from the last 20 or 30 sec refreshing every sec... should be much better.. (Even if there are missing ticks.. it doesn't really matter... we will be alerted) : )


Is this too hard to code?


cheers

 
FrenchyTrader:
I'm not sure what you're looking for, perhaps something like below helps?
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Property SaveAs Script
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#property show_inputs
extern string Symbolx="";
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void init(){
    if(Symbolx==""){Symbolx=Symbol();}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void start(){
    while(!IsStopped()){
        static int SavLstSecond=0;
        static int RuningVolCount=0;
        static int SavLstVolCnt=0;
        
        int CurSecond=TimeSeconds(TimeCurrent());
        if(CurSecond!=SavLstSecond){
            static int StartTickCount=0;
            StartTickCount=GetTickCount();
            RuningVolCount=0;
        }
        
        int CurVolCount=iVolume(Symbolx,PERIOD_M1,0);
        if(SavLstVolCnt>CurVolCount) SavLstVolCnt=0;
        
        if(SavLstVolCnt>0
        && GetTickCount()<StartTickCount+1000){
            RuningVolCount+=(CurVolCount-SavLstVolCnt);
        }

        if(StartTickCount<1)
            Comment(Symbolx+": Waiting For New Second To Begin...");
        if(StartTickCount>0)
            Comment(Symbolx+": Ticks Per Second="+RuningVolCount);
        
        SetGlobalVariables(); static int LstFresherTme=0;
        int Trigger=GlobalVariableGet("GV_SetOffAltCnt");
        int Fresher=GlobalVariableGet("GV_DelaySeconds");
        if(RuningVolCount>=Trigger){
            if(GetTickCount()>LstFresherTme+(Fresher*1000)){
                Alert(Symbolx+": Ticks Per Second == "+RuningVolCount);
                LstFresherTme=GetTickCount();
        }   }
        
        SavLstSecond=CurSecond;
        SavLstVolCnt=CurVolCount;
        Sleep(1); RefreshRates();
    }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void deinit(){
    GlobalVariableDel("GV_SetOffAltCnt");
    GlobalVariableDel("GV_DelaySeconds");
    Comment("");
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void SetGlobalVariables(){
    if(!GlobalVariableCheck("GV_SetOffAltCnt"))
        GlobalVariableSet("GV_SetOffAltCnt",5);
    if(!GlobalVariableCheck("GV_DelaySeconds"))
        GlobalVariableSet("GV_DelaySeconds",30);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

Hi


Thank you Ubzen,


I can almost enjoy the result : )


I see we get for the last second, the number of ticks received by MT4.


Is it possible to have an external paramater in sec that is set up to 30.

So we need to sum all ticks received for the last 30 sec from the current second.

Actually on market, i get 0 tick up to 3 ticks per sec => let's say an average of 1,5 ticks/sec

So for the parameter 30... it should like "EURUSD: Ticks for 30 seconds = 45"


The main measure was the Average in millisec elapsed between 2 ticks. But if it's complicated, I can use the total of ticks for the X parameter time. if it gets > 90 ticks, get alerted.

 
FrenchyTrader:

Is it possible to have an external paramater in sec that is set up to 30.

Yes you can use a GlobalVariable like I did. Or you can use an External Variable like I did.

So we need to sum all ticks received for the last 30 sec from the current second.

Yes I coded this function which tries to sum all Ticks from last 30 seconds and Average them. You'll want to test it :(

void SavCurRunCnt(int RuningVolCount, int SavLstSecond){
    SetGlobalVariables();
    int SecondsForAvg=GlobalVariableGet("GV_NumSecForAvg");
    SecVolCntRay[SavLstSecond]=RuningVolCount;
    int Count=0, SumTicks=0;
    for(int i=SavLstSecond; Count<SecondsForAvg; i--){
        int j=i; if(j<0) j=ArraySize(SecVolCntRay)-i;
        SumTicks+=SecVolCntRay[j];
        Count++;
    }
    if(SumTicks==0) return;
    int AvgMilSecPerTic=(SecondsForAvg*1000) / SumTicks;
    Comment("Average For The Last "+SecondsForAvg+" Seconds="+AvgMilSecPerTic);
}

Actually on market, i get 0 tick up to 3 ticks per sec => let's say an average of 1,5 ticks/sec
So for the parameter 30... it should like "EURUSD: Ticks for 30 seconds = 45"

Well thats really up_to you and what you want to display, You can display the SumTicks : AverageTicks | MilliSeconds Between Ticks... Up to you.

The main measure was the Average in millisec elapsed between 2 ticks. But if it's complicated, I can use the total of ticks for the X parameter time. if it gets > 90 ticks, get alerted.

I just did Because 1_Second=1000 MilliSeconds, should I get 5_Ticks within the same second, then average MilSec between them = 1000/5; I'm not sure if it equates the same thing but thats what I did.

Just some notes.

Your version is Indicator therefore it has little less control with timing, and depends on the frequency of in_coming ticks. Mines a contentious script, therefore the concept of missing ticks is irrelevant. Its checking the tick_count from the broker about every 20 milli_seconds or so.

Anyways, I'm not the fastest coder so I'm hoping you have enough to built your own Indicator or Script. If you're looking for a programmer then check the jobs section.

Reason: