Why does it only open a position Sell or only Buy?

 
//+------------------------------------------------------------------+
//|                                                     MultyRSI.mq4 |
//|                                        Copyright 2020, TradeMath |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, TradeMath"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
double takeProfit = 40; //Variabili globali
double stopLoss = 60;
int ticket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  
     double nDigits=CalculateNormalizedDigits();
     double takeProfitLevel = Ask+(takeProfit*nDigits);
     double stopLossLevel =  Ask-(stopLoss*nDigits);
     string signal = "";
     int RSIval15m = iRSI(_Symbol,PERIOD_M15,14,PRICE_CLOSE,0);
     int RSIval30m = iRSI(_Symbol,PERIOD_M30,14,PRICE_CLOSE,0);
     int RSIval60m = iRSI(_Symbol,PERIOD_H1,14,PRICE_CLOSE,0);
     
     if (RSIval15m < 30)
     if (RSIval30m < 30)
     if (RSIval60m < 30)
        {
           
           signal = "BUY"; 
           if(signal == "BUY" && OrdersTotal() == 0)
              {
              
                 ticket = OrderSend(_Symbol,OP_BUY,0.50,Ask,3,0,0,NULL,0,0,clrGreen);
                 OrderModify(ticket,0,stopLossLevel,takeProfitLevel,0);
                 signal = "";
              
              }
           
        }
        
     if (RSIval15m < 70)
     if (RSIval30m < 70)
     if (RSIval60m < 70)
        {
        
        signal = "SELL"; 
           if(signal == "SELL" && OrdersTotal() == 0)
              {
              
                 ticket = OrderSend(_Symbol,OP_SELL,0.50,Bid,3,0,0,NULL,0,0,clrRed);
                 OrderModify(ticket,0,stopLossLevel,takeProfitLevel,0);
                 
              }
        
        }
  }
double CalculateNormalizedDigits() //Funzione per normalizare le cifre
   {
      if(Digits<=3)
         {
            return(0.01);
         }
      else if(Digits>=4)
         {
            return(0.0001);
         }
      else return(0);
   }



This the code, who is kind enough to give us a peek ?? Thanks

 
TradeMath: I can't understand what I'm wrong. 

"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.

Do you really expect an answer with the information you've provided? There are no mind readers here and our crystal balls are cracked.

Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
 
William Roeder:

"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.

Do you really expect an answer with the information you've provided? There are no mind readers here and our crystal balls are cracked.

Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you



Hi, sorry, the program works partially, it just opens a sell position for me. Then he gives me errors:  OrderModify error 130, OrderModify error 4051,  invalid ticket for OrderModify function. I did as I saw in a programming guide ea. I can't understand where I'm wrong.

 
In future please post in the correct section
I will move your topic to the MQL4 and Metatrader 4 section.

 

@TradeMath Have you bothered to lookup the error codes? Pretty big clues there.

https://book.mql4.com/appendix/errors

Error Codes - Appendixes - MQL4 Tutorial
Error Codes - Appendixes - MQL4 Tutorial
  • book.mql4.com
GetLastError() - the function that returns codes of error. Code constants of errors are determined in stderror.mqh file. To draw the text messages use the ErrorDescription() function described in the stdlib.mqh file. Error codes returned from a trade server or client...
 
Federico Langemark :




I went to see the list of errors! But I did not understand much .. now I am better studying various concepts of the mql4 code.