简体   繁体   English

mql4 中有没有一种方法可以逐秒获取价格?

[英]Is there a way in mql4 to get prices second by second?

I am a beginner in mql4 and I'm trying something out.我是 mql4 的初学者,我正在尝试一些东西。

I need to calculate the speed rate of price changes from one second to another.我需要计算价格从一秒到另一秒的变化速度。 Either on mql4 or pine script.在 mql4 或 pine 脚本上。 Is there a way to achieve that?有没有办法做到这一点?

Yes in TradingView, if you have a paid version, you can access the 1 second timeframe and then make your calculation.是的,在 TradingView 中,如果您有付费版本,您可以访问 1 秒的时间范围,然后进行计算。

it is so easy.just use predifined variable "Ask".非常简单。只需使用预定义变量“Ask”。 Use following codes: {double Price=Ask;使用以下代码:{double Price=Ask; Comment("Ask");}评论(“问”);}

If you want to calculate something, you can do this by如果你想计算一些东西,你可以这样做

  • every Tick = OnTick()每个 Tick = OnTick()
  • every x Seconds = OnTimer()每 x 秒 = OnTimer()

My code down shows the OnTimer() Event every 1 Second.我的代码每 1 秒显示一次 OnTimer() 事件。

 //+------------------------------------------------------------------+ //| MQL4 Code | //| | //+------------------------------------------------------------------+ #property strict int OnInit(){ // Timer event for every -1- Second EventSetTimer(1); return(INIT_SUCCEEDED); } void OnDeinit(const int reason){ EventKillTimer(); } void OnTick(){ } void OnTimer(){ // Check every Second new values get_Current_Price(); } void get_Current_Price(){ // MQL Get Current Price. // Get Ask and Bid of the current pair with MarketInfo // and save the values in variables. double PriceAsk = MarketInfo(Symbol(), MODE_ASK); double PriceBid = MarketInfo(Symbol(), MODE_BID); // Print and Comment the values. Print ("Bid = " + DoubleToString(PriceBid, Digits) + " Ask = " + DoubleToString(PriceAsk, Digits)); Comment("Bid = " + DoubleToString(PriceBid, Digits) + " Ask = " + DoubleToString(PriceAsk, Digits)); // MessageBox possible, but will not be the best way //MessageBox("Bid = " + DoubleToString(PriceBid, Digits) + " Ask = " + DoubleToString(PriceAsk, Digits)); // calculate what ever you need }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM