Download MetaTrader 5

have tried to print the arrows but all to no avail, please help me out, my codes are below.

To add comments, please log in or register
younghadiz
135
younghadiz  

have tried to print the arrows but all to no avail .

please help out .

these are codes belo.


#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red

extern bool Alerts = TRUE;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {
 
   return (0);
}


int deinit() {
   return (0);
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----



   if( Alerts==TRUE)
{

 if ( Close[4]>Open[4] &&  Close[3]>Open[3]&&  Close[2]>Open[2]&&  Close[1]<Open[2]  )
 
   {
      string SELLSIGNAL="SELLSIGNAL"+(string)Time[1];
       if(ObjectFind(0,SELLSIGNAL)!=0)
          {
          ObjectCreate(SELLSIGNAL,OBJ_ARROW_DOWN,0,Time[1],Low[1]-(Period()*Point*2));
          ObjectSet(SELLSIGNAL,OBJPROP_WIDTH,5);
          ObjectSet(SELLSIGNAL, OBJPROP_ARROWCODE,242);
          ObjectSet(SELLSIGNAL, OBJPROP_COLOR,Red);  
          ObjectSetInteger(0,SELLSIGNAL,OBJPROP_ANCHOR,ANCHOR_TOP);
 
   }
  
else if ( Close[4]<Open[4] &&  Close[3]<Open[3]&&  Close[2]<Open[2]&&  Close[1]>Open[2])
   {
  string BUYSIGNAL="BUYSIGNAL"+(string)Time[1];
       if(ObjectFind(0,BUYSIGNAL)!=0)
          {
          ObjectCreate(BUYSIGNAL,OBJ_ARROW_UP,0,Time[1],High[1]+(Period()*Point*2));
          ObjectSet(BUYSIGNAL,OBJPROP_COLOR,clrBlue);
          ObjectSet(SELLSIGNAL, OBJPROP_ARROWCODE,241);
          ObjectSet(BUYSIGNAL,OBJPROP_WIDTH,10);
          ObjectSetInteger(0,BUYSIGNAL,OBJPROP_ANCHOR,ANCHOR_BOTTOM);
   }

 }
 }
 }
//----

   return(0);
  }
Carl Schreiber
7545
Carl Schreiber  

1) use the SRC-button to ppost code!

2) check what the functions return!

3) check the errors_ _LastError

younghadiz
135
younghadiz  
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red

extern bool Alerts = TRUE;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {
 
   return (0);
}


int deinit() {
   return (0);
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----



   if( Alerts==TRUE)
{

 if ( Close[4]>Open[4] &&  Close[3]>Open[3]&&  Close[2]>Open[2]&&  Close[1]<Open[2]  )
 
   {
      string SELLSIGNAL="SELLSIGNAL"+(string)Time[1];
       if(ObjectFind(0,SELLSIGNAL)!=0)
          {
          ObjectCreate(SELLSIGNAL,OBJ_ARROW_DOWN,0,Time[1],Low[1]-(Period()*Point*2));
          ObjectSet(SELLSIGNAL,OBJPROP_WIDTH,5);
          ObjectSet(SELLSIGNAL, OBJPROP_ARROWCODE,242);
          ObjectSet(SELLSIGNAL, OBJPROP_COLOR,Red);  
          ObjectSetInteger(0,SELLSIGNAL,OBJPROP_ANCHOR,ANCHOR_TOP);
 
   }
  
else if ( Close[4]<Open[4] &&  Close[3]<Open[3]&&  Close[2]<Open[2]&&  Close[1]>Open[2])
   {
  string BUYSIGNAL="BUYSIGNAL"+(string)Time[1];
       if(ObjectFind(0,BUYSIGNAL)!=0)
          {
          ObjectCreate(BUYSIGNAL,OBJ_ARROW_UP,0,Time[1],High[1]+(Period()*Point*2));
          ObjectSet(BUYSIGNAL,OBJPROP_COLOR,clrBlue);
          ObjectSet(SELLSIGNAL, OBJPROP_ARROWCODE,241);
          ObjectSet(BUYSIGNAL,OBJPROP_WIDTH,10);
          ObjectSetInteger(0,BUYSIGNAL,OBJPROP_ANCHOR,ANCHOR_BOTTOM);
   }

 }
 }
 }
//----

   return(0);
  } 
