#property copyright "Aiman."
#property show_inputs
#include <stdlib.mqh>
extern double Lots = 0.01;
extern string currency = "JPY";
extern bool buy = true;
extern bool sell = true;
extern int Pips = 150;
extern int StopLoss = 0;
extern int TakeProfit = 0;
int Slippage = 5;
string Currencies[]={"EUR","GBP","JPY","USD","AUD","NZD","CHF","CAD"};
string myPairs[];
int init ()
{
int i,j;
string pair;
for (i=0; i<ArraySize(Currencies); i++)
for (j=0; j<ArraySize(Currencies); j++)
{
pair = Currencies[i]+Currencies[j]+StringSubstr(Symbol(),6,1);
if (MarketInfo(pair,MODE_TRADEALLOWED)==1 && StringFind(pair,currency,0)!=-1)
{
ArrayResize(myPairs,ArraySize(myPairs)+1);
myPairs[ArraySize(myPairs)-1]=pair;
}
}
}
int deinit ()
{
Comment ("");
return (0);
}
int start()
{
for (int i=0; i<ArraySize(myPairs); i++)
{
if (buy)
{
if (StringSubstr(myPairs[i],0,3)==currency) PO_order(myPairs[i],OP_BUYSTOP);
else PO_order(myPairs[i],OP_SELLSTOP);
}
if (sell)
{
if (StringSubstr(myPairs[i],0,3)==currency) PO_order(myPairs[i],OP_SELLSTOP);
else PO_order(myPairs[i],OP_BUYSTOP);
}
}
return(0);
}
void PO_order (string pair, int PO_type)
{
double bid = MarketInfo(pair,MODE_BID);
double ask = MarketInfo(pair,MODE_ASK);
double point = MarketInfo(pair,MODE_POINT);
int err;
double PO,SL,TP;
string comment;
if (PO_type==OP_BUYSTOP)
{
comment ="Placing BuyStop for "+pair+"= ";
PO =ask+Pips*point;
if (StopLoss>0) SL=ask-(StopLoss*point)+Pips*point; else SL=0;
if (TakeProfit>0) TP=bid+(TakeProfit*point)+Pips*point; else TP=0;
}
if (PO_type==OP_SELLSTOP)
{
comment ="Placing SellStop for "+pair+"= ";
PO =bid-Pips*point;
if (StopLoss>0) SL=bid+(StopLoss*point)-Pips*point; else SL=0;
if (TakeProfit>0) TP=ask-(TakeProfit*point)-Pips*point; else TP=0;
}
bool loop=true;
int cnt=0;
while(loop)
{
OrderSend(pair,PO_type,Lots,PO,Slippage,SL,TP,"",0,0,CLR_NONE);
err=GetLastError();
Print (comment, ErrorDescription(err));
cnt++;
if (cnt>20 || err==0) loop = false;
Sleep(50);
}
if (err>0) Print (comment+ErrorDescription(err));
}