Help Please Changing A Line Of Code

To add comments, please log in or register
beto_gauer
181
beto_gauer  

Hi there guys.

Can someone help me and tell me how I can change this indicator to use ONLY 1minute timeframe data in it´s calculation, regardless of timeframe it is loaded in?

Those are pascal willain effective volume formula, but the code is not correct because Pascal uses 1 minute data for the calculation of effective volume. I knew there was something wrong with the lines being plotted, I looked into the formula in metaeditor and I can see the code only uses the term "bars", there is no reference to timeframe anywhere.

William Roeder
20208
William Roeder  
beto_gauer: Can someone help me and tell me how I can change this indicator
Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help
          urgent help.

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum

beto_gauer
181
beto_gauer  

I was analyzing the code of another indicator that has multi time frame selection (so the indicator can plot 1h data on 5m chart, for example), as far as I could tell, there was only one line of code that was giving the instruction:


extern ENUM_TIMEFRAMES BTF = PERIOD_CURRENT;


Then I copied it and pasted on the code of the indicator that I want to use 1minute timeframe data only in it´s calculation:

#property copyright "Copyright © 2018, Gehtsoft USA LLC"
#property link      "http://fxcodebase.com"
#property version   "1.0"
#property strict

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Green
#property indicator_label1 "Plot"

extern ENUM_TIMEFRAMES BTF = PERIOD_CURRENT;    (HERE IS WHERE I PASTED THE LINE OF CODE FROM THE OTHER INDICATOR)
 
input double PI = 0;  

double Plot[];
double Raw[];
string IndicatorName;
string IndicatorObjPrefix;

string GenerateIndicatorName(const string target)
{
   string name = target;
   int try = 2;
   while (WindowFind(name) != -1)
   {
      name = target + " #" + IntegerToString(try++);
   }
   return name;
}
 

 

int init()
{
   IndicatorName = GenerateIndicatorName("Cumulative Effective Volume");
   IndicatorObjPrefix = "__" + IndicatorName + "__";
   IndicatorShortName(IndicatorName);
   IndicatorBuffers(2);
   IndicatorDigits(Digits);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, Plot);
  
   SetIndexBuffer(1, Raw);
   return(0);
}

int deinit()
{
   ObjectsDeleteAll(ChartID(), IndicatorObjPrefix);
   return(0);
}

int start()
{
   if (Bars <= 1) 
      return 0;
   int ExtCountedBars = IndicatorCounted();
   if (ExtCountedBars < 0) 
      return -1;


   int limit = Bars - 2;
   int i = limit;
 
   double HighPrice;
   double LowPrice;
 
   while (i >= 0)
   { 

    HighPrice=MathMax(High[i],Close[i+1]);
    LowPrice=MathMin(Low[i],Close[i+1]);   
   
   
     
       
          if((HighPrice-LowPrice)!= 0)
          {
      Raw[i]=  ((Close[i]-Close[i+1] +PI)/(HighPrice-LowPrice +PI )) *Volume[i];
          }
          else
          {
          Raw[i]=0;
          }
   
       
      i--;
   } 
   
   i = limit;
   
   while (i >= 0)
   { 

     
      if (Close[i]!=Close[i+1])
          {
      Plot[i]= Plot[i+1]+  Raw[i];
      }
          else
          {
         Plot[i]=Plot[i+1];
          }
       
      i--;
   } 
   return 0;
}


I pressed to compile and it did it with no errors. Well I loaded the indicator on a chart and for my surprise there was another option on indicator settings to choose the timeframe, but it does not matter what timeframe you choose on the settings, nothing happens, the data plotted keeps the same.

William Roeder
20208
William Roeder  
beto_gauer: I pressed to compile and it did it with no errors. Well I loaded the indicator on a chart and for my surprise there was another option on indicator settings to choose the timeframe, but it does not matter what timeframe you choose on the settings, nothing happens, the data plotted keeps the same.

Of course nothing changed - all you did was add an unused input variable.

You're going to have to convert your bar index to the timeframe (BTF) index and stop using the predefined variables (current TF only.)
          Don't mix apples and oranges.

To add comments, please log in or register