Referencing paste price on Date/Time

 

Hi All,

I want to adjust my code to reference a past time and date. Is it possible to reference the last open? So Today -1 and server time = 16:30. I currently am coding it manually.

Current Code - extern double BuyPrice=2972.10

Ideal Code - extern double BuyPrice=(Today -1 - 16:30)


Thanks

 

The last open on the daily chart;

double open = iOpen(Symbol(),PERIOD_D1,0);

Yesterday's open on the daily chart;

double open = iOpen(Symbol(),PERIOD_D1,1);

If you want a higher resolution you can see:

MqlDateTime 

And

TimeToStruct();
 
Marco vd Heijden:

The last open on the daily chart;

Yesterday's open on the daily chart;

If you want a higher resolution you can see:

And


I am trading SPX500 and want to reference the past market open at 9:30, 16:30 in server time. Would that be using the MqlDateTime?

 
  1. Marco vd Heijden: The last open on the daily chart;
    double open = iOpen(Symbol(),PERIOD_D1,0);

    On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

    The function linked to, opens a hidden chart for the symbol/TF in question (if not already open,) thus updating history, and temporarily placing the symbol on Market Watch (if not already there,) so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.

    On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
              Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum
              Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
              Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum
              SymbolInfoInteger doesn't work - Symbols - General - MQL5 programming forum 2019.09.03
              OnCalculate during weekend MT5 - General - MQL5 programming forum

  2. sutascape: Ideal Code - extern double BuyPrice=(Today -1 - 16:30)
    datetime boy = yesterday(); // Beginning of Yesterday
    #define HR1630 59400
    int i430 = iBarShift(_Symbol, _Period, boy+HR1630;
    double BuyPrice = iOpen(_Symbol, _Period, i430);
              Find bar of the same time one day ago - MQL4 programming forum

  3. You do understand that chart times are broker's times. On forex, your 4:30 is meaningless unless your broker uses NY+7.
              When is the time zone problem going to be fixed? - General - MQL5 programming forum 2020.05.07
Reason: