1. Handle of the indicator CANNOT be created AT EVERY TICK - this is a gross mistake. An indicator handle is created ONCE in OnInit.
//--- input parameters *** //--- RSI input int Inp_RSI_ma_period = 14; // RSI: averaging period input ENUM_APPLIED_PRICE Inp_RSI_applied_price= PRICE_CLOSE; // RSI: type of price *** int handle_iRSI; // variable for storing the handle of the iRSI indicator *** //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create handle of the indicator iRSI handle_iRSI=iRSI(Symbol(),Period(),Inp_RSI_ma_period,Inp_RSI_applied_price); //--- if the handle is not created if(handle_iRSI==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle of the iRSI indicator for the symbol %s/%s, error code %d", Symbol(), EnumToString(Period()), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } *** //--- return(INIT_SUCCEEDED); }
2. The array (into which you copy these indicators) must be expanded using ArraySetAsSeries (in this case, the index [0] is the indicator value on the RIGHT BAR on the chart.
//+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { double rsi[]; ArraySetAsSeries(rsi,true); int start_pos=0,count=3; if(!iGetArray(handle_iRSI,0,start_pos,count,rsi)) return; m_trade....
3. Once you correct the first two errors, you can search for the following errors.
thank you @Vladimir Karputov for your help. thank you very much.
I edited the code to correct format as you said.
now we have this code:
#include <Trade/Trade.mqh> CTrade trade; input int Inp_RSI_ma_period = 14; input ENUM_APPLIED_PRICE Inp_RSI_applied_price= PRICE_CLOSE; int handle_iRSI; input int Inp_CCI_period = 14; input ENUM_APPLIED_PRICE Inp_CCI_applied_price= PRICE_CLOSE; int handle_iCCI; int OnInit() { handle_iRSI=iRSI(Symbol(),Period(),Inp_RSI_ma_period,Inp_RSI_applied_price); if(handle_iRSI==INVALID_HANDLE) { PrintFormat("Failed to create handle of the iRSI indicator for the symbol %s/%s, error code %d", Symbol(), EnumToString(Period()), GetLastError()); return(INIT_FAILED); } handle_iCCI=iCCI(Symbol(),Period(),Inp_CCI_period,Inp_CCI_applied_price); if(handle_iCCI==INVALID_HANDLE) { PrintFormat("Failed to create handle of the CCSI indicator for the symbol %s/%s, error code %d", Symbol(), EnumToString(Period()), GetLastError()); return(INIT_FAILED); } return(INIT_SUCCEEDED); } void OnTick() { double ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); double bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); int start_pos=0,count=3; double rsi[]; ArraySetAsSeries(rsi,true); if(CopyBuffer(handle_iRSI,0,start_pos,count,rsi)<0) return; int currentRSI=rsi[0]; double cci[]; ArraySetAsSeries(cci,true); if(CopyBuffer(handle_iCCI,0,start_pos,count,cci)<0) return; int currentCCI=cci[0]; if(currentRSI>70 && currentCCI>100 && PositionsTotal()==0) trade.Sell(0.1,NULL,0,bid+200*_Point,bid-400*_Point,NULL); if(currentRSI<30 && currentCCI<-100 && PositionsTotal()==0) trade.Buy(0.1,NULL,0,ask-200*_Point,ask+400*_Point,NULL); Comment("RSI:\n"+rsi[0]+"\n"+rsi[1]+"\n"+rsi[2]+"\n\nCCI:\n"+cci[0]+"\n"+cci[1]+"\n"+cci[2]); }
but the main problem exists. << in backtesting this code trades on eur/usd but doesn't trade on iranian symbols!>>
live real trading is not important, just working this EA in backtesting is important in this case that is not related to broker. we have price and... data, we have an EA that works on EUR/USD and ... but that doesn't work on iranian symbol in backtesting. maybe it is because of my strategy tester confige. I don't know how to solve this problem.
in attached picture u can see the sell condition but the code did't sold.
thank you @Vladimir Karputov for your help. thank you very much.
I edited the code to correct format as you said.
now we have this code:
but the main problem exists. << in backtesting this code trades on eur/usd but doesn't trade on iranian symbols!>>
live real trading is not important, just working this EA in backtesting is important in this case that is not related to broker. we have price and... data, we have an EA that works on EUR/USD and ... but that doesn't work on iranian symbol in backtesting. maybe it is because of my strategy tester confige. I don't know how to solve this problem.
in attached picture u can see the sell condition but the code did't sold.
Hi Soroush,
I've also tried to do some backtesting with Rial, but came across the same problem, just wanted to know if you were able to solve the issue ?
thank you @Vladimir Karputov for your help. thank you very much.
I edited the code to correct format as you said.
now we have this code:
but the main problem exists. << in backtesting this code trades on eur/usd but doesn't trade on iranian symbols!>>
live real trading is not important, just working this EA in backtesting is important in this case that is not related to broker. we have price and... data, we have an EA that works on EUR/USD and ... but that doesn't work on iranian symbol in backtesting. maybe it is because of my strategy tester confige. I don't know how to solve this problem.
in attached picture u can see the sell condition but the code did't sold.
You choose the symbol, testing period and timeframe in the strategy tester yourself.
Just set up the strategy tester correctly.
You choose the symbol, testing period and timeframe in the strategy tester yourself.
Just set up the strategy tester correctly.
I'm setting it up correctly, but it still doesn't work! I think it has something to do with having the deposit in local currency RLS.
I'm setting it up correctly, but it still doesn't work! I think it has something to do with having the deposit in local currency RLS.
Read the Log tab (Journal) - what does the tester write?
Read the Log tab (Journal) - what does the tester write?
The Journal says nothing, that's the problem! There's no error, or at least I'm not able to find one.
This is the log:
DQ 0 22:55:43.335 Startup MetaTester 5 x64 build 2605 (11 Sep 2020) OD 0 22:55:43.360 Server MetaTester 5 started on 127.0.0.1:3000 CO 0 22:55:43.364 Startup initialization finished NM 0 22:55:43.585 127.0.0.1 login (build 2634) OK 0 22:55:43.601 Network 4372 bytes of account info loaded PM 0 22:55:43.601 Network 1482 bytes of tester parameters loaded LF 0 22:55:43.602 Network 700 bytes of input parameters loaded OO 0 22:55:43.637 Network 98677 bytes of symbols list loaded (7987 symbols) OE 0 22:55:43.638 Tester expert file added: Experts\sample1.ex5. 53811 bytes loaded CK 0 22:55:43.652 Tester 3563 Mb available, 44 blocks set for ticks generating DO 0 22:55:43.652 Tester initial deposit 1000000000 RLS, leverage 1:1 FF 0 22:55:43.658 Tester successfully initialized DO 0 22:55:43.658 Network 104 Kb of total initialization data received QG 0 22:55:43.658 Tester Intel Core i5-6300U @ 2.40GHz, 8115 MB MR 0 22:55:43.826 Symbols فولاد: symbol to be synchronized DE 0 22:55:43.827 Symbols فولاد: symbol synchronized, 3880 bytes of symbol info received HS 0 22:55:43.827 History فولاد: history synchronization started CI 0 22:55:43.831 History فولاد: load 25 bytes of history data to synchronize in 0:00:00.002 JG 0 22:55:43.831 History فولاد: history synchronized from 2014.01.01 to 2020.09.12 QN 0 22:55:43.855 History فولاد,Daily: history cache allocated for 415 bars and contains 233 bars from 2019.01.01 00:00 to 2019.12.31 00:00 PN 0 22:55:43.855 History فولاد,Daily: history begins from 2019.01.01 00:00 KN 0 22:55:43.856 Tester فولاد,Daily (MofidSecurities-Server): every tick generating NK 0 22:55:43.856 Tester فولاد,Daily: testing of Experts\sample1.ex5 from 2020.01.01 00:00 to 2020.09.12 00:00 started with inputs: HI 0 22:55:43.856 Tester MA_Period=20 DS 0 22:55:47.358 Tester final balance 1000000000 RLS CL 0 22:55:47.367 Tester فولاد,Daily: 4167670 ticks, 152 bars generated. Environment synchronized in 0:00:00.230. Test passed in 0:00:03.551 (including ticks preprocessing 0:00:00.281). RJ 0 22:55:47.367 Tester فولاد,Daily: total time from login to stop testing 0:00:03.781 (including 0:00:00.230 for history data synchronization) LR 0 22:55:47.367 Tester 368 Mb memory used including 0.47 Mb of history data, 128 Mb of tick data PE 0 22:55:47.367 Tester log file "C:\Users\User\AppData\Roaming\MetaQuotes\Tester\D0F8212F48C8CF37CH8KL550E51CC139\Agent-127.0.0.1-3000\logs\20200913.log" written CM 0 22:55:47.367 test Experts\sample1.ex5 on فولاد,Daily thread finished CJ 0 22:55:47.391 127.0.0.1 prepare for shutdown
I, unfortunately, cannot check this symbol - since the name of the symbol is NOT IN ENGLISH.
My advice: set NORMAL currency in the tester (eg USD), set NORMAL symbol in the tester (eg EURUSD), set NORMAL leverage in the tester (eg 1: 100), set NORMAL deposit in the tester (eg $ 1000).
Then run the test.
I, unfortunately, cannot check this symbol - since the name of the symbol is NOT IN ENGLISH.
My advice: set NORMAL currency in the tester (eg USD), set NORMAL symbol in the tester (eg EURUSD), set NORMAL leverage in the tester (eg 1: 100), set NORMAL deposit in the tester (eg $ 1000).
Then run the test.
I've tried all different combinations, unfortunately nothing works, even with the ExpertMACD that comes preloaded with the MQL5. it woks for all foreign symbols like GOOG, but for local symbols that are provided by my broker, it doesn't work! I believe it has something to do with the RLS as deposit currency, our local symbols don't work with USD as deposit since in the symbol information, the base currency is defined as RLS. I even changed the bace currency to USD in the symbol setting, but still no luck there.
I've tried all different combinations, unfortunately nothing works, even with the ExpertMACD that comes preloaded with the MQL5. it woks for all foreign symbols like GOOG, but for local symbols that are provided by my broker, it doesn't work! I believe it has something to do with the RLS as deposit currency, our local symbols don't work with USD as deposit since in the symbol information, the base currency is defined as RLS. I even changed the bace currency to USD in the symbol setting, but still no luck there.
Let's try to figure it out.
Using the link, we will determine how much $ is in the deposit
Now open the symbol property '
فولاد
' and show a screenshot of the properties.
- 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
I've wrote a simple expert that runs(buy and sell) correctly on EUR/USD backtest
but in mt5 strategy tester when I change the symbol to Iranian stocks symbols it doesn't work and I can see in visual mode that the price and RSI and CCI go to buy or sell condition but it doesn't do the job!
I've changed the deposit from USD to RLS and tried a lot but it doesn't work.
I've tested it in original version of mt5 and got same result. I called to my broker and asked if they banned somthing on their server and they said there is not any limitation.
u can see my strategy tester config scrshots that works on eur/usd and those don't work on iranian symbols.
How can I solve this problem and backtest my codes on Iranian stocks symbol.
this is my simple code: