Dandi
Dandi

Reputation: 1

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

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?

Upvotes: 0

Views: 701

Answers (3)

Dragon
Dragon

Reputation: 89

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
}

Upvotes: 0

samad hamdast
samad hamdast

Reputation: 1

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

Upvotes: 0

G.Lebret
G.Lebret

Reputation: 3108

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

Upvotes: 0

Related Questions