#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow

//---- inputs

extern bool ShowComments = true;
extern bool ShowLastMonth = true;
extern bool Shift_NFPStart_OneWeek = false;
extern bool Shift_LastNFPStart_OneWeek = false;
extern color DuringNFP_NoTradeZone_Color = Red;
extern color AfterNFP_NoTradeZone_Color = Orange;

extern color StartTrading_Color = Green;

extern color PrevWeek_Color = Navy;
extern color PrevWeek_Color_W1chart = DeepSkyBlue;

extern color CurrWeek_Color = MediumVioletRed;
extern color CurrWeek_Color_W1chart = DeepPink;

extern color LastDuringNFP_NoTradeZone_Color = Purple;
extern color LastAfterNFP_NoTradeZone_Color = RoyalBlue;

extern color LastStartTrading_Color = Green;

//NFP moving average
extern int MA_Period=336;
extern int MA_Shift=0;
extern int MA_Method=0;

extern int TradeCount = 0;//Starts out at 0 at NFP_Start, then after NFP_End, after first trade is taken on pair, TradeCount goes to 1, and no matter how that trade turns out, additional will have true before a new trade can be taken.

extern string indicator = "Sentinel_indi_Don2";

extern double	EUR = 1.0,	// weights
					JPY = 1.0,
					GBP = 1.0,
					CHF = 1.0,
					CAD = 1.0,
					AUD = 1.0;
extern bool AverageGains = False;
extern bool PipsAsWholeNumbers = True;
extern bool Reverse_Sentinal_On_NonUSDBased = True;
//Sentinel moving average
extern int MA1_Value = 336;//<-- Moving average value set to 336 by default
extern int MA1_Shift = 0;//<-- Shift for the MA. Set to 0 by default.
extern int MA1_Method = 0;//<-- MA Method (0 is SMA, 1 is EMA, 2 is SMMA, 3 is LWMA). Anything above/below these values is set to SMA (0) automatically.
extern bool Use_2nd_MA = False;
extern int MA2_Value = 12;//<-- 2nd Moving average value
extern int MA2_Shift = 0;//<-- Shift for the MA2. Set to 0 by default.
extern int MA2_Method = 2;//<-- MA2 Method (0 is SMA, 1 is EMA, 2 is SMMA, 3 is LWMA). Anything above/below these values is set to SMA (0) automatically.
extern bool Use_3rd_MA = False;
extern int MA3_Value = 18;//<-- 3rd Moving average value
extern int MA3_Shift = 0;//<-- Shift for the MA3. Set to 0 by default.
extern int MA3_Method = 2;//<-- MA3 Method (0 is SMA, 1 is EMA, 2 is SMMA, 3 is LWMA). Anything above/below these values is set to SMA (0) automatically.

extern bool Alerts_On = False;

//Don's Money Management input parameters
extern bool  UseDonsMM = True;
extern double Lots = 0.1;
extern int StopLoss = 200;
extern int  PercentRiskPerTrade = 10;//10%

double MODETICKVALUE;

//---- buffers
double ExtMapBuffer1[];

int init()
{
IndicatorBuffers(1);

SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,0.0);

   MODETICKVALUE=MarketInfo(Symbol(),MODE_TICKVALUE) ;
   
   //----------------------- ADJUST LOTS IF USING MONEY MANAGEMENT
   if (UseDonsMM == True) {
   Lots = LotSize();
   }

return(0);
}

int deinit()
{

ObjectsDeleteAll();             // all objects are removed from the chart.

return(0);
}

int start()
{
   
//-----------------------------------------------------------------------------------------------------------------------------
   
   //WE FIRST HAVE TO DO SOME DEFINITIONS BEFORE WE CAN DRAW ANY OBJECTS ON CHART FOR THIS MONTH
   
   //NFP cooling-off period Open Time
   //Define the year to use in NFP_StartTime
   int year=TimeYear(TimeCurrent());
   
   //Define the month to use in NFP_StartTime
   int month=TimeMonth(TimeCurrent());
   
   //Define the Start Date to use in NFP_StartTime. Which Date, 1-7, is the first Friday of the month?
   datetime DayOfMonthIs1;
   datetime DayOfMonthIs2;
   datetime DayOfMonthIs3;
   datetime DayOfMonthIs4;
   datetime DayOfMonthIs5;
   datetime DayOfMonthIs6;
   datetime DayOfMonthIs7;
   
   DayOfMonthIs1 = StrToTime(year+"."+month+"."+1);
   DayOfMonthIs2 = StrToTime(year+"."+month+"."+2);
   DayOfMonthIs3 = StrToTime(year+"."+month+"."+3);
   DayOfMonthIs4 = StrToTime(year+"."+month+"."+4);
   DayOfMonthIs5 = StrToTime(year+"."+month+"."+5);
   DayOfMonthIs6 = StrToTime(year+"."+month+"."+6);
   DayOfMonthIs7 = StrToTime(year+"."+month+"."+7);

   int StartDate;
   if (TimeDay(DayOfMonthIs1) == 1 && TimeDayOfWeek(DayOfMonthIs1) == 5) StartDate = 1;
   if (TimeDay(DayOfMonthIs2) == 2 && TimeDayOfWeek(DayOfMonthIs2) == 5) StartDate = 2;
   if (TimeDay(DayOfMonthIs3) == 3 && TimeDayOfWeek(DayOfMonthIs3) == 5) StartDate = 3;
   if (TimeDay(DayOfMonthIs4) == 4 && TimeDayOfWeek(DayOfMonthIs4) == 5) StartDate = 4;
   if (TimeDay(DayOfMonthIs5) == 5 && TimeDayOfWeek(DayOfMonthIs5) == 5) StartDate = 5;
   if (TimeDay(DayOfMonthIs6) == 6 && TimeDayOfWeek(DayOfMonthIs6) == 5) StartDate = 6;
   if (TimeDay(DayOfMonthIs7) == 7 && TimeDayOfWeek(DayOfMonthIs7) == 5) StartDate = 7;
   
   //Define the NFP_StartTime, using the year, month, StartDate above, with predefined hours NFP is released
   datetime NFP_StartTime;
   NFP_StartTime=StrToTime(year+"."+month+"."+StartDate+" "+15+":"+30+":"+00);
   
   int OneSecond = 1;
   int OneMinute = 60*OneSecond;
   int OneHour = 60*OneMinute;
   int OneDay = 24*OneHour;
   int OneWeek = 7*OneDay;
   
   if (Shift_NFPStart_OneWeek == true) {
   NFP_StartTime=NFP_StartTime+OneWeek;
   }
   
//--------
   
   //NFP cooling-off period Open Bar
   //below, we are looking to make sure the bar that MT4 associates with the given time above, is really the bar we want to use/associate
   int NFPStartBar = iBarShift( NULL, 0, NFP_StartTime, true);//Get the bar, on the current chart, that MT4 gives, with the time given
   double NFPStartBar_OpenPrice = iOpen(NULL,0,NFPStartBar);//Get the open price of that bar, on the current chart
   datetime NFPStartBar_OpenTime = iTime(NULL,0,NFPStartBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double NFPStartBar_HighPrice = iHigh(NULL,0,NFPStartBar);//Go back and get the high price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double NFPStartBar_LowPrice = iLow(NULL,0,NFPStartBar);//Go back and get the low price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double NFPStartBar_ClosePrice = iClose(NULL,0,NFPStartBar);//Go back and get the close price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
         
//---------

   //NFP cooling-off period Close Time
   //From when NFP released at 7:30 (my time = Central time), define the NFP_EndTime by counting forward the rest of Friday 8 hours and 30 minutes (to 4PM Central Time), 2 days for the weekend, plus 7 hours from when the market open at 4PM Central time to 11PM Sunday night Central Time.
   int NFP_EndTime = NFP_StartTime + ( /*Rest of Friday*/ ((8*OneHour)+(30*OneMinute)) + /*Saturday and Sunday*/ (2*OneDay) + /* (from 4PM CST Sunday to 11PM CST Sunday/Midnight EST Monday */ (7*OneHour) );

//---------
   
   //NFP cooling-off period Close Bar
   //below, we are looking to make sure the bar that MT4 associates with the given time above, is really the bar we want to use/associate, or do we need to take 1 bar away to use the correct bar
   int NFPEndBar = iBarShift( NULL, 0, NFP_EndTime, true);//Get the bar, on the current chart, that MT4 gives, with the time given
   double NFPEndBar_OpenPrice = iOpen(NULL,0,NFPEndBar);//Get the open price of that bar, on the current chart
   datetime NFPEndBar_OpenTime = iTime(NULL,0,NFPEndBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double NFPEndBar_HighPrice = iHigh(NULL,0,NFPEndBar);//Go back and get the high price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double NFPEndBar_LowPrice = iLow(NULL,0,NFPEndBar);//Go back and get the low price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double NFPEndBar_ClosePrice = iClose(NULL,0,NFPEndBar);//Go back and get the close price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   //If the above calculations use the correct bar, then there is no need to correct the bar used by taking away a bar. If the wrong bar was chosen, we need to correct. If the above was not correct, there will be correction equations below
   //Below, I'm correcting the NFPEnfBar, because MT4 is choosing the bar we want to start trading with as the end bar, so we need to move one bar back and use that as the end bar
   int RealNFPEndBar = NFPEndBar+1;//Correct the bar on the chart to use by shifting to use the bar left of the bar MT4 gave
   double RealNFPEndBar_OpenPrice = iOpen(NULL,0,RealNFPEndBar);//Get the open price of that bar, on the current chart
   datetime RealNFPEndBar_OpenTime = iTime(NULL,0,RealNFPEndBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double RealNFPEndBar_HighPrice = iHigh(NULL,0,RealNFPEndBar);//Go back and get the high price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double RealNFPEndBar_LowPrice = iLow(NULL,0,RealNFPEndBar);//Go back and get the low price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double RealNFPEndBar_ClosePrice = iClose(NULL,0,RealNFPEndBar);//Go back and get the close price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   
//---------
   
   //Highest High and Lowest Low of NFP cooling-off period
   //From the NFP Start Bar to NFP End Bar calcualated above, get the highest high price and lowest low price from that period of time
   double NFP_HighestHigh = High[iHighest(NULL,0,2,(NFPStartBar-RealNFPEndBar),RealNFPEndBar)];
   double NFP_LowestLow = Low[iLowest(NULL,0,1,(NFPStartBar-RealNFPEndBar),RealNFPEndBar)];

//---------
   
   //Start Trading Bar
   int StartTradingBar = NFPEndBar;//What MT4 designated as our NFPEndBar is actually the bar we want to start trading on.
   double StartTradingBar_OpenPrice = iOpen(NULL,0,StartTradingBar);//Get the open price of that bar, on the current chart
   datetime StartTradingBar_OpenTime = iTime(NULL,0,StartTradingBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double StartTradingBar_HighPrice = iHigh(NULL,0,StartTradingBar);//Go back and get the high price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double StartTradingBar_LowPrice = iLow(NULL,0,StartTradingBar);//Go back and get the low price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double StartTradingBar_ClosePrice = iClose(NULL,0,StartTradingBar);//Go back and get the close price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   
//---------
   
   //Previous Week Open Bar
   datetime PrevWeekOpenTime = iTime(NULL,PERIOD_W1,1);
   //below, we are looking to make sure the bar that MT4 associates with the given time above, is really the bar we want to use/associate, or do we need to take 1 bar away to use the correct bar
   int PrevWeekOpenBar = iBarShift( NULL, 0, PrevWeekOpenTime, false);//Get the bar, on the current chart, that MT4 gives, with the time given
   double PrevWeekOpenBar_OpenPrice = iOpen(NULL,0,PrevWeekOpenBar);//Get the open price of that bar, on the current chart
   datetime PrevWeekOpenBar_OpenTime = iTime(NULL,0,PrevWeekOpenBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double PrevWeekOpenBar_HighPrice = iHigh(NULL,0,PrevWeekOpenBar);//Go back and get the high price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double PrevWeekOpenBar_LowPrice = iLow(NULL,0,PrevWeekOpenBar);//Go back and get the low price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double PrevWeekOpenBar_ClosePrice = iClose(NULL,0,PrevWeekOpenBar);//Go back and get the close price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   //If the above calculations use the correct bar, then there is no need to correct the bar used by taking away a bar. If the wrong bar was chosen, we need to correct. If the above was not correct, there will be correction equations below
   //Below, I'm correcting the NFPEnfBar, because MT4 is choosing the bar we want to start trading with as the end bar, so we need to move one bar back and use that as the end bar
   int PrevWeek_RealOpenBar = PrevWeekOpenBar-1;//Get the bar, on the current chart, that MT4 gives, with the time given
   double PrevWeek_RealOpenBar_OpenPrice = iOpen(NULL,0,PrevWeek_RealOpenBar);//Get the open price of that bar, on the current chart
   datetime PrevWeek_RealOpenBar_OpenTime = iTime(NULL,0,PrevWeek_RealOpenBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double PrevWeek_RealOpenBar_HighPrice = iHigh(NULL,0,PrevWeek_RealOpenBar);//Go back and get the high price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double PrevWeek_RealOpenBar_LowPrice = iLow(NULL,0,PrevWeek_RealOpenBar);//Go back and get the low price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double PrevWeek_RealOpenBar_ClosePrice = iClose(NULL,0,PrevWeek_RealOpenBar);//Go back and get the close price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   
//---------
   
   //Current Week Open Bar
   datetime CurrWeekOpenTime = iTime(NULL,PERIOD_W1,0);
   //below, we are looking to make sure the bar that MT4 associates with the given time above, is really the bar we want to use/associate, or do we need to take 1 bar away to use the correct bar
   int CurrWeekOpenBar = iBarShift( NULL, 0, CurrWeekOpenTime, false);//Get the bar, on the current chart, that MT4 gives, with the time given
   double CurrWeekOpenBar_OpenPrice = iOpen(NULL,0,CurrWeekOpenBar);//Get the open price of that bar, on the current chart
   datetime CurrWeekOpenBar_OpenTime = iTime(NULL,0,CurrWeekOpenBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double CurrWeekOpenBar_HighPrice = iHigh(NULL,0,CurrWeekOpenBar);//Go back and get the high price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double CurrWeekOpenBar_LowPrice = iLow(NULL,0,CurrWeekOpenBar);//Go back and get the low price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double CurrWeekOpenBar_ClosePrice = iClose(NULL,0,CurrWeekOpenBar);//Go back and get the close price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   //If the above calculations use the correct bar, then there is no need to correct the bar used by taking away a bar. If the wrong bar was chosen, we need to correct. If the above was not correct, there will be correction equations below
   //Below, I'm correcting the NFPEnfBar, because MT4 is choosing the bar we want to start trading with as the end bar, so we need to move one bar back and use that as the end bar
   int CurrWeek_RealOpenBar = CurrWeekOpenBar-1;//Get the bar, on the current chart, that MT4 gives, with the time given
   double CurrWeek_RealOpenBar_OpenPrice = iOpen(NULL,0,CurrWeek_RealOpenBar);//Get the open price of that bar, on the current chart
   datetime CurrWeek_RealOpenBar_OpenTime = iTime(NULL,0,CurrWeek_RealOpenBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double CurrWeek_RealOpenBar_HighPrice = iHigh(NULL,0,CurrWeek_RealOpenBar);//Go back and get the high price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double CurrWeek_RealOpenBar_LowPrice = iLow(NULL,0,CurrWeek_RealOpenBar);//Go back and get the low price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double CurrWeek_RealOpenBar_ClosePrice = iClose(NULL,0,CurrWeek_RealOpenBar);//Go back and get the close price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get

//---------
   
   //Previous Week Close Bar   
   datetime PrevWeek_RealCloseTime = CurrWeekOpenTime;
   //below, we are looking to make sure the bar that MT4 associates with the given time above, is really the bar we want to use/associate, or do we need to take 1 bar away to use the correct bar
   int PrevWeek_RealCloseBar = iBarShift( NULL, 0, PrevWeek_RealCloseTime, false);//Get the bar, on the current chart, that MT4 gives, with the time given
   double PrevWeek_RealCloseBar_OpenPrice = iOpen(NULL,0,PrevWeek_RealCloseBar);//Get the open price of that bar, on the current chart
   datetime PrevWeek_RealCloseBar_OpenTime = iTime(NULL,0,PrevWeek_RealCloseBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double PrevWeek_RealCloseBar_HighPrice = iHigh(NULL,0,PrevWeek_RealCloseBar);//Go back and get the high price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double PrevWeek_RealCloseBar_LowPrice = iLow(NULL,0,PrevWeek_RealCloseBar);//Go back and get the low price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double PrevWeek_RealCloseBar_ClsePrice = iClose(NULL,0,PrevWeek_RealCloseBar);//Go back and get the close price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get

//---------
   
   //Previous Week Highest High and Lowest Low
   double PrevWeek_HighestHigh = High[iHighest(NULL,0,2,(PrevWeek_RealOpenBar-PrevWeek_RealCloseBar),PrevWeek_RealCloseBar)];
   double PrevWeek_LowestLow = Low[iLowest(NULL,0,1,(PrevWeek_RealOpenBar-PrevWeek_RealCloseBar),PrevWeek_RealCloseBar)];

//---------
   
   //MT4 Previous Week High and Low
   double PrevWeek_High = iHigh(NULL,PERIOD_W1,1);
   double PrevWeek_Low = iLow(NULL,PERIOD_W1,1);
   
//---------  
   
   //Current Week Close Bar
   datetime CurrWeek_RealCloseTime = iTime(NULL,0,1);//This is correct on how I want to use it. It doesn't use this bar's close as week close, it uses last bar's close as week close.
   //below, we are looking to make sure the bar that MT4 associates with the given time above, is really the bar we want to use/associate, or do we need to take 1 bar away to use the correct bar
   int CurrWeek_RealCloseBar = iBarShift( NULL, 0, CurrWeek_RealCloseTime, true);
   double CurrWeek_RealCloseBar_OpenPrice = iOpen(NULL,0,CurrWeek_RealCloseBar);//Get the open price of that bar, on the current chart
   datetime CurrWeek_RealCloseBar_OpenTime = iTime(NULL,0,CurrWeek_RealCloseBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double CurrWeek_RealCloseBar_HighPrice = iHigh(NULL,0,CurrWeek_RealCloseBar);
   double CurrWeek_RealCloseBar_LowPrice = iLow(NULL,0,CurrWeek_RealCloseBar);
   double CurrWeek_RealCloseBar_ClsePrice = iClose(NULL,0,CurrWeek_RealCloseBar);

//---------
   
   //Current Week Highest High and Lowest Low
   double CurrWeek_HighestHigh = High[iHighest(NULL,0,2,(CurrWeek_RealOpenBar-CurrWeek_RealCloseBar),CurrWeek_RealCloseBar)];
   double CurrWeek_LowestLow = Low[iLowest(NULL,0,1,(CurrWeek_RealOpenBar-CurrWeek_RealCloseBar),CurrWeek_RealCloseBar)];
       
//---------
   
   //MT4 Current Week High and Low
   double CurrWeek_High = iHigh(NULL,PERIOD_W1,0);
   double CurrWeek_Low = iLow(NULL,PERIOD_W1,0);
//---------
   
   //Current Bar
   datetime CurrBarOpenTime = iTime(NULL,0,0);
   int CurrBar = iBarShift( NULL, 0, CurrBarOpenTime, true);
   double CurrBar_OpenPrice = iOpen(NULL,0,CurrBar);
   datetime CurrBar_OpenTime = iTime(NULL,0,CurrBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double CurrBar_HighPrice = iHigh(NULL,0,CurrBar);
   double CurrBar_LowPrice = iLow(NULL,0,CurrBar);
   datetime CurrBar_ClosePrice = iClose(NULL,0,CurrBar);
   datetime CurrBar_CloseTime = TimeCurrent();//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
    
//-----------------------------------------------------------------------------------------------------------------------------
   
   //DRAW OBJECTS ON CHART
   // Draw the objects on chart for NFP "cooling-off period" Open Bar, NFP "cooling-off period" Close Bar,
   // Start Trading Bar (or start looking FOR trades bar), NFP Highest High, NFP Lowest Low, Previous Week Open Bar,
   // Previous Week Close Bar, Previous Week Highest High to Lowest Low, Current Week Open Bar, Current Week Close Bar,
   // Current Week Highest High and Lowest Low, and Current Bar
   
   //NFP cooling-off period Open Bar
   //If Time now is passed the NFP_StartTime (defined by either automatic or user inputs), create a vertical line marking it on the chart
   if (TimeCurrent() >= NFP_StartTime) {
   ObjectCreate("NFPStart_OpenBar", 0, 0, NFPStartBar_OpenTime,0);
   }
   
   ObjectSet("NFPStart_OpenBar", OBJPROP_COLOR, DuringNFP_NoTradeZone_Color );
   
//---------
   
   //NFP cooling-off period Close Bar
   //If Time now is passed the NFP_EndTime (end of NFP cooling off period, defined by either automatic or user inputs), create a vertical line marking it on the chart
   if (TimeCurrent() > NFP_EndTime) {
   ObjectCreate("RealNFPEnd_CloseBar", 0, 0, RealNFPEndBar_OpenTime,0);
   }
   
   ObjectSet("RealNFPEnd_CloseBar", OBJPROP_COLOR, DuringNFP_NoTradeZone_Color );

//---------
   
   //NFP cooling-off period Highest High and Lowest Low
   //If Time now is passed the NFP_EndTime (end of NFP cooling off period, defined by either automatic or user inputs), create a horizontal line marking the NFP cooling-off period's highest high, a horizontal line marking the NFP cooling-off period's lowest low, a rectangle for the no-trade zone during NFP cooling-off period, and a rectangle marking the same no-trade zone after the NFP cooling-off period
   if (TimeCurrent() >= NFP_StartTime) {
   ObjectCreate("NFP_HighestHigh", 1, 0, 0, NFP_HighestHigh );
   ObjectCreate("NFP_LowestLow", 1, 0, 0, NFP_LowestLow );
   }
   
   if (TimeCurrent() > NFP_StartTime && TimeCurrent() < NFP_EndTime) {
   ObjectCreate("DuringNFP_NoTradeZone", 16, 0, NFPStartBar_OpenTime, NFP_HighestHigh, TimeCurrent(), NFP_LowestLow );
   } else if (TimeCurrent() > NFP_StartTime && TimeCurrent() > NFP_EndTime) {
   ObjectCreate("DuringNFP_NoTradeZone", 16, 0, NFPStartBar_OpenTime, NFP_HighestHigh, RealNFPEndBar_OpenTime, NFP_LowestLow );
   }
   
   if (TimeCurrent() > NFP_EndTime) {
   ObjectCreate("AfterNFP_NoTradeZone", 16, 0, StartTradingBar_OpenTime, NFP_HighestHigh, TimeCurrent(), NFP_LowestLow );
   }

   ObjectSet("NFP_HighestHigh", OBJPROP_COLOR, DuringNFP_NoTradeZone_Color );
   ObjectSet("NFP_LowestLow", OBJPROP_COLOR, DuringNFP_NoTradeZone_Color );
   ObjectSet("DuringNFP_NoTradeZone", OBJPROP_COLOR, DuringNFP_NoTradeZone_Color );
   ObjectSet("AfterNFP_NoTradeZone", OBJPROP_COLOR, AfterNFP_NoTradeZone_Color );
   
//---------
   
   //Start Trading Bar Open
   //If Time now is passed the NFP_EndTime (end of NFP cooling off period, defined by either automatic or user inputs), create a vertical line marking it on the chart
   if (TimeCurrent() >= StartTradingBar_OpenTime) {   
   //Draw the line of first the MT4 Time and Prices, and if needed corrected, Real Time and Prices of correctectly chosen bar
   ObjectCreate("StartTrading_OpenBar", 0, 0, StartTradingBar_OpenTime,0);
   //Then color the line that marks the bar on the chart
   ObjectSet("StartTrading_OpenBar", OBJPROP_COLOR, StartTrading_Color);
   }
   
//---------
   
   //Previous Week Open Bar
   //Draw the line of first the MT4 Time and Prices, and if needed corrected, Real Time and Prices of correctectly chosen bar
   ObjectCreate("PrevWeek_RealOpenBar", 0, 0, PrevWeek_RealOpenBar_OpenTime,0);
   ObjectSet("PrevWeek_RealOpenBar", 6, PrevWeek_Color );
   ObjectSet("PrevWeek_RealOpenBar", 7, 2 );
   
//---------
   
   //Previous Week Close Bar
   ObjectCreate("PrevWeek_RealCloseBar", 0, 0, PrevWeek_RealCloseBar_OpenTime,0);
   ObjectSet("PrevWeek_RealCloseBar", 6, PrevWeek_Color );
   ObjectSet("PrevWeek_RealCloseBar", 7, 2 );

//---------
   
   //Previous Week Highest High and Lowest Low
   ObjectCreate("PrevWeek_HighPrice", 1, 0, 0, PrevWeek_HighestHigh );
   ObjectSet("PrevWeek_HighPrice", 6, PrevWeek_Color );
   ObjectSet("PrevWeek_HighPrice", 7, 2 );  
   
   ObjectCreate("PrevWeek_LowPrice", 1, 0, 0, PrevWeek_LowestLow );
   ObjectSet("PrevWeek_LowPrice", 6, PrevWeek_Color );
   ObjectSet("PrevWeek_LowPrice", 7, 2 );
   
   ObjectCreate("PrevWeek_LowToHigh", 16, 0, PrevWeek_RealOpenBar_OpenTime, PrevWeek_HighestHigh, PrevWeek_RealCloseBar_OpenTime, PrevWeek_LowestLow );
   ObjectSet("PrevWeek_LowToHigh", 6, PrevWeek_Color );

//---------
   
   //MT4 Previous Week High and Low
   ObjectCreate("PrevWeek_W1chart_High_to_ThisChart_HighestHigh", 16, 0, PrevWeek_RealOpenBar_OpenTime, PrevWeek_High, PrevWeek_RealCloseBar_OpenTime, PrevWeek_HighestHigh );
   ObjectSet("PrevWeek_W1chart_High_to_ThisChart_HighestHigh", 6, PrevWeek_Color_W1chart );
   ObjectCreate("PrevWeek_ThisChart_LowestLow_to_W1Chart_Low", 16, 0, PrevWeek_RealOpenBar_OpenTime, PrevWeek_LowestLow, PrevWeek_RealCloseBar_OpenTime, PrevWeek_Low );
   ObjectSet("PrevWeek_ThisChart_LowestLow_to_W1Chart_Low", 6, PrevWeek_Color_W1chart );

//---------
   
   //Current Week Open Bar
   ObjectCreate("CurrWeek_RealOpenBar", 0, 0, CurrWeek_RealOpenBar_OpenTime,0);
   ObjectSet("CurrWeek_RealOpenBar", 6, CurrWeek_Color );
   ObjectSet("CurrWeek_RealOpenBar", 7, 2 );

//---------
   
   //Current Week Close Bar
   ObjectCreate("CurrWeek_RealCloseBar", 0, 0, CurrWeek_RealCloseBar_OpenTime,0);
   ObjectSet("CurrWeek_RealCloseBar", 6, CurrWeek_Color );
   ObjectSet("CurrWeek_RealCloseBar", 7, 2 );

//---------
   
   //Previous Week Highest High and Lowest Low
   ObjectCreate("CurrWeek_HighPrice", 1, 0, 0, CurrWeek_HighestHigh );
   ObjectSet("CurrWeek_HighPrice", 6, CurrWeek_Color );
   ObjectSet("CurrWeek_HighPrice", 7, 2 );

//---------
   
   ObjectCreate("CurrWeek_LowPrice", 1, 0, 0, CurrWeek_LowestLow );
   ObjectSet("CurrWeek_LowPrice", 6, CurrWeek_Color );
   ObjectSet("CurrWeek_LowPrice", 7, 2 );

//---------
   
   ObjectCreate("CurrWeek_LowToHigh", 16, 0, CurrWeek_RealOpenBar_OpenTime, CurrWeek_HighestHigh, CurrWeek_RealCloseBar_OpenTime, CurrWeek_LowestLow );
   ObjectSet("CurrWeek_LowToHigh", 6, CurrWeek_Color );
   
//---------

   //MT4 Current Week High and Low
   ObjectCreate("CurrWeek_W1chart_High_to_ThisChart_HighestHigh", 16, 0, CurrWeek_RealOpenBar_OpenTime, CurrWeek_High, CurrWeek_RealCloseBar_OpenTime, CurrWeek_HighestHigh );
   ObjectSet("CurrWeek_W1chart_High_to_ThisChart_HighestHigh", 6, CurrWeek_Color_W1chart );
   ObjectCreate("CurrWeek_ThisChart_LowestLow_to_W1Chart_Low", 16, 0, CurrWeek_RealOpenBar_OpenTime, CurrWeek_LowestLow, CurrWeek_RealCloseBar_OpenTime, CurrWeek_Low );
   ObjectSet("CurrWeek_ThisChart_LowestLow_to_W1Chart_Low", 6, CurrWeek_Color_W1chart );
     
//-----------------------------------------------------------------------------------------------------------------------------

   //Make the 336 simple moving average on the main chart
   int limit;
   int bar;
   int counted_bars = IndicatorCounted();
   //---- check for possible errors
   if (counted_bars<0) return(-1);
   //---- last counted bar will be recounted
   if (counted_bars>0) counted_bars--;
   limit = Bars - counted_bars;
   
   for(int i=limit; i>=0; i--)
   {
   ExtMapBuffer1[i] = iMA(NULL,0,336,0,MODE_SMA,PRICE_CLOSE,i);
   }
   
//-----------------------------------------------------------------------------------------------------------------------------

if (ShowLastMonth == true) //below is the same code as above, except month has been replaced by lastmonth.
{

//---------
   
   //WE FIRST HAVE TO DO SOME DEFINITIONS BEFORE WE CAN DRAW ANY OBJECTS ON CHART FOR LAST MONTH
   //NFP cooling-off period Open Time for last month 
   //Define the month to use in NFP_StartTime for last month
   month=month-1;
   
   if (TimeMonth(TimeCurrent()) == 1) {
   year = year-1;
   month = 12;
   }
   
   //Define the Start Date to use in NFP_StartTime. Which Date, 1-7, is the first Friday of the month?
   datetime LastNFP_DayOfMonthIs1;
   datetime LastNFP_DayOfMonthIs2;
   datetime LastNFP_DayOfMonthIs3;
   datetime LastNFP_DayOfMonthIs4;
   datetime LastNFP_DayOfMonthIs5;
   datetime LastNFP_DayOfMonthIs6;
   datetime LastNFP_DayOfMonthIs7;
   
   LastNFP_DayOfMonthIs1 = StrToTime(year+"."+month+"."+1);
   LastNFP_DayOfMonthIs2 = StrToTime(year+"."+month+"."+2);
   LastNFP_DayOfMonthIs3 = StrToTime(year+"."+month+"."+3);
   LastNFP_DayOfMonthIs4 = StrToTime(year+"."+month+"."+4);
   LastNFP_DayOfMonthIs5 = StrToTime(year+"."+month+"."+5);
   LastNFP_DayOfMonthIs6 = StrToTime(year+"."+month+"."+6);
   LastNFP_DayOfMonthIs7 = StrToTime(year+"."+month+"."+7);

   int LastNFP_StartDate;
   if (TimeDay(LastNFP_DayOfMonthIs1) == 1 && TimeDayOfWeek(LastNFP_DayOfMonthIs1) == 5) LastNFP_StartDate = 1;
   if (TimeDay(LastNFP_DayOfMonthIs2) == 2 && TimeDayOfWeek(LastNFP_DayOfMonthIs2) == 5) LastNFP_StartDate = 2;
   if (TimeDay(LastNFP_DayOfMonthIs3) == 3 && TimeDayOfWeek(LastNFP_DayOfMonthIs3) == 5) LastNFP_StartDate = 3;
   if (TimeDay(LastNFP_DayOfMonthIs4) == 4 && TimeDayOfWeek(LastNFP_DayOfMonthIs4) == 5) LastNFP_StartDate = 4;
   if (TimeDay(LastNFP_DayOfMonthIs5) == 5 && TimeDayOfWeek(LastNFP_DayOfMonthIs5) == 5) LastNFP_StartDate = 5;
   if (TimeDay(LastNFP_DayOfMonthIs6) == 6 && TimeDayOfWeek(LastNFP_DayOfMonthIs6) == 5) LastNFP_StartDate = 6;
   if (TimeDay(LastNFP_DayOfMonthIs7) == 7 && TimeDayOfWeek(LastNFP_DayOfMonthIs7) == 5) LastNFP_StartDate = 7;
   
   //Define the NFP_StartTime, using the year, month, StartDate above, with predefined hours NFP is released
   datetime LastNFP_StartTime;
   if (TimeMonth(TimeCurrent()) == 1) {
   LastNFP_StartTime=StrToTime(year+"."+month+"."+LastNFP_StartDate+" "+15+":"+30+":"+00);
   }
   
   if (Shift_LastNFPStart_OneWeek == true) {
   LastNFP_StartTime=LastNFP_StartTime+OneWeek;
   }
   
//--------
   
   //NFP cooling-off period Open Bar
   //below, we are looking to make sure the bar that MT4 associates with the given time above, is really the bar we want to use/associate, or do we need to take 1 bar away to use the correct bar
   int LastNFPStartBar = iBarShift( NULL, 0, LastNFP_StartTime, true);//Get the bar, on the current chart, that MT4 gives, with the time given
   double LastNFPStartBar_OpenPrice = iOpen(NULL,0,LastNFPStartBar);//Get the open price of that bar, on the current chart
   datetime LastNFPStartBar_OpenTime = iTime(NULL,0,LastNFPStartBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double LastNFPStartBar_HighPrice = iHigh(NULL,0,LastNFPStartBar);//Go back and get the high price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double LastNFPStartBar_LowPrice = iLow(NULL,0,LastNFPStartBar);//Go back and get the low price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double LastNFPStartBar_ClosePrice = iClose(NULL,0,LastNFPStartBar);//Go back and get the close price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
         
//---------

   //NFP cooling-off period Close Time
   //From when NFP released at 7:30 (my time = Central time), define the NFP_EndTime by counting forward the rest of Friday 8 hours and 30 minutes (to 4PM Central Time), 2 days for the weekend, plus 7 hours from when the market open at 4PM Central time to 11PM Sunday night Central Time.
   int LastNFP_EndTime = LastNFP_StartTime + ( /*Rest of Friday*/ ((8*OneHour)+(30*OneMinute)) + /*Saturday and Sunday*/ (2*OneDay) + /* (from 4PM CST Sunday to 11PM CST Sunday/Midnight EST Monday */ (7*OneHour) );

//---------
   
   //NFP cooling-off period Close Bar
   //below, we are looking to make sure the bar that MT4 associates with the given time above, is really the bar we want to use/associate, or do we need to take 1 bar away to use the correct bar
   int LastNFPEndBar = iBarShift( NULL, 0, LastNFP_EndTime, true);//Get the bar, on the current chart, that MT4 gives, with the time given
   double LastNFPEndBar_OpenPrice = iOpen(NULL,0,LastNFPEndBar);//Get the open price of that bar, on the current chart
   datetime LastNFPEndBar_OpenTime = iTime(NULL,0,LastNFPEndBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double LastNFPEndBar_HighPrice = iHigh(NULL,0,LastNFPEndBar);//Go back and get the high price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double LastNFPEndBar_LowPrice = iLow(NULL,0,LastNFPEndBar);//Go back and get the low price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double LastNFPEndBar_ClosePrice = iClose(NULL,0,LastNFPEndBar);//Go back and get the close price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   //If the above calculations use the correct bar, then there is no need to correct the bar used by taking away a bar. If the wrong bar was chosen, we need to correct. If the above was not correct, there will be correction equations below
   //Below, I'm correcting the NFPEnfBar, because MT4 is choosing the bar we want to start trading with as the end bar, so we need to move one bar back and use that as the end bar
   int LastRealNFPEndBar = LastNFPEndBar+1;//Correct the bar on the chart to use by shifting to use the bar left of the bar MT4 gave
   double LastRealNFPEndBar_OpenPrice = iOpen(NULL,0,LastRealNFPEndBar);//Get the open price of that bar, on the current chart
   datetime LastRealNFPEndBar_OpenTime = iTime(NULL,0,LastRealNFPEndBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double LastRealNFPEndBar_HighPrice = iHigh(NULL,0,LastRealNFPEndBar);//Go back and get the high price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double LastRealNFPEndBar_LowPrice = iLow(NULL,0,LastRealNFPEndBar);//Go back and get the low price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double LastRealNFPEndBar_ClosePrice = iClose(NULL,0,LastRealNFPEndBar);//Go back and get the close price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   
//---------
   
   //Highest High and Lowest Low of NFP cooling-off period
   //From the NFP Start Bar to NFP End Bar calcualated above, get the highest high price and lowest low price from that period of time
   double LastNFP_HighestHigh = High[iHighest(NULL,0,2,(LastNFPStartBar-LastRealNFPEndBar),LastRealNFPEndBar)];
   double LastNFP_LowestLow = Low[iLowest(NULL,0,1,(LastNFPStartBar-LastRealNFPEndBar),LastRealNFPEndBar)];

//---------
   
   //Start Trading Bar
   int LastStartTradingBar = LastNFPEndBar;//What MT4 designated as our NFPEndBar is actually the bar we want to start trading on.
   double LastStartTradingBar_OpenPrice = iOpen(NULL,0,LastStartTradingBar);//Get the open price of that bar, on the current chart
   datetime LastStartTradingBar_OpenTime = iTime(NULL,0,LastStartTradingBar);//Go back and get the open time of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double LastStartTradingBar_HighPrice = iHigh(NULL,0,LastStartTradingBar);//Go back and get the high price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double LastStartTradingBar_LowPrice = iLow(NULL,0,LastStartTradingBar);//Go back and get the low price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get
   double LastStartTradingBar_ClosePrice = iClose(NULL,0,LastStartTradingBar);//Go back and get the close price of that bar, on the current chart, to make sure there is no discrepancy between the bar we need to get and the one we did get

//-----------------------------------------------------------------------------------------------------------------------------
   
   //DRAW OBJECTS ON CHART
   // Draw the objects on chart for last month for NFP "cooling-off period" Open Bar, NFP "cooling-off period" Close Bar,
   // Start Trading Bar (or start looking FOR trades bar), NFP Highest High, NFP Lowest Low, Previous Week Open Bar,
   // Previous Week Close Bar, Previous Week Highest High to Lowest Low, Current Week Open Bar, Current Week Close Bar,
   // Current Week Highest High and Lowest Low, and Current Bar
   
   //NFP cooling-off period Open Bar for last month
   //If Time now is passed the NFP_StartTime (defined by either automatic or user inputs), create a vertical line marking it on the chart
   if (TimeCurrent() >= NFP_StartTime) {
   ObjectCreate("LastNFPStart_OpenBar", 0, 0, LastNFPStartBar_OpenTime,0);
   }

   ObjectSet("LastNFPStart_OpenBar", OBJPROP_COLOR, LastDuringNFP_NoTradeZone_Color );
   
//---------
   
   //NFP cooling-off period Close Bar
   //If Time now is passed the NFP_EndTime (end of NFP cooling off period, defined by either automatic or user inputs), create a vertical line marking it on the chart
   if (TimeCurrent() >= LastNFP_EndTime) {
   ObjectCreate("LastRealNFPEnd_CloseBar", 0, 0, LastRealNFPEndBar_OpenTime,0);
   }

   ObjectSet("LastRealNFPEnd_CloseBar", OBJPROP_COLOR, LastDuringNFP_NoTradeZone_Color );

//---------
   
   //NFP cooling-off period Highest High and Lowest Low
   //If Time now is passed the NFP_EndTime (end of NFP cooling off period, defined by either automatic or user inputs), create a horizontal line marking the NFP cooling-off period's highest high, a horizontal line marking the NFP cooling-off period's lowest low, a rectangle for the no-trade zone during NFP cooling-off period, and a rectangle marking the same no-trade zone after the NFP cooling-off period
   if (TimeCurrent() >= LastNFP_EndTime) {
   ObjectCreate("LastNFP_HighestHigh", 1, 0, 0, LastNFP_HighestHigh );
   ObjectCreate("LastNFP_LowestLow", 1, 0, 0, LastNFP_LowestLow );
   ObjectCreate("LastDuringNFP_NoTradeZone", 16, 0, LastNFPStartBar_OpenTime, LastNFP_HighestHigh, LastRealNFPEndBar_OpenTime, LastNFP_LowestLow );
   }
   
   if (TimeCurrent() < NFP_StartTime) {
   ObjectCreate("LastAfterNFP_NoTradeZone", 16, 0, LastStartTradingBar_OpenTime, LastNFP_HighestHigh, TimeCurrent(), LastNFP_LowestLow );
   } else {
   ObjectCreate("LastAfterNFP_NoTradeZone", 16, 0, LastStartTradingBar_OpenTime, LastNFP_HighestHigh, NFPStartBar_OpenTime, LastNFP_LowestLow );
   }
      
   ObjectSet("LastNFP_HighestHigh", OBJPROP_COLOR, LastDuringNFP_NoTradeZone_Color );
   ObjectSet("LastNFP_LowestLow", OBJPROP_COLOR, LastDuringNFP_NoTradeZone_Color );
   ObjectSet("LastDuringNFP_NoTradeZone", OBJPROP_COLOR, LastDuringNFP_NoTradeZone_Color );
   ObjectSet("LastAfterNFP_NoTradeZone", OBJPROP_COLOR, LastAfterNFP_NoTradeZone_Color );
   
//---------
   
   //Start Trading Bar Open
   //If Time now is passed the NFP_EndTime (end of NFP cooling off period, defined by either automatic or user inputs), create a vertical line marking it on the chart
   if (TimeCurrent() >= LastStartTradingBar_OpenTime) {   
   //Draw the line of first the MT4 Time and Prices, and if needed corrected, Real Time and Prices of correctectly chosen bar
   ObjectCreate("LastStartTrading_OpenBar", 0, 0, LastStartTradingBar_OpenTime,0);
   //Then color the line that marks the bar on the chart
   ObjectSet("LastStartTrading_OpenBar", OBJPROP_COLOR, LastStartTrading_Color);
   }
   
//---------

   
if (TimeCurrent() == NFP_StartTime) {
TradeCount = 0;
}

double NFP_MA = iCustom(NULL, 0, "Moving Averages",MA_Period,MA_Shift,MA_Method,0, 0);

double Sentinel = iCustom(NULL, 0, "Sentinel_indi_Don2",EUR,JPY,GBP,CHF,CAD,AUD,AverageGains,PipsAsWholeNumbers,Reverse_Sentinal_On_NonUSDBased,MA1_Value,MA1_Shift,MA1_Method,Use_2nd_MA,MA2_Value,MA2_Shift,MA2_Method,Use_3rd_MA,MA3_Value,MA3_Shift,MA3_Method,0,  0);
double Sentinel_MA = iCustom(NULL, 0, "Sentinel_indi_Don2",EUR,JPY,GBP,CHF,CAD,AUD,AverageGains,PipsAsWholeNumbers,Reverse_Sentinal_On_NonUSDBased,MA1_Value,MA1_Shift,MA1_Method,Use_2nd_MA,MA2_Value,MA2_Shift,MA2_Method,Use_3rd_MA,MA3_Value,MA3_Shift,MA3_Method,1,  0);

double ThisBarOpen = CurrBar_OpenPrice;

  //Alerts

   if (Alerts_On == True) {
   if(TradeCount == 0) {
   if ( CurrBarOpenTime > NFP_EndTime && ThisBarOpen > NFP_HighestHigh && Sentinel > Sentinel_MA && ThisBarOpen > NFP_MA ) Alert("Buy ", Symbol(),ThisBarOpen,"!!!"); TradeCount=TradeCount+1;
   } else if (TradeCount > 0) {
   if ( CurrBarOpenTime > NFP_EndTime && ThisBarOpen > NFP_HighestHigh && Sentinel > Sentinel_MA && ThisBarOpen > NFP_MA && ThisBarOpen > CurrWeek_HighestHigh && ThisBarOpen > PrevWeek_HighestHigh )  Alert("Buy Again ", Symbol(),ThisBarOpen,"!!!"); TradeCount=TradeCount+1;
   }
   }
   
   if (Alerts_On == True) {
   if(TradeCount == 0) {
   if ( CurrBarOpenTime > NFP_EndTime && ThisBarOpen < NFP_LowestLow && Sentinel < Sentinel_MA && ThisBarOpen < NFP_MA ) Alert("Sell ", Symbol(),ThisBarOpen,"!!!"); TradeCount=TradeCount+1;
   } else if (TradeCount > 0) {
   if ( CurrBarOpenTime > NFP_EndTime && ThisBarOpen < NFP_LowestLow && Sentinel < Sentinel_MA && ThisBarOpen < NFP_MA && ThisBarOpen < CurrWeek_LowestLow && ThisBarOpen < PrevWeek_LowestLow ) Alert("Sell Again ", Symbol(),ThisBarOpen,"!!!"); TradeCount=TradeCount+1;
   }
   }

//-----------------------------------------------------------------------------------------------------------------------------  
   
   // strings below used for comments, concerning NFP Start Bar, NFP End Bar, Start Trading Bar, Previous Week Open Bar,
   // Previous Week Close Bar, Current Week Open Bar, Current Week Close Bar, and Current Bar characteritics
   string value1 = NFPStartBar;  
   string value2 = TimeToStr(NFPStartBar_OpenTime,TIME_DATE|TIME_MINUTES);
   string value7 = RealNFPEndBar;
   string value8 = TimeToStr(RealNFPEndBar_OpenTime,TIME_DATE|TIME_MINUTES);
   string value13 = StartTradingBar;
   string value14 = TimeToStr(StartTradingBar_OpenTime,TIME_DATE|TIME_MINUTES);
   string value25 = PrevWeek_RealOpenBar;
   string value26 = TimeToStr(PrevWeek_RealOpenBar_OpenTime,TIME_DATE|TIME_MINUTES);
   string value31 = PrevWeek_RealCloseBar;
   string value32 = TimeToStr(PrevWeek_RealCloseBar_OpenTime,TIME_DATE|TIME_MINUTES);
   string value37 = CurrWeek_RealOpenBar;
   string value38 = TimeToStr(CurrWeek_RealOpenBar_OpenTime,TIME_DATE|TIME_MINUTES);
   string value19 = CurrWeek_RealCloseBar;
   string value20 = TimeToStr(CurrWeek_RealCloseBar_OpenTime,TIME_DATE|TIME_MINUTES);
   string value43 = CurrBar;
   string value44 = TimeToStr(CurrBar_OpenTime,TIME_DATE|TIME_MINUTES);
   string value49 = TimeToStr(TimeLocal() );
   string value82 = TimeToStr(TimeCurrent() );
   
   if (Symbol() == "USDJPY") {
   string value3 = DoubleToStr(NFPStartBar_OpenPrice,2);
   string value4 = DoubleToStr(NFPStartBar_HighPrice,2);
   string value5 = DoubleToStr(NFPStartBar_LowPrice,2);
   string value6 = DoubleToStr(NFPStartBar_ClosePrice,2);
   string value9 = DoubleToStr(RealNFPEndBar_OpenPrice,2);
   string value10 = DoubleToStr(RealNFPEndBar_HighPrice,2);
   string value11 = DoubleToStr(RealNFPEndBar_LowPrice,2);
   string value12 = DoubleToStr(RealNFPEndBar_ClosePrice,2);
   
   string value15 = DoubleToStr(StartTradingBar_OpenPrice,2);
   string value16 = DoubleToStr(StartTradingBar_HighPrice,2);
   string value17 = DoubleToStr(StartTradingBar_LowPrice,2);
   string value18 = DoubleToStr(StartTradingBar_ClosePrice,2);
   string value27 = DoubleToStr(PrevWeek_RealOpenBar_OpenPrice,2);
   string value28 = DoubleToStr(PrevWeek_RealOpenBar_HighPrice,2);
   string value29 = DoubleToStr(PrevWeek_RealOpenBar_LowPrice,2);
   string value30 = DoubleToStr(PrevWeek_RealOpenBar_ClosePrice,2);
   string value33 = DoubleToStr(PrevWeek_RealCloseBar_OpenPrice,2);
   string value34 = DoubleToStr(PrevWeek_RealCloseBar_HighPrice,2);
   string value35 = DoubleToStr(PrevWeek_RealCloseBar_LowPrice,2);
   string value36 = DoubleToStr(PrevWeek_RealCloseBar_ClsePrice,2);
   string value50 = DoubleToStr(PrevWeek_HighestHigh,2);
   string value51 = DoubleToStr(PrevWeek_High,2);
   string value52 = DoubleToStr(PrevWeek_LowestLow,2);
   string value53 = DoubleToStr(PrevWeek_Low,2);
   string value39 = DoubleToStr(CurrWeek_RealOpenBar_OpenPrice,2);
   string value40 = DoubleToStr(CurrWeek_RealOpenBar_HighPrice,2);
   string value41 = DoubleToStr(CurrWeek_RealOpenBar_LowPrice,2);
   string value42 = DoubleToStr(CurrWeek_RealOpenBar_ClosePrice,2);
   string value21 = DoubleToStr(CurrWeek_RealCloseBar_OpenPrice,2);
   string value22 = DoubleToStr(CurrWeek_RealCloseBar_HighPrice,2);
   string value23 = DoubleToStr(CurrWeek_RealCloseBar_LowPrice,2);
   string value24 = DoubleToStr(CurrWeek_RealCloseBar_ClsePrice,2);
   string value54 = DoubleToStr(CurrWeek_HighestHigh,2);
   string value55 = DoubleToStr(CurrWeek_High,2);
   string value56 = DoubleToStr(CurrWeek_LowestLow,2);
   string value57 = DoubleToStr(CurrWeek_Low,2);
   string value45 = DoubleToStr(CurrBar_OpenPrice,2);
   string value46 = DoubleToStr(CurrBar_HighPrice,2);
   string value47 = DoubleToStr(CurrBar_LowPrice,2);
   string value48 = DoubleToStr(CurrBar_ClosePrice,2);
   } else {
   value3 = DoubleToStr(NFPStartBar_OpenPrice,4);
   value4 = DoubleToStr(NFPStartBar_HighPrice,4);
   value5 = DoubleToStr(NFPStartBar_LowPrice,4);
   value6 = DoubleToStr(NFPStartBar_ClosePrice,4);
   value9 = DoubleToStr(RealNFPEndBar_OpenPrice,4);
   value10 = DoubleToStr(RealNFPEndBar_HighPrice,4);
   value11 = DoubleToStr(RealNFPEndBar_LowPrice,4);
   value12 = DoubleToStr(RealNFPEndBar_ClosePrice,4);
   
   value15 = DoubleToStr(StartTradingBar_OpenPrice,4);
   value16 = DoubleToStr(StartTradingBar_HighPrice,4);
   value17 = DoubleToStr(StartTradingBar_LowPrice,4);
   value18 = DoubleToStr(StartTradingBar_ClosePrice,4);
   value27 = DoubleToStr(PrevWeek_RealOpenBar_OpenPrice,4);
   value28 = DoubleToStr(PrevWeek_RealOpenBar_HighPrice,4);
   value29 = DoubleToStr(PrevWeek_RealOpenBar_LowPrice,4);
   value30 = DoubleToStr(PrevWeek_RealOpenBar_ClosePrice,4);
   value33 = DoubleToStr(PrevWeek_RealCloseBar_OpenPrice,4);
   value34 = DoubleToStr(PrevWeek_RealCloseBar_HighPrice,4);
   value35 = DoubleToStr(PrevWeek_RealCloseBar_LowPrice,4);
   value36 = DoubleToStr(PrevWeek_RealCloseBar_ClsePrice,4);
   value50 = DoubleToStr(PrevWeek_HighestHigh,4);
   value51 = DoubleToStr(PrevWeek_High,4);
   value52 = DoubleToStr(PrevWeek_LowestLow,4);
   value53 = DoubleToStr(PrevWeek_Low,4);
   value39 = DoubleToStr(CurrWeek_RealOpenBar_OpenPrice,4);
   value40 = DoubleToStr(CurrWeek_RealOpenBar_HighPrice,4);
   value41 = DoubleToStr(CurrWeek_RealOpenBar_LowPrice,4);
   value42 = DoubleToStr(CurrWeek_RealOpenBar_ClosePrice,4);
   value21 = DoubleToStr(CurrWeek_RealCloseBar_OpenPrice,4);
   value22 = DoubleToStr(CurrWeek_RealCloseBar_HighPrice,4);
   value23 = DoubleToStr(CurrWeek_RealCloseBar_LowPrice,4);
   value24 = DoubleToStr(CurrWeek_RealCloseBar_ClsePrice,4);
   value54 = DoubleToStr(CurrWeek_HighestHigh,4);
   value55 = DoubleToStr(CurrWeek_High,4);
   value56 = DoubleToStr(CurrWeek_LowestLow,4);
   value57 = DoubleToStr(CurrWeek_Low,4);
   value45 = DoubleToStr(CurrBar_OpenPrice,4);
   value46 = DoubleToStr(CurrBar_HighPrice,4);
   value47 = DoubleToStr(CurrBar_LowPrice,4);
   value48 = DoubleToStr(CurrBar_ClosePrice,4);
   }
   
   string value79=DoubleToStr(LotSize(), 2);
   
   string value80;
   
   if(LotSize() >= 1) {
   value80= "Standard lots";
   }
   
   if(LotSize() < 1) {
   value80= "Mini lots";
   } 
   
   if(LotSize() < 0.1) {
   value80= "Micro lots";
   }
   
   int value81;
   
   if (LotSize() >= 1) {
   value81 = LotSize()*1;
   }
   
   if (LotSize() < 1) {
   value81 = LotSize()*10;
   }
   
   if (LotSize() < 0.1) {
   value81 = LotSize()*100;
   }
   
   string value76 = DoubleToStr(AccountBalance(),2);
   string value78 = DoubleToStr(MODETICKVALUE,2);
   
   if (ShowComments == true) {
Comment (
// Comments below concerning Last NFP Start Bar, Last NFP End Bar, Last Start Trading Bar, NFP Start Bar, NFP End Bar, Start Trading Bar, Previous Week Open Bar,
// Previous Week Close Bar, Current Week Open Bar, Current Week Close Bar, and Current Bar characteritics
"NFP_OpenBar = " + value1 + ", (open) Time = " + value2 + ", Open " + value3 + ", High " + value4 + ", Low " + value5 + ", Close " + value6 + "\n" +
"NFP_CloseBar = " + value7 + ", (open) Time = " + value8 + ", Open " + value9 + ", High " + value10 + ", Low " + value11 + ", Close " + value12 + "\n" +
"StartTradingBar = " + value13 + ", (open) Time = " + value14 + ", Open " + value15 + ", High " + value16 + ", Low " + value17 + ", Close " + value18 + "\n" +
"PrevWeek_OpenBar = " + value25 + ", (open) Time = " + value26 + ", Open " + value27 + ", High " + value28 + ", Low " + value29 + ", Close " + value30 + "\n" +
"PrevWeek_CloseBar = " + value31 + ", (open) Time = " + value32 + ", Open " + value33 + ", High " + value34 + ", Low " + value35 + ", Close " + value36 + "\n" +
"PrevWeek_ThisChart_HighestHigh = " + value50 + ", PrevWeek_ThisChart_LowestLow = " + value52 + "\n" +
"PrevWeek_W1chart_High = " + value51 + ", PrevWeek_W1chart_Low = " + value53 + "\n" +
"CurrWeek_OpenBar = " + value37 + ", (open) Time = " + value38 + ", Open " + value39 + ", High " + value40 + ", Low " + value41 + ", Close " + value42 + "\n" +
"CurrWeek_CloseBar = " + value19 + ", (open) Time = " + value20 + ", Open " + value21 + ", High " + value22 + ", Low " + value23 + ", Close " + value24 + "\n" +
"CurrWeek_ThisChart_HighestHigh = " + value54 + ", CurrWeek_ThisChart_LowestLow = " + value56 + "\n" +
"CurrWeek_W1chart_High = " + value55 + ", CurrWeek_W1chart_Low = " + value57 + "\n" +
"CurrBar = " + value43 + ", (open) Time = " + value44 + ", Open " + value45 + ", High " + value46 + ", Low " + value47 + ", Close " + value48 + "\n" +
"Don Money Management: (Account Balance x (Risk Percent Per Trade x 0.01)) / (Stop Loss x Tick Value)" + "\n" +
"Account Balance = " + value76 + "\n" +
"Risk Percent Per Trade = " + PercentRiskPerTrade + " %" + "\n" +
"Stop Loss = " + StopLoss + "\n" +
"Tick Value = " + value78 + "\n" +
"Number of Lots to Trade Per Pair = " + value79 + " ( " + value81 + " " + value80 + " )" + " Remember: Remove half position at 50 pips Take Profit" + "\n" +
//"TradeCount = " + TradeCount + "\n" +
"Server Time = " + value82 + "\n" +
"Current Time = " + value49
);
}
//---------
  
} //end of start (is this in the right place?)

return(0);
}
//+------------------------------------------------------------------+
	//----------------------- MONEY MANAGEMENT FUNCTION  
   //----------------------- SOURCE : DON ISBELL
double lot;
double LotSize()
{
     
     lot=NormalizeDouble((AccountBalance()*(PercentRiskPerTrade*0.01))/(StopLoss*MODETICKVALUE),2);
	  
	  return (lot);
}