Download MetaTrader 5

newbie question no orders appearing

To add comments, please log in or register
brolarbear
26
brolarbear  


//+------------------------------------------------------------------+
//|                                                      MAvsRSI.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"


#property indicator_separate_window
#property indicator_buffers 2
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_color1 Black   //RSI color
#property indicator_color2 Green
#property indicator_level1 32      //SetLevelValue(0,50);
#property indicator_level2 50      //SetLevelValue(1,68);
#property indicator_level3 68      //SetLevelValue(2,32);
#property indicator_levelcolor DimGray      //color indicator value

#define BIGMACMATT 42069
//--- input parameters
extern int RSI_Period    = 13;    //8-25
extern int RSI_Price     =  0;     /*PRICE_CLOSE    0   Close price.
                                     PRICE_OPEN     1   Open price.
                                     PRICE_HIGH     2   High price.
                                     PRICE_LOW      3   Low price.
                                     PRICE_MEDIAN   4   Median price, (high+low)/2.
                                     PRICE_TYPICAL  5   Typical price, (high+low+close)/3.
                                     PRICE_WEIGHTED 6   Weighted close price, (high+low+close+close)/4. */

extern int RSI_MA_Period = 7;
extern int RSI_MA_Type = 0;       // 0 SMA , 1 EMA , 2 SMMA , 3 LWMA
input double Lots = 0.01;
//--- buffers
double RSIBuf[];
double MaBuf[];

int init()
{
IndicatorShortName("MA of the RSI");

//---- drawing settings  RSI  (0,......)
SetIndexBuffer(0,RSIBuf);
SetIndexLabel(0,"RSI");                    //SetIndexLabel(0,NULL); wrong
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);  //SetIndexStyle(0,DRAW_NONE);wrong this is draw nothing

//---- drawing settings of Moving Average on RSI
SetIndexBuffer(1,MaBuf);
SetIndexLabel(1," ("+RSI_MA_Period+") Period MA of RSI");       //SetIndexLabel(1,"MA of the RSI");
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);                       //SetIndexStyle(1,DRAW_LINE);




//SetLevelValue(0,50);
//SetLevelValue(1,68);
//SetLevelValue(2,32);
//SetLevelStyle(STYLE_DOT,1,DimGray);

return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int start()
{
bool tradedirection;
int i;
int res;
double MA,RSI[];

ArrayResize(RSI,RSI_MA_Period);
int counted_bars=IndicatorCounted();
int limit = Bars-counted_bars-1;
for(i=limit; i>=0; i--)

RSIBuf[i] = (iRSI(NULL,0,RSI_Period,RSI_Price,i));
MA = 0;
for(int x=i; x<i; x++) {
RSI[x-i] = RSIBuf[x];
MA += RSIBuf[x]/RSI_MA_Period;}

   if(OrdersTotal()>0 && MA>50)
   {
      if (!OrderClose(OrderTicket(),1,Ask,3,Blue)){
              Print("OrderModify error ",GetLastError());}
   }
  
   if(OrdersTotal()>0 && MA<50)
   {
      if (!OrderClose(OrderTicket(),1,Bid,3,Red)){
      Print("OrderModify error ",GetLastError());}
   }
  
   if(MA<50 && OrdersTotal() <1)
      {
       tradedirection = false;
       res=OrderSend(Symbol(),OP_SELL,1,Bid,3,0,0,"",BIGMACMATT,0,Red);
      }
  
   if(MA>50 && OrdersTotal() <1)
      {
      tradedirection = true;
      res=OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"",BIGMACMATT,0,Blue);
      }

for(int j=limit; j>=0; j--)       //was missing
   {MaBuf[j] = (iMAOnArray(RSIBuf,0,RSI_MA_Period,0,RSI_MA_Type,j));}


return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0); 

}
brolarbear
26
brolarbear  
This is my first code in MQL4 and just trying to get it working. there are no orders going through but no errors or warnings pop up.
Keith Watford
Moderator
10570
Keith Watford  
It is an indicator. Indicators cannot handle orders
brolarbear
26
brolarbear  
Keith Watford:
It is an indicator. Indicators cannot handle orders
is there a simple way to make it an EA or do i need to re do it?
whroeder1
16275
whroeder1  
brolarbear: is there a simple way to make it an EA or do i need to re do it?
Don't do that. Write your EA and just get the value of the indicator. You should write a self documenting function instead of calling iCustom directly, see Detailed explanation of iCustom - MQL4 forum
brolarbear
26
brolarbear  
whroeder1:
Don't do that. Write your EA and just get the value of the indicator. You should write a self documenting function instead of calling iCustom directly, see Detailed explanation of iCustom - MQL4 forum
So is iCustom basically how you get value from other indicators or files?
honest_knave
Moderator
2297
honest_knave  
brolarbear:
So is iCustom basically how you get value from other indicators or files?

Yes, other indicators.

No, not other files. 

To add comments, please log in or register