【问题标题】:Is there a way in mql4 to get prices second by second?mql4 中有没有一种方法可以逐秒获取价格?
【发布时间】:2022-12-21 04:05:29
【问题描述】:

我是 mql4 的初学者,我正在尝试一些东西。

我需要计算价格从一秒到另一秒的变化速度。在 mql4 或 pine 脚本上。 有没有办法做到这一点?

【问题讨论】:

  • 请提供足够的代码,以便其他人可以更好地理解或重现问题。

标签: pine-script mql4 mql5 mql mt4


【解决方案1】:

是的,在 TradingView 中,如果您有付费版本,您可以访问 1 秒的时间范围,然后进行计算。

【讨论】:

    【解决方案2】:

    非常简单。只需使用预定义变量“Ask”。 使用以下代码: {double Price=要价; 评论(“问”);}

    【讨论】:

    • 这是不正确的,不回答问题。虽然您可以使用 Ask 变量获取价格,但这不是逐秒的,并且仅在价格变化时刷新。
    【解决方案3】:

    如果你想计算一些东西,你可以这样做

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

    我的代码每 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
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      • 2014-10-27
      • 2016-11-16
      • 2016-05-29
      • 1970-01-01
      • 2023-04-03
      • 2010-10-10
      相关资源
      最近更新 更多