Hi, I have a dilemma

Christer Lundqvist  
Hi, I have a dilemma, how do I write the code so that the first thread goes in first, and the second one goes in after the first so he can take the crumbs after the first thread,
I know I need an if statement, but how do I do it so that it will be good, and when he has finished trading the first thread and has taken care of the crumbs,
then it has to wait for the first thread to go back in before the second thread goes in again.

First the main trade, then the second trade that takes care of the crumbs.

//------ THIS IS THE FIRST TRADE.
 //Open Buy Order.
   if(Cross(0, MA[0] > MA2[0]) && MA[1] < MA2[1]) //Moving Average crosses above Moving Average, Moving Average < Moving Average.
     {
      MqlTick last_tick;
      SymbolInfoTick(Symbol(), last_tick);
      price = last_tick.ask;
      SL = SL_Pips * myPoint; //Stop Loss = value in points (relative to price)
      TP = TP_Pips * myPoint; //Take Profit = value in points (relative to price)
      if(TimeCurrent() - LastOpenTime() < NextOpenTradeAfterHours * 3600) return; //next open trade after time after previous trade's open   
      if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && MQLInfoInteger(MQL_TRADE_ALLOWED))
        {
         ticket = myOrderSend (ORDER_TYPE_BUY,  price,  MM_Size(), "");
         if (ticket == 0) return;
        }
      else //not autotrading => only send alert
         myAlert ("order", "");
      myOrderModifyRel (ORDER_TYPE_BUY, ticket, 0, TP);
      myOrderModifyRel (ORDER_TYPE_BUY, ticket, SL, 0);
     }
   
//----- THIS IS THE SECOND TRADE.
   //Open Buy Order.
   if(Cross(1, Close[0] > MA[0]) && Close[1] < MA[1]) //Candlestick Close crosses above Moving Average, Candlestick Close < Moving Average.
      {
      MqlTick last_tick;
      SymbolInfoTick(Symbol(), last_tick);
      price = last_tick.ask;
      SL = SL_Pips * myPoint; //Stop Loss = value in points (relative to price)
      TP = TP_Pips_Small * myPoint; //Take Profit = value in points (relative to price)
      if(TimeCurrent() - LastOpenTime() < NextOpenTradeAfterHours * 3600) return; //next open trade after time after previous trade's open   
      if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && MQLInfoInteger(MQL_TRADE_ALLOWED))
         {
         ticket = myOrderSend(ORDER_TYPE_BUY, price, MM_Size(), "");
         if(ticket == 0) return;
         }
      else //not autotrading => only send alert
         myAlert("order", "");
      myOrderModifyRel(ORDER_TYPE_BUY, ticket, SL, 0);
      myOrderModifyRel(ORDER_TYPE_BUY, ticket, 0, TP);
      }
Carl Schreiber  

Learn to code:

    https://www.mql5.com/en/articles/496
    https://www.mql5.com/en/articles/100
    https://www.mql5.com/en/articles/599
    and for debugging: https://www.metatrader5.com/en/metaeditor/help/development/debug
    https://www.mql5.com/en/search#!keyword=cookbook
    Bear in mind there's virtually nothing that hasn't already been programmed for MT4/MT5 and is ready for you!
    => Search in the articles: https://www.mql5.com/en/articles
    => Search in the codebase: https://www.mql5.com/en/code
    => Search in general: https://www.mql5.com/en/search or via Google with: "site:mql5.com .." (forgives misspelling)

Quick Start: Short Guide for Beginners
Quick Start: Short Guide for Beginners
  • www.mql5.com
Hello dear reader! In this article, I will try to explain and show you how you can easily and quickly get the hang of the principles of creating Expert Advisors, working with indicators, etc. It is beginner-oriented and will not feature any difficult or abstruse examples.
Reason: