What is the difference between ticket number 2 and ticket number 3 if it is only one buy or sell that can meet conditionals within a daily time frame

 

Hi! I have an EA that only submits one short or long trade every daily time frame, I see when running a back test this EA submits a single short trade but then attached to it is also a buy order. How is a buy order possible if the EA is coded to only allow one long or short trade per day?

      static datetime prevTime=0;
      datetime lastTime[1];
      if(CopyTime(_Symbol,PERIOD_D1,0,1,lastTime)==1 && prevTime!=lastTime[0])
        {
         prevTime=lastTime[0];

         if(OneDayCalculationMA > 0.9 && OneDayCalculationOS > 0.15 && OSOneMinute > 0.15 && BuyPrice <= DailyOpen && BuyPrice <= OneMinuteOpen && OrdersTotal() == 0 && PositionsTotal() == 0 && totalOrders == 0)
           {
            double EnterLong = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
            EnterLong = NormalizeDouble(EnterLong,_Digits);
            trade.Buy(Lots,NULL,EnterLong,StopLoss,NULL,"Enter Long");
           }
         // Check conditions to enter a short position
         if(OneDayCalculationMA < -0.9 && OneDayCalculationOS < -0.15 && OSOneMinute < -0.15 && SellPrice >= DailyOpen && SellPrice >= OneMinuteOpen && OrdersTotal() == 0 && PositionsTotal() == 0 && totalOrders == 0)
           {
            double EnterShort = SymbolInfoDouble(_Symbol,SYMBOL_BID);
            EnterShort = NormalizeDouble(EnterShort,_Digits);
            trade.Sell(Lots,NULL,EnterShort,StopLoss,NULL,"Enter Short");
           }
        }
Files:
 
Look at history deals, pay attention to the direction of the deal.
I think the buy you see is nothing else than the deal that close the sell trade.

Basically you are watching into the wrong place, and probably you also not fully understood differences between Orders, Deals and Positions on MT5...
 
Fabio Cavalloni #:
Look at history deals, pay attention to the direction of the deal.
I think the buy you see is nothing else than the deal that close the sell trade.

Basically you are watching into the wrong place, and probably you also not fully understood differences between Orders, Deals and Positions on MT5...
I understand, thank you for clarifying!
 
Colin Kimble #:
I understand, thank you for clarifying!
Does Meta 5 allow for the position to remain open for a specified time frame?
 
Colin Kimble #: Does Meta 5 allow for the position to remain open for a specified time frame?

Orders, Positions and and Deals are totally independent of time-frame.

Positions do not have an expiration time/date and remain open until:

  • their stops are triggered, or
  • they are closed by the trader, or
  • closed by broker (e.g. margin stop-out).
 
Fernando Carreiro #:

Orders, Positions and and Deals are totally independent of time-frame.

Positions do not have an expiration time/date and remain open until:

  • their stops are triggered, or
  • they are closed by the trader, or
  • closed by broker (e.g. margin stop-out).

My script doesn't mention their closing and it hasn't hit my stop loss. What else causes an open position to close? Thank you for all your wisdom!

 
Fernando Carreiro #:

Orders, Positions and and Deals are totally independent of time-frame.

Positions do not have an expiration time/date and remain open until:

  • their stops are triggered, or
  • they are closed by the trader, or
  • closed by broker (e.g. margin stop-out).

If the closing of a position is independent to time, the how come does the timing of the positions closing correspond to the time frame used on the bar?

I have tested on both a one minute time frame.

   static datetime dtBarCurrentOneMinute  = WRONG_VALUE;
   datetime dtBarPreviousOneMinute = dtBarCurrentOneMinute;
   dtBarCurrentOneMinute  = iTime(_Symbol,PERIOD_M1, 0);
   bool     bNewBarEventOneMinute  = (dtBarCurrentOneMinute != dtBarPreviousOneMinute);

   if(bNewBarEventOneMinute)
     {

Here is the one hour one

   static datetime dtBarCurrentOneMinute  = WRONG_VALUE;
   datetime dtBarPreviousOneMinute = dtBarCurrentOneMinute;
   dtBarCurrentOneMinute  = iTime(_Symbol,PERIOD_H1, 0);
   bool     bNewBarEventOneMinute  = (dtBarCurrentOneMinute != dtBarPreviousOneMinute);

   if(bNewBarEventOneMinute)
     {

As seen in the screenshot each one closes the short position according to the time frame of the bar, so how then can the closing of a position be independent of what time frame is being used?

Files:
 
Colin Kimble #: My script doesn't mention their closing and it hasn't hit my stop loss. What else causes an open position to close? Thank you for all your wisdom!

What type of account? On a "netting" account, an opposite order of the same volume closes the position.

 
Colin Kimble #: If the closing of a position is independent to time, the how come does the timing of the positions closing correspond to the time frame used on the bar?e frame is being used?

Probably because your EA is closing/reversing the position on a "timely" fashion based on the time-frame.

I have already advised you multiple times for you to start with a small and simple project so that you can properly learn the platform's functionality and the programming language.

However, since you continue to reject the advice, this will be my last post on any of your topics.

 
Fernando Carreiro #:

Probably because your EA is closing/reversing the position on a "timely" fashion based on the time-frame.

I have already advised you multiple times for you to start with a small and simple project so that you can properly learn the platform's functionality and the programming language.

However, since you continue to reject the advice, this will be my last post on any of your topics.

I resolved the issue, it's quiet funny how easy and simple coding is. It's always a small issue, lol.