ِِِِِAli EA

 
Salam,

This is an EA I want to share!

Its name "Ali" is the name of one of my friends who suggest the idea!

The idea behind it is:

The EURUSD go the opposite way of the USDCHF,

Well!

We place 2 Buy or Sell orders, one for the EURUSD and one for USDCHF and when the price of one of them go up to 5 pips we place another order of this currency.

We take the profit by calculating all the opened positions (3 or 2) and close them all.

No big profit and no big loss!

Files:
ali.mq4  4 kb
 

salaam

Mohammed:
Salam,

This is an EA I want to share!

Its name "Ali" is the name of one of my friends who suggest the idea!

The idea behind it is:

The EURUSD go the opposite way of the USDCHF,

Well!

We place 2 Buy or Sell orders, one for the EURUSD and one for USDCHF and when the price of one of them go up to 5 pips we place another order of this currency.

We take the profit by calculating all the opened positions (3 or 2) and close them all.
No big profit and no big loss!

Salaam Mohammed,

Thank you for sharing an ea.

I want a little more explaination how if works, if you don't mind.

Peace.

SFX

 

I was working on something similar. So you close positions when you have P/L of +5?

 

Interesting, I'll let it run over night and see what happens.

 
Mohammed:
Salam,

This is an EA I want to share!

Its name "Ali" is the name of one of my friends who suggest the idea!

The idea behind it is:

The EURUSD go the opposite way of the USDCHF,

Well!

We place 2 Buy or Sell orders, one for the EURUSD and one for USDCHF and when the price of one of them go up to 5 pips we place another order of this currency.

We take the profit by calculating all the opened positions (3 or 2) and close them all.
No big profit and no big loss!

Thanks for EA my friend,

Who realy works... i have 2 buys on eur/usd and 1 buy usd/chf.

What is the settings.. is default? and the best time frame?

Thanks

Fast_cris

 

Time frame doesn't matter. You can use the default settings.

But, it doesn't seem to be closing trades? I looked at the code and I'm not sure why. I'll have another look.

I also think I might change it so that it opens a Lot of USD/CHF with the same dollar value as the lot of EUR/USD, because right now the hedge is a bit lop-sided. Or was that intentional?

 

I've tried this strategy before, well the difference in movement is depicted in the EUR/CHF pair, since you would be indiretly buying or seling it when you enter into the 2 positions.....

 

Update!

Salam,

The previous version was not able to close the opened position.

Please try this verison!

The idea:

The EURUSD go in the opposite direction of USDCHF.

When we buy EURUSD and USDCFH it's very like that we buy EURUSD and sell EURUSD. but the only advantage is that some brokers limit you to hedge your positions by buy and selling the same currency.

The both of opened positions now going in contrary directions and they maintain the loss (it's almost the spread of opening 2 passions).

When one of the two currency make profit (5 pips) we open another position of this currency.

We take profit at 5Pips and close all the poisons or we close them when we make 10 Pips loss.

//---- Includes

#include

//---- Trades limits

extern double ProfitToTake = 5;

extern double LossToPrevent = -15;

extern int Sell = 1; // use 0 for Buy

extern double Lots = 0.1;

extern int Slippage = 5;

extern int Level=5;

//--- Global variables

int MagicNumber = 101090;

string ExpertComment = "Ali";

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

int init()

{

return(0);

}

int deinit()

{

return(0);

}

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

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

int start()

{

int cnt,total;

if(Bars<100) {Print("bars less than 100"); return(0);}

total = OrdersTotal();

if(total < 1)

{

if(Sell==0)

{

RefreshRates();

OrderSend("EURUSD",OP_BUY,Lots,MarketInfo("EURUSD",MODE_ASK),Slippage,0,MarketInfo("EURUSD",MODE_ASK)+100*Point,ExpertComment,MagicNumber,0,Green);

RefreshRates();

OrderSend("USDCHF",OP_BUY,Lots,MarketInfo("USDCHF",MODE_ASK),Slippage,0,MarketInfo("USDCHF",MODE_ASK)+100*Point,ExpertComment,MagicNumber,0,Green);

}

else

{

RefreshRates();

OrderSend("EURUSD",OP_SELL,Lots,MarketInfo("EURUSD",MODE_BID),Slippage,0,MarketInfo("EURUSD",MODE_BID)-100*Point,ExpertComment,MagicNumber,0,Red);

RefreshRates();

OrderSend("USDCHF",OP_SELL,Lots,MarketInfo("USDCHF",MODE_BID),Slippage,0,MarketInfo("USDCHF",MODE_BID)-100*Point,ExpertComment,MagicNumber,0,Red);

}

return(0);

}

ProfitProtect();

return(0);

}

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

void ProfitProtect()

{

int total = OrdersTotal();

double MyCurrentProfit=0;

for (int cnt = 0 ; cnt < total ; cnt++)

{

OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

if (OrderMagicNumber() == MagicNumber)

{

MyCurrentProfit += OrderProfit();

RefreshRates();

if (OrderProfit()>=(Level) && total < 3)

{

if(OrderType() ==OP_BUY )

{

OrderSend(OrderSymbol(),OP_BUY,Lots,MarketInfo(OrderSymbol(),MODE_ASK),Slippage,0,MarketInfo(OrderSymbol(),MODE_ASK)+100*Point,ExpertComment,MagicNumber,0,Green);

}

if(OrderType() ==OP_SELL )

{

OrderSend(OrderSymbol(),OP_SELL,Lots,MarketInfo(OrderSymbol(),MODE_BID),Slippage,0,MarketInfo(OrderSymbol(),MODE_BID)-100*Point,ExpertComment,MagicNumber,0,Red);

}

}

}

}

if(MyCurrentProfit >= ProfitToTake)

CloseAll();

if(MyCurrentProfit <= LossToPrevent)

CloseAll();

}

void CloseAll()

{

int total = OrdersTotal();

for (int cnt = 0 ; cnt <= total ; cnt++)

{

OrderSelect(0,SELECT_BY_POS,MODE_TRADES);

if (OrderMagicNumber() == MagicNumber)

{

RefreshRates();

if(OrderType()==OP_BUY)

OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Violet);

if(OrderType()==OP_SELL)

OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Violet);

}

}

}

 
Mohammed:
Salam,

