stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Some Coding Help Please
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1074
Page 1 of 1
Author:  s01 [ Sun Nov 18, 2012 10:26 pm ]
Post subject:  Some Coding Help Please

Hi Gang.

I have another little project I'm working on and have run into a wall, and rather than keep banging my head on the table, figured I'd post it here. This section of the forum seems to get more coding questions than the indicator section, so I figured I'd post it here. If it's in the wrong place, let me know and I'll post in the other next time.

OK,

I thought this would be a pretty painless mod to an existing indicator, but no. I am just trying to get some simple numbers along with some text posted on the main chart, in a certain place. This would be incorporated into the main indicator, but 1st I just need to get it to display correctly before attempting that. Trying baby steps as I go along learning.

So what I would like it to display are the Main and Signal numbers along with some simple text when conditions are met, and in x / y coridinates. It would look like this on the screen. along with the change in colors. Trying to get it to work with the ObjectCreate functions.

I'm trying to stay away from making labels as I don't see anyway to convert the numbers from a label.

12.0/17.4/OS or 67.5/86.1/OB or 35.3/45.7/MID

Right now I'm getting this error, but I know it's much more involved than that:
'\end_of_program' - unbalanced left parenthesis

Thanks for the help in advance.

Code: Select all

//+------------------------------------------------------------------+
//|                                          DD_Color Stochastic.mq4 |
//|                                                       mod by s01 |
//+------------------------------------------------------------------+
//|                                             Color Stochastic.mq4 |
//|                                                           mladen |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      ""

#property indicator_separate_window
#property indicator_buffers   8
#property indicator_color1 Magenta
#property indicator_style1 STYLE_DOT
#property indicator_color2 SeaGreen
#property indicator_style2 STYLE_DOT
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_width3 3
#property indicator_width4 3

#property indicator_minimum   0
#property indicator_maximum 100

#property indicator_level5     10  // Added this section // s01
#property indicator_level6     15
#property indicator_level7     85
#property indicator_level8     90


#property indicator_color5 Magenta  // added this section // s01
#property indicator_color6 Magenta
#property indicator_color7 Magenta
#property indicator_color8 Magenta
 


//---- input parameters
//
//    nice setings for trend = 35,10,1
//    Try 8,3,3 for scalp
//

extern string note1  = "Show Screen Text";    // added the next 2 lines // s01
extern bool ShowText = true;
extern string note2  = "Stochastic settings";
extern string note3  = "for trend 35,10,1";
extern string note4  = "for scalp 8,3,3";
extern int       KPeriod     =  8;
extern int       Slowing     =  3;
extern int       DPeriod     =  3;
extern string note5 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int       MAMethod    =   0;
extern string note6 = "0=high/low, 1=close/close";
extern int       PriceField  =   0;
extern string note7 = "overbought level";
extern int       overBought  =  85;
extern string note8 = "oversold level";
extern int       overSold    =  15;


//---- buffers
//
//
//
//
//