Keith Watford
Moderator
10566
Keith Watford  
int start()
  {
//----



   if( Alerts==TRUE)
{

 if ( Close[4]>Open[4] &&  Close[3]>Open[3]&&  Close[2]>Open[2]&&  Close[1]<Open[2]  )
 
   {
      string SELLSIGNAL="SELLSIGNAL"+(string)Time[1];
       if(ObjectFind(0,SELLSIGNAL)!=0)
          {
          ObjectCreate(SELLSIGNAL,OBJ_ARROW_DOWN,0,Time[1],Low[1]-(Period()*Point*2));
          ObjectSet(SELLSIGNAL,OBJPROP_WIDTH,5);
          ObjectSet(SELLSIGNAL, OBJPROP_ARROWCODE,242);
          ObjectSet(SELLSIGNAL, OBJPROP_COLOR,Red);  
          ObjectSetInteger(0,SELLSIGNAL,OBJPROP_ANCHOR,ANCHOR_TOP);
 
   }
  
else if ( Close[4]<Open[4] &&  Close[3]<Open[3]&&  Close[2]<Open[2]&&  Close[1]>Open[2])
   {
  string BUYSIGNAL="BUYSIGNAL"+(string)Time[1];
       if(ObjectFind(0,BUYSIGNAL)!=0)
          {
          ObjectCreate(BUYSIGNAL,OBJ_ARROW_UP,0,Time[1],High[1]+(Period()*Point*2));
          ObjectSet(BUYSIGNAL,OBJPROP_COLOR,clrBlue);
          ObjectSet(SELLSIGNAL, OBJPROP_ARROWCODE,241);
          ObjectSet(BUYSIGNAL,OBJPROP_WIDTH,10);
          ObjectSetInteger(0,BUYSIGNAL,OBJPROP_ANCHOR,ANCHOR_BOTTOM);
   }

 }
 }
 }
//----

   return(0);
  } 
Check the positioning of your curly braces
younghadiz
135
younghadiz  
have adjusted it but the problem still persist. and i want it to be print / draw arrow like attached image below




#property indicator_chart_window
#property indicator_color1 Green
#property indicator_color2 Red

extern bool Alerts=TRUE;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {

   return (0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   return (0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//----
   if(Alerts==TRUE)
     {
      if(Close[4]>Open[4] && Close[3]>Open[3] && Close[2]>Open[2] && Close[1]<Open[2])
        {
        Alert ("INDICATOR: ",Symbol()+" "+Period()+": Sell Alert @ "+DoubleToStr(Bid,Digits));
         string SELLSIGNAL="SELLSIGNAL"+(string)Time[1];
         if(ObjectFind(0,SELLSIGNAL)!=0)
           {
            ObjectCreate(SELLSIGNAL,OBJ_ARROW_DOWN,0,Time[1],High[1]);
            ObjectSet(SELLSIGNAL,OBJPROP_WIDTH,5);
            ObjectSet(SELLSIGNAL,OBJPROP_ARROWCODE,242);
            ObjectSet(SELLSIGNAL,OBJPROP_COLOR,Red);
            ObjectSetInteger(0,SELLSIGNAL,OBJPROP_ANCHOR,ANCHOR_TOP);
           }
          if(Close[3]<Open[3] && Close[2]<Open[2] && Close[1]>Open[2])
           {
           Alert ("INDICATOR: ",Symbol()+" "+Period()+": Buy Alert @ "+DoubleToStr(Ask,Digits));
           
               string BUYSIGNAL="BUYSIGNAL"+(string)Time[1];
         if(ObjectFind(0,BUYSIGNAL)!=0)
           {
            ObjectCreate(BUYSIGNAL,OBJ_ARROW_BUY,0,Time[1],Low[1]);
            ObjectSet(BUYSIGNAL,OBJPROP_WIDTH,5);
            ObjectSet(BUYSIGNAL,OBJPROP_ARROWCODE,241);
            ObjectSet(BUYSIGNAL,OBJPROP_COLOR,Green);
            ObjectSetInteger(0,BUYSIGNAL,OBJPROP_ANCHOR,ANCHOR_BOTTOM);
              }
           }
        }
     }
//----
   return(prev_calculated);
  }
//+------------------------------------------------------------------+
younghadiz
135
younghadiz  
IMAGE HERE
Keith Watford
Moderator
10566
Keith Watford  

Your curly braces are still not positioned correctly

if(Close[3]<Open[3] && Close[2]<Open[2] && Close[1]>Open[2])

 will never return true as it is in the block conditional on

if(Close[4]>Open[4] && Close[3]>Open[3] && Close[2]>Open[2] && Close[1]<Open[2])
younghadiz
135
younghadiz  
k, can u please give me  a CORRECTION .
Keith Watford
Moderator
10566
Keith Watford  
younghadiz:
k, can u please give me  a CORRECTION .

I could just correct your bracing, but next time you will make the same mistake again and again.

It is a better learning experience for you to work through the logic of your code yourself and find out where the braces should be. 

younghadiz
135
younghadiz  
could you please indicate where i made mistake please , because i couldnt find it.thanks a lot.
Keith Watford
Moderator
10566
Keith Watford  
younghadiz:
could you please indicate where i made mistake please , because i couldnt find it.thanks a lot.

Go back 5 or so posts and you will see that I indicated the braces controlled by  

 if ( Close[4]>Open[4] &&  Close[3]>Open[3]&&  Close[2]>Open[2]&&  Close[1]<Open[2]  )
12
To add comments, please log in or register