Previous MA value and signal as a indicator text

 

Hi all,

I am new to MQL4 coding. I need to write an indicator where it shows the value of previous MA 20 and 8. also if 20 is above 8 then it should be sell else if 8 is above 20 then it should be buy. cant understand how to write, My Indicators keeps coming up with problems. I am hoping for a simple comment on the chart.

 
SmartSarb: My Indicators keeps coming up with problems. I am hoping for a simple comment on the chart.
  1. problems: "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  2. You have only four choices: We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using SRC) and the nature of your problem.
 
whroeder1:
  1. problems: "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  2. You have only four choices: We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using SRC) and the nature of your problem.


Mate, im new to this forum and still in early learning days, Im sure you were same one day. If it was my code then below is the code.

int counted_bars=IndicatorCounted();

   int i;

   double FiftyMA ;

   double OneSixtyMA ;

   double FourHundredMA ;

   string Position;

   

    //find index of bar shown at leftmost side of screen

   i = Bars-counted_bars-1;

   

   //work from leftmost bar to rightmost bar 

   while(i>=0)

   {

      //find current MA value, will also be used as y-coordinate

      FiftyMA   = iMA(NULL,_Period,50,0,MODE_EMA,PRICE_CLOSE,i);

      OneSixtyMA = iMA(NULL,_Period,160,0,MODE_EMA,PRICE_CLOSE,i);

      FourHundredMA   = iMA(NULL,_Period,400,0,MODE_EMA,PRICE_CLOSE,i);

      

      if(OneSixtyMA > FourHundredMA){

         if(FiftyMA > OneSixtyMA){

            Position = "Long";

         }

      }

      if(OneSixtyMA < FourHundredMA){

         if(FiftyMA < OneSixtyMA){

            Position = "Short";

         }

      }

      

             

 
SmartSarb:


Mate, im new to this forum and still in early learning days, Im sure you were same one day. If it was my code then below is the code.

   

             

 
SmartSarb: I am hoping for a simple comment on the chart.
  1. Use SRC
  2. Your code just decides on a direction. Nothing more. Where do you post a comment or other objects?
  3. You've posted no problem. So there is no answer.
Reason: