Help to update code

 

Hi at all.

This is my first try to add some changes to an code. But I really dont konw how to do this. I tryed some things, but without success.

I downloaded this code from the net. It works. But I want to see the input propertys in the indicator options window. There is ony the Alert true/false option.

The Indicator have some other functions I want to be able to change in that window also.

This I want to add:

extern int Price=0;
extern int Mode=1;
extern int ShortPeriod=5;
extern int LongPeriod=13;

I already added it, and see in the opions window, but when I cange the values, nothing happens...

This is the code I want to add the input settings:

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Aqua
#property indicator_levelcolor LightGray
#property indicator_levelstyle STYLE_DOT
#property indicator_level1 8
#property indicator_level2 -8
#property indicator_level3 0
#property indicator_minimum -20
#property indicator_maximum 20
extern bool Alerts_On = false;

//---- buffers
double IND[];
bool EntryFlag,TradeFlag;
datetime CurrBar;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorShortName("Separation");
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,IND);
//----

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
     int limit;
     int counted_bars=IndicatorCounted();
     if(counted_bars<0) return(-1);
     if(counted_bars>0) counted_bars-=10;
     limit=Bars-counted_bars;

     int Price=0;
     int Mode=1;
     int ShortPeriod=5;
     int LongPeriod=13;
         
     for(int i=0; i<limit; i++)
       {
        IND[i]=(iMA(NULL,0,ShortPeriod,0,Mode,Price,i)-iMA(NULL,0,LongPeriod,0,Mode,Price,i)) / Point;
        
        if (Time[0] != CurrBar) {
         bool NewBar = true;
         CurrBar = Time[0]; }
        else NewBar = false;
        
        if (NewBar)
        {
        if (MathAbs(IND[0]) > 8 && EntryFlag)
         TradeFlag = true;
        else if (MathAbs(IND[0]) < 8)
         EntryFlag = true;
        
        if (Alerts_On && EntryFlag && TradeFlag && NewBar) {
         Alert("Separation - Potential Trade Signal (M",Period()," ",Symbol(),")"); // ** Alerts By Omelette **
         TradeFlag = false;
         EntryFlag = false; }
        }
       
       }
  //----
    return(0);
  }
//+------------------------------------------------------------------+


This I tryed, but the changes have no affect to the indicator at all.

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Aqua
#property indicator_levelcolor LightGray
#property indicator_levelstyle STYLE_DOT
#property indicator_level1 8
#property indicator_level2 -8
#property indicator_level3 0
#property indicator_minimum -20
#property indicator_maximum 20
extern bool Alerts_On = false;
extern int Price=0;
extern int Mode=1;
extern int ShortPeriod=5;
extern int LongPeriod=13;

//---- buffers
double IND[];
bool EntryFlag,TradeFlag;
datetime CurrBar;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorShortName("Separation");
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,IND);
//----

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
     int limit;
     int counted_bars=IndicatorCounted();
     if(counted_bars<0) return(-1);
     if(counted_bars>0) counted_bars-=10;
     limit=Bars-counted_bars;

     int Price=0;
     int Mode=1;
     int ShortPeriod=5;
     int LongPeriod=13;
         
     for(int i=0; i<limit; i++)
       {
        IND[i]=(iMA(NULL,0,ShortPeriod,0,Mode,Price,i)-iMA(NULL,0,LongPeriod,0,Mode,Price,i)) / Point;
        
        if (Time[0] != CurrBar) {
         bool NewBar = true;
         CurrBar = Time[0]; }
        else NewBar = false;
        
        if (NewBar)
        {
        if (MathAbs(IND[0]) > 8 && EntryFlag)
         TradeFlag = true;
        else if (MathAbs(IND[0]) < 8)
         EntryFlag = true;
        
        if (Alerts_On && EntryFlag && TradeFlag && NewBar) {
         Alert("Separation - Potential Trade Signal (M",Period()," ",Symbol(),")"); // ** Alerts By Omelette **
         TradeFlag = false;
         EntryFlag = false; }
        }
       
       }
  //----
    return(0);
  }
//+------------------------------------------------------------------+


Many thanks for help.

It would be nice to understand, how this works.

With kind regards

Robert

 

above the for loop there are these 4 boys :

     int Price=0;
     int Mode=1;
     int ShortPeriod=5;
     int LongPeriod=13;
         
     for(int i=0; i<limit; i++)

which override whatever your inputs are

If you place 

#property strict

on top of mql4 code it will inform you of things like that

 
Lorentzos Roussos #:

above the for loop there are these 4 boys :

which override whatever your inputs are

If you place 

on top of mql4 code it will inform you of things like that

Thank you for the answer. I have really no experience in coding. I added the #property strict on top of the code, and got this result.


I try to understand but I have no knowlede about coding. Can you maybe modify the code for me? I dont know how to do that right.

 
Tesla963 #:

Thank you for the answer. I have really no experience in coding. I added the #property strict on top of the code, and got this result.


I try to understand but I have no knowlede about coding. Can you maybe modify the code for me? I dont know how to do that right.

Sorry , i meant in general if you add the strict property . For now you can just delete the 4 highlighted lines above the for loop . 

 
Lorentzos Roussos #:

Sorry , i meant in general if you add the strict property . For now you can just delete the 4 highlighted lines above the for loop . 

Thank you so much :) Now it works as I wish.

And I understand a little bit more...


Thank you!

 
Tesla963 #:

Thank you so much :) Now it works as I wish.

And I understand a little bit more...


Thank you!

Cheers