The previous version was not able to close the opened position.

Please try this verison!

The idea:

The EURUSD go in the opposite direction of USDCHF.

When we buy EURUSD and USDCFH it's very like that we buy EURUSD and sell EURUSD. but the only advantage is that some brokers limit you to hedge your positions by buy and selling the same currency.

The both of opened positions now going in contrary directions and they maintain the loss (it's almost the spread of opening 2 passions).

When one of the two currency make profit (5 pips) we open another position of this currency.

We take profit at 5Pips and close all the poisons or we close them when we make 10 Pips loss.

//---- Includes

#include

//---- Trades limits

extern double ProfitToTake = 5;

extern double LossToPrevent = -15;

extern int Sell = 1; // use 0 for Buy

extern double Lots = 0.1;

extern int Slippage = 5;

extern int Level=5;

//--- Global variables

int MagicNumber = 101090;

string ExpertComment = "Ali";

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

int init()

{

return(0);

}

int deinit()

{

return(0);

}

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

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

int start()

{

int cnt,total;

if(Bars<100) {Print("bars less than 100"); return(0);}

total = OrdersTotal();

if(total < 1)

{

if(Sell==0)

{

RefreshRates();

OrderSend("EURUSD",OP_BUY,Lots,MarketInfo("EURUSD",MODE_ASK),Slippage,0,MarketInfo("EURUSD",MODE_ASK)+100*Point,ExpertComment,MagicNumber,0,Green);

RefreshRates();

OrderSend("USDCHF",OP_BUY,Lots,MarketInfo("USDCHF",MODE_ASK),Slippage,0,MarketInfo("USDCHF",MODE_ASK)+100*Point,ExpertComment,MagicNumber,0,Green);

}

else

{

RefreshRates();

OrderSend("EURUSD",OP_SELL,Lots,MarketInfo("EURUSD",MODE_BID),Slippage,0,MarketInfo("EURUSD",MODE_BID)-100*Point,ExpertComment,MagicNumber,0,Red);

RefreshRates();

OrderSend("USDCHF",OP_SELL,Lots,MarketInfo("USDCHF",MODE_BID),Slippage,0,MarketInfo("USDCHF",MODE_BID)-100*Point,ExpertComment,MagicNumber,0,Red);

}

return(0);

}

ProfitProtect();

return(0);

}

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

void ProfitProtect()

{

int total = OrdersTotal();

double MyCurrentProfit=0;

for (int cnt = 0 ; cnt < total ; cnt++)

{

OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

if (OrderMagicNumber() == MagicNumber)

{

MyCurrentProfit += OrderProfit();

RefreshRates();

if (OrderProfit()>=(Level) && total < 3)

{

if(OrderType() ==OP_BUY )

{

OrderSend(OrderSymbol(),OP_BUY,Lots,MarketInfo(OrderSymbol(),MODE_ASK),Slippage,0,MarketInfo(OrderSymbol(),MODE_ASK)+100*Point,ExpertComment,MagicNumber,0,Green);

}

if(OrderType() ==OP_SELL )

{

OrderSend(OrderSymbol(),OP_SELL,Lots,MarketInfo(OrderSymbol(),MODE_BID),Slippage,0,MarketInfo(OrderSymbol(),MODE_BID)-100*Point,ExpertComment,MagicNumber,0,Red);

}

}

}

}

if(MyCurrentProfit >= ProfitToTake)

CloseAll();

if(MyCurrentProfit <= LossToPrevent)

CloseAll();

}

void CloseAll()

{

int total = OrdersTotal();

for (int cnt = 0 ; cnt <= total ; cnt++)

{

OrderSelect(0,SELECT_BY_POS,MODE_TRADES);

if (OrderMagicNumber() == MagicNumber)

{

RefreshRates();

if(OrderType()==OP_BUY)

OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Violet);

if(OrderType()==OP_SELL)

OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Violet);

}

}

}

Hi my friend,

I have made some backtest to the new version... i used original settings and in atachment is the results.

What is the best settings for this?

Fast_cris

Files:
ali.gif  6 kb
ali.htm  670 kb
 
Fast_cris:
Hi my friend,

I have made some backtest to the new version... i used original settings and in atachment is the results.

What is the best settings for this?

Fast_cris

Salam my friend Fast_cris,

These kind of EAs can't be backtested!

That's because:

Trading is permitted for the symbol under test only, no portfolio testing

Attempts to trade using another symbol will return error

Please refer to:

http://www.metaquotes.net/experts/articles/tester_limits

 

Thanks My friend,

I understand now....

But can you please explain a litle better these settings.

extern double ProfitToTake = 5;

extern double LossToPrevent = -15;

extern int Slippage = 5;

extern int Level=5;

Thanks

Fast_cris