Diffent Period OpenTicket Problem

 
I read the RSI indicator parameters of the 1-hour period on the 15 minute period,  I read the parameter was correct. However, when I run the EA open order, I found that the parameters of the indicators read were not accurate,Causing incorrect Openorder locatio
//+------------------------------------------------------------------+
//|                                                      kdj俯冲进场.mq4 |
//|                        Copyright 2022, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+


extern int MAXSLIP=3;
extern bool soundalert=true;
extern int lot=1;                  //每次下单的手数
extern int k1=5;
extern int d1=2;
extern int j1=2;

//********************************************************************************************************************************
extern int cciperiod=5;
extern int cciapplied_price=5;
extern int wprperiod=5;
extern int masmaema=0;   //0 PRICE_CLOSE 1 MODE_LWMA  2 MODE_SMMA  3  MODE_LWMA
extern int rsiperiod=5;
extern int rsiapplied_price=5;   //0 PRICE_CLOSE 1 open 2PRICE_HIGH 3PRICE_LOW 4PRICE_MEDIAN 5 PRICE_TYPICAL Typical price, (high + low + close)/3             6PRICE_WEIGHTED
//macd控制
           
extern int Macdfast_ema_period=6;
extern int Macdslow_ema_period=13;
extern int Macdsignal_period=4;
extern int Macdapplied_price=0;  //PRICE_CLOSE0  PRICE_OPEN1 PRICE_HIGH2 PRICE_LOW3  PRICE_MEDIAN4 PRICE_TYPICAL5  PRICE_WEIGHTED6

//********************************************************************************************************************************
   extern int rviperiod=5;

   extern int Osma_fast_ema_period=6;
   extern int Osma_slow_ema_period=13;
   extern int Osma_signal_period=4;
   extern int Osma_applied_price=5;   //0-PRICE_CLOSE
   
//******************BOOL BAND**********************
extern bool alertsMessage=true;
extern bool alertsSound=true;
extern bool alertsEmail=false;
double PointValue;
extern int MaxPeriod=20;
extern int MaxDeviation=2;
extern int MaxShift=0;
extern int Maxapplied_price=0;
//******************BOOL BAND************************
string a1="Z";  //这个是控制交易品种名称用的

datetime doAlertA1;
datetime g_datetime_364;
datetime g_datetime_368;
datetime cc;
datetime cc1;
int inx=0;
int inx1=0;

int OnInit()
  {

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
       
//****************************************************************************************************************************************************************************         
    double close1=iClose(Symbol(),60,1);  double close2=iClose(Symbol(),60,2);  double close3=iClose(Symbol(),60,3);  double close4=iClose(Symbol(),60,4);  double close5=iClose(Symbol(),60,5); double close6=iClose(Symbol(),60,6);     
    double cci1=iCCI(Symbol(),60,cciperiod,cciapplied_price,1);
    double cci2=iCCI(Symbol(),60,cciperiod,cciapplied_price,2);
    double cci3=iCCI(Symbol(),60,cciperiod,cciapplied_price,3);
    double wpr1=iWPR(Symbol(),60,wprperiod,1);
    double wpr2=iWPR(Symbol(),60,wprperiod,2);
    double wpr3=iWPR(Symbol(),60,wprperiod,3);
    double rsi1=iRSI(Symbol(),60,rsiperiod,rsiapplied_price,1);
    double rsi2=iRSI(Symbol(),60,rsiperiod,rsiapplied_price,2);
    double rsi3=iRSI(Symbol(),60,rsiperiod,rsiapplied_price,3);
    
    bool rsijinduo=false;
    bool rsijinkong=false;
    if((rsi1>rsi2)&&(rsi2<rsi3)) rsijinduo=true;
    if((rsi1<rsi2)&&(rsi2>rsi3)) rsijinkong=true;
    bool cciwprjinduo=false;
    bool cciwprjinkong=false;
    if(((cci1>cci2)&&(cci2<cci3))||((wpr1>wpr2)&&(wpr2<wpr3))) cciwprjinduo=true;
    if(((cci1<cci2)&&(cci2>cci3))||((wpr1<wpr2)&&(wpr2>wpr3))) cciwprjinkong=true;

    double MacdPeriodmain1=iMACD(Symbol(),60,Macdfast_ema_period,Macdslow_ema_period,Macdsignal_period,0,MODE_MAIN,1);
    double MacdPeriodsingal1=iMACD(Symbol(),60,Macdfast_ema_period,Macdslow_ema_period,Macdsignal_period,0,MODE_SIGNAL,1);
    double MacdPeriodmain2=iMACD(Symbol(),60,Macdfast_ema_period,Macdslow_ema_period,Macdsignal_period,0,MODE_MAIN,2);
    double MacdPeriodsingal2=iMACD(Symbol(),60,Macdfast_ema_period,Macdslow_ema_period,Macdsignal_period,0,MODE_SIGNAL,2);
    double MacdPeriodmain3=iMACD(Symbol(),60,Macdfast_ema_period,Macdslow_ema_period,Macdsignal_period,0,MODE_MAIN,3);
    double MacdPeriodsingal3=iMACD(Symbol(),60,Macdfast_ema_period,Macdslow_ema_period,Macdsignal_period,0,MODE_SIGNAL,3);

    bool AllBuy=false;
    bool AllSell=false;
    if(cciwprjinduo&&rsijinduo) AllBuy=true;
    if(cciwprjinkong&&rsijinkong) AllSell=true;
   bool HaveBuy=openstat(Symbol(),"buy",60);
   bool HaveSell=openstat(Symbol(),"sell",60);
   if((!HaveBuy)&&AllBuy)
      {
        if(openticket(true,lot,60,"")) Alert("Open",Symbol(),"success");
      }
    if((!HaveSell)&&AllSell)
      {
        if(openticket(false,lot,60,"")) Alert("Open",Symbol(),"success"); 
      }           
  
  }
//+------------------------------------------------------------------+

bool openstat(string name,string ordertp,int magicx){
      bool stat=false;
      bool 是否开有单=false;
      if(OrdersTotal()>0){
        for(int d52=0;d52<OrdersTotal();d52++){
           if(OrderSelect(d52,SELECT_BY_POS,MODE_TRADES)==true)
             {
               if((magicx==15)||(magicx==30)||(magicx==60)||(magicx==240))
                  {
                      if((OrderMagicNumber()==15)||(OrderMagicNumber()==30)||(OrderMagicNumber()==60)||(OrderMagicNumber()==240))
                        {
                           是否开有单=true;
                        }
                  }
              
               if((OrderMagicNumber()==magicx)||(是否开有单))
                 {
  
                    if(ordertp=="buy"){
                         if(OrderType()==OP_BUY){
                             stat=true;
                             break;
                         }
                       } 
                    if(ordertp=="sell"){
                      if(OrderType()==OP_SELL){
                        stat=true;
                        break;
                      }
                    }
                    if(ordertp=="buystop"){
                      if(OrderType()==OP_BUYSTOP){
                        stat=true;
                        break;
                      }
                    }    
                    if(ordertp=="sellstop"){
                      if(OrderType()==OP_SELLSTOP){
                        stat=true;
                        break;
                      }
                    }    
                    if(ordertp=="buylimit"){
                      if(OrderType()==OP_BUYLIMIT){
                        stat=true;
                        break;
                      }
                    }    
                    if(ordertp=="selllimit"){
                      if(OrderType()==OP_SELLLIMIT){
                        stat=true;
                        break;
                      }
                    }    
                  }
               }
            }
        }
        return(stat);
   }

  bool  openticket(bool rr,int openlot,int magic,string danzi){
      int aa=0;
      bool bb=false;
      if(rr){
      if(openlot<1) openlot=1;
         string comm=danzi;
         aa=openOrder(Symbol(),OP_BUY,openlot,Ask,MAXSLIP,0,0,comm,magic,0,clrRed);
             {   
                 if(aa>0){
                 if(soundalert) {
                   Alert(Symbol(),"buysuccess");
                    Sleep(1000);
                    bb=true;
                    return(bb);
                 } 
                    
                 }
                 else
                 {
                 if(soundalert) Alert(Symbol(),"not success,code",GetLastError());
                 Alert("Symbol()=",Symbol(),"lot=",lot,"com=",comm,"magic=",magic);
                 }
             }
         }
      if(!rr){
             string comm=danzi;

            aa=openOrder(Symbol(),OP_SELL,openlot,Bid,MAXSLIP,0,0,comm,magic,0,clrGreen); {
                    if(aa>0){
                    
                   if(soundalert){
                    Alert(Symbol(),"sell success");
                    
                   Sleep(1000);
                   bb=true;
                   return(bb);
                    
                   } 
                    }
                    else 
                    if(soundalert){
                    if(Symbol()=="fu") Alert("Symbol()=",Symbol());
                    Alert(Symbol(),"not success,code",GetLastError());
                    Alert("Symbol()=",Symbol(),"lot=",lot,"com=",comm,"magic=",magic);
                    } 
                }
         }
          return(bb);
   }  
   
   
   
 int openOrder(string symbol, int orderType, int lots, double openOrderPrice, int slippage, double stopLossPrice, double takeProfitPrice, string commentStr, int magicNumber, int expiration, color desiredColor)
{
   int ticketOpened=0;
   for(int i = 0; i < 3; i ++)
   {
      if(IsTradeAllowed() == false)
      {
         Sleep(1000);
         i--;
         continue;
      }
      RefreshRates();
      if(orderType == OP_BUY) openOrderPrice = MarketInfo(Symbol(),MODE_ASK);
      if(orderType == OP_SELL) openOrderPrice = MarketInfo(Symbol(),MODE_BID);
      stopLossPrice = NormalizeDouble(stopLossPrice, Digits);
      takeProfitPrice = NormalizeDouble(takeProfitPrice, Digits);
      if(lots<1) lots=1;
      ticketOpened = OrderSend(symbol, orderType, lots, openOrderPrice, slippage, stopLossPrice, 0, commentStr, magicNumber, expiration, desiredColor);
      if(ticketOpened <= 0)
      {
         
         Print(Symbol(), orderType,"/", lots,"/", openOrderPrice, "/",slippage,"/", stopLossPrice, "/",0,"/", commentStr,"/", magicNumber,"/", expiration,"/", desiredColor);
         Print(Symbol()," 增加 "+getOrderTypeStr(orderType)+" 出错 #",GetLastError());
         Sleep(6000);
      }
      else
      {
         
         return(ticketOpened);
         Sleep(3000);
      }
   }   
   return (ticketOpened);
}


