Download MetaTrader 5
To add comments, please log in or register
Find out the latest MQL5.community news!
Sunrain Forex
18
Sunrain Forex 2014.02.26 17:18 

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);

}

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

whroeder1
13653
whroeder1 2014.02.26 17:58  

  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
Keith Watford
Moderator
8016
Keith Watford 2014.02.26 21:15  
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
Keith Watford
Moderator
8016
Keith Watford 2014.02.26 21:28  
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() );

}
Sunrain Forex
18
Sunrain Forex 2014.02.27 15:25  
I attach file already, Please help me.
whroeder1
13653
whroeder1 2014.02.27 16:36  
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.

Sunrain Forex
18
Sunrain Forex 2014.02.28 12:11  
How to modify?
Daniel Petrovai
440
Daniel Petrovai 2014.03.03 05:11  
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());
        }
     }
  }
//========================================================================
/
To add comments, please log in or register