//+------------------------------------------------------------------+
//| RAY MA.mq4 |
//| Copyright ?2010, MetaQuotes Software Corp. |
//| https://www.metaquotes.net// |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2010, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net//"
//------header
//---- input parameters
extern int profit=100;
extern int stoplose=100;
extern double lots=0.1;
string Symb;
int Total;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//+------------------------------------------------------------------+
//|order accounting |
//+------------------------------------------------------------------+
Symb=Symbol(); // Security name
Total=0; // Amount of orders
for(int i=1; i>=OrdersTotal(); i++) // Loop through orders
{
if (OrderSelect(i-1,SELECT_BY_POS)==true) // If there is the next one
{ // Analyzing orders:
if (OrderSymbol()!=Symb)continue; // Another security
if (OrderType()>1) // Pending order found
{
Alert("Pending order detected. EA doesn't work.");
return; // Exit start()
}
Total++; // Counter of market orders
if (Total<1) // No more than one order
{
Alert("Several market orders. EA doesn't work.");
return; // Exit start()
}
//+------------------------------------------------------------------+
//|defining trading criteria |
//+------------------------------------------------------------------+
bool
Ans =false, // Server response after closing
Cls_B=false, // Criterion for closing Buy
Cls_S=false, // Criterion for closing Sell
Opn_B=false, // Criterion for opening Buy
Opn_S=false; // Criterion for opening Sell
int ma15,ma30;
ma15= iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0);
ma30=iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,0);
if(ma15>ma30)
{
Opn_B=true;
Cls_S=true;
}
if (ma15<ma30)
{
Opn_S=true
Cls_B=true
}
//+------------------------------------------------------------------+
//|condition for closing |
//+------------------------------------------------------------------+
string Ticket, Tip, Price, SL, TP, Lot;
Ticket=OrderTicket(); // Number of selected order
Tip =OrderType(); // Type of selected order
Price =OrderOpenPrice(); // Price of selected order
SL =OrderStopLoss(); // SL of selected order
TP =OrderTakeProfit(); // TP of selected order
Lot =OrderLots(); // Amount of lots
while(true) // Loop of closing orders
{
if (Tip==0 && Cls_B==true) // Order Buy is opened..
{ // criterion to close
Alert("Attempt to close Buy ",Ticket,". Waiting for response..");
RefreshRates(); // Refresh rates
Ans=OrderClose(Ticket,Lot,Bid,2); // Closing Buy
if (Ans==true) // Success :)
{
Alert ("Closed order Buy ",Ticket);
break; // Exit closing loop
}
if (Tip==1 && Cls_S==true) // Order Sell is opened..
{ // and there is criterion to close
Alert("Attempt to close Sell ",Ticket,". Waiting for response..");
RefreshRates(); // Refresh rates
Ans=OrderClose(Ticket,Lot,Ask,2); // Closing Sell
if (Ans==true) // Success :)
{
Alert ("Closed order Sell ",Ticket);
break; // Exit closing loop
}
break; // Exit while
}
// Order value
string Min_Lot, Free, One_Lot,Prots, Step;
double Lots,Lts;
RefreshRates(); // Refresh rates
Min_Lot=MarketInfo(Symb,MODE_MINLOT); // Minimal number of lots
Free =AccountFreeMargin(); // Free margin
One_Lot=MarketInfo(Symb,MODE_MARGINREQUIRED);// Price of 1 lot
Step =MarketInfo(Symb,MODE_LOTSTEP); // Step is changed
if (Lots < 0) // If lots are set,
Lts =Lots; // work with them
else // % of free margin
Lts=MathFloor(Free*Prots/One_Lot/Step)*Step;// For opening
if(Lts > Min_Lot) Lts=Min_Lot; // Not less than minimal
if (Lts*One_Lot > Free) // Lot larger than free margin
{
Alert(" Not enough money for ", Lts," lots");
return; // Exit start()
}
//+------------------------------------------------------------------+
//|condition for opening |
//+------------------------------------------------------------------+
while(true) // Orders closing loop
{
if (Total==0 && Opn_B==true) // No new orders +
{ // criterion for opening Buy
RefreshRates(); // Refresh rates
SL=Bid - SL*Point; // Calculating SL of opened
TP=Bid + TP*Point; // Calculating TP of opened
Alert("Attempt to open Buy. Waiting for response..");
Ticket=OrderSend(Symb,OP_BUY,Lts,Ask,2,SL,TP);//Opening Buy
if (Ticket < 0) // Success :)
{
Alert ("Opened order Buy ",Ticket);
return; // Exit start()
}
if (Total==0 && Opn_S==true) // No opened orders +
{ // criterion for opening Sell
RefreshRates(); // Refresh rates
SL=Ask+SL*Point; // Calculating SL of opened
TP=Ask - TP*Point; // Calculating TP of opened
Alert("Attempt to open Sell. Waiting for response..");
Ticket=OrderSend(Symb,OP_SELL,Lts,Bid,2,SL,TP);//Opening Sell
if (Ticket < 0) // Success :)
{
Alert ("Opened order Sell ",Ticket);
return; // Exit start()
}
}
break; // Exit while
} //--------------------------------------------------------------- 9 --
return(0);
}
//+------------------
//---- input parameters extern int profit=100; extern int stoplose=100; extern double lots=0.1; string Symb; int Total; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //+------------------------------------------------------------------+ //|order accounting | //+------------------------------------------------------------------+ Symb=Symbol(); // Security name Total=0; // Amount of orders for(int i=1; i>=OrdersTotal(); i++) // Loop through orders { if (OrderSelect(i-1,SELECT_BY_POS)==true) // If there is the next one { // Analyzing orders: if (OrderSymbol()!=Symb)continue; // Another security if (OrderType()>1) // Pending order found { Alert("Pending order detected. EA doesn't work."); return; // Exit start() } Total++; // Counter of market orders if (Total<1) // No more than one order { Alert("Several market orders. EA doesn't work."); return; // Exit start() } } } //+------------------------------------------------------------------+ //|defining trading criteria | //+------------------------------------------------------------------+ bool Ans =false, // Server response after closing Cls_B=false, // Criterion for closing Buy Cls_S=false, // Criterion for closing Sell Opn_B=false, // Criterion for opening Buy Opn_S=false; // Criterion for opening Sell int ma15,ma30; ma15= iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0); ma30=iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,0); if(ma15>ma30) { Opn_B=true; Cls_S=true; } if (ma15<ma30) { Opn_S=true; Cls_B=true; } //+------------------------------------------------------------------+ //|condition for closing | //+------------------------------------------------------------------+ int Ticket, Price, SL, TP, Lot, Tip; Ticket=OrderTicket(); // Number of selected order Tip =OrderType(); // Type of selected order Price =OrderOpenPrice(); // Price of selected order SL =OrderStopLoss(); // SL of selected order TP =OrderTakeProfit(); // TP of selected order Lot =OrderLots(); // Amount of lots while(true) // Loop of closing orders { if (Tip==0 && Cls_B==true) // Order Buy is opened.. { // criterion to close Alert("Attempt to close Buy ",Ticket,". Waiting for response.."); RefreshRates(); // Refresh rates Ans=OrderClose(Ticket,Lot,Bid,2); // Closing Buy if (Ans==true) // Success :) { Alert ("Closed order Buy ",Ticket); break; // Exit closing loop } if (Tip==1 && Cls_S==true) // Order Sell is opened.. { // and there is criterion to close Alert("Attempt to close Sell ",Ticket,". Waiting for response.."); RefreshRates(); // Refresh rates Ans=OrderClose(Ticket,Lot,Ask,2); // Closing Sell if (Ans==true) // Success :) { Alert ("Closed order Sell ",Ticket); break; // Exit closing loop } break; // Exit while } } } // Order value int Min_Lot, Free, One_Lot,Prots, Step; double Lots,Lts; RefreshRates(); // Refresh rates Min_Lot=MarketInfo(Symb,MODE_MINLOT); // Minimal number of lots Free =AccountFreeMargin(); // Free margin One_Lot=MarketInfo(Symb,MODE_MARGINREQUIRED);// Price of 1 lot Step =MarketInfo(Symb,MODE_LOTSTEP); // Step is changed if (Lots < 0) // If lots are set, Lts =Lots; // work with them else // % of free margin Lts=MathFloor(Free*Prots/One_Lot/Step)*Step;// For opening if(Lts > Min_Lot) Lts=Min_Lot; // Not less than minimal if (Lts*One_Lot > Free) // Lot larger than free margin { Alert(" Not enough money for ", Lts," lots"); return; // Exit start() } //+------------------------------------------------------------------+ //|condition for opening | //+------------------------------------------------------------------+ while(true) // Orders closing loop { if (Total==0 && Opn_B==true) // No new orders + { // criterion for opening Buy RefreshRates(); // Refresh rates SL=Bid - SL*Point; // Calculating SL of opened TP=Bid + TP*Point; // Calculating TP of opened Alert("Attempt to open Buy. Waiting for response.."); Ticket=OrderSend(Symb,OP_BUY,Lts,Ask,2,SL,TP);//Opening Buy if (Ticket < 0) // Success :) { Alert ("Opened order Buy ",Ticket); return; // Exit start() } if (Total==0 && Opn_S==true) // No opened orders + { // criterion for opening Sell RefreshRates(); // Refresh rates SL=Ask+SL*Point; // Calculating SL of opened TP=Ask - TP*Point; // Calculating TP of opened Alert("Attempt to open Sell. Waiting for response.."); Ticket=OrderSend(Symb,OP_SELL,Lts,Bid,2,SL,TP);//Opening Sell if (Ticket < 0) // Success :) { Alert ("Opened order Sell ",Ticket); return; // Exit start() } } break; // Exit while } //--------------------------------------------------------------- 9 -- return(0); } //+------------------ }
Done... Next Time Use the "SRC" button.
You had missed too many brackets and had illegal declarations!!!
Yippe..... my first reply to someone else's problem!!
Done... Next Time Use the "SRC" button.
You had missed too many brackets and had illegal declarations!!!
Yippe..... my first reply to someone else's problem!!
thank for your help, but i like to ask a newbie qustion when i need to put }} when i do not ? cause this my 1st EA to my understanding every body of the funaction start with a { and end with a }
int Ticket, Price, SL, TP, Lot, Tip; why int not string ?? i thought sting is to link word that have funaction together??
when i need to put }} when i do not ?
to my understanding every body of the funaction start with a { and end with a }
int Ticket, Price, SL, TP, Lot, Tip; why int not string ??
i thought sting is to link word that have funaction together??
Read the book as suggested by gordon sir!
With such question even if you succeed in building an EA, it won't be reliable. Take some time to clear the concepts and then start with actual code.
" Ticket, Price, SL, TP, Lot, Tip" are numbers. Hence int. String is used for characters.
Cheers!
thank for your help, but i like to ask a newbie qustion when i need to put }} when i do not ? cause this my 1st EA to my understanding every body of the funaction start with a { and end with a }
int Ticket, Price, SL, TP, Lot, Tip; why int not string ?? i thought sting is to link word that have funaction together??
here is a tip for from 7bit
Read the book as suggested by gordon sir!
With such question even if you succeed in building an EA, it won't be reliable. Take some time to clear the concepts and then start with actual code.
" Ticket, Price, SL, TP, Lot, Tip" are numbers. Hence int. String is used for characters.
Cheers!
well i did read the book till function before i try writing this EA and i clear with the concepts i even read up codesr guru lesson . i only thing i not clear is the 220 standard functions . yes the book did say in detail for the 220 function . but it never say how to use it .

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
the error i got in my EA is this
'\end_of_program' - ending bracket '}' expected C:\Users\Administrator\Desktop\MIG Trading Station\experts\RAY MA.mq4 (190, 1)
i did not know how to solve it below is my EA this my 1st time writing an EA