0

I am a beginner in mql4 and I'm trying something out.

I need to calculate the speed rate of price changes from one second to another. Either on mql4 or pine script. Is there a way to achieve that?

Dandi
  • 1

3 Answers3

0

Yes in TradingView, if you have a paid version, you can access the 1 second timeframe and then make your calculation.

G.Lebret
  • 2,826
  • 2
  • 16
  • 27
0

it is so easy.just use predifined variable "Ask". Use following codes: {double Price=Ask; Comment("Ask");}

  • This is incorrect and does not answer the question. Whilst you can get prices using the Ask variable, this is not second by second, and is refreshed only as prices change. – PaulB Nov 28 '22 at 12:34
0

If you want to calculate something, you can do this by

  • every Tick = OnTick()
  • every x Seconds = OnTimer()

My code down shows the OnTimer() Event every 1 Second.

//+------------------------------------------------------------------+
//|                                                       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
}
Dragon
  • 49
  • 7