Each currency pair to have it's own GlobalVariable, for example "MyEA_EURUSD".
If you were restricting the EA to one trade per day the code would be:
string sCheck = "MyEA_" + Symbol();
datetime t = TimeCurrent();
datetime tTrade = t - TimeHour(t)*60*60 - TimeMinute(t)*60 - TimeSeconds(t);
if(!GlobalVariableCheck(sCheck)) GlobalVariableSet(sCheck, tTrade -PERIOD_D1 * 60);
if(GlobalVariableGet(sCheck) < tTrade) {
OrderSend(......);
GlobalVariableSet(sCheck, tTrade);
}
Sorry for bringing this back to the top but i'm having the same problem right now. Unfortunately sxTed didn't answered the question to me. Because describing a trading time is something different than the amount of orders for each currency pairs.
I tried to modify sxTed's lines but I think I failed horrible in solving this problem:
string sCheck = "MyEA_" + Symbol(); // already the first error in the code, second quotes should be at the end of the line. //I would correct this one to: string sCheck = "MyEA_ + Symbol()"; //However symbol() is not a function anymore ?? int start () { // Closing Orders here if(!GlobalVariableCheck(sCheck)) //checking Globalvariable, GV available so it becomes true (independently of what kind of GV we have)... GlobalVariableSet(sCheck, Symbol() ); //.. assigning a new GlobalVariable to the function of the current symbol the EA is attached on (does it actually work like this?) if(GlobalVariableGet(sCheck) == Symbol()) { // checking if our Symbol is the one which the EA is attached on --> becomes true... // Order Criteria (Open trades here) // What now? Actually i'm missing any kind of numbers or smth that limits the open orders per currency pair.
PLEASE: don't link me to any literature at this place or tell me to hire someone, i'm studying the book right now and got stucked!!!
For each currency pair I use a separate EA.
To verify if an position should be opened, I test if there is no open order "if (OrdersTotal<1)" but this will block all other currency pairs to open positions and I miss opportunities.
In other words: I want to open only one position per currency pair = multiple positions should be possible but in different currency pairs.
What code should I use instead of the "if (OrdersTotal<1)"? Can anyone help me? Thank you in advance for your help.
int total=OrdersTotal(); int count = 0; int magno = 12345; for(int pos=0;pos<total;pos++) { if(OrderSelect(pos,SELECT_BY_POS) == false) continue; if (OrderMagicNumber() != magno) continue; if (OrderSymbol() != Symbol()) continue; count++; } // Now you know how many orders for this symbol are open by this EA. if (count < 1) { // do something - open order perhaps }Does this help?
Does this help?
Does this help?
int total=OrdersTotal();
limits the total openorders of ALL currency pairs or not?
I inserted your code as followed
int total=OrdersTotal(); int count = 0; for(int pos=0;pos<total;pos++) { if(OrderSelect(pos,SELECT_BY_POS) == false) continue; if (OrderSymbol() != Symbol()) continue; count++; } if (Sell_1_1 < Sell_1_2 && CloseSell1_1 > CloseSell1_2 && count < 1) Order = SIGNAL_SELL; // Trigger for Sell if (Buy_1_1 > Buy_1_2 && CloseBuy1_1 < CloseBuy1_2 && count < 1) Order = SIGNAL_BUY; // Trigger for Buy if (order == SIGNAL_BUY) { OrderSend(...) }
and it's still opening only one trade at all. What was sxTed trying to tell us with his global variable?
limits the total openorders of ALL currency pairs or not?
I inserted your code as followed
and it's still opening only one trade at all. What was sxTed trying to tell us with his global variable?
How many charts do you have your EA on ?
For testing the code i opened 5 charts but I want to open N charts. The amount shall not matter.
For each currency pair I use a separate EA.
To verify if an position should be opened, I test if there is no open order "if (OrdersTotal<1)" but this will block all other currency pairs to open positions and I miss opportunities.
In other words: I want to open only one position per currency pair = multiple positions should be possible but in different currency pairs.
What code should I use instead of the "if (OrdersTotal<1)"? Can anyone help me? Thank you in advance for your help.
Code it like this :
int Total_Order = OrdersTotal(); for (pos = 0; pos <= Total_Order; pos ++) { if (OrderSelect (pos, SELECT_BY_POS) == true) { if (OrderSymbol () == Symbol ()) { Print (":( Sorry already have that symbol opened "); // get outta here do something else break ; } else { Print ("No order opened for this symbol"); Print ("Let\'s call waitress and order some drink :)"); // do some order then break out and get out } } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
For each currency pair I use a separate EA.
To verify if an position should be opened, I test if there is no open order "if (OrdersTotal<1)" but this will block all other currency pairs to open positions and I miss opportunities.
In other words: I want to open only one position per currency pair = multiple positions should be possible but in different currency pairs.
What code should I use instead of the "if (OrdersTotal<1)"? Can anyone help me? Thank you in advance for your help.