How can self documentation function this RSI and engulfing candle

To add comments, please log in or register
Aung Swar
69
Aung Swar  

if RSI over 70
if Close[0]>Open[1]

Sell ----

Close
if RSI = 50

if RSI below 30
if Close[0]<Open[1]

Buy

Close
if RSI = 50


I tried to code it but not work .someone help me

Keith Watford
Moderator
18542
Keith Watford  
Aung Swar:

if RSI over 70
if Close[0]>Open[1]

Sell ----

Close
if RSI = 50

if RSI below 30
if Close[0]<Open[1]

Buy

Close
if RSI = 50


I tried to code it but not work .someone help me

Show your code if you want help.

Aung Swar
69
Aung Swar  
extern int  _MagicNumber = 1122;

int start()
  {
//---- Memorize indicator values for further analysis
   double RSIValue  =  iRSI(_Symbol,_Period,14,PRICE_CLOSE,0);
   
   

   int _GetLastError=0,_OrdersTotal=OrdersTotal();
//---- search among all open positions
   for(int z=_OrdersTotal-1; z>=0; z --)
     {
      // if an error occurs at finding the position, go to the next one
      if(!OrderSelect(z,SELECT_BY_POS))
        {
         _GetLastError=GetLastError();
         Print("OrderSelect( ",z,", SELECT_BY_POS ) - Error #",
               _GetLastError);
         continue;
        }

      // if the position was opened not for the current symbol, 
      // skip it
      if(OrderSymbol()!=Symbol()) continue;

      // if MagicNumber does not equal to _MagicNumber, skip 
      // this position
      if(OrderMagicNumber()!=_MagicNumber) continue;

      //---- if BUY position is opened,
      if(OrderType()==OP_BUY)
        {
         //-
       if(RSIValue>30)
            //---- close the position
            if(!OrderClose(OrderTicket(),OrderLots(),
               Bid,5,Green))
              {
               _GetLastError=GetLastError();
               Alert("Error OrderClose № ",_GetLastError);
               return(-1);
              }
           }
         // if signal has not changed, exit: it's too early for 
         // opening a new position
         else
           { return(0); }
        }
      //---- if SELL position is opened,
      if(OrderType()==OP_SELL)
        {
         
         if (RSIValue < 70 )
           {
            //---- close the position
            if(!OrderClose(OrderTicket(),OrderLots(),
               Ask,5,Red))
              {
               _GetLastError=GetLastError();
               Alert("Error OrderClose № ",_GetLastError);
               return(-1);
              }
           }
         // if signal has not changed, exit: it's too early to open 
         // a new position
         else return(0);
        }
     

//+------------------------------------------------------------------+
//| if execution has reached this point, this means no open position |
//| check whether it is possible to open a position                  |
//+------------------------------------------------------------------+

//---- 
   if(( RSIValue < 32 )&&(  Close[0]<Open[1]  ))
      {
      //---- open a BUY position
      if(OrderSend(Symbol(),OP_BUY,0.1,Ask,5,0.0,0.0,
         "test",_MagicNumber,0,Green)<0)
        {
         _GetLastError=GetLastError();
         Alert("Error OrderSend № ",_GetLastError);
         return(-1);
        }
      return(0);
     }
     
     
     
     
//
   if ((RSIValue >72 ) &&(Close[0]>Open[1]))
     {
      //---- open a SELL position
      if(OrderSend(Symbol(),OP_SELL,0.1,Bid,5,0.0,0.0,
         "test",
         _MagicNumber,0,Red)<0)
        {
         _GetLastError=GetLastError();
         Alert("Error OrderSend № ",_GetLastError);
         return(-1);
        }
      return(0);
     }

  return(0);
  }
Aung Swar
69
Aung Swar  
Keith Watford:

Show your code if you want help.

Here my code thanks
Keith Watford
Moderator
18542
Keith Watford  
Aung Swar:
Here my code thanks

So what is the problem? It doesn't work is not good enough.

Why the returns after finding a buy or sell (of symbol and magic number)?

William Roeder
19863
William Roeder  
  1. "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.

  2. You open a buy when RSI is below 32 (and Bid below previous candle open.) You close buys the moment RSI goes above 30. Does that make sense to you?
Aung Swar
69
Aung Swar  
William Roeder:
  1. "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.

  2. You open a buy when RSI is below 32 (and Bid below previous candle open.) You close buys the moment RSI goes above 30. Does that make sense to you?
But in backtesting.It is not work as I hope.Please help me some customisation in code.How can be more good in this strategy.My engulfing candle set up is not work .I want to open order when RSI below or above 72/32 and sell at Close[0] below than Open[1] and buy at Close[0] above than Open[1] .But this entry rule is not work .only RSI work but still not close code does not work.please help me.How can I get creative idea.
Aung Swar
69
Aung Swar  
Keith Watford:

So what is the problem? It doesn't work is not good enough.

Why the returns after finding a buy or sell (of symbol and magic number)?

Not work enough bro.cannot active order by engulfing candle and order not close at I command
Aung Swar
69
Aung Swar  
Aung Swar:
But in backtesting.It is not work as I hope.Please help me some customisation in code.How can be more good in this strategy.My engulfing candle set up is not work .I want to open order when RSI below or above 72/32 and sell at  Close[0] below than Open[1] and buy at Close[0] above than Open[1] .But this entry rule is not work .only RSI work but still not close code does not work.please help me.How can I get creative idea.
as this photo, multiple buy orders
Files:
Aung Swar
69
Aung Swar  
William Roeder:
  1. "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.

  2. You open a buy when RSI is below 32 (and Bid below previous candle open.) You close buys the moment RSI goes above 30. Does that make sense to you?

multiple buy orders in this photo .So CODES not wotk .help me.

Files:
William Roeder
19863
William Roeder  
  1. Help you with what? I asked two questions, and you ignored them. You just said the same things again — not useful.

  2. Of course, it opens multiple orders. You don't check and prevent it. Refactor your code.
    1. Find your open order (or not)
    2. If it's not time to close it, it's not time to open more. Prevent it.
    3. If it's time to close it, do it.
    4. Only then do you know you have no open orders, and can check if it's time to open.
    1. MT4: Learn to code it.
      MT5: Learn to code. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
    2. or pay (Freelance) someone to code it.
                Hiring to write script - General - MQL5 programming forum
    We're not going to code it for you.
To add comments, please log in or register