Download MetaTrader 5

Spread Average - page 2

To add comments, please log in or register
raven.chrono
324
raven.chrono  
RaptorUK:
But you still don't need to use RefreshRates(),  Bid and Ask are never going to be out of date in that code.



Thank you so much.... It is really a big help for me...
whroeder1
17125
whroeder1  
raven_chrono:
I would like to ask if the formula that i used to compute the average of spread per tick is:
Average=(Ask-Bid)/Tick

Why not just use a EMA

Not tested, not compiled

int start(){
    #define ALPHA 0.0001
    double spread = (Ask-Bid) / pips2dbl;
    static double spreadAve; spreadAve += (spread - spreadAve) * ALPHA;

    #define PM    5.0         // PowerMean 5 is close enough to infinity
    static double spreadMax;  // https://en.wikipedia.org/wiki/Power_mean
    double pm = MathPow(spreadMax, PM); pm += (MathPow(spread, PM) - pm) * ALPHA;
    spreadMax = MathPow(pm, 1./PM)

    static double spreadMin; 
    pm = MathPow(spreadMin, -PM); pm += (MathPow(spread, -PM) - pm) * ALPHA;
    spreadMin = MathPow(pm, -1./PM)
Not tested, not compiled
In an indicator spreadAve, spreadMin, spreadMax would be replaced by buffers[0].
raven.chrono
324
raven.chrono  
WHRoeder:

Why not just use a EMA

Not tested, not compiled

Not tested, not compiled
In an indicator spreadAve, spreadMin, spreadMax would be replaced by buffers[0].

Thank you for your reply i hope you can help me also on how to apply it on an indicator. can you lend me some codes?



tnx...

whroeder1
17125
whroeder1  
raven_chrono: how to apply it on an indicator.
Since there are no slaves here, you have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt and the nature of your problem.
raven.chrono
324
raven.chrono  
WHRoeder:
Since there are no slaves here, you have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt and the nature of your problem.


#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1  Black
#property indicator_color2  White
#property indicator_color3  Red
#property indicator_color4  Yellow

#property indicator_width2  1
#property indicator_width3  1
#property indicator_width4  1

//---- indicator buffers
double SpreadBuffer[];
double MaxBuffer[];
double MinBuffer[];
double AveBuffer[];

int init()
  {
   SetIndexBuffer(0,SpreadBuffer);
   SetIndexBuffer(1,MaxBuffer);
   SetIndexBuffer(2,MinBuffer);
   SetIndexBuffer(3,AveBuffer);
   
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   
   IndicatorDigits(0);
   IndicatorShortName("Spread");
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   SetIndexLabel(3,NULL);
   
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
   SetIndexEmptyValue(3,0.0);
   
   
   return(0);
  }
int deinit()
  {
   Comment("");
   return(0);
  }

int start()
  {
    int counted_bars=IndicatorCounted();
     double pm;
    #define ALPHA 0.0001
    #define PM    5.0         // PowerMean 5 is close enough to infinity    
    
     if(counted_bars>0) 
     counted_bars--;
     MessageBox(DoubleToStr(Bars-counted_bars,0));
   for(int i=0;i<(Bars-counted_bars);i++)
   {

    double spread = (Ask-Bid); // pips2dbl;
    static double spreadAve; spreadAve += (spread - spreadAve) * ALPHA;


    static double spreadMax;  // http://en.wikipedia.org/wiki/Power_mean
    pm = MathPow(spreadMax, PM); pm += (MathPow(spread, PM) - pm) * ALPHA;
    spreadMax = MathPow(pm, 1./PM);

    static double spreadMin; 
    pm = MathPow(spreadMin, -PM); pm += (MathPow(spread, -PM) - pm) * ALPHA;
    spreadMin = MathPow(pm, -1./PM);
    Comment(spreadAve,spreadMax,spreadMin);
    SpreadBuffer[i]=spreadAve;
    MaxBuffer[i]=spreadMax;
    MinBuffer[i]=spreadMin;
    
   }    
   return(0);
  }

This is what ive done so far but nothing happens...
whroeder1
17125
whroeder1  
  1.   SetIndexStyle(1,DRAW_HISTOGRAM);
       SetIndexStyle(2,DRAW_HISTOGRAM);
       SetIndexStyle(3,DRAW_HISTOGRAM);
    Don't complicate things until you get it working. Use lines
  2. //   IndicatorDigits(0);
    
    Don't complicate things until you get it working.
  3. //   SetIndexEmptyValue(1,0.0);
    //   SetIndexEmptyValue(2,0.0);
    //   SetIndexEmptyValue(3,0.0);
    
    Don't complicate things until you get it working.
  4. //     if(counted_bars>0) 
    //     counted_bars--;
    
    Contradictory information on IndicatorCounted() - MQL4 forum
  5. //     MessageBox(DoubleToStr(Bars-counted_bars,0));
    
    Indicators can NOT wait
  6.  for(int i=0;i<(Bars-counted_bars);i++)
       {
    
        double spread = (Ask-Bid); // pips2dbl;
     :
    Why are computing a new spread for every bar. Compute it once per tick.
       for(int i=0;i<(Bars-counted_bars);i++)
       {
    
        AveBuffer[i]=spreadAve;
        MaxBuffer[i]=spreadMax;
        MinBuffer[i]=spreadMin;
        
       }    
       return(0);
    

  7.   SpreadBuffer[i]=spreadAve;
        MaxBuffer[i]=spreadMax;
        MinBuffer[i]=spreadMin;
    SpreadBuffer is no draw? you meant AveBuffer
  8. Since you are not initializing the statics they start at zero and slowly increase. So you see zero. What does
        static double spreadMin;
        pm = MathPow(spreadMin, -PM)
    do? It computes 1/(min ^^ pm) but min is initially zero so you get a hidden divide by zero. Indicator stops, you see nothing.
        double spread = (Ask-Bid); // pips2dbl;
        static double spreadAve=0.0002; spreadAve += (spread - spreadAve) * ALPHA;
    
    
        static double spreadMax=0.0003;  // https://en.wikipedia.org/wiki/Power_mean
        pm = MathPow(spreadMax, PM); pm += (MathPow(spread, PM) - pm) * ALPHA;
        spreadMax = MathPow(pm, 1./PM);
    
        static double spreadMin=0.0001; 
        pm = MathPow(spreadMin, -PM); pm += (MathPow(spread, -PM) - pm) * ALPHA;
        spreadMin = MathPow(pm, -1./PM);
    

  9. The comment is for your debugging. For indicators I suggest using this instead:
    //{Log
    // send information to OutputDebugString() to be viewed and logged by
    // SysInternal's DebugView (free download from microsoft) This is ideal for
    // debugging as an alternative to Print(). The function will take up to 10
    // stringa (or numeric) arguments to be concatenated into one debug message.
    //}
    #import "kernel32.dll"
       void     OutputDebugStringA(string msg);
    #import
    void     Log(string s1, string s2="", string s3="", string s4="", string s5="",
             string s6="", string s7="", string s8="", string s9="", string s10=""){
       if(IsDllsAllowed()){
          string out  = WindowExpertName() +": "
                                           +s1 +s2 +s3 +s4 +s5 +s6 +s7 +s8 +s9 +s10;
          OutputDebugStringA(out);
    }  }
    

mzm
5
mzm  

Hi guys.How can i find MAX spread that Alpari uses on every currency pairs? I wanna modify my orders and i need to know

max spread .Of course there is a link in myalpari that min spreads have been written.But min spreads aren't important.How can i find that?

Simon Gniadkowski
Moderator
18058
Simon Gniadkowski  
mzm:

Hi guys.How can i find MAX spread that Alpari uses on every currency pairs? I wanna modify my orders and i need to know

max spread .Of course there is a link in myalpari that min spreads have been written.But min spreads aren't important.How can i find that?

Wait till next weekend and you will get some idea of the max spreads.
12
To add comments, please log in or register