Hello evrybody,
I have a problem setting a symbol name to a strategy i created. this is some test code to reproduce the problem...
What a mess. Why are you using OOP ? It seems you don't understand what you are doing.
Just one example :
//--- Constructor Instrument() { int size = ArrayResize(sAr, 3); for(int s=0;s<size;s++){ sAr[s]=stratAr[s];} }
stratAr[] is a global array, that breaks encapsulation.
public: Strategy *sAr[]; string symbol;
Your Strategy class contains a property "symbol" and you add again a property "symbol" to your Instrument class, why ?
The problem is after setting the symbol to the strategy on the Init() function the symbol name of the last symbol is copied to all insAr[x].sAr[y].symbol
i don't understand why because insAr[x] is an object. the variable symbol of insAr[x] should hold the symbol of that instrument but it looks like its being copied over by the next insAr[x+1] ???
You set the same Strategy array to you Instrument in your constructor :
for(int s=0;s<size;s++){ sAr[s]=stratAr[s];} // Instrument constructor
Then you set the same value to symbol for the 3 strategies.
for(int i=0;i<size;i++){sAr[i].symbol=symbol;} // Instrument Init
As your Strategy array is global you change the same value each time, and only the last one is kept.
I still wonder what you are trying to do ?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello evrybody,
I have a problem setting a symbol name to a strategy i created. this is some test code to reproduce the problem...
//+------------------------------------------------------------------+ //| test.mqh | //| Copyright 2014, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, MetaQuotes Software Corp." #property link "https://www.mql5.com" //+------------------------------------------------------------------+ //| defines | //+------------------------------------------------------------------+ // #define MacrosHello "Hello, world!" // #define MacrosYear 2010 //+------------------------------------------------------------------+ //| DLL imports | //+------------------------------------------------------------------+ // #import "user32.dll" // int SendMessageA(int hWnd,int Msg,int wParam,int lParam); // #import "my_expert.dll" // int ExpertRecalculate(int wParam,int lParam); // #import //+------------------------------------------------------------------+ //| EX5 imports | //+------------------------------------------------------------------+ // #import "stdlib.ex5" // string ErrorDescription(int error_code); // #import //+------------------------------------------------------------------+ #define EXPERT_NAME "test" // Name of the Expert AdvisorThe problem is after setting the symbol to the strategy on the Init() function the symbol name of the last symbol is copied to all insAr[x].sAr[y].symbol
i don't understand why because insAr[x] is an object. the variable symbol of insAr[x] should hold the symbol of that instrument but it looks like its being copied over by the next insAr[x+1] ???
thank you
result:
2014.09.21 13:48:23.421 test (GBPUSD,H1) 9 - symbol_2 ==> third strategy ==> symbol_5
2014.09.21 13:48:23.421 test (GBPUSD,H1) 8 - symbol_2 ==> second strategy ==> symbol_5
2014.09.21 13:48:23.421 test (GBPUSD,H1) 7 - symbol_2 ==> first strategy ==> symbol_5
2014.09.21 13:48:23.421 test (GBPUSD,H1) 6 - symbol_1 ==> third strategy ==> symbol_5
2014.09.21 13:48:23.421 test (GBPUSD,H1) 5 - symbol_1 ==> second strategy ==> symbol_5
2014.09.21 13:48:23.421 test (GBPUSD,H1) 4 - symbol_1 ==> first strategy ==> symbol_5
2014.09.21 13:48:23.421 test (GBPUSD,H1) 3 - symbol_0 ==> third strategy ==> symbol_5
2014.09.21 13:48:23.421 test (GBPUSD,H1) 2 - symbol_0 ==> second strategy ==> symbol_5
2014.09.21 13:48:23.421 test (GBPUSD,H1) 1 - symbol_0 ==> first strategy ==> symbol_5