Hello, Friends, I have an EA that is running on one pair but sending orders for another pair. It is based on correlations with two pairs and then it trades their cross pair. The Strategy Tester does not allow to test such an EA. Is there any way how to overcome it?
Thank you very much! Pavel
Hi again, here is what I wrote, but the program reports OrderSend Error 138 in the Journal...
//+------------------------------------------------------------------+
int start() {
string symbol_to_trade, order_comment = " ";
double order_size_in_lots = 0.2, price = 1.5000, StopLoss = 0.0, ProfitTarget = 0.0;
int trade_direction = OP_BUY, Slippage = 3, MAGIC_NUMBER = 999, NO_EXPIRY, ticket;
color order_color = Green;
symbol_to_trade = Symbol();
if (iClose("GBPJPY", PERIOD_H4, 0) != 0.0) // just a nonsense to make it test and send the order
ticket = OrderSend(symbol_to_trade, trade_direction, order_size_in_lots, price, Slippage,
StopLoss, ProfitTarget, order_comment, MAGIC_NUMBER, NO_EXPIRY, order_color);
Print (ticket);
return(0); }
//+------------------------------------------------------------------+
So either I do something wrong or the ST does not work with two pairs at once... Pavel
Hi again, here is what I wrote, but the program reports OrderSend Error 138 in the Journal...
So either I do something wrong ...
Yep.
What is an Error 138?
https://docs.mql4.com/trading/errors
Does it have anything to do with you using a price of 1.5000 ?
Hello, dabbler, YES!! You helped me A LOT, I did not realise that the code could not be so simplified. The problem was really with the price. I rewrote the start() function and it really works! So this way we can use the ST for two different pairs but the EA has to run on the pair that is tested. So it looks like a lot of work for me with rewriting it...
Thank you again and have a nice weekend! Pavel
int start() { string symbol_to_trade, order_comment = " "; double order_size_in_lots = 0.2, price, StopLoss = 0.0, ProfitTarget = 0.0; int trade_direction = OP_BUY, Slippage = 3, MAGIC_NUMBER = 999, ticket; datetime expiry = 0; color order_color = Green; symbol_to_trade = Symbol(); RefreshRates(); // ----------------------- price = Ask; // ----------------------- if (iClose("GBPJPY", PERIOD_H4, 0) != 0.0) { ticket = OrderSend(symbol_to_trade, trade_direction, order_size_in_lots, price, Slippage, StopLoss, ProfitTarget, order_comment, MAGIC_NUMBER, expiry, order_color); if (ticket == -1) Print ("Ticket ERROR"); else { Print ("OrderSend() SUCCEEDED"); OrderSelect(ticket, SELECT_BY_TICKET); ProfitTarget = OrderOpenPrice(); ProfitTarget += 0.0035; OrderModify(ticket, OrderOpenPrice(), StopLoss, ProfitTarget, 0, Green); } } return(0); }
Hello, dabbler, YES!! You helped me A LOT, I did not realise that the code could not be so simplified. The problem was really with the price. I rewrote the start() function and it really works! So this way we can use the ST for two different pairs but the EA has to run on the pair that is tested. So it looks like a lot of work for me with rewriting it...
Have you made any progress with this ? I'm trying to do something similar, by necessity not choice, and it doesn't seem to be working . . . not even if I do something simple like this . . .
Comment("Open of bar 50: ", iOpen("CADJPY", PERIOD_H1, 50));
from EURJPY in the Strategy Tester.
I'm trying to do something similar, by necessity not choice, and it doesn't seem to be working . . . not even if I do something simple like this . . .
from EURJPY in the Strategy Tester.
Mine works when run from GBPUSD in the tester (revised) ...
bool first; int init(){ first=true; } int start(){ if( first ){ first = false; for( int n=0; n<50; n++ ){ double val = iClose("EURUSD",PERIOD_M15,n); if( val==0 ) Print("Error = " + GetLastError() + " @ " + TimeToStr( iTime(NULL,PERIOD_M15,n) ) ); else Print("iClose=" + DoubleToStr(val,Digits) + " @ " + TimeToStr( iTime(NULL,PERIOD_M15,n) ) ); } } return(0); }
I checked the date and price on a few bars and they are ok apart from the zero bar which gives me the open price rather than the close.
Mine works when run from GBPUSD in the tester (revised) ...
I checked the date and price on a few bars and they are ok apart from the zero bar which gives me the open price rather than the close.
helps if I use a symbol I have data for at the date I'm running with the ST.
Hello, what I learned from this discussion is that I should always write an EA so that it runs on the chart where it will be actually trading. This is probably the only condition. I could access data from other currency pairs with no problems, the only thing that did not work was sending the orders (OrderSend()). I will rewrite my EA and then I will be able to back-test it automatically in the Strategy Tester.
Thank you all and many pips! Pavel
- 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, Friends, I have an EA that is running on one pair but sending orders for another pair. It is based on correlations with two pairs and then it trades their cross pair. The Strategy Tester does not allow to test such an EA. Is there any way how to overcome it?
Thank you very much! Pavel