double KFull[];
double DFull[];
double Upper[];
double Lower[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
{
      SetIndexBuffer(0,DFull);
      SetIndexBuffer(1,KFull);
      SetIndexBuffer(2,Upper);
      SetIndexBuffer(3,Lower);
      SetIndexLabel(1,"Fast");
      SetIndexLabel(2,NULL);
      SetIndexLabel(3,NULL);
         
         //
         //
         //
         //
         //
         
         DPeriod = MathMax(DPeriod,1);
         if (DPeriod==1) {
               SetIndexStyle(0,DRAW_NONE);
               SetIndexLabel(0,NULL);
            }
         else {
               SetIndexStyle(0,DRAW_LINE); 
               SetIndexLabel(0,"Slow");
            }               
         
         //
         //
         //
         //
         //
         
   string shortName = "DD_Color Stochastic ("+KPeriod+","+Slowing+","+DPeriod+","+maDescription(MAMethod)+","+priceDescription(PriceField);
         if (overBought < overSold) overBought = overSold;
         if (overBought < 100)      shortName  = shortName+","+overBought;
         if (overSold   >   0)      shortName  = shortName+","+overSold;
   IndicatorShortName(shortName+")");
   return(0);
}

//
//
//
//
//

int deinit()
  {

   ObjectDelete("52");            // s01 mod
   ObjectDelete("/OB");
   ObjectDelete("/OS");
   ObjectDelete("/MID");

   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
{
   int    counted_bars=IndicatorCounted();
   int    limit;
   int    i;
   
   
   
   
   if(counted_bars<0) return(-1);
   limit=Bars-counted_bars;
      
   //
   //
   //
   //
   //
   
   for(i=limit; i>=0; i--)
      {
            KFull[i] = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_MAIN,i);
            DFull[i] = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_SIGNAL,i);

            //
            //
            //
            //
            //
                                 
            if (KFull[i] > overBought) { Upper[i] = KFull[i]; Upper[i+1] = KFull[i+1]; }
            else                       { Upper[i] = EMPTY_VALUE;
                                         if (Upper[i+2] == EMPTY_VALUE)
                                             Upper[i+1]  = EMPTY_VALUE; }                            
            if (KFull[i] < overSold)   { Lower[i] = KFull[i]; Lower[i+1] = KFull[i+1]; }                   
            else                       { Lower[i] = EMPTY_VALUE;
                                         if (Lower[i+2] == EMPTY_VALUE)
                                             Lower[i+1]  = EMPTY_VALUE; }                            
      }

// --------------------
   
//+---------------------------------------------------------------------------------------------+
//+                       On Screen Display for use with Daily Data                             +
//+---------------------------------------------------------------------------------------------+

// -------------------- // this section new .. s01

   if (ShowText)
   
      {
                                                                                            //        /*  // for debugging
// -------------------- 

      if (KFull[i] > overBought)
         ObjectCreate("52",0,0,Time[0],0);
     //    ObjectCreate("52", OBJ_TEXT, 0, 0, 0)
         ObjectSet("52",(DoubleToStr,(KFull[i],0)+"/"+DoubleToStr(DFull[i],0);       
     //    ObjectSet("52",(NumberToStr,(KFull[i],0)+"/"+NumberToStr,(DFull[i],0);
         ObjectCreate("52", OBJ_TEXT, 10, "Arial Bold", Red)
         ObjectSetText("52",( +"/OB");  //   ,10,"Arial Bold",Red);
         ObjectSet("52", OBJPROP_XDISTANCE, 180);
         ObjectSet("52", OBJPROP_YDISTANCE, 40);
  
      if (KFull[i] < overSold)       
         ObjectCreate("52",0,0,Time[0],0);
     //    ObjectCreate("52", OBJ_TEXT, 0, 0, 0)
         ObjectSet("52",(DoubleToStr,(KFull[i],0)+"/"+DoubleToStr(DFull[i],0);       
     //    ObjectSet("52",(NumberToStr,(KFull[i],0)+"/"+NumberToStr,(DFull[i],0);
         ObjectCreate("52", OBJ_TEXT, 10, "Arial Bold", Lime)
         ObjectSetText("52",( +"/OS");  //   ,10,"Arial Bold",Lime);
         ObjectSet("52", OBJPROP_XDISTANCE, 180);
         ObjectSet("52", OBJPROP_YDISTANCE, 40);
 
      if (KFull[i] < overBought) + (KFull > overSold)
         ObjectCreate("52",0,0,Time[0],0);
     //    ObjectCreate("52", OBJ_TEXT, 0, 0, 0)
         ObjectSet("52",(DoubleToStr,(KFull[i],0)+"/"+DoubleToStr(DFull[i],0);       
     //    ObjectSet("52",(NumberToStr,(KFull[i],0)+"/"+NumberToStr,(DFull[i],0);
         ObjectCreate("52", OBJ_TEXT, 10, "Arial Bold", Gray)
         ObjectSetText("52",( +"/MID");  //   ,10,"Arial Bold",Gray);
         ObjectSet("52", OBJPROP_XDISTANCE, 180);
         ObjectSet("52", OBJPROP_YDISTANCE, 40);     
                                                                                            //      */  // for debugging 
      } 

   return(0);
}
 
// --------------------  // this is returning this error // '\end_of_program' - unbalanced left parenthesis	

 
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

string priceDescription(int mode)
{
   string answer;
   switch(mode)
   {
      case 0:  answer = "Low/High"    ; break; 
      case 1:  answer = "Close/Close" ; break;
      default: answer = "Invalid price field requested";
                                    Alert(answer);
   }
   return(answer);
}
string maDescription(int mode)
{
   string answer;
   switch(mode)
   {
      case MODE_SMA:  answer = "SMA"  ; break; 
      case MODE_EMA:  answer = "EMA"  ; break;
      case MODE_SMMA: answer = "SMMA" ; break;
      case MODE_LWMA: answer = "LWMA" ; break;
      default:        answer = "Invalid MA mode requested";
                                    Alert(answer);
   }
   return(answer);
}

// ------------------------------------- end ------------------------------------ // 
I could use some help, or at least a push in the right direction.
I left some of my attemps in there with // so you could get an idea of what I've tried so far.

Thanks, s01 / Steve
Author:  SteveHopwood [ Sun Nov 18, 2012 11:06 pm ]
Post subject:  Re: Some Coding Help Please

s01 wrote:Hi Gang.

I have another little project I'm working on and have run into a wall, and rather than keep banging my head on the table, figured I'd post it here. This section of the forum seems to get more coding questions than the indicator section, so I figured I'd post it here. If it's in the wrong place, let me know and I'll post in the other next time.

OK,

I thought this would be a pretty painless mod to an existing indicator, but no. I am just trying to get some simple numbers along with some text posted on the main chart, in a certain place. This would be incorporated into the main indicator, but 1st I just need to get it to display correctly before attempting that. Trying baby steps as I go along learning.

So what I would like it to display are the Main and Signal numbers along with some simple text when conditions are met, and in x / y coridinates. It would look like this on the screen. along with the change in colors. Trying to get it to work with the ObjectCreate functions.

I'm trying to stay away from making labels as I don't see anyway to convert the numbers from a label.

12.0/17.4/OS or 67.5/86.1/OB or 35.3/45.7/MID

Right now I'm getting this error, but I know it's much more involved than that:
'\end_of_program' - unbalanced left parenthesis

Thanks for the help in advance.

Code: Select all

//+------------------------------------------------------------------+
//|                                          DD_Color Stochastic.mq4 |
//|                                                       mod by s01 |
//+------------------------------------------------------------------+
//|                                             Color Stochastic.mq4 |
//|                                                           mladen |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      ""

#property indicator_separate_window
#property indicator_buffers   8
#property indicator_color1 Magenta
#property indicator_style1 STYLE_DOT
#property indicator_color2 SeaGreen
#property indicator_style2 STYLE_DOT
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_width3 3
#property indicator_width4 3

#property indicator_minimum   0
#property indicator_maximum 100

#property indicator_level5     10  // Added this section // s01
#property indicator_level6     15
#property indicator_level7     85
#property indicator_level8     90


#property indicator_color5 Magenta  // added this section // s01
#property indicator_color6 Magenta
#property indicator_color7 Magenta
#property indicator_color8 Magenta
 


//---- input parameters
//
//    nice setings for trend = 35,10,1
//    Try 8,3,3 for scalp
//

extern string note1  = "Show Screen Text";    // added the next 2 lines // s01
extern bool ShowText = true;
extern string note2  = "Stochastic settings";
extern string note3  = "for trend 35,10,1";
extern string note4  = "for scalp 8,3,3";
extern int       KPeriod     =  8;
extern int       Slowing     =  3;
extern int       DPeriod     =  3;
extern string note5 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int       MAMethod    =   0;
extern string note6 = "0=high/low, 1=close/close";
extern int       PriceField  =   0;
extern string note7 = "overbought level";
extern int       overBought  =  85;
extern string note8 = "oversold level";
extern int       overSold    =  15;


//---- buffers
//
//
//
//
//

double KFull[];
double DFull[];
double Upper[];
double Lower[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
{
      SetIndexBuffer(0,DFull);
      SetIndexBuffer(1,KFull);
      SetIndexBuffer(2,Upper);
      SetIndexBuffer(3,Lower);
      SetIndexLabel(1,"Fast");
      SetIndexLabel(2,NULL);
      SetIndexLabel(3,NULL);
         
         //
         //
         //
         //
         //
         
         DPeriod = MathMax(DPeriod,1);
         if (DPeriod==1) {
               SetIndexStyle(0,DRAW_NONE);
               SetIndexLabel(0,NULL);
            }
         else {
               SetIndexStyle(0,DRAW_LINE); 
               SetIndexLabel(0,"Slow");
            }               
         
         //
         //
         //
         //
         //
         
   string shortName = "DD_Color Stochastic ("+KPeriod+","+Slowing+","+DPeriod+","+maDescription(MAMethod)+","+priceDescription(PriceField);
         if (overBought < overSold) overBought = overSold;
         if (overBought < 100)      shortName  = shortName+","+overBought;
         if (overSold   >   0)      shortName  = shortName+","+overSold;
   IndicatorShortName(shortName+")");
   return(0);
}

//
//
//
//
//

int deinit()
  {

   ObjectDelete("52");            // s01 mod
   ObjectDelete("/OB");
   ObjectDelete("/OS");
   ObjectDelete("/MID");

   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
{
   int    counted_bars=IndicatorCounted();
   int    limit;
   int    i;
   
   
   
   
   if(counted_bars<0) return(-1);
   limit=Bars-counted_bars;
      
   //
   //
   //
   //
   //
   
   for(i=limit; i>=0; i--)
      {
            KFull[i] = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_MAIN,i);
            DFull[i] = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_SIGNAL,i);

            //
            //
            //
            //
            //
                                 
            if (KFull[i] > overBought) { Upper[i] = KFull[i]; Upper[i+1] = KFull[i+1]; }
            else                       { Upper[i] = EMPTY_VALUE;
                                         if (Upper[i+2] == EMPTY_VALUE)
                                             Upper[i+1]  = EMPTY_VALUE; }                            
            if (KFull[i] < overSold)   { Lower[i] = KFull[i]; Lower[i+1] = KFull[i+1]; }                   
            else                       { Lower[i] = EMPTY_VALUE;
                                         if (Lower[i+2] == EMPTY_VALUE)
                                             Lower[i+1]  = EMPTY_VALUE; }                            
      }

// --------------------
   
//+---------------------------------------------------------------------------------------------+
//+                       On Screen Display for use with Daily Data                             +
//+---------------------------------------------------------------------------------------------+

// -------------------- // this section new .. s01

   if (ShowText)
   
      {
                                                                                            //        /*  // for debugging
// -------------------- 

      if (KFull[i] > overBought)
         ObjectCreate("52",0,0,Time[0],0);
     //    ObjectCreate("52", OBJ_TEXT, 0, 0, 0)
         ObjectSet("52",(DoubleToStr,(KFull[i],0)+"/"+DoubleToStr(DFull[i],0);       
     //    ObjectSet("52",(NumberToStr,(KFull[i],0)+"/"+NumberToStr,(DFull[i],0);
         ObjectCreate("52", OBJ_TEXT, 10, "Arial Bold", Red)
         ObjectSetText("52",( +"/OB");  //   ,10,"Arial Bold",Red);
         ObjectSet("52", OBJPROP_XDISTANCE, 180);
         ObjectSet("52", OBJPROP_YDISTANCE, 40);
  
      if (KFull[i] < overSold)       
         ObjectCreate("52",0,0,Time[0],0);
     //    ObjectCreate("52", OBJ_TEXT, 0, 0, 0)
         ObjectSet("52",(DoubleToStr,(KFull[i],0)+"/"+DoubleToStr(DFull[i],0);       
     //    ObjectSet("52",(NumberToStr,(KFull[i],0)+"/"+NumberToStr,(DFull[i],0);
         ObjectCreate("52", OBJ_TEXT, 10, "Arial Bold", Lime)
         ObjectSetText("52",( +"/OS");  //   ,10,"Arial Bold",Lime);
         ObjectSet("52", OBJPROP_XDISTANCE, 180);
         ObjectSet("52", OBJPROP_YDISTANCE, 40);
 
      if (KFull[i] < overBought) + (KFull > overSold)
         ObjectCreate("52",0,0,Time[0],0);
     //    ObjectCreate("52", OBJ_TEXT, 0, 0, 0)
         ObjectSet("52",(DoubleToStr,(KFull[i],0)+"/"+DoubleToStr(DFull[i],0);       
     //    ObjectSet("52",(NumberToStr,(KFull[i],0)+"/"+NumberToStr,(DFull[i],0);
         ObjectCreate("52", OBJ_TEXT, 10, "Arial Bold", Gray)
         ObjectSetText("52",( +"/MID");  //   ,10,"Arial Bold",Gray);
         ObjectSet("52", OBJPROP_XDISTANCE, 180);
         ObjectSet("52", OBJPROP_YDISTANCE, 40);     
                                                                                            //      */  // for debugging 
      } 

   return(0);
}
 
// --------------------  // this is returning this error // '\end_of_program' - unbalanced left parenthesis	

 
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

string priceDescription(int mode)
{
   string answer;
   switch(mode)
   {
      case 0:  answer = "Low/High"    ; break; 
      case 1:  answer = "Close/Close" ; break;
      default: answer = "Invalid price field requested";
                                    Alert(answer);
   }
   return(answer);
}
string maDescription(int mode)
{
   string answer;
   switch(mode)
   {
      case MODE_SMA:  answer = "SMA"  ; break; 
      case MODE_EMA:  answer = "EMA"  ; break;
      case MODE_SMMA: answer = "SMMA" ; break;
      case MODE_LWMA: answer = "LWMA" ; break;
      default:        answer = "Invalid MA mode requested";
                                    Alert(answer);
   }
   return(answer);
}

// ------------------------------------- end ------------------------------------ // 
I could use some help, or at least a push in the right direction.
I left some of my attemps in there with // so you could get an idea of what I've tried so far.

Thanks, s01 / Steve
Welcome to the World of Insanity occupied by so many of the rest of us.

Crqpql4 has a neat little trick up its sleeve. It lulls us into a sense of false security by taking us to the cause of so many of the syntax error we make.

So, if we type
if (OrderType() ++ OP_BUY)

it takes us straight to the fact that we have used the wrong operand.

Then it hits us with the real humdinger.

Declare a variable as, say a datetime:
datetime TimeNow;
Type if (datetime != iTime(NULL, 0, 0) {some code}

There is a missing right bracket in the above. If you are lucky and the compiler is in a good mood, then it will whinge that the next function definition is unexpected. If you are unlucky, or the compiler is in a bad mood, then it will take you right to the end of the file and grizzle about some unbalanced parenthesis somewhere that you will never find. Well, maybe not never, but many, many many hours later.

Guess how I know?

I am not going to look at your code - I have enough problems of my own to sort out without trying to take on yours. If you are lucky, George will happen along and sort you out.

What I can say is this: start again with the original file; start making your changes a line at a time; every time (and I really do mean every time) you make a change, do a recompile. This is time-consuming, but nowhere near as time-consuming as trying to find a bloop when you have no idea where it could possibly be.

Hehe. As I ask so often here: guess how I know this to be true? :lol:

:D
Author:  gaheitman [ Sun Nov 18, 2012 11:29 pm ]
Post subject:  Re: Some Coding Help Please

s01 wrote:Hi Gang.

I have another little project I'm working on and have run into a wall, and rather than keep banging my head on the table, figured I'd post it here. This section of the forum seems to get more coding questions than the indicator section, so I figured I'd post it here. If it's in the wrong place, let me know and I'll post in the other next time.
A bunch of your ObjectSet() calls have incorrect parenthesis. For example, you have

Code: Select all

         ObjectSet("52",(DoubleToStr,(KFull[i],0)+"/"+DoubleToStr(DFull[i],0);       
and it should be

Code: Select all

         ObjectSet("52",DoubleToStr(KFull[i],0)+"/"+DoubleToStr(DFull[i],0));       
This command isn't correct either:

Code: Select all

         ObjectSetText("52",( +"/OB");  //   ,10,"Arial Bold",Red);
But I'm not sure what you are trying to do here.

You might want to use an editor that matches parenthesis.

George
Author:  dietcoke [ Mon Nov 19, 2012 12:15 am ]
Post subject:  Re: Some Coding Help Please

s01 wrote:Hi Gang.

I have another little project I'm working on and have run into a wall, and rather than keep banging my head on the table, figured I'd post it here. This section of the forum seems to get more coding questions than the indicator section, so I figured I'd post it here. If it's in the wrong place, let me know and I'll post in the other next time.

OK,

I thought this would be a pretty painless mod to an existing indicator, but no. I am just trying to get some simple numbers along with some text posted on the main chart, in a certain place. This would be incorporated into the main indicator, but 1st I just need to get it to display correctly before attempting that. Trying baby steps as I go along learning.

So what I would like it to display are the Main and Signal numbers along with some simple text when conditions are met, and in x / y coridinates. It would look like this on the screen. along with the change in colors. Trying to get it to work with the ObjectCreate functions.

I'm trying to stay away from making labels as I don't see anyway to convert the numbers from a label.

12.0/17.4/OS or 67.5/86.1/OB or 35.3/45.7/MID

Right now I'm getting this error, but I know it's much more involved than that:
'\end_of_program' - unbalanced left parenthesis

Thanks for the help in advance.


I could use some help, or at least a push in the right direction.
I left some of my attemps in there with // so you could get an idea of what I've tried so far.

Thanks, s01 / Steve

The code for Objects is a bit tricky but having said that you wouldn't be the first to have a problem with Empty4 screen objects

Often, the best learning resource is looking at someone elses code in an existing EA/Indi that does what you are trying to do. Eg.

The code below will give you an idea of how to code a label.

I've put in your objectname to set you off.

Try and apply this to your Indi and post if you are hving continuing issues.

Code: Select all

  
 if ( ObjectFind ( "52") == -1 )
   {
      ObjectCreate  ( "52", OBJ_LABEL, 0, 0, 0 )
      ObjectSet      ( "52", OBJPROP_XDISTANCE, col );
      ObjectSet      ( "52", OBJPROP_YDISTANCE, row );
      ObjectSet      ( "52", OBJPROP_BACK, true );
      ObjectSetText  ( "52","your Text", FontSize, "Font", Color);
   }
   
}
Author:  s01 [ Mon Nov 19, 2012 1:58 am ]
Post subject:  Re: Some Coding Help Please

OK, Progress , Thanks,

I have reviewd my original code and see that it Zero chance of working ... doh

I have rewrote it and can now get text to show up in the proper place.

But, it is still a work in progress. I need to define when the proper text is displayed. Right now with the top - if DFull line is // frontslashed out the display is red. Without the // the display disapears. Even though the code compiles and shows no errors in the journal or experts tabs below.

I think I'm calling the right buffers this time, but not sure. And even though I can get text to display correctly in the proper place, I still would line a way to get the numbers from the signal and main lines to show along with the text.

The overBought and overSold numbers from the settings should be applied along with the colors. Since they are both changeable options, they should change when set different.

Thanks for the help so far, I really do apprecieate it greatly.

Steve

Code: Select all

//+------------------------------------------------------------------+
//|                                          DD_Color Stochastic.mq4 |
//|                                                       mod by s01 |
//+------------------------------------------------------------------+
//|                                             Color Stochastic.mq4 |
//|                                                           mladen |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      ""

#property indicator_separate_window
#property indicator_buffers   8
#property indicator_color1 Magenta
#property indicator_style1 STYLE_DOT
#property indicator_color2 SeaGreen
#property indicator_style2 STYLE_DOT
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_width3 3
#property indicator_width4 3

#property indicator_minimum   0
#property indicator_maximum 100

#property indicator_level5     10  // Added this section // s01
#property indicator_level6     15
#property indicator_level7     85
#property indicator_level8     90


#property indicator_color5 Magenta  // added this section // s01
#property indicator_color6 Magenta
#property indicator_color7 Magenta
#property indicator_color8 Magenta
 


//---- input parameters
//
//    nice setings for trend = 35,10,1
//    Try 8,3,3 for scalp
//

extern string note1  = "Show Screen Text";   
extern bool ShowText = true;
extern string note2  = "Stochastic settings";
extern string note3  = "for trend 35,10,1";
extern string note4  = "for scalp 8,3,3";
extern int       KPeriod     =  8;
extern int       Slowing     =  3;
extern int       DPeriod     =  3;
extern string note5 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int       MAMethod    =   0;
extern string note6 = "0=high/low, 1=close/close";
extern int       PriceField  =   0;
extern string note7 = "overbought level";
extern int       overBought  =  85;
extern string note8 = "oversold level";
extern int       overSold    =  15;


//---- buffers
//
//
//
//
//

double KFull[];
double DFull[];
double Upper[];
double Lower[];
//double overSold(); // 'overSold' - no dll defined for the import function
//double overBought(); // ^^^ same error ^^^

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
{
      SetIndexBuffer(0,DFull);
      SetIndexBuffer(1,KFull);
      SetIndexBuffer(2,Upper);
      SetIndexBuffer(3,Lower);
      SetIndexLabel(1,"Fast");
      SetIndexLabel(2,NULL);
      SetIndexLabel(3,NULL);
         
         //
         //
         //
         //
         //
         
         DPeriod = MathMax(DPeriod,1);
         if (DPeriod==1) {
               SetIndexStyle(0,DRAW_NONE);
               SetIndexLabel(0,NULL);
            }
         else {
               SetIndexStyle(0,DRAW_LINE); 
               SetIndexLabel(0,"Slow");
            }               
         
         //
         //
         //
         //
         //
         
   string shortName = "DD_Color Stochastic ("+KPeriod+","+Slowing+","+DPeriod+","+maDescription(MAMethod)+","+priceDescription(PriceField);
         if (overBought < overSold) overBought = overSold;
         if (overBought < 100)      shortName  = shortName+","+overBought;
         if (overSold   >   0)      shortName  = shortName+","+overSold;
   IndicatorShortName(shortName+")");
   return(0);
}

//
//
//
//
//

int deinit()
  {

   ObjectDelete("52");            // s01 mod
   ObjectDelete("/ OB");
   ObjectDelete("/ OS");
   ObjectDelete("/ btw");

   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
{
   int    counted_bars=IndicatorCounted();
   int    limit;
   int    i;
   
   
   
   
   if(counted_bars<0) return(-1);
   limit=Bars-counted_bars;
      
   //
   //
   //
   //
   //
   
   for(i=limit; i>=0; i--)
      {
            KFull[i] = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_MAIN,i);
            DFull[i] = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_SIGNAL,i);

            //
            //
            //
            //
            //
                                 
            if (KFull[i] > overBought) { Upper[i] = KFull[i]; Upper[i+1] = KFull[i+1]; }
            else                       { Upper[i] = EMPTY_VALUE;
                                         if (Upper[i+2] == EMPTY_VALUE)
                                             Upper[i+1]  = EMPTY_VALUE; }                            
            if (KFull[i] < overSold)   { Lower[i] = KFull[i]; Lower[i+1] = KFull[i+1]; }                   
            else                       { Lower[i] = EMPTY_VALUE;
                                         if (Lower[i+2] == EMPTY_VALUE)
                                             Lower[i+1]  = EMPTY_VALUE; }                            
      }

// --------------------
   
//+---------------------------------------------------------------------------------------------+
//+                       On Screen Display for use with Daily Data                             +
//+---------------------------------------------------------------------------------------------+

// --------------------

   if (ShowText)
   
      {
                                                                                             //       /*  // for debugging
// -------------------- 

       if ( ObjectFind ( "52") == -1 )
   {
   
//      if (DFull[i] < overSold  > overBought)
   
            ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
            ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
            ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
            ObjectSet      ( "52", OBJPROP_BACK, false );
            ObjectSetText  ( "52","45.3/55.6 / btw", 10, "Arial Bold", Silver);   
   
      if (DFull[i] > overBought) 
            ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
            ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
            ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
            ObjectSet      ( "52", OBJPROP_BACK, false );
           ObjectSetText  ( "52","45.3/55.6 / OB", 10, "Arial Bold", Lime);
            
      if (DFull[i] > overSold) 
            ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
            ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
            ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
            ObjectSet      ( "52", OBJPROP_BACK, false );
            ObjectSetText  ( "52","45.3/55.6 / OS", 10, "Arial Bold", Red);
            
            
   }    
                                                                                            //      */  // for debugging 
      } 

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

 
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

string priceDescription(int mode)
{
   string answer;
   switch(mode)
   {
      case 0:  answer = "Low/High"    ; break; 
      case 1:  answer = "Close/Close" ; break;
      default: answer = "Invalid price field requested";
                                    Alert(answer);
   }
   return(answer);
}
string maDescription(int mode)
{
   string answer;
   switch(mode)
   {
      case MODE_SMA:  answer = "SMA"  ; break; 
      case MODE_EMA:  answer = "EMA"  ; break;
      case MODE_SMMA: answer = "SMMA" ; break;
      case MODE_LWMA: answer = "LWMA" ; break;
      default:        answer = "Invalid MA mode requested";
                                    Alert(answer);
   }
   return(answer);
}

// ------------------------------------- end ------------------------------------ //
Author:  gaheitman [ Mon Nov 19, 2012 8:42 am ]
Post subject:  Re: Some Coding Help Please

I've updated the code to fix the display of the between OB/OS, and will let you do the other two. For if() statements, you have to have all the things you want done based on the test in curly braces.

Code: Select all

//+------------------------------------------------------------------+
//|                                          DD_Color Stochastic.mq4 |
//|                                                       mod by s01 |
//+------------------------------------------------------------------+
//|                                             Color Stochastic.mq4 |
//|                                                           mladen |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      ""

#property indicator_separate_window
#property indicator_buffers   8
#property indicator_color1 Magenta
#property indicator_style1 STYLE_DOT
#property indicator_color2 SeaGreen
#property indicator_style2 STYLE_DOT
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_width3 3
#property indicator_width4 3

#property indicator_minimum   0
#property indicator_maximum 100

#property indicator_level5     10  // Added this section // s01
#property indicator_level6     15
#property indicator_level7     85
#property indicator_level8     90


#property indicator_color5 Magenta  // added this section // s01
#property indicator_color6 Magenta
#property indicator_color7 Magenta
#property indicator_color8 Magenta



//---- input parameters
//
//    nice setings for trend = 35,10,1
//    Try 8,3,3 for scalp
//

extern string note1  = "Show Screen Text";
extern bool ShowText = true;
extern string note2  = "Stochastic settings";
extern string note3  = "for trend 35,10,1";
extern string note4  = "for scalp 8,3,3";
extern int       KPeriod     =  8;
extern int       Slowing     =  3;
extern int       DPeriod     =  3;
extern string note5 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int       MAMethod    =   0;
extern string note6 = "0=high/low, 1=close/close";
extern int       PriceField  =   0;
extern string note7 = "overbought level";
extern int       overBought  =  85;
extern string note8 = "oversold level";
extern int       overSold    =  15;


//---- buffers
//
//
//
//
//

double KFull[];
double DFull[];
double Upper[];
double Lower[];
//double overSold(); // 'overSold' - no dll defined for the import function
//double overBought(); // ^^^ same error ^^^

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
{
	SetIndexBuffer(0,DFull);
	SetIndexBuffer(1,KFull);
	SetIndexBuffer(2,Upper);
	SetIndexBuffer(3,Lower);
	SetIndexLabel(1,"Fast");
	SetIndexLabel(2,NULL);
	SetIndexLabel(3,NULL);

	//
	//
	//
	//
	//

	DPeriod = MathMax(DPeriod,1);
	if (DPeriod==1)
	{
		SetIndexStyle(0,DRAW_NONE);
		SetIndexLabel(0,NULL);
	}
	else
	{
		SetIndexStyle(0,DRAW_LINE);
		SetIndexLabel(0,"Slow");
	}

	//
	//
	//
	//
	//

	string shortName = "DD_Color Stochastic ("+KPeriod+","+Slowing+","+DPeriod+","+maDescription(MAMethod)+","+priceDescription(PriceField);
	if (overBought < overSold) overBought = overSold;
	if (overBought < 100)      shortName  = shortName+","+overBought;
	if (overSold   >   0)      shortName  = shortName+","+overSold;
	IndicatorShortName(shortName+")");
	return(0);
}

//
//
//
//
//

int deinit()
{

	ObjectDelete("52");            // s01 mod
	ObjectDelete("/ OB");
	ObjectDelete("/ OS");
	ObjectDelete("/ btw");

	return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
{
	int    counted_bars=IndicatorCounted();
	int    limit;
	int    i;




	if (counted_bars<0) return(-1);
	limit=Bars-counted_bars;

	//
	//
	//
	//
	//

	for (i=limit; i>=0; i--)
	{
		KFull[i] = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_MAIN,i);
		DFull[i] = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_SIGNAL,i);

		//
		//
		//
		//
		//

		if (KFull[i] > overBought)
		{
			Upper[i] = KFull[i];
			Upper[i+1] = KFull[i+1];
		}
		else
		{
			Upper[i] = EMPTY_VALUE;
			if (Upper[i+2] == EMPTY_VALUE)
				Upper[i+1]  = EMPTY_VALUE;
		}
		if (KFull[i] < overSold)
		{
			Lower[i] = KFull[i];
			Lower[i+1] = KFull[i+1];
		}
		else
		{
			Lower[i] = EMPTY_VALUE;
			if (Lower[i+2] == EMPTY_VALUE)
				Lower[i+1]  = EMPTY_VALUE;
		}
	}

// --------------------

//+---------------------------------------------------------------------------------------------+
//+                       On Screen Display for use with Daily Data                             +
//+---------------------------------------------------------------------------------------------+

// --------------------

	if (ShowText)

	{
		//       /*  // for debugging
// --------------------

//		if ( ObjectFind ( "52") == -1 )
//		{

			if (DFull[0] > overSold  && DFull[0] < overBought)
			{

				ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
				ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
				ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
				ObjectSet      ( "52", OBJPROP_BACK, false );
				ObjectSetText  ( "52",DoubleToStr(KFull[0],1)+" / "+DoubleToStr(DFull[0],1)+" / btw", 10, "Arial Bold", Silver);
			}

			if (DFull[0] >= overBought)
			{
				ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
				ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
				ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
				ObjectSet      ( "52", OBJPROP_BACK, false );
				ObjectSetText  ( "52","45.3/55.6 / OB", 10, "Arial Bold", Lime);
			}
			if (DFull[0] <= overSold)
			{
				ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
				ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
				ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
				ObjectSet      ( "52", OBJPROP_BACK, false );
				ObjectSetText  ( "52","45.3/55.6 / OS", 10, "Arial Bold", Red);


			}
			//      */  // for debugging
//		}

		return(0);
	}
}

// --------------------


//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

string priceDescription(int mode)
	{
		string answer;
		switch (mode)
		{
		case 0:
			answer = "Low/High"    ;
			break;
		case 1:
			answer = "Close/Close" ;
			break;
		default:
			answer = "Invalid price field requested";
			Alert(answer);
		}
		return(answer);
	}
	string maDescription(int mode)
	{
		string answer;
		switch (mode)
		{
		case MODE_SMA:
			answer = "SMA"  ;
			break;
		case MODE_EMA:
			answer = "EMA"  ;
			break;
		case MODE_SMMA:
			answer = "SMMA" ;
			break;
		case MODE_LWMA:
			answer = "LWMA" ;
			break;
		default:
			answer = "Invalid MA mode requested";
			Alert(answer);
		}
		return(answer);
	}

// ------------------------------------- end ------------------------------------ //
George
Author:  s01 [ Mon Nov 19, 2012 1:45 pm ]
Post subject:  Re: Some Coding Help Please

gaheitman wrote:I've updated the code to fix the display of the between OB/OS, and will let you do the other two. For if() statements, you have to have all the things you want done based on the test in curly braces.
George
We (you) almost have it, it works somewhat. I did have to add a } at the end of the lime section, but it worked then.

It displays the text and numbers on the main screen in the proper places, but the numbers do not refresh on each tic, and if it gets to an OB/OS condition I have to click on the propertys or recompile, then it sets it right ... green, red, or silver and sets the numbers, but it is stuck there again until I either go back and recompile or go into the indicator propertys again then it resets to the proper settings.

So is there a way to get it to refresh every tick?

Code: Select all

//+------------------------------------------------------------------+
//|                                          DD_Color Stochastic.mq4 |
//|                                                       mod by s01 |
//+------------------------------------------------------------------+
//|                                             Color Stochastic.mq4 |
//|                                                           mladen |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      ""

#property indicator_separate_window
#property indicator_buffers   8
#property indicator_color1 Magenta
#property indicator_style1 STYLE_DOT
#property indicator_color2 SeaGreen
#property indicator_style2 STYLE_DOT
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_width3 3
#property indicator_width4 3

#property indicator_minimum   0
#property indicator_maximum 100

#property indicator_level5     10  // Added this section // s01
#property indicator_level6     15
#property indicator_level7     85
#property indicator_level8     90


//#property indicator_color5 Magenta  // added this section // s01 // not working so removed
//#property indicator_color6 Magenta
//#property indicator_color7 Magenta
//#property indicator_color8 Magenta
 


//---- input parameters
//
//    nice setings for trend = 35,10,1
//    Try 8,3,3 for scalp
//

extern string note1  = "Show Screen Text";   
extern bool ShowText = true;
extern string note2  = "Stochastic settings";
extern string note3  = "for trend 35,10,1";
extern string note4  = "for scalp 8,3,3";
extern int       KPeriod     =  8;
extern int       Slowing     =  3;
extern int       DPeriod     =  3;
extern string note5 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int       MAMethod    =   0;
extern string note6 = "0=high/low, 1=close/close";
extern int       PriceField  =   0;
extern string note7 = "overbought level";
extern int       overBought  =  85;
extern string note8 = "oversold level";
extern int       overSold    =  15;


//---- buffers
//
//
//
//
//

double KFull[];
double DFull[];
double Upper[];
double Lower[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
{
      SetIndexBuffer(0,DFull);
      SetIndexBuffer(1,KFull);
      SetIndexBuffer(2,Upper);
      SetIndexBuffer(3,Lower);
      SetIndexLabel(1,"Fast");
      SetIndexLabel(2,NULL);
      SetIndexLabel(3,NULL);
         
         //
         //
         //
         //
         //
         
         DPeriod = MathMax(DPeriod,1);
         if (DPeriod==1) {
               SetIndexStyle(0,DRAW_NONE);
               SetIndexLabel(0,NULL);
            }
         else {
               SetIndexStyle(0,DRAW_LINE); 
               SetIndexLabel(0,"Slow");
            }               
         
         //
         //
         //
         //
         //
         
   string shortName = "DD_Color Stochastic ("+KPeriod+","+Slowing+","+DPeriod+","+maDescription(MAMethod)+","+priceDescription(PriceField);
         if (overBought < overSold) overBought = overSold;
         if (overBought < 100)      shortName  = shortName+","+overBought;
         if (overSold   >   0)      shortName  = shortName+","+overSold;
   IndicatorShortName(shortName+")");
   return(0);
}

//
//
//
//
//

int deinit()
  {

   ObjectDelete("52");            // s01 mod
   ObjectDelete("/ OB");
   ObjectDelete("/ OS");
   ObjectDelete("/ btw");

   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
{
   int    counted_bars=IndicatorCounted();
   int    limit;
   int    i;
   
   
   
   
   if(counted_bars<0) return(-1);
   limit=Bars-counted_bars;
      
   //
   //
   //
   //
   //
   
   for(i=limit; i>=0; i--)
      {
            KFull[i] = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_MAIN,i);
            DFull[i] = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_SIGNAL,i);

            //
            //
            //
            //
            //
                                 
            if (KFull[i] > overBought) { Upper[i] = KFull[i]; Upper[i+1] = KFull[i+1]; }
            else                       { Upper[i] = EMPTY_VALUE;
                                         if (Upper[i+2] == EMPTY_VALUE)
                                             Upper[i+1]  = EMPTY_VALUE; }                            
            if (KFull[i] < overSold)   { Lower[i] = KFull[i]; Lower[i+1] = KFull[i+1]; }                   
            else                       { Lower[i] = EMPTY_VALUE;
                                         if (Lower[i+2] == EMPTY_VALUE)
                                             Lower[i+1]  = EMPTY_VALUE; }                            
      }

// --------------------
   
//+---------------------------------------------------------------------------------------------+
//+                       On Screen Display for use with Daily Data                             +
//+---------------------------------------------------------------------------------------------+

// --------------------

   if (ShowText)
   
  {
                                                                                             //       /*  // for debugging
// -------------------- 

       if ( ObjectFind ( "52") == -1 )
   {
   
  //    if (DFull[i] < overSold  > overBought) // remember this !!!!!!!!
      if (DFull[0] > overSold  && DFull[0] < overBought)
         {
            ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
            ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
            ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
            ObjectSet      ( "52", OBJPROP_BACK, false );
            ObjectSetText  ( "52", DoubleToStr(KFull[0],1)+" / "+DoubleToStr(DFull[0],1)+" / btw", 10, "Arial Bold", Silver);
         }

         if (DFull[0] >= overBought)
         {
            ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
            ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
            ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
            ObjectSet      ( "52", OBJPROP_BACK, false );
            ObjectSetText  ( "52", DoubleToStr(KFull[0],1)+" / "+DoubleToStr(DFull[0],1)+" / OB", 10, "Arial Bold", Red);
         }
         if (DFull[0] <= overSold)
         {
            ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
            ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
            ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
            ObjectSet      ( "52", OBJPROP_BACK, false );
            ObjectSetText  ( "52", DoubleToStr(KFull[0],1)+" / "+DoubleToStr(DFull[0],1)+" / OS", 10, "Arial Bold", Lime);
         }              
    }    
                                                                                            //      */  // for debugging 
   } 

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

 
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

string priceDescription(int mode)
{
   string answer;
   switch(mode)
   {
      case 0:  answer = "Low/High"    ; break; 
      case 1:  answer = "Close/Close" ; break;
      default: answer = "Invalid price field requested";
                                    Alert(answer);
   }
   return(answer);
}
string maDescription(int mode)
{
   string answer;
   switch(mode)
   {
      case MODE_SMA:  answer = "SMA"  ; break; 
      case MODE_EMA:  answer = "EMA"  ; break;
      case MODE_SMMA: answer = "SMMA" ; break;
      case MODE_LWMA: answer = "LWMA" ; break;
      default:        answer = "Invalid MA mode requested";
                                    Alert(answer);
   }
   return(answer);
}

// ------------------------------------- end ------------------------------------ //
You have helped me so much I really do welcome the help.

Steve
Author:  gaheitman [ Mon Nov 19, 2012 2:25 pm ]
Post subject:  Re: Some Coding Help Please

s01 wrote:
gaheitman wrote:I've updated the code to fix the display of the between OB/OS, and will let you do the other two. For if() statements, you have to have all the things you want done based on the test in curly braces.
George
We (you) almost have it, it works somewhat. I did have to add a } at the end of the lime section, but it worked then.

It displays the text and numbers on the main screen in the proper places, but the numbers do not refresh on each tic, and if it gets to an OB/OS condition I have to click on the propertys or recompile, then it sets it right ... green, red, or silver and sets the numbers, but it is stuck there again until I either go back and recompile or go into the indicator propertys again then it resets to the proper settings.

So is there a way to get it to refresh every tick?

Code: Select all

//+------------------------------------------------------------------+
//|                                          DD_Color Stochastic.mq4 |
//|                                                       mod by s01 |
//+------------------------------------------------------------------+
//|                                             Color Stochastic.mq4 |
//|                                                           mladen |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      ""

#property indicator_separate_window
#property indicator_buffers   8
#property indicator_color1 Magenta
#property indicator_style1 STYLE_DOT
#property indicator_color2 SeaGreen
#property indicator_style2 STYLE_DOT
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_width3 3
#property indicator_width4 3

#property indicator_minimum   0
#property indicator_maximum 100

#property indicator_level5     10  // Added this section // s01
#property indicator_level6     15
#property indicator_level7     85
#property indicator_level8     90


//#property indicator_color5 Magenta  // added this section // s01 // not working so removed
//#property indicator_color6 Magenta
//#property indicator_color7 Magenta
//#property indicator_color8 Magenta
 


//---- input parameters
//
//    nice setings for trend = 35,10,1
//    Try 8,3,3 for scalp
//

extern string note1  = "Show Screen Text";   
extern bool ShowText = true;
extern string note2  = "Stochastic settings";
extern string note3  = "for trend 35,10,1";
extern string note4  = "for scalp 8,3,3";
extern int       KPeriod     =  8;
extern int       Slowing     =  3;
extern int       DPeriod     =  3;
extern string note5 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int       MAMethod    =   0;
extern string note6 = "0=high/low, 1=close/close";
extern int       PriceField  =   0;
extern string note7 = "overbought level";
extern int       overBought  =  85;
extern string note8 = "oversold level";
extern int       overSold    =  15;


//---- buffers
//
//
//
//
//

double KFull[];
double DFull[];
double Upper[];
double Lower[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
{
      SetIndexBuffer(0,DFull);
      SetIndexBuffer(1,KFull);
      SetIndexBuffer(2,Upper);
      SetIndexBuffer(3,Lower);
      SetIndexLabel(1,"Fast");
      SetIndexLabel(2,NULL);
      SetIndexLabel(3,NULL);
         
         //
         //
         //
         //
         //
         
         DPeriod = MathMax(DPeriod,1);
         if (DPeriod==1) {
               SetIndexStyle(0,DRAW_NONE);
               SetIndexLabel(0,NULL);
            }
         else {
               SetIndexStyle(0,DRAW_LINE); 
               SetIndexLabel(0,"Slow");
            }               
         
         //
         //
         //
         //
         //
         
   string shortName = "DD_Color Stochastic ("+KPeriod+","+Slowing+","+DPeriod+","+maDescription(MAMethod)+","+priceDescription(PriceField);
         if (overBought < overSold) overBought = overSold;
         if (overBought < 100)      shortName  = shortName+","+overBought;
         if (overSold   >   0)      shortName  = shortName+","+overSold;
   IndicatorShortName(shortName+")");
   return(0);
}

//
//
//
//
//

int deinit()
  {

   ObjectDelete("52");            // s01 mod
   ObjectDelete("/ OB");
   ObjectDelete("/ OS");
   ObjectDelete("/ btw");

   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
{
   int    counted_bars=IndicatorCounted();
   int    limit;
   int    i;
   
   
   
   
   if(counted_bars<0) return(-1);
   limit=Bars-counted_bars;
      
   //
   //
   //
   //
   //
   
   for(i=limit; i>=0; i--)
      {
            KFull[i] = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_MAIN,i);
            DFull[i] = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_SIGNAL,i);

            //
            //
            //
            //
            //
                                 
            if (KFull[i] > overBought) { Upper[i] = KFull[i]; Upper[i+1] = KFull[i+1]; }
            else                       { Upper[i] = EMPTY_VALUE;
                                         if (Upper[i+2] == EMPTY_VALUE)
                                             Upper[i+1]  = EMPTY_VALUE; }                            
            if (KFull[i] < overSold)   { Lower[i] = KFull[i]; Lower[i+1] = KFull[i+1]; }                   
            else                       { Lower[i] = EMPTY_VALUE;
                                         if (Lower[i+2] == EMPTY_VALUE)
                                             Lower[i+1]  = EMPTY_VALUE; }                            
      }

// --------------------
   
//+---------------------------------------------------------------------------------------------+
//+                       On Screen Display for use with Daily Data                             +
//+---------------------------------------------------------------------------------------------+

// --------------------

   if (ShowText)
   
  {
                                                                                             //       /*  // for debugging
// -------------------- 

       if ( ObjectFind ( "52") == -1 )
   {
   
  //    if (DFull[i] < overSold  > overBought) // remember this !!!!!!!!
      if (DFull[0] > overSold  && DFull[0] < overBought)
         {
            ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
            ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
            ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
            ObjectSet      ( "52", OBJPROP_BACK, false );
            ObjectSetText  ( "52", DoubleToStr(KFull[0],1)+" / "+DoubleToStr(DFull[0],1)+" / btw", 10, "Arial Bold", Silver);
         }

         if (DFull[0] >= overBought)
         {
            ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
            ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
            ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
            ObjectSet      ( "52", OBJPROP_BACK, false );
            ObjectSetText  ( "52", DoubleToStr(KFull[0],1)+" / "+DoubleToStr(DFull[0],1)+" / OB", 10, "Arial Bold", Red);
         }
         if (DFull[0] <= overSold)
         {
            ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
            ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
            ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
            ObjectSet      ( "52", OBJPROP_BACK, false );
            ObjectSetText  ( "52", DoubleToStr(KFull[0],1)+" / "+DoubleToStr(DFull[0],1)+" / OS", 10, "Arial Bold", Lime);
         }              
    }    
                                                                                            //      */  // for debugging 
   } 

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

 
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

string priceDescription(int mode)
{
   string answer;
   switch(mode)
   {
      case 0:  answer = "Low/High"    ; break; 
      case 1:  answer = "Close/Close" ; break;
      default: answer = "Invalid price field requested";
                                    Alert(answer);
   }
   return(answer);
}
string maDescription(int mode)
{
   string answer;
   switch(mode)
   {
      case MODE_SMA:  answer = "SMA"  ; break; 
      case MODE_EMA:  answer = "EMA"  ; break;
      case MODE_SMMA: answer = "SMMA" ; break;
      case MODE_LWMA: answer = "LWMA" ; break;
      default:        answer = "Invalid MA mode requested";
                                    Alert(answer);
   }
   return(answer);
}

// ------------------------------------- end ------------------------------------ //
You have helped me so much I really do welcome the help.

Steve
My version did update on every tick. You uncommented this line that I had commented out:

Code: Select all

       if ( ObjectFind ( "52") == -1 )
as well as the curly brace after it (which caused you to need to add another one later).

The line says "only do the following if you can't find the object." Since the object is already created, it was never updated again. Removing that line will make it update.

Here's my version of the loop with the extraneous stuff removed.

Code: Select all

	if (ShowText)

	{
		if (DFull[0] > overSold  && DFull[0] < overBought)
		{

			ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
			ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
			ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
			ObjectSet      ( "52", OBJPROP_BACK, false );
			ObjectSetText  ( "52",DoubleToStr(KFull[0],1)+" / "+DoubleToStr(DFull[0],1)+" / btw", 10, "Arial Bold", Silver);
		}

		if (DFull[0] >= overBought)
		{
			ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
			ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
			ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
			ObjectSet      ( "52", OBJPROP_BACK, false );
			ObjectSetText  ( "52",DoubleToStr(KFull[0],1)+" / "+DoubleToStr(DFull[0],1)+" / OB", 10, "Arial Bold", Lime);
		}
		if (DFull[0] <= overSold)
		{
			ObjectCreate   ( "52", OBJ_LABEL, 0, 0, 0 );
			ObjectSet      ( "52", OBJPROP_XDISTANCE, 1550 );
			ObjectSet      ( "52", OBJPROP_YDISTANCE, 180 );
			ObjectSet      ( "52", OBJPROP_BACK, false );
			ObjectSetText  ( "52",DoubleToStr(KFull[0],1)+" / "+DoubleToStr(DFull[0],1)+" / OS", 10, "Arial Bold", Red);

		}
	}
George
Author:  s01 [ Mon Nov 19, 2012 4:56 pm ]
Post subject:  Re: Some Coding Help Please

George,

Your fantastic, many many thanks.

Seems to work just like I though it should ..

Sorry about all the screwups .. I will get better.

Again Thank You!

Steve / s01
All times are UTC Page 1 of 1