[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 704

 
ToLik_SRGV:

Also Odysseus, in the previous example you had it like this:

And now it's like this:

You didn't delete anything, or am I imagining it?
here's the orinal code
 IndicatorBuffers(7);
   SetIndexBuffer(0, MACDBuffer);
   SetIndexBuffer(1, SignalBuffer);
   SetIndexBuffer(2, FastEMABuffer);
   SetIndexBuffer(3, SlowEMABuffer);
   SetIndexBuffer(4, SignalEMABuffer);
   SetIndexBuffer(5, Buffer1);
   SetIndexBuffer(6, Buffer2);
   SetIndexStyle(0, DRAW_NONE);
   SetIndexStyle(1, DRAW_LINE,EMPTY);
  SetIndexStyle(2, DRAW_LINE,EMPTY,2 );
   SetIndexStyle(3, DRAW_NONE,EMPTY,2);
   SetIndexStyle(4, DRAW_NONE);
   SetIndexStyle(5, DRAW_HISTOGRAM,EMPTY, 2);
   SetIndexStyle(6, DRAW_HISTOGRAM,EMPTY, 2);
   SetIndexDrawBegin(0, SlowEMA);
   SetIndexDrawBegin(1, SlowEMA);
   IndicatorShortName("ZeroLag MACD Colored(" + FastEMA + "," + SlowEMA + "," + SignalEMA + ")");
   SetIndexLabel(0, "MACD");
   SetIndexLabel(1, "Signal");
   SetIndexLabel(5, "MACD");
   SetIndexLabel(6, "MACD");
 
odiseif:
here's the final code
Sorry, my mistake. ..... is the original.
//+------------------------------------------------------------------+
//|                                                 ZeroLag MACD.mq4 |
//|                                                               RD |
//|                                                 marynarz15@wp.pl |
//| Colored by SVK © 2009.                                           |
//+------------------------------------------------------------------+
#property copyright "RD"
#property link      "marynarz15@wp.pl"
//----
#property indicator_separate_window
#property  indicator_buffers 7
#property indicator_color1 Black
#property indicator_color2 Blue
#property indicator_color3 Black
#property indicator_color4 Black
#property indicator_color5 Black
#property indicator_color6 Lime
#property indicator_color7 Red

//---- input parameters
extern int FastEMA = 12;
extern int SlowEMA = 26;
extern int SignalEMA = 9;

//---- buffers
double MACDBuffer[];
double SignalBuffer[];
double FastEMABuffer[];
double SlowEMABuffer[];
double SignalEMABuffer[];

double Buffer1[];
double Buffer2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(7);
   SetIndexBuffer(0, MACDBuffer);
   SetIndexBuffer(1, SignalBuffer);
   SetIndexBuffer(2, FastEMABuffer);
   SetIndexBuffer(3, SlowEMABuffer);
   SetIndexBuffer(4, SignalEMABuffer);
   SetIndexBuffer(5, Buffer1);
   SetIndexBuffer(6, Buffer2);
   SetIndexStyle(0, DRAW_NONE);
   SetIndexStyle(1, DRAW_LINE,EMPTY);
   SetIndexStyle(2, DRAW_NONE);
   SetIndexStyle(3, DRAW_NONE);
   SetIndexStyle(4, DRAW_NONE);
   SetIndexStyle(5, DRAW_HISTOGRAM);
   SetIndexStyle(6, DRAW_HISTOGRAM);
   SetIndexDrawBegin(0, SlowEMA);
   SetIndexDrawBegin(1, SlowEMA);
   IndicatorShortName("ZeroLag MACD Colored(" + FastEMA + "," + SlowEMA + "," + SignalEMA + ")");
   SetIndexLabel(0, "MACD");
   SetIndexLabel(1, "Signal");
   SetIndexLabel(5, "MACD");
   SetIndexLabel(6, "MACD");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   double prev,current;
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0) 
       return(-1);
   if(counted_bars > 0) 
       counted_bars--;
   limit = Bars - counted_bars;
   double EMA, ZeroLagEMAp, ZeroLagEMAq;
   for(int i = 0; i < limit; i++)
     {
       FastEMABuffer[i] = 100.0*iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i);
       SlowEMABuffer[i] = 100.0*iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, i);
     }
   for(i = 0; i < limit; i++)
     {
        EMA = iMAOnArray(FastEMABuffer, Bars, FastEMA, 0, MODE_EMA, i);
        ZeroLagEMAp = FastEMABuffer[i] + FastEMABuffer[i] - EMA;
        EMA = iMAOnArray(SlowEMABuffer, Bars, SlowEMA, 0, MODE_EMA, i);
        ZeroLagEMAq = SlowEMABuffer[i] + SlowEMABuffer[i] - EMA;
        MACDBuffer[i] = ZeroLagEMAp - ZeroLagEMAq;
        FastEMABuffer[i] = 0.0;
        SlowEMABuffer[i] = 0.0;
     }
   for(i = 0; i < limit; i++)
       SignalEMABuffer[i] = iMAOnArray(MACDBuffer, Bars, SignalEMA, 0, MODE_EMA, i);
   for(i = 0; i < limit; i++)
     {
       EMA = iMAOnArray(SignalEMABuffer, Bars, SignalEMA, 0, MODE_EMA, i);
       SignalBuffer[i] = SignalEMABuffer[i] + SignalEMABuffer[i] - EMA;
       SignalEMABuffer[i] = 0.0;
     }
