+ Reply to Thread
Page 10 of 11 FirstFirst ... 8 9 10 11 LastLast
Results 91 to 100 of 106

Thread: Usefull MQ4 Code Snippets/Functions

  1. #16
    Senior Member Nabi Ahmed Gill is a jewel in the rough Nabi Ahmed Gill is a jewel in the rough Nabi Ahmed Gill is a jewel in the rough Nabi Ahmed Gill's Avatar
    Join Date
    Mar 2012
    Posts
    1,022
    Thanks
    0
    Thanked 310 Times in 129 Posts
    SubscribeSubscribe
    subscribed 0
    Quote Originally Posted by peteonthenet View Post
    In this thread, we will collect and discuss useful code snippets/functions that we can incorporate in Expert Advisors to make coding process faster and easier
    yar yua mq 4 code ka ha muaja ot es code ka bar main ko pata nahi ha yar ya to main es forum main abi newbie hoon es lya ya forum sa mq4 ka bara main nahi bata sakta hon elsya main es par search karoon ga.

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  2. #15
    Member abdul hamid p is an unknown quantity at this point abdul hamid p's Avatar
    Join Date
    May 2012
    Location
    cave
    Posts
    123
    Thanks
    0
    Thanked 11 Times in 8 Posts
    SubscribeSubscribe
    subscribed 0
    can you make a code for me. i want entry market automatically just when US session. Open BUY when the price above Open Market and Open Sell when the price below Open Market. Stop lose 20 and there is no profit target just close when US session end. thanks

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  3. #14
    Member joget has a spectacular aura about joget has a spectacular aura about joget's Avatar
    Join Date
    Feb 2012
    Location
    gresik
    Posts
    363
    Thanks
    3
    Thanked 157 Times in 44 Posts
    SubscribeSubscribe
    subscribed 0
    great thread, can you make an EA code based on the intersection of the RSI indicator (14, close) with Simple MA indicator (3, previous indicators data). I have tried making it but it does not go as expected because of an error writing the code for Simple MA indicators (3, previous indicators data).

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  4. #13
    Member xiaotanghao is a jewel in the rough xiaotanghao is a jewel in the rough xiaotanghao is a jewel in the rough xiaotanghao's Avatar
    Join Date
    Feb 2012
    Posts
    315
    Thanks
    0
    Thanked 267 Times in 66 Posts
    SubscribeSubscribe
    subscribed 0
    Thank you for you show the codes here.Now I just wonder whether you have time to teach me to write the codes.Maybe I should ask you will you teach me these codes there?I wish I can manage the code myself.

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  5. #12
    Banned FxBd is an unknown quantity at this point FxBd's Avatar
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Quote Originally Posted by peteonthenet View Post
    Following is a custom function which when called will return total of active trades for a particular magic number:


    Code:
    int CountAllTrades(int magic) {
       int c=0;
       for (int j=OrdersTotal()-1;j>=0;j--)
       {
          OrderSelect(j,SELECT_BY_POS,MODE_TRADES);
          if (OrderSymbol()==Symbol() && OrderMagicNumber()==magic) c++;
       }
       
       return(c);
    }
    This code is really very nice.I think it will help the new traders to make a position in the forex market by collecting and making the right use of the same categories codes in future.

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  6. #11
    Banned motiurbd will become famous soon enough motiurbd's Avatar
    Join Date
    May 2011
    Location
    Bangladesh
    Posts
    179
    Thanks
    0
    Thanked 65 Times in 20 Posts
    Quote Originally Posted by peteonthenet View Post
    Here is the code fuction which will return the total number of lots which are currently running in open trades :

    Parameters: key is magic number, and type is the type of trades .


    Code:
    double gettotallot(int _key, int type)
    {
    double _lot=0;
     for(int k=OrdersTotal(); k>=0; k--)
                    {  
                      if (OrderSelect(k,SELECT_BY_POS,MODE_TRADES)&& OrderSymbol()==Symbol()&& OrderMagicNumber()==_key && OrderType()==type)
                      _lot+=OrderLots();
                      } 
                  return(_lot); 
     }
    Awesome dude... I am learning a lot from your post.. Please carry on... And can you please also show us how to build an EA that will close all our opened order at once? Thanks and keep going

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  7. #10
    Junior Member peteonthenet is on a distinguished road peteonthenet's Avatar
    Join Date
    Aug 2011
    Location
    India
    Posts
    51
    Thanks
    1
    Thanked 20 Times in 15 Posts
    SubscribeSubscribe
    subscribed 0

    Function to calculate total lots opened

    Here is the code fuction which will return the total number of lots which are currently running in open trades :

    Parameters: key is magic number, and type is the type of trades .


    Code:
    double gettotallot(int _key, int type)
    {
    double _lot=0;
     for(int k=OrdersTotal(); k>=0; k--)
                    {  
                      if (OrderSelect(k,SELECT_BY_POS,MODE_TRADES)&& OrderSymbol()==Symbol()&& OrderMagicNumber()==_key && OrderType()==type)
                      _lot+=OrderLots();
                      } 
                  return(_lot); 
     }

  8. The Following User Says Thank You to peteonthenet For This Useful Post:

    Alizahid (2020-10-20)

  9. #9
    Junior Member peteonthenet is on a distinguished road peteonthenet's Avatar
    Join Date
    Aug 2011
    Location
    India
    Posts
    51
    Thanks
    1
    Thanked 20 Times in 15 Posts
    SubscribeSubscribe
    subscribed 0
    Here is code function which can be used say when ea needs to trade only during certain hours of the day and skip of certain day of the week :

    Code:
      bool ValidTime() 
      {
       if (DayOfWeek()==1 && Hour()<=6) return(false);  
        return(true);
       }

  10. The Following 1 Users Say Thank You to peteonthenet For This Useful Post:

    Alizahid (2020-10-20)

  11. #8
    Junior Member peteonthenet is on a distinguished road peteonthenet's Avatar
    Join Date
    Aug 2011
    Location
    India
    Posts
    51
    Thanks
    1
    Thanked 20 Times in 15 Posts
    SubscribeSubscribe
    subscribed 0

    CloseAllTrade Script

    Here is a code which can be saved as a script file in the Scripts Folder.

    To execute the script, drage and drop the script on the current chart, this will close all open trades and also pending orders of all symbols.


    Code:
    int start()
    {
       double total;
       int cnt;
       while(OrdersTotal()>0)
       {
          // close opened orders first
          total = OrdersTotal();
          for (cnt = total ; cnt >=0 ; cnt--)
          {
             if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) 
             {
                switch(OrderType())
                {
                   case OP_BUY       :
                      RefreshRates();
                      OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,Violet);break;
                       
                   case OP_SELL      :
                      RefreshRates();
                      OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Violet); break;
                }             
             }
          }
          // and close pending
          total = OrdersTotal();      
          for (cnt = total ; cnt >=0 ; cnt--)
          {
             if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) 
             {
                switch(OrderType())
                {
                   case OP_BUYLIMIT  :OrderDelete(OrderTicket()); break;
                   case OP_SELLLIMIT :OrderDelete(OrderTicket()); break;
                   case OP_BUYSTOP   :OrderDelete(OrderTicket()); break;
                   case OP_SELLSTOP  :OrderDelete(OrderTicket()); break;
                }
             }
          }
       }
       return(0);
    }

  12. The Following User Says Thank You to peteonthenet For This Useful Post:

    Alizahid (2020-10-20)

  13. #7
    Junior Member peteonthenet is on a distinguished road peteonthenet's Avatar
    Join Date
    Aug 2011
    Location
    India
    Posts
    51
    Thanks
    1
    Thanked 20 Times in 15 Posts
    SubscribeSubscribe
    subscribed 0

    Code to take Screenshot of Chart and save it to local drive

    Here is the Code that you can put in any EA to take a screenshot of the Chart and save it to disk, you can call this on any event like if there is any new trade taken, you can save the screenshot.


    the system function to take screenshot is:
    Code:
    WindowScreenShot(filename,size_x,size_y)

    Here is the example usage:

    Code:
    string filename= "Chart"+Symbol();
    WindowScreenShot(filename,570,428)

    The above will save the chart with name "ChartEURUSD". You can make the filename very dynamic so every time screenshot is taken, it would save it with different name.

  14. The Following User Says Thank You to peteonthenet For This Useful Post:

    Alizahid (2020-10-20)

+ Reply to Thread
Page 10 of 11 FirstFirst ... 8 9 10 11 LastLast

Subscribe to this Thread (1)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Currently Active UsersCurrently Active Users

There are currently users online. members and guests

Forex Forum India | Forex Community Place Statistics Forex Forum India Statistics

Most users ever online was .

Welcome to our newest member,

Threads:

Posts:

Member: