[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 67

 

Hello, everyone.

I decided to become a writer. I wanted to write something in MQL4. I've read something about it and decided to write an Expert Advisor, which would open position when RSI with period 8 cross 70 and close position when crosses 30 and nothing else would happen. I wrote it, here is the code

//+------------------------------------------------------------------+
//| 4doc.mq4 |
//| Alex |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Alex"
#property link "http://www.metaquotes.net"

//---- input parameters
extern int PerRSI=8;
extern int intNamber=77771;

extern double Lots=1.0;

/+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int
cnt=0,
ticket,
total;
double
rsi_0, //value. rsi_0 current
rsi_1; // Value. rsi_1 1st bar
if (Bars<100)
{
Print("bars less than 100");
return(0);
}
rsi_0=iRSI(NULL,0, PerRSI,0,0); // Current bar
rsi_1=iRSI(NULL,0, PerRSI,0,1); // Current bar plus 1
total=OrdersTotal();
if(total<1)
if(rsi_0 < rsi_1 && rsi_0 > 70) // If line has crossed 70
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0, "My RSI", MagicNamber,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ",OrderOpenPrice())
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
for(cnt=0;cnt<total;cnt++)
{
RefreshRates();
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // this is an open position? OP_BUY or OP_SELL
OrderSymbol()==Symbol()) // tool match?
{
if(OrderType()==OP_SELL) // position is open
{
if(rsi_0 > rsi_1 && rsi_0 < 30) // If line has crossed 30
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
return(0); // exit

}}}}}

I have tested it and it works mostly as I wanted. I have decided to change the code, to open a position when SSI - 14 crosses level 100, and to close a position when crosses level 100. I changed RSI code for CCI , here it is.

//+------------------------------------------------------------------+
//| CCI-DOC.mq4 |
//| Alex |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Alex"
#property link "http://www.metaquotes.net"

//---- input parameters
extern int PerCCI=14;
extern inttern MagicNamber=88881;

extern double Lots=1.0;

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int
cnt=0,
ticket,
total;
double
cci_0, // cci_0 value. cci_0 current
cci_1; // cci_1 value. cci_1 1st bar
if (Bars<100)
{
Print("bars less than 100");
return(0);
}
cci_0=iRSI(NULL,0, PerCCI,0,0); // Current bar
cci_1=iRSI(NULL,0, PerCCI,0,1); // current bar plus 1
total=OrdersTotal();
if(total<1)
if(cci_0 < cci_1 && cci_0 > 100) // if(line has crossed 100
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0, "My CCI", MagicNamber,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ",OrderOpenPrice())
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
for(cnt=0;cnt<total;cnt++)
{

OrderSelect(cnt,SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // this is an open position? OP_BUY or OP_SELL
OrderSymbol()==Symbol()) // tool match?
{
if(OrderType()==OP_SELL) // position is open
{
if(cci_0 > cci_1 && cci_0 < -100) // if line has crossed -100
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
return(0); // exit
}}}}}

Started to test CCI ..... well, nothing happens, does not sell or buy, no errors in the log, at the end of the test opens curve chart, but it is not CCI, but RSI 70-30 with period 14..... Maybe one of the experienced writers will understand and tell why and how to fix it.

 
pepsi писал(а) >>
Then the demo in the log shows everything more clearly. It's clearer where to look for the error. On my own...

>> thank you

 

Hello again!!!!!!!

I would like to /non-intrusively/;-)) remind you of your question on p. 64 about trading conditions for MA... thank you in advance (for a kick in the pants for a dummie)

 

Gentlemen, can you tell me if I use several different time charts of the same trading instrument in the terminal?

How is traffic consumed by the program? Does it consume traffic of the minimum timeframe, or traffic of all timeframes?

 
igrok2008 >> :

Hello again!!!!!!!

I would like to /non-intrusively/;-)) remind you of your question on p. 64 about trading conditions for MA... thank you in advance (for the kick in the pants to the dummies)

int start()
  {
//----
    double MA_0=iMA(NULL, 0, pMA, pSh, mode, price,0);
    double MA_1=iMA(NULL, 0, pMA, pSh, mode, price,1);

    перед использованием в коде open_1 или  open_0 их нужно инициализировать, т. е. объяснить программе
    к виду каких данных эти опены относятся( целые, дробные, строчные, логические)

    double open_0=Open[0]; //  double - дробное число. 0 и 1 это номера ячееек,
    double open_1=Open[1]; // которые в данном случае являются номерами баров
        
    if( MA_1< Open[1] && MA_0>Open[0])
     if( CheckOrders(OP_SELL))//продажа
      {
       if(!OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, 0, 0, NULL, MagicNumber))
         Print("Не открыт ордер Buy. Ошибка №", GetLastError()); 
       }
       
    if( MA_1>Open[1] && MA_0<Open[0])
     if( CheckOrders(OP_BUY))//покупка
      {
       if(!OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, 0, 0, NULL, MagicNumber))
         Print("Не открыт ордер Sell. Ошибка №", GetLastError()); 
       }
//----
   return(0);
  }
 
KONDOR >> :

Thanks for the reply!!!

1. Let me clarify, do the two lines with double open_0 and double_1 need to be written BEFORE the double MA lines, or is it uncritical ??????...

2. In the trading conditions you can replace open[0,1] by open_0,1 ????????.....

 
igrok2008 >> :

Thanks for the reply!!!

1. Let me clarify, do the two lines with double open_0 and double_1 need to be written BEFORE the double MA lines, or is it uncritical ??????...

2. You can replace open[0,1] with open_0,1 ????????.....

1. not critical.

2. can

 

Help please... I may be lazy, but I can not figure out how to connect the program to trade on a demo or real account... Please explain what to write and where to sing, I'm begging you... thanks in advance!))

 
I wrote - I wrote, I traded in the tester, but on the demo or real does not want to do transactions, and in general there are no signals, although they should be there(((
 
keekkenen >> :

1. not critical

2. can

CGFCB<J i.e. THANK YOU!!!!

Reason: