Prevent EA from getting restarted every time when switched to another time period - page 2 12 New comment gvdraganov 2014.12.22 17:50 #11 Finally done with my first code ever written and after a week of work, it finally does everything I wanted it to.. many many thanks for your help! Should we not talk again in the next days, merry Christmas!If you are interested, here's the final code.#include <WinUser32.mqh> #import "user32.dll" #import #define N_minutes 60000 extern int templateIndex = 0; string Charts[] = {"EURUSD", "GBPUSD", "USDJPY"}; int Periods[] = {PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1, PERIOD_MN1}; double MACD; double RSI; int i=0,limit=100; int start() { for(int N=0;N<3;N++) { for(int M=0;M<8;M++) { string Period_ID = 0; switch(Periods[M]) { case PERIOD_MN1: Period_ID = "MN1"; break; case PERIOD_W1: Period_ID = "W1"; break; case PERIOD_D1: Period_ID = "D1"; break; case PERIOD_H4: Period_ID = "H4"; break; case PERIOD_H1: Period_ID = "H1"; break; case PERIOD_M30: Period_ID = "M30"; break; case PERIOD_M15: Period_ID = "M15"; break; case PERIOD_M5: Period_ID = "M5"; break; } MACD = iMACD(Charts[N],Periods[M],12,26,9,PRICE_CLOSE,MODE_MAIN,0); RSI = iRSI(Charts[N],Periods[M],14,PRICE_CLOSE,0); if(RSI>70) { if(WindowHandle(Charts[N],Periods[M])>0) { long currChart,prevChart=ChartFirst(); while(i<limit) { if(ChartSymbol(prevChart)==Charts[N] && ChartPeriod(prevChart)==Periods[M]) { PostMessageA(WindowHandle(Charts[N],Periods[M]),WM_COMMAND,34800+templateIndex,0); ChartSetInteger(prevChart,CHART_BRING_TO_TOP,2,true); Alert("Chart already opened: ",Charts[N],", ",Period_ID); } currChart=ChartNext(prevChart); if(currChart<0) { break; } prevChart=currChart; i++; } } else { long IDChart = ChartOpen(Charts[N],Periods[M]); PostMessageA(WindowHandle(Charts[N],Periods[M]),WM_COMMAND,34800+templateIndex,0); Alert("New chart: ",Charts[N],", ",Period_ID); } } } } Alert("Finished"); Sleep(5*N_minutes); return; } Please is this possible Beta version of the One trade per bar Carl Schreiber 2014.12.22 17:54 #12 Thanks for posting the result!But are you sure PostMessageA() is working? We had to replace all the Windows'-..A()-functions (ASCII) by ..W()-functions (Wide, ANSI)? gvdraganov 2014.12.22 18:05 #13 Well, it seems to work for me.. so far I couldn't recreate a situation in which it didn't work and I have tested it extensively. William Roeder 2014.12.24 13:08 #14 You converted Periods to a constant initialized array. You could do the same with PeriodsToTextint Periods[] = {PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1, PERIOD_MN1}; : string Period_ID = 0; switch(Periods[M]) { case PERIOD_MN1: Period_ID = "MN1"; break; case PERIOD_W1: Period_ID = "W1"; break; case PERIOD_D1: Period_ID = "D1"; break; case PERIOD_H4: Period_ID = "H4"; break; case PERIOD_H1: Period_ID = "H1"; break; case PERIOD_M30: Period_ID = "M30"; break; case PERIOD_M15: Period_ID = "M15"; break; case PERIOD_M5: Period_ID = "M5"; break; }int Periods[] = {PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1, PERIOD_MN1}; string PeriodsToText[] = {"M5", "M15", "M30", "H1", "H4", "D1", "W1", "MN1"}; : string Period_ID = PeriodsToText[M]; How to code? Help please divergence indi Get current timeframe 12 New comment
Finally done with my first code ever written and after a week of work, it finally does everything I wanted it to.. many many thanks for your help! Should we not talk again in the next days, merry Christmas!
If you are interested, here's the final code.
Thanks for posting the result!
But are you sure PostMessageA() is working? We had to replace all the Windows'-..A()-functions (ASCII) by ..W()-functions (Wide, ANSI)?
PERIOD_H1, PERIOD_H4, PERIOD_D1,
PERIOD_W1, PERIOD_MN1};
:
string Period_ID = 0;
switch(Periods[M])
{
case PERIOD_MN1: Period_ID = "MN1"; break;
case PERIOD_W1: Period_ID = "W1"; break;
case PERIOD_D1: Period_ID = "D1"; break;
case PERIOD_H4: Period_ID = "H4"; break;
case PERIOD_H1: Period_ID = "H1"; break;
case PERIOD_M30: Period_ID = "M30"; break;
case PERIOD_M15: Period_ID = "M15"; break;
case PERIOD_M5: Period_ID = "M5"; break;
}
PERIOD_H1, PERIOD_H4, PERIOD_D1,
PERIOD_W1, PERIOD_MN1};
string PeriodsToText[] = {"M5", "M15", "M30",
"H1", "H4", "D1",
"W1", "MN1"};
:
string Period_ID = PeriodsToText[M];