I have created a testing EA to calculate High Low value index, and draw arrow for these points on chart. However, while using for..loop it is drawing only 0 and 1 element from the array(s). Rest of the elements 2 to 9 are not drawn.
Please help me to locate the issue ...
externint MajorSwingSize = 3;
externint PeriodsInMajorSwing = 13;
externint MinorSwingSize = 1;
externint PeriodsInMinorSwing = 5;
int idxMajorSwingHigh[];
int idxMinorSwingHigh[];
int idxMajorSwingLow[];
int idxMinorSwingLow[];
//+----------------------------------------------------------------------------------------------------------+//| Custom indicator initialization function//+----------------------------------------------------------------------------------------------------------+intOnInit()
{
//---return(INIT_SUCCEEDED);
}
//+----------------------------------------------------------------------------------------------------------+//| Initialization Function//+----------------------------------------------------------------------------------------------------------+voidOnTick()
{
MqlRates MyRates[];
ArraySetAsSeries(MyRates,true);
int data = CopyRates(Symbol(),PERIOD_CURRENT,0,Bars(Symbol(),PERIOD_CURRENT),MyRates);
if(Check_IsNewCandle())
{
int limit = 1000;
int countA = 0, countB = 0, countC = 0, countD = 0;
for(int i = 1; i < limit; i++)
{
// Minor Swing High Logicif(iHighest(Symbol(),PERIOD_CURRENT,MODE_HIGH,PeriodsInMinorSwing*2,i) == i + PeriodsInMinorSwing)
{
if(countA < 10)
{
ArrayResize(idxMinorSwingHigh,countA+1);
idxMinorSwingHigh[countA] = (int)(i+PeriodsInMinorSwing);
countA++;
}
}
// Major Swing High Logicif(iHighest(Symbol(),PERIOD_CURRENT,MODE_HIGH,PeriodsInMajorSwing*2,i)==i+PeriodsInMajorSwing)
{
if(countB < 10)
{
ArrayResize(idxMajorSwingHigh,countB+1);
idxMajorSwingHigh[countB] = (int)(i+PeriodsInMajorSwing);
countB++;
}
}
// Minor Swing Low Logicif(iLowest(Symbol(),PERIOD_CURRENT,MODE_LOW,PeriodsInMinorSwing*2,i)==i+PeriodsInMinorSwing)
{
if(countC < 10)
{
ArrayResize(idxMinorSwingLow,countC+1);
idxMinorSwingLow[countC] = (int)(i+PeriodsInMinorSwing);
countC++;
}
}
// Major Swing Low Logicif(iLowest(Symbol(),PERIOD_CURRENT,MODE_LOW,PeriodsInMajorSwing*2,i)==i+PeriodsInMajorSwing)
{
if(countD < 10)
{
ArrayResize(idxMajorSwingLow,countD+1);
idxMajorSwingLow[countD] = (int)(i+PeriodsInMajorSwing);
countD++;
}
}
}
// Create OBJECT ARROW for High Low Pointsfor(int i = 0; i < 10; i++)
{
//ArrowSwing_MajorHigh(PERIOD_CURRENT,MyRates[idxMajorSwingHigh[i]].time,MyRates[idxMajorSwingHigh[i]].high);
DrawArrow_HighLow(PERIOD_CURRENT,(string)"Major",(string)"High",MyRates[idxMajorSwingHigh[i]].time,MyRates[idxMajorSwingHigh[i]].high);
DrawArrow_HighLow(PERIOD_CURRENT,(string)"Major",(string)"Low",MyRates[idxMajorSwingLow[i]].time,MyRates[idxMajorSwingLow[i]].low);
DrawArrow_HighLow(PERIOD_CURRENT,(string)"Minor",(string)"High",MyRates[idxMinorSwingHigh[i]].time,MyRates[idxMinorSwingHigh[i]].high);
DrawArrow_HighLow(PERIOD_CURRENT,(string)"Minor",(string)"Low",MyRates[idxMinorSwingLow[i]].time,MyRates[idxMinorSwingLow[i]].low);
}
/*
// PRINT Statement to check array values
for(int y = 0; y < 10; y++)
{
Print("MAJOR [",y,"] High [",idxMajorSwingHigh[y],"] MyRates [",MyRates[idxMajorSwingHigh[y]].high,
"] Low [",idxMajorSwingLow[y],"] MyRates [",MyRates[idxMajorSwingLow[y]].low,"]");
}
for(int y = 0; y < 10; y++)
{
Print("MINOR [",y,"] High [",idxMinorSwingHigh[y],"] MyRates [",MyRates[idxMinorSwingHigh[y]].high,
"] Low [",idxMinorSwingLow[y],"] MyRates [",MyRates[idxMinorSwingLow[y]].low,"]");
}
*/
}
}
//+----------------------------------------------------------------------------------------------------------+//+----------------------------------------------------------------------------------------------------------+//| Function: DrawArrow_HighLow()//+----------------------------------------------------------------------------------------------------------+bool DrawArrow_HighLow(constENUM_TIMEFRAMES chartTimeFrame, // chart's IDstring swingType, // Major or Minorstring priceType, // High or Lowdatetime anchorTime, // anchor point timedouble anchorPrice) // anchor point price
{
color anchorColor = NULL;
int anchorWidth = NULL;
string arrowName = NULL;
ENUM_ARROW_ANCHOR anchorPosition = NULL;
if(swingType == "Major")
{
anchorColor = clrPurple; anchorWidth = 3;
if(priceType == "High")
{
arrowName = "Major Swing High"; anchorPosition = ANCHOR_TOP;
}
elseif(priceType == "Low")
{
arrowName = "Major Swing Low"; anchorPosition = ANCHOR_BOTTOM;
}
}
elseif(swingType == "Minor")
{
anchorColor = clrCornflowerBlue; anchorWidth = 1;
if(priceType == "High")
{
arrowName = "Minor Swing High"; anchorPosition = ANCHOR_TOP;
}
elseif(priceType == "Low")
{
arrowName = "Minor Swing Low"; anchorPosition = ANCHOR_BOTTOM;
}
}
ResetLastError(); //--- reset the error value//--- create an arrowif(!ObjectCreate(chartTimeFrame,arrowName,OBJ_ARROW,0,anchorTime,anchorPrice))
{
Print(__FUNCTION__,
": failed to create ArrowSwing_MajorHigh! Error code = ",GetLastError());
return(false);
}
ObjectSetInteger(chartTimeFrame,arrowName,OBJPROP_ARROWCODE,108); // Arrow CodeObjectSetInteger(chartTimeFrame,arrowName,OBJPROP_ANCHOR,anchorPosition); // Anchor TypeObjectSetInteger(chartTimeFrame,arrowName,OBJPROP_COLOR,anchorColor); // Arrow ColorObjectSetInteger(chartTimeFrame,arrowName,OBJPROP_STYLE,DRAW_ARROW); // BorderLine StyleObjectSetInteger(chartTimeFrame,arrowName,OBJPROP_WIDTH,anchorWidth); // Arrow SizeObjectSetInteger(chartTimeFrame,arrowName,OBJPROP_BACK,false); // display in the foreground (false) or background (true)ObjectSetInteger(chartTimeFrame,arrowName,OBJPROP_HIDDEN,true); // True = hide object name in the object list //--- successful executionreturn(true);
} // END Of DrawArrow_HighLow()//+----------------------------------------------------------------------------------------------------------+//| Function: ArrowSwing_MajorHigh() --> Alternate code to print only MajorHigh Arrow//+----------------------------------------------------------------------------------------------------------+bool ArrowSwing_MajorHigh(constENUM_TIMEFRAMES chartTimeFrame, // chart's IDdatetime timeMajorHigh, // anchor point timedouble priceMajorHigh) // anchor point price
{
ResetLastError(); //--- reset the error value//--- create an arrowif(!ObjectCreate(chartTimeFrame,"Major Swing High",OBJ_ARROW,0,timeMajorHigh,priceMajorHigh))
{
Print(__FUNCTION__,
": failed to create ArrowSwing_MajorHigh! Error code = ",GetLastError());
return(false);
}
ObjectSetInteger(chartTimeFrame,"Major Swing High",OBJPROP_ARROWCODE,108); // Arrow CodeObjectSetInteger(chartTimeFrame,"Major Swing High",OBJPROP_ANCHOR,ANCHOR_TOP); // Anchor TypeObjectSetInteger(chartTimeFrame,"Major Swing High",OBJPROP_COLOR,clrPurple); // Arrow ColorObjectSetInteger(chartTimeFrame,"Major Swing High",OBJPROP_STYLE,DRAW_ARROW); // BorderLine StyleObjectSetInteger(chartTimeFrame,"Major Swing High",OBJPROP_WIDTH,3); // Arrow SizeObjectSetInteger(chartTimeFrame,"Major Swing High",OBJPROP_BACK,false); // display in the foreground (false) or background (true)ObjectSetInteger(chartTimeFrame,"Major Swing High",OBJPROP_HIDDEN,true); // True = hide object name in the object list //--- successful executionreturn(true);
}
//+----------------------------------------------------------------------------------------------------------+bool Check_IsNewCandle()
{
bool newCandle;
staticdatetime dtBarCurrent = WRONG_VALUE;
datetime dtBarPrevious = dtBarCurrent;
// "SERIES_LASTBAR_DATE" Open time of the last bar of the symbol - period
dtBarCurrent = (datetime)SeriesInfoInteger(Symbol(),PERIOD_CURRENT,SERIES_LASTBAR_DATE);
if(dtBarCurrent != dtBarPrevious) newCandle = true;
else newCandle = false;
//---return(newCandle);
} // END Of Check_IsNewCandle()
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi Friends
I have created a testing EA to calculate High Low value index, and draw arrow for these points on chart. However, while using for..loop it is drawing only 0 and 1 element from the array(s). Rest of the elements 2 to 9 are not drawn.
Please help me to locate the issue ...