//---- dispatch values between 2 buffers
   bool up=true;
   for(i=limit-1; i>=0; i--)
     {
      current=MACDBuffer[i];
      prev=MACDBuffer[i+1];
      if(current>prev) up=true;
      if(current<prev) up=false;
      if(!up)
        {
         Buffer2[i]=current;
         Buffer1[i]=0.0;
        }
      else
        {
         Buffer1[i]=current;
         Buffer2[i]=0.0;
        }
     }     
   return(0);
  }
//+------------------------------------------------------------------+
 
ToLik_SRGV:

Sergey, I didn't fully understand what exactly you changed, because at the address you provided you need to register to see the source code of CCI Filter.
I found only one error, iWPR has no applied_price parameter, so it is correct:


All, thanks, now rrrrrr works!!!

 
ToLik_SRGV:

In principle, there is no difference.
Try my function, it's simple enough, pass the "medj," and the desired trawl as parameters.
This function should be called at start at any place, as long as it starts with every tick.

Obviously, the orders must have different sliders.

Roger:
I get it, you define a variable ro at the beginning of the function, but you don't assign it anywhere, i.e. it's 0.

ToLik_SRGV, thanks, it still doesn't work correctly. It means I have the wrong place to hide the problem. Thanks anyway, I'll figure it out on my own.Roger,
 

As usual here ))) As usual to the good people )))

What's the problem, I can't figure it out. Problems with global variables. I do it in indicator code:

string Global="Global"; //имя глобальной переменной
int param; // параметр глобальной переменной
int init()
  {
  GlobalVariablesDeleteAll(NULL); 
   return(0);
  }
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  { //привожу простой пример
  double bar1= iMA(Symbol(),PERIOD_M5,13,0,MODE_SMMA,PRICE_TYPICAL,0);
  double bar2= iOpen(Symbol(),PERIOD_M5,0);
   if (bar1>bar2){ param = 1; GlobalVariableSet(Global,param); }
   if (bar1<bar2){ param = 2; GlobalVariableSet(Global,param); } 

//----
   return(0);
  }

Then I try to get the value of a global variable from an Expert Advisor with this code

string Global="Global";  
int param;

int start()
  {
  int i= GlobalVariableSet(Global,param);
  Print (i);   // Здесь он мне и выводит всякую лабуду вида : 1279217736


   return(0);
  }
What am I doing wrong? I was supposed to get either 1 or 2 parameter values, but I got ..... And why do I have to write the name and variable again at the beginning of EA code? They seem to exist as globals, but the compilation does not work without them.
 

Can I open two BUY/SELL positions simultaneously?

I tried it - I wrote simple code which opens BUY and SELL positions simultaneously, connected to EUR/USD in real time, they seem to open.

But that was a demo account and strategy tester, what about in real time, will my brokerage company mind?

I have never tried it before, I don't think that I started this kind of experiment.

 
Infinity:...
You need another function to read the value of global variables:)))
int i= GlobalVariableGet(Global);
 
Lim1:

Can I open two BUY/SELL positions simultaneously?

I tried it - I wrote simple code which opens BUY and SELL positions simultaneously, connected to EUR/USD in real time, they seem to open.

But that was a demo account and strategy tester, what about in real time, will my brokerage company mind?

I have never tried it before, I don't think that I started this kind of thing in real trading.

Open... while they let you... :)
In general - ask the support team of your DC
 
ToLik_SRGV:
In order to read the value of global variables we need another function :)))

So clear, looking in the book and not seeing, works thanks! Moving on) with questions. All about the same global variables. I have added the following condition to the indicator:

string EUR="EURUSD"; //имя глобальной переменной
string GBP="GBPUSD"; //имя глобальной переменной
string valuta="";
int param; // параметр глобальной переменной
int init()
  {
  GlobalVariablesDeleteAll(NULL); 
   return(0);
  }
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  { string symb = Symbol();  //Здесь узнаю на какой валюте стоит индикатор
    
    if (symb==EUR) {valuta=EUR;}   // здесь сравнивая ,в переменную занощу имя глобальной переменной
    if (symb==GBP) {valuta=GBP;}   // которую следует использовать
  //привожу простой пример
  double bar1= iMA(Symbol(),PERIOD_M5,13,0,MODE_SMMA,PRICE_TYPICAL,0);
  double bar2= iOpen(Symbol(),PERIOD_M5,0);
   if (bar1>bar2){ param = 1; GlobalVariableSet(valuta,param); }   // а здесь присваиваю параметр глобальной переменной
   if (bar1<bar2){ param = 2; GlobalVariableSet(valuta,param); } 
   return(0);
  }

I want to define which global variable should be assigned a value, depending on what currency the indicator is based on.

I understand that in the global variable GlobalVariableSet(valuta,param), the name (valuta) should contain the value assigned to it above

call again the global variable in the Expert Advisor code

string valuta="valuta";

int i= GlobalVariableGet(valuta); // but I don't get the value, .... i.e. i get 0. May be it's impossible to change the global variable name this way?

I think I've got it figured out - it turns out that I can't call a global variable with this name, but if I register the string name GlobalVariableGet("EURUSD") it works).

 

Firstly, from the help

double GlobalVariableGet( string name)

Returns the value of the existing global variable or 0 in case of an error. Call GetLastError() to get error information.


Can you see the contents of the GV, but can't retrieve it?

Reason: