Need Help With ChartSetSymbolPeriod No Data

 

Hi there, really could use some help here.  My code is pretty simple, I drag the EA onto a chart template and it get's the values from a Fibonacci indicator on the template.  The problem is when I call the ChartSetSymbolPeriod method  when iterating between periods or symbols I either get object data from the previous period or pair or no data at all.  The indicators are in the chart template and the objects are drawn on the chart.  I've tested everything from ChartRedraw to WindowRedraw with no luck at all.  Any tips?  Even the test Alert there is showing the Ask price from the previous element in the Pairs array.  I'm super confused because the chart is drawn correctly on the screen, but the output is from the previous pair.  

Thanks so much.  I'm a newbie, so please go easy.


Here is my skeleton code...


//+------------------------------------------------------------------+
//|                                                    TIMERTEST.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

static string Pairs[8] = {"ETHUSD","XRPUSD"};

static int PairsTimeFrame[2] = {1,1};
static int PairsCounter = 0;
double BuyZoneFloor = 0;
double BuyZoneCeiling = 0;
double SellZoneFloor = 0;
double SellZoneCeiling = 0;
color ArrowColor;
double InnerPairsCounter = 0;
static double PairsCheck = 0;

int OnInit()
  {
//--- create timer
   //ChartApplyTemplate(0, "ADX");
   EventSetTimer(5);   
   //SendMail("test", "test");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//-
   EventKillTimer(); 
//---

   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
      if(PairsCounter == 2 ){
         PairsCounter = 0;
         
      }
   

      ChartSetSymbolPeriod(0, Pairs[PairsCounter], PairsTimeFrame[PairsCounter]);
      ChartRedraw();
      WindowRedraw();
      BuyZoneFloor = ObjectGet("BuyZone", OBJPROP_PRICE1);
      BuyZoneCeiling = ObjectGet("BuyZone", OBJPROP_PRICE2);
      SellZoneFloor = ObjectGet("SellZone", OBJPROP_PRICE1);
      SellZoneCeiling = ObjectGet("SellZone", OBJPROP_PRICE2);
      
      Alert(Ask);
      if((Ask > BuyZoneFloor) && (Ask < BuyZoneCeiling)){
         // we will do something here
      } else if((Ask >  SellZoneFloor) && (Ask < SellZoneCeiling)){
         ArrowColor = StringToColor("255,0,0");
      }else{
         // we will do something here
      }

      Comment( 
      Symbol() + ": " + Symbol() + "\n" +
      Period() + ": " + "Period" + "\n" +
      BuyZoneFloor + ": " + Pairs[PairsCounter] + "\n" +
      BuyZoneCeiling + ": " + Pairs[PairsCounter] + "\n" +
      SellZoneFloor + ": " + Pairs[PairsCounter] + "\n" +
      SellZoneCeiling + ": " + Pairs[PairsCounter] + "\n" 
      );
     
 
  
      
      BuyZoneFloor = 0;
      BuyZoneCeiling = 0;
      SellZoneFloor = 0;
      SellZoneCeiling = 0;
      PairsCheck = -1;
      
      PairsCounter++;

   
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   
  }
//+------------------------------------------------------------------+




Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2021.02.28
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
checkmarkit:







solved it!  i didn't realize ChartSetSymbolPeriod ran asynchronously.  I set a boolean flag after chart change and returned to OnInit and it's all working dandy now!
This website uses cookies. Learn more about our Cookies Policy.