You are currently not signed in.

Please sign in or register.

Need a script for MT4

Page: 1
May 15, 2012 09:58 am
#1
gerard User

Posts: 1
Member since: 26/01/2012

 

Hey guys

Looking for a simple script to close one or many positions at a specific time I choose. If you have such, please, post it or give a download link.
Thanks!

May 16, 2012 07:02 pm
ironical User

Posts: 734
Member since: 22/04/2011

I found something very close to wat u want. But u need to know coding to change it according to ur needs

The good or ill of a man lies within his own will. – Epictetus

Attachements:

forex.zip

May 17, 2012 02:26 pm
Champ User

Posts: 711
Member since: 17/05/2011

How to use these notepads[erm]. You also need to post a full tutorial on "how to use these notepads"[grin].

http://www.fxstat.com/widget/link?t=tiny&c=1&s=24959&o1=growth&o2=drawdown&o3=profitfactor

May 18, 2012 06:44 pm
ironical User

Posts: 734
Member since: 22/04/2011

Originally posted by Champ

How to use these notepads<img alt=" />. You also need to post a full tutorial on "how to use these notepads"<img alt=" />.



Even I dont know exactly how to use it. I only copied it from another source. A developer can help in running this code.

The good or ill of a man lies within his own will. – Epictetus

May 23, 2012 07:56 am
Sasha User

Posts: 836
Member since: 16/05/2011

Originally posted by gerard

 

Hey guys

Looking for a simple script to close one or many positions at a specific time I choose. If you have such, please, post it or give a download link.
Thanks!



MT4 comes with many scripts already built into it. You can also make simple scripts even if u dont know programming. Just search on google for "make your own forex EA". You will get websites where u can make simple EAs easily.

May 23, 2012 09:31 am
forexi007 User

Posts: 28
Member since: 25/01/2012

Scripts Don't work like that.  Scripts only run once and are performed instantly by the user. 

 

You need an EA .  I have a Free EA - Discipline Trader EA - You can Insert the Time you wish to close the trades ( ALL) and it will do it for you. 

http://www.pipinvestment.com/software/download

May 23, 2012 09:32 am
forexi007 User

Posts: 28
Member since: 25/01/2012

// Copy Paste into MetaEditor, then Save as into Experts Folder, then Compile

extern int        TimeEnd_Hour          = 23;  // HOUR 

extern int        TimeEnd_Min           = 59;  // MIN

 

int Cur_Hour;int Cur_Min;bool   result;double price;int    cmd,error;

 

int start()

  {

    Cur_Hour=Hour();

    Cur_Min=Minute();

    

   

   if (Cur_Hour>=TimeEnd_Hour && Cur_Min>=TimeEnd_Min) 

   {   

 

   if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES))

     {

      cmd=OrderType();

      //---- first order is buy or sell

      if(cmd==OP_BUY || cmd==OP_SELL)

        {

         while(true)

           {

            if(cmd==OP_BUY) price=Bid;

            else            price=Ask;

            result=OrderClose(OrderTicket(),OrderLots(),price,3,White);

            if(result!=TRUE) { error=GetLastError(); Print("LastError = ",error); }

            else error=0;

            if(error==135) RefreshRates();

            else break;

           }

        }

     }

   }

   else Print( "Error when order select ", GetLastError());

//----

   return(0);

  }

//+------------------------------------------------------------------+

Or use this code. I haven't tried it, but it should work

Nov 25, 2012 10:01 am
illiterate User

Posts: 561
Member since: 21/04/2011

Hey forexi007, u look pretty good in developing EAs. How about ur trading skills? Coz I havnt seen any of ur accounts here. Please link 1 or 2 if u r currently trading. I would like to see live performance of ur EAs.

https://www.fxstat.com/widget/link?t=medium&c=1&s=25892&o1=growth&o2=drawdown&o3=monthly&o4=equity

Dec 19, 2012 06:08 pm
tasukigap User

Posts: 7
Member since: 19/12/2012

Originally posted by gerard

 

Hey guys

Looking for a simple script to close one or many positions at a specific time I choose. If you have such, please, post it or give a download link.
Thanks!

 



 

closed any open trade at specific time??will you closed your open trade on loss condition :)

 

try this

put it on script folde (mt4/expert/script)

 

#property copyright "Mn"
#property show_confirm
#property show_inputs
#include <stdlib.mqh>

extern int  mSlippage =  3;
extern double mProfTgt = 1000;  
extern string mCAP = "**** USE ENTIRELY AT OWN RISK *****";
extern string mCAPx = "**** Profit level above which the order closes *****";
extern double mProfit   = 100.00;
extern string mCAPxx    = "** TAKE CARE SETTING THESE OPTIONS *****";
extern string mCAPxxx   = "** Set to 1 for all pairs : Set to 0 for CurrentChart Only *****";
extern int   mAllSymbol = 0;
extern string mCAPxxxx  = "** Set to 1 to close Longs in profit : 0 to ignore Longs *****";
extern int    mLong     = 1;
extern string mCAPxxxxx = "** Set to 1 to close Shorts in profit : 0 to ignore Shorts *****";
extern int    mShort    = 1;

// ---------------------------------------------------------------------------------- +
int start()
{
  int mType, mTotal = OrdersTotal();
  double mTotProf = 0;
 
  for(int i = mTotal - 1; i >= 0; i--)
  {
    OrderSelect(i, SELECT_BY_POS);
    mType   = OrderType();
    bool mResult = false;
   
    if(OrderSymbol() == Symbol() || mAllSymbol == 1)
      {
        mTotProf += OrderProfit();
      }
   }
 
  if(mTotProf > mProfTgt)
   {
    for(i = mTotal - 1; i >= 0; i--)
     {
       OrderSelect(i, SELECT_BY_POS);
       mType   = OrderType();
       mResult = false;
   
       if(OrderSymbol() == Symbol() || mAllSymbol == 1)
         {
           switch(mType)
            {
             case OP_BUY  :
              {
               if(mLong == 1)
                 mResult = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, CLR_NONE );
               break;
              }
             case OP_SELL :
               {
                if(mShort == 1)
                  mResult = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, CLR_NONE );
                break;
               }
            default      :
               break;
            }
   
           if(mResult == false)
            {
              Alert("Order " , OrderTicket() , " Failed to close. Error:" , GetLastError() );
              Sleep(2000);
            }
         }   // if(OrderSymbol
      }        // for i
    }          // if mTotProf
    
  return(0);
 }

 

cheer

#1 Forex expert advisor vendor Tasukigap Ea

Dec 25, 2012 04:49 am
Sasha User

Posts: 836
Member since: 16/05/2011

Hello tasuki gap.

Will this script close only profitable trades or all trades? or will it ask for a time to close trades?

Page: 1