Profit display of YTD..

 

Hi,

I have managed to create a variable for Daily profit, Weekly profit and monthly profit, but can't find the PERIOD_?? for Yearly.

I have searched everywhere, but can't find the code for PERIOD_YR

 double GetBalanceMonthly() // Monthly Start Balance

{
   double _resD=AccountBalance();
   datetime lastClose=iTime(NULL,PERIOD_MN1,0);
      for(int pos=0; pos<OrdersHistoryTotal(); pos++) if(
         OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)&&lastClose<OrderCloseTime())
           {// 
            if (OrderType()<2)_resD+=-1*(OrderProfit()+OrderSwap()+OrderCommission());
           }
   return _resD;
   
    static datetime _dt_w = iTime(NULL, PERIOD_MN1, 0);
      static bool _goal_is_hit = false;
      if(_dt_w != iTime(NULL, PERIOD_MN1, 0))
      {
         _dt_w = iTime(NULL, PERIOD_MN1, 0);
   
         monthly_balance=AccountBalance();
         double monthlyProfit=daily_balance-monthly_balance;
       //  DailyGoalEA=false;
    
      }
  }
  

Yearly  , same as above, I just need to change monthly to yearly and the Period_MN1 to whatever the Yearly variable code is...
Any help would be greatly appreciated.

 
Kristina Suh :

Hi,

I have managed to create a variable for Daily profit, Weekly profit and monthly profit, but can't find the PERIOD_?? for Yearly.

I have searched everywhere, but can't find the code for PERIOD_YR

Yearly  , same as above, I just need to change monthly to yearly and the Period_MN1 to whatever the Yearly variable code is...
Any help would be greatly appreciated.

All available timeframes are shown in: Chart Timeframes

Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
  • www.mql5.com
Chart Timeframes - Chart Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Vladimir Karputov:

All available timeframes are shown in: Chart Timeframes

Do you know how to calculate the Yearly Balance from (Opening Account Balance 1/1/2021)?

 
Kristina Suh:

Do you know how to calculate the Yearly Balance from (Opening Account Balance 1/1/2021)?

Request a trade history for the desired period of time. Sum up the trading result of all deals

 
Vladimir Karputov:

Request a trade history for the desired period of time. Sum up the trading result of all deals

do you have the code to do this?

 
Kristina Suh:

Hi,

I have managed to create a variable for Daily profit, Weekly profit and monthly profit, but can't find the PERIOD_?? for Yearly.

I have searched everywhere, but can't find the code for PERIOD_YR

Yearly  , same as above, I just need to change monthly to yearly and the Period_MN1 to whatever the Yearly variable code is...
Any help would be greatly appreciated.

  This?

 MqlDateTime YEAR_BEGIN;
 YEAR_BEGIN.year=Year();
 YEAR_BEGIN.mon=01;
 YEAR_BEGIN.day=01;
 YEAR_BEGIN.hour=00;
 YEAR_BEGIN.min=00;
 YEAR_BEGIN.sec=00;

  YEAR_BEGIN = StructToTime(YEAR_BEGIN);

Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Date Type Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Date Type Structure
  • www.mql5.com
Date Type Structure - Data Structures - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5