Specific number of Orders per Currency Pair

 

Hello, i have added a function that allows a Specific number of Trades per Currency pair (marked yellow), it all worked fine but then i realized that 3 other functions stopped working (marked white). i then saw that it is the return function that makes it happen. I tried to replace the return function, but then i can't trade a specific number of Trades.

i have tried a few things in the last couple of days.

Is there a way i can let all 4 functions play without one not working?


i appreciate any kind of help!

Files:
Mql4Code.mq4  8 kb
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. Please don't add text inside quoted text or CODE blocks, put it outside.
              MQL4 forum editor problem - MQL4 programming forum (2015)

 
William Roeder #:
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. Please don't add text inside quoted text or CODE blocks, put it outside.
              MQL4 forum editor problem - MQL4 programming forum (2015)


Thank you William Roeder!

 
Streezey211 #:

Thank you William Roeder

Finally, found the Awnser!
Thank God!!
I feel very relieved now!

So here is what i did:
I restructured the 2 Sections (Yellow & White). Placing the Yellow section above the white section made it possible for the return function (white)  not to skip the yellow section (i believe).


//==============================================================
/////////////////// GIVE ALL ORDERS TP AND SL /////////////////
  for (int SLTP= OrdersTotal()-1;SLTP>=0;SLTP--)
  {


  if (OrderSelect(SLTP,SELECT_BY_POS,MODE_TRADES))
  
  if (OrderSymbol()==Symbol())
  
  if (OrderType()==OP_SELL)
  
  { if (OrderStopLoss()==0)

  
  OrderModify(
               OrderTicket(),       
               OrderOpenPrice(),    // Price
               Bid+(400*_Point),    // Stop Loss
               OrderTakeProfit(),    // Take Profit
               0,
               CLR_NONE             // color           
               );
               
               }
  {
  if (OrderSelect(SLTP,SELECT_BY_POS,MODE_TRADES))
   if (OrderSymbol()==Symbol())
      if(OrderType()==OP_BUY)
       
      
      { if (OrderStopLoss()==0)
      
      OrderModify(
                  OrderTicket(),
                  OrderOpenPrice(),
                  Ask - (400*_Point),
                  OrderTakeProfit(),
                  0,
                  CLR_NONE
                  );
                  
  
  }
  }
  }
/////////////////// SL TO PROFIT/////////////////
  for (int b= OrdersTotal()-1;b>=0;b--)
  {
  if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
  
  if (OrderSymbol()==Symbol())
  
  if (OrderType()==OP_SELL)
  {
  if( OrderOpenPrice()==Bid+(150*_Point)) //if order is 1500point in profit
  
  OrderModify(
               OrderTicket(),
               OrderOpenPrice(),
               Bid + (100*_Point), //set +300 points in profit if price is OrderStopLoss()>Bid+(1500*_Point)) in profit
               OrderTakeProfit(),
               0,
               CLR_NONE
               );
               
               }
  {
  if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
   if (OrderSymbol()==Symbol())
      if(OrderType()==OP_BUY)
      
      { if (OrderOpenPrice() == Ask-(150*_Point))
      
      OrderModify(
                  OrderTicket(),
                  OrderOpenPrice(),
                  Ask - (100*_Point),
                  OrderTakeProfit(),
                  0,
                  CLR_NONE
                  );
                  
  
  }
  }
  }
//////////////////////////////////////////////////Close all Positions at the end of the day ////////////////////////////////// 
//If Time is Up then we close all Positions
if (MarketState=="closed")


  {
  //Go trough all the open Trades
  for(int i=OrdersTotal()-1; i>=0; i--) 
  {
  //Select an order
  OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
  
  //Get the Currency pair for the order
  string CurrencyPair=OrderSymbol();
  
 
  //Check if Buy Position
  if(OrderType()==OP_BUY)
  {
  //Close current Position
  OrderClose (OrderTicket(),OrderLots(),Bid,3,NULL);
  }
    //Check if Sell Position
  if (OrderType()==OP_SELL)
  //Close current Position
  OrderClose (OrderTicket(),OrderLots(),Ask,3,NULL);
  }}
//////////////////////////////////////////////////////////////////////Only 4 orders per currency pair/////////////////////
int total,orders,t;
string symbol;
total= OrdersTotal();

for (t=0;t<total;t++)

{
OrderSelect(t,SELECT_BY_POS);
if (OrderSymbol() == Symbol()) orders++;
}

if(orders>3) return; //if orders bigger than 0 dont trade! because a position is already open for this pair
/////////////////////////////////////////////////////////////////////Execute Code/////////////////////////////////////////

 
 if (VolumeSignal=="USDCHF")

   {
if  (USDCHFVolume>0)
int USDCHFUP=OrderSend("USDCHF",OP_BUY,SetLotSize3(),Ask,3,0,0,NULL,0,0,Blue);
   
if (USDCHFVolume<0)
 int USDCHFDOWN=OrderSend("USDCHF",OP_SELL,SetLotSize3(),Bid,3,0,0,NULL,0,0,Red);
}