Hello!
When executing a script while visual backtesting, in order to learn how to do it right, i set an alert to do:
Alert (PRICE_CLOSE);
It returns the last actual price the pair has, shouldnt it return the last price in the visual chart, instead of the last REAL price the pair has??
Can I do anything to substitute that function and have the actual price in the visual backtesting?
Thankyou for your time.
PRICE_CLOSE is a constant that is used in a completely different context (you will learn about this soon (but not in this posting)).
The close price of a candle can be optained with the Close[] array. Close[0] is always the close price of the current candle (and since the current candle is not yet closed this is the last known price, the current price). Close[1] would be the close of the candle before it (this candle is already closed), Close[2] the candle before that and so on. The same with Open[], High[], Low[], Volume[].
First of all thanks a lot for answering!!
Second, I have the same problem with Close[0], if i set up an alert like this one:
Alert(Close[0]);
And I run this script in the window which im visualy backtesting, it will show up an alert, with the last close price of today.
Any ideas?
Thx again :)
I cant find the log to see what is printed, but tested it other way (just used Close[0] in the script Im programming) and it will use actual price instead of the charts suposed close price. I think it must have somethign to do with the visual testing, because I have used thoose functions while in backtests and they worked fine.
I think you are referring to dragging a script onto the chart of a visual-mode backtest. As far as I am aware, there is no way of making this work the way you want it to work. The script does not have access to the simulated backtest environment. Values such as TimeCurrent() and Close[0] will be the real current time and price, not the simulated values in the backtesting. Similarly, OrdersTotal() etc will refer to the real live list of orders, not the simulated orders in the backtesting.
One option is to create a pseudo-script in form of a custom indicator which only does anything on the first tick it receives. For example:
#property indicator_chart_window void start() { static bool FirstTick = true; if (FirstTick) { Print("Current price: " + Close[0]); FirstTick = false; } }
(This will have its output logged in the main Experts log in the Terminal, not the log in the Journal of the Strategy Tester.)
However, this route has a number of quirks. An indicator such as this does see the simulated prices in the backtesting, but it gets real live values for things like TimeCurrent() and OrdersTotal(), not the simulated backtest values. It is running half inside and half outside the simulated environment.
There are also issues with "multi-timeframe" indicators which are manually added to visual-mode backtesting. Basically, they can see into the future, and have tricked many people into thinking that they have discovered the source of endless wealth...
Wow thankyou!
There is no way I could figure that out by myself lol....
"I" solved the problem by using an indicator which will have this:
int start {
GlobalVariableSet("Price", Close[0]);
.......
}
This way I can allways use the close price in my backtesting scripts!!
Thanks both of you again for the help!!
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- 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!
When executing a script while visual backtesting, in order to learn how to do it right, i set an alert to do:
Alert (PRICE_CLOSE);
It returns the last actual price the pair has, shouldnt it return the last price in the visual chart, instead of the last REAL price the pair has??
Can I do anything to substitute that function and have the actual price in the visual backtesting?
Thankyou for your time.