Close all order on friday.

 

Please help me, I modify already but It is not work.

step 1.If today is friday && have profit >= 5 usd

step 2.Close all order.

step 3.Stop trade on friday.

////////////////////////////////////////////////////////////

In begining:

PHP Code:


extern string FridaySetup = "======= Friday Setting =======";

extern bool CloseOrderFriday = TRUE;

extern double CloseProfitFriday =5;

extern int CloseAfterHourFriday = 1;

////////////////////////////////////////////////////////////

Conditions in the code before SendOrder tag:


PHP Code:



if ( checkFriday()){

Comment("No Trade On Friday");

return (0);

}




And this:


PHP Code:


bool checkFriday()

{


if ( (CloseAfterHourFriday != 0) && (DayOfWeek() == 5) && (Hour() >= CloseAfterHourFriday) && (AccountProfit()>= CloseProfitFriday) )

int total = OrdersTotal();

for(int i=total-1;i>=0;i--)

{

OrderSelect(i, SELECT_BY_POS);

int type = OrderType();


bool result = false;

switch(type)

{

//Close opened long positions

case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );

break;

//Close opened short positions

case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );

break;


//Close pending orders

case OP_BUYLIMIT :

case OP_BUYSTOP :

case OP_SELLLIMIT :

case OP_SELLSTOP : result = OrderDelete( OrderTicket() );

}

if(result == false)

{

Alert("Order ", OrderTicket(), " failed to close. Error:", GetLastError() );

Sleep(3000);

}

}

return(0);

}

////////////////////////////////////////////////////////////

 

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. onlinetoriches: It is not work.
    "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  3. What are Function return values ? How do I use them ? - MQL4 forum
 
bool checkFriday()

{



if ( (CloseAfterHourFriday != 0) && (DayOfWeek() == 5) && (Hour() >= CloseAfterHourFriday) && (AccountProfit()>= CloseProfitFriday) )

int total = OrdersTotal(); //---THIS IS THE ONLY LINE OF CODE THAT IS CONTROLLED BY THE ABOVE IF CONDITION

for(int i=total-1;i>=0;i--) //---THIS AND THE FOLLOWING CODE WILL BE EXECUTED REGARDLESS OF WHETHER THE ABOVE IF CONDITION IS TRUE/FALSE
   //REST OF YOUR CODE
 
I don't use switch much so not 100% certain
switch(type)

{

//Close opened long positions

case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );

break;

//Close opened short positions

case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );

break;



//Close pending orders IF NOT OP_BUY OR OP_SELL, IT MUST BE A PENDING ORDER-SO USE default

default : result = OrderDelete( OrderTicket() );

}
 
I attach file already, Please help me.
 
onlinetoriches: I attach file already, Please help me.
  int li_112;
   double ld_116;
   double ld_124;
   double ld_132; ...
Ask the owner of the source code to give it to you or have him convert it for you.

Decompiled code is stolen code. Either you are a thief, a fence, or the receiver of stolen (intellectual) property. Either way we will not be an accomplice after the fact to theft. See also https://www.mql5.com/en/forum/134317

If you post decompiled code again, you will likely be banned and Mt4 doesn't allow compilation of decompiled code any more.

 
How to modify?
 
onlinetoriches:
How to modify?


Here is a four simple steps to do what you want :

#include <stdlib.mqh>
// this will help with error description
/*
You need to copy/paste #include <stdlib.mqh> if not already done so
Then copy/paste the CloseThisSymbolAll function to the end of your EA
Change the name of the variable "MagicNumber " to the name you use in 
your EA for magic number
Then modify your line (copy/pste) to match the following :
*/
if ( (CloseAfterHourFriday != 0) && (DayOfWeek() == 5) && (Hour() >= CloseAfterHourFriday) && (AccountProfit()>= CloseProfitFriday) )
CloseThisSymbolAll();



//========================================================================

void CloseThisSymbolAll()
  {
   int trade;
   for(trade=OrdersTotal();trade>=0;trade--)
     {
      OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
     // if(OrderSymbol()!=Symbol()) continue;
     // if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
        {
         if(OrderType()==OP_BUY)OrderClose(OrderTicket(),OrderLots(),Bid,slip,Blue);
         if(OrderType()==OP_SELL)OrderClose(OrderTicket(),OrderLots(),Ask,slip,Red);
         if(OrderType()==OP_BUYLIMIT)OrderDelete(OrderTicket(),Blue);
         if(OrderType()==OP_SELLLIMIT)OrderDelete(OrderTicket(),Blue);
         if(OrderType()==OP_BUYSTOP)OrderDelete(OrderTicket(),Blue);
         if(OrderType()==OP_SELLSTOP)OrderDelete(OrderTicket(),Blue);
         ErrorDescription(GetLastError());
        }
     }
  }
//========================================================================

If you follow the steps,When conditions are met, the new CloseThisSymbolAll() function will select and close ALL orders that were placed by this EA only.

If you want to close all orders regardless of the fact that they were or weren't place by this EA you just need to comment this two lines :

Then the EA will close ALL orders regardless of symbol or magic number. Let me know if you have questions.

//========================================================================

void CloseThisSymbolAll()
  {
   int trade;
   for(trade=OrdersTotal();trade>=0;trade--)
     {
      OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
      //if(OrderSymbol()!=Symbol()) continue;
      //if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
        {
         if(OrderType()==OP_BUY)OrderClose(OrderTicket(),OrderLots(),Bid,slip,Blue);
         if(OrderType()==OP_SELL)OrderClose(OrderTicket(),OrderLots(),Ask,slip,Red);
         if(OrderType()==OP_BUYLIMIT)OrderDelete(OrderTicket(),Blue);
         if(OrderType()==OP_SELLLIMIT)OrderDelete(OrderTicket(),Blue);
         if(OrderType()==OP_BUYSTOP)OrderDelete(OrderTicket(),Blue);
         if(OrderType()==OP_SELLSTOP)OrderDelete(OrderTicket(),Blue);
         ErrorDescription(GetLastError());
        }
     }
  }
//========================================================================
 
Thank , good job
Reason: