• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 12:08am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 12:08am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

want script to open order by magic number change 4 replies

MT4: Can comments or magic number be modified if order open? 4 replies

Need coding help with magic number 4 replies

Need coding help with magic number 0 replies

can we manually assign a magic number 4 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
Tags: Need Script/EA can only generate Magic number
Cancel

Need Script/EA can only generate Magic number

  • Post #1
  • Quote
  • First Post: Oct 16, 2007 4:53pm Oct 16, 2007 4:53pm
  •  Syed Fayyaz
  • | Joined Sep 2007 | Status: Member | 1 Post
Hello

Does anybody knows Script/EA that can be used to generate Magic number
when Placing order Manualy. Any help in this will be appreciated.

Thanks
Syed4x.
  • Post #2
  • Quote
  • Oct 16, 2007 5:21pm Oct 16, 2007 5:21pm
  •  jhernandez
  • | Joined Mar 2006 | Status: Member | 27 Posts
You can make a quick script like the one below and use it to execute orders. It's quick and painless and will attach a Magic Number and Comment to your order.

PHP Code
 //+------------------------------------------------------------------+
//|                                                    buyscript.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property show_inputs

int MAGIC = 123456789;
extern string Name_Expert = "My Expert Name";
extern double Lots = 1.0;
extern double StopLoss = 30;
extern double TakeProfit = 100;

int start()
  {
   Print(
"Opening order");
   
int ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,GetStopLossBuy(),GetTakeProfitBuy(),Name_Expert,MAGIC,0,Blue);
   if(
ticket<0) {
         Print(
"OrderSend failed with error #",GetLastError());
   }
   return(
0);
}

double GetTakeProfitBuy() {     return(Ask+TakeProfit*Point); } 
//double GetTakeProfitSell() {     return(Bid-TakeProfit*Point); } 

double GetStopLossBuy() {     return (Bid-StopLoss*Point);} 
//double GetStopLossSell() {     return(Ask+StopLoss*Point); } 
Pippin' ain't easy.
 
 
  • Post #3
  • Quote
  • Jul 10, 2008 10:40am Jul 10, 2008 10:40am
  •  fab4x
  • | Joined Jun 2006 | Status: Member | 112 Posts
Quoting jhernandez
Disliked
You can make a quick script like the one below and use it to execute orders. It's quick and painless and will attach a Magic Number and Comment to your order.

PHP Code
 //+------------------------------------------------------------------+
//|                                                    buyscript.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property show_inputs
 
int MAGIC = 123456789;
extern string Name_Expert = "My Expert Name";
extern double Lots = 1.0;
extern double StopLoss = 30;
extern double TakeProfit = 100;
 
int start()
  {
   Print(
"Opening order");
   
int ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,GetStopLossBuy(),GetTakeProfitBuy(),Name_Expert,MAGIC,0,Blue);
   if(
ticket<0) {
         Print(
"OrderSend failed with error #",GetLastError());
   }
   return(
0);
}
 
double GetTakeProfitBuy() {     return(Ask+TakeProfit*Point); } 
//double GetTakeProfitSell() {     return(Bid-TakeProfit*Point); } 
 
double GetStopLossBuy() {     return (Bid-StopLoss*Point);} 
//double GetStopLossSell() {     return(Ask+StopLoss*Point); } 
Ignored

Is there a way to have the script generate a random magic number each time script is attached?

Thanks
 
 
  • Post #4
  • Quote
  • Jul 10, 2008 10:57am Jul 10, 2008 10:57am
  •  Zen_Leow
  • Joined Jun 2008 | Status: Programming for a better future. | 649 Posts
Quoting fab4x
Disliked
Is there a way to have the script generate a random magic number each time script is attached?

Thanks
Ignored
I'm curious... why would you want a random magic number? doesn't that kinda defeat the purpose of having a magic number? not looking for a fight just curious about how you wanna apply this.
Programming for a better future.
 
 
  • Post #5
  • Quote
  • Jul 10, 2008 11:00am Jul 10, 2008 11:00am
  •  Zen_Leow
  • Joined Jun 2008 | Status: Programming for a better future. | 649 Posts
Anyway here's a link to the documentation on how to generate random numbers

http://docs.mql4.com/math/MathRand

and... I'm still curious. =p
Programming for a better future.
 
 
  • Post #6
  • Quote
  • Last Post: May 27, 2011 8:05am May 27, 2011 8:05am
  •  samarrone
  • | Joined Jan 2010 | Status: Member | 71 Posts
When placing a market order, or instant execution order, is there a way to set a magic number to that order in the comment section of the ticket ?
 
 
  • Platform Tech
  • /
  • Need Script/EA can only generate Magic number
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023