string getOrderTypeStr(int orderType){
   string orderTypeStr;
   switch(orderType){
      case OP_BUY       : orderTypeStr = "即时成交 B单";
                          break;
      case OP_SELL      : orderTypeStr = "即时成交 S单";
                          break;

      //Close pending orders
      case OP_BUYLIMIT  : orderTypeStr = "挂 B单";
                          break;
      case OP_BUYSTOP   : orderTypeStr = "挂 B单";
                          break;
      case OP_SELLLIMIT : orderTypeStr = "挂 S单";
                          break;
      case OP_SELLSTOP  : orderTypeStr = "挂 S单";
                          break;
      default           : orderTypeStr = "没有这种类型";
                          break;
   }
   return(orderTypeStr);
} 

      

 
  1.     double cci1=iCCI(Symbol(),60,cciperiod,cciapplied_price,1);
        double cci2=iCCI(Symbol(),60,cciperiod,cciapplied_price,2);
    

    Do not hard code constants. Use the appropriate symbol PERIOD_H1.

    On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

  2. Your code
        bool rsijinduo=false;
        bool rsijinkong=false;
        if((rsi1>rsi2)&&(rsi2<rsi3)) rsijinduo=true;
        if((rsi1<rsi2)&&(rsi2>rsi3)) rsijinkong=true;
    Simplified
        bool rsijinduo =rsi1>rsi2 && rsi2<rsi3;
        bool rsijinkong=rsi1<rsi2 && rsi2>rsi3;
  3.       stopLossPrice = NormalizeDouble(stopLossPrice, Digits);
          takeProfitPrice = NormalizeDouble(takeProfitPrice, Digits);
    

    You used NormalizeDouble, Its use is usually wrong, as it is in your case.

    1. Floating point has an infinite number of decimals, it's you were not understanding floating point and that some numbers can't be represented exactly. (like 1/10.)
                Double-precision floating-point format - Wikipedia, the free encyclopedia

      See also The == operand. - MQL4 programming forum (2013)

    2. Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.

    3. SL/TP (stops) need to be normalized to tick size (not Point) — code fails on non-currencies.
                On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum #10 (2011)

      And abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum (2012)

    4. Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on non-currencies. So do it right.
                Trailing Bar Entry EA - MQL4 programming forum (2013)
                Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 programming forum (2012)

    5. Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
                (MT4 2013)) (MT5 2022))

    6. MathRound() and NormalizeDouble() are rounding in a different way. Make it explicit.
                MT4:NormalizeDouble - MQL5 programming forum (2017)
                How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum (2017)

    7. Prices (and lots) you get from the terminal are already correct (normalized).

    8. PIP, Point, or Tick are all different in general.
                What is a TICK? - MQL4 programming forum (2014)