//+-------------------------------------------------------------------------------------------------------+ //| Global Variables | //+-------------------------------------------------------------------------------------------------------+ double symbol_points[]; string symbol_loop[] = {"GBPUSD", "EURUSD"}; datetime old_time; //+-------------------------------------------------------------------------------------------------------+ //| Include Files | //+-------------------------------------------------------------------------------------------------------+ #include <Trade/Trade.mqh> CTrade trade; //+-------------------------------------------------------------------------------------------------------+ //| On OnInit | //+-------------------------------------------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+-------------------------------------------------------------------------------------------------------+ //| OnTick | //+-------------------------------------------------------------------------------------------------------+ void OnTick(){ datetime GMT = iTime(_Symbol, PERIOD_M15, 1); if (GMT > old_time){ old_time = GMT; for (int i = 0; i < ArraySize(symbol_loop); i++){ string symbol = symbol_loop[i]; double Low = low(symbol, 1); if(isCandlestickBullish(symbol, 1)){ createObject(old_time, Low, 233, 1, clrRed, "Testing", symbol); } } } } bool isCandlestickBullish(string symbol, int shift) { double openPrice = iOpen(symbol, PERIOD_CURRENT, shift); double closePrice = iClose(symbol, PERIOD_CURRENT, shift); return closePrice > openPrice; } bool isPrevCandlestickBullish(string symbol, int shift) { double openPrice = iOpen(symbol, PERIOD_CURRENT, shift); double closePrice = iClose(symbol, PERIOD_CURRENT, shift); return closePrice > openPrice; } //+-------------------------------------------------------------------------------------------------------+ //| EA Candlestick Displays | //+-------------------------------------------------------------------------------------------------------+ void createObject(datetime time, double price, int arrowcode, int direction, color clr, string txt, string psymbol) { string objName = ""; StringConcatenate(objName, "Signal@", " ", psymbol, " ", time, " at ", DoubleToString(price, _Digits), " (", arrowcode, ")"); if (ObjectCreate(0, objName, OBJ_ARROW, 0, time, price)) { ObjectSetInteger(0, objName, OBJPROP_ARROWCODE, arrowcode); ObjectSetInteger(0, objName, OBJPROP_COLOR, clr); ObjectSetString(0, objName, OBJPROP_SYMBOL, psymbol); if (direction > 0) ObjectSetInteger(0, objName, OBJPROP_ANCHOR, ANCHOR_TOP); if (direction < 0) ObjectSetInteger(0, objName, OBJPROP_ANCHOR, ANCHOR_BOTTOM); } string objectNameDesc = objName + txt; if (ObjectCreate(0, objectNameDesc, OBJ_TEXT, 0, time, price)) { ObjectSetString(0, objectNameDesc, OBJPROP_TEXT, " " + txt); ObjectSetInteger(0, objectNameDesc, OBJPROP_COLOR, clr); if (direction > 0) ObjectSetInteger(0, objectNameDesc, OBJPROP_ANCHOR, ANCHOR_TOP); if (direction < 0) ObjectSetInteger(0, objectNameDesc, OBJPROP_ANCHOR, ANCHOR_BOTTOM); } } double low(string symbol, int shift) { return iLow(symbol, PERIOD_CURRENT, shift); }
To be able to add graphical objects for other symbols (i.e. other charts), you would need to ...
- Scan all open charts, using ChartFirst and ChartNext to find the one you wish to use (i.e. the desired symbol, time-frame, etc.). There may be more than one or none at all.
- If none exist, then you would have to open up a new chart for the desired symbol.
- Once you have identified the desired chart id, then you can add graphical objects to that chart.
To be able to add graphical objects for other symbols (i.e. other charts), you would need to ...
- Scan all open charts, using ChartFirst and ChartNext to find the one you wish to use (i.e. the desired symbol, time-frame, etc.). There may be more than one or none at all.
- If none exist, then you would have to open up a new chart for the desired symbol.
- Once you have identified the desired chart id, then you can add graphical objects to that chart.
How can I confirm whether a chart has been opened? I included the following code in an EA which shows trades are being opened close yet the first value returns 12345 and the next -1. Does that mean if though trades are being places and i can see them in the visualize section the chart isnt actually open?
long chartID1 = ChartFirst(); long chartID2 = ChartNext(chartID1); Print(chartID1); Print(chartID2);
Even when adding the following function, the values of the charts opened return the same value suggesting something is wrong:
void OpenChartsForSymbols() { for (int i = 0; i < ArraySize(symbol_loop); i++) { string symbol = symbol_loop[i]; int timeframe = PERIOD_M15; // Adjust the timeframe as needed // Check if the chart is already open for the symbol and timeframe long chartID = ChartID(); if (chartID == 0) { // The chart is not open, so open it chartID = ChartOpen(symbol, timeframe); if (chartID <= 0) { // Handle any errors that occurred during chart opening } } } }
Finally ive used this code from the MQL5 documentation for looping the chartID, will this be effective?
long currChart,prevChart=ChartFirst(); int i=0,limit=100; Print("ChartFirst =", ChartSymbol(prevChart)," ID =",prevChart); while(i<limit)// We have certainly not more than 100 open charts { currChart=ChartNext(prevChart); // Get the new chart ID by using the previous chart ID if(currChart<0) break; // Have reached the end of the chart list Print(i,ChartSymbol(currChart)," ID =",currChart); prevChart=currChart;// let's save the current chart ID for the ChartNext() i++;// Do not forget to increase the counter
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi Everyone,
not entirely how this works since this is my first post:)
Everything in this EA works fine, i tested it all multiple times. The only issue lies in the createObject. It works fine when i create objects just for one symbol which i make corresponding in the strategy tester although when backtesting on multiple symbols or i dont make the symbol the same in the strategy tester as in the code, the objects no longer appear at all. How can this be solved? Thanks in advance;)