Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.
From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.
Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
Elite Section
Get access to private discussions, specialized support, indicators and trading systems reported every week.
Advanced Elite Section
For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
Hello, there, I have an EA, which profits are based on TrailingStopLoss. It has constant StopLoss, but doesn't have constant TakeProfit.
I'll ask any coder here to edit this EA to have TakeProfit, that can be defined by the user, and to remove the TrailingStopLoss.
Here is it:
//--- Indicators settings
extern int MA_Period=120;
extern int MA_Shift=60;
extern int Price=10;
extern int Mode=8;
//--- Global variables
int CurrentBar = 1;
int MagicNumber = 122334;
string ExpertComment = "EA";
int NumberOfTries = 1;
//+------------------------------------------------------------------
int init()
{
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------
bool isNewSymbol(string current_symbol)
{
//loop through all the opened order and compare the symbols
int total = OrdersTotal();
for(int cnt = 0 ; cnt < total ; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
string selected_symbol = OrderSymbol();
if (current_symbol == selected_symbol && OrderMagicNumber()==MagicNumber)
return (False);
}
return (True);
}
//+------------------------------------------------------------------+
int start()
{
int cnt, ticket, total;
double mSL; //Broker stop loss minimum value
double OsUSD_P = 0 , OsUSD_C = 0 ;
if(Bars < 100) {Print("bars less than 100"); return(0);}
int base = true;
if (Symbol() == "EURUSD" || Symbol() == "GBPUSD" || Symbol() == "AUDUSD") base = 1;
if (Symbol() == "USDJPY" || Symbol() == "USDCHF") base = 2;
if (base == 1)
{
if (OsUSD_C > 0 && OsUSD_P < 0 )
SellCondition = true;
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) //<-- Long position is opened
{
if(CloseBuyCondition) //<-- Close the order and exit!
{
CloseOrder(OrderType());
}
TrailOrder(OrderType());
}
if(OrderType()==OP_SELL) //<-- Go to short position
{
if(CloseSellCondition) //<-- Close the order and exit!
{
CloseOrder(OP_SELL);
}
TrailOrder(OrderType());
}
}
}
return(0);
}
//+------------------------------------------------------------------+
if U will set TrailingStop to 0 , traling stop will not be used.
As for order takeproft change this part:
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage ,Ask-StopLoss*Point,0 ,ExpertComment,MagicNumber,0,Green)
__________________
You need proffesional mql coder? Contact me! I will help you!
........................................ http://www.fxservice.eu/
........................................
You type "Triling" , I understand it as "TrailingStop" and put it, but now the EA doesn't even open an order. Help.
Try this:
Code:
#include <stdlib.mqh>
//---- Trades limits
extern double TakeProfit = 150;
extern double TrailingStop = 50;
extern double StopLoss = 50;
extern double Lots = 0.1;
extern int Slippage = 100;
//--- Indicators settings
extern int MA_Period=120;
extern int MA_Shift=60;
extern int Price=10;
extern int Mode=8;
//--- Global variables
int CurrentBar = 1;
int MagicNumber = 122334;
string ExpertComment = "EA";
int NumberOfTries = 1;
//+------------------------------------------------------------------
int init()
{
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------
bool isNewSymbol(string current_symbol)
{
//loop through all the opened order and compare the symbols
int total = OrdersTotal();
for(int cnt = 0 ; cnt < total ; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
string selected_symbol = OrderSymbol();
if (current_symbol == selected_symbol && OrderMagicNumber()==MagicNumber)
return (False);
}
return (True);
}
//+------------------------------------------------------------------+
int start()
{
int cnt, ticket, total;
double mSL; //Broker stop loss minimum value
double OsUSD_P = 0 , OsUSD_C = 0 ;
if(Bars < 100) {Print("bars less than 100"); return(0);}
OsUSD_C = USDINDEX(CurrentBar,MA_Period,MA_Shift,Price,Mode) ;
OsUSD_P = USDINDEX(CurrentBar+1,MA_Period,MA_Shift,Price,Mod e);
//--- Trading conditions
bool BuyCondition = false , SellCondition = false , CloseBuyCondition = false , CloseSellCondition = false ;
int base = true;
if (Symbol() == "EURUSD" || Symbol() == "GBPUSD" || Symbol() == "AUDUSD") base = 1;
if (Symbol() == "USDJPY" || Symbol() == "USDCHF") base = 2;
if (base == 1)
{
if (OsUSD_C > 0 && OsUSD_P < 0 )
SellCondition = true;
if (OsUSD_C < 0 && OsUSD_P > 0 )
BuyCondition = true;
}
if (base == 2)
{
if (OsUSD_C > 0 && OsUSD_P < 0)
BuyCondition = true;
if (OsUSD_C < 0 && OsUSD_P > 0)
SellCondition = true;
}
total = OrdersTotal();
if(total < 1 || isNewSymbol(Symbol()))
{
if(BuyCondition) //<-- BUY condition
{
ticket = OpenOrder(OP_BUY); //<-- Open BUY order
}
if(SellCondition) //<-- SELL condition
{
ticket = OpenOrder(OP_SELL); //<-- Open SELL order
}
}
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) //<-- Long position is opened
{
if(CloseBuyCondition) //<-- Close the order and exit!
{
CloseOrder(OrderType());
}
TrailOrder(OrderType());
}
if(OrderType()==OP_SELL) //<-- Go to short position
{
if(CloseSellCondition) //<-- Close the order and exit!
{
CloseOrder(OP_SELL);
}
TrailOrder(OrderType());
}
}
}
return(0);
}
//+------------------------------------------------------------------+
void TrailOrder(int type)
{
if(TrailingStop>0)
{
if(OrderMagicNumber() == MagicNumber)
{
if(type==OP_BUY)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
}
}
}
if(type==OP_SELL)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
}
}
}
}
}
}
int OpenOrder(int type)
{
int ticket=0;
int err=0;
int c = 0;
if(type==OP_BUY)
{
for(c = 0 ; c < NumberOfTries ; c++)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage ,Ask-StopLoss*Point,Ask+TakeProfit*Point ,ExpertComment,MagicNumber,0,Green);
err=GetLastError();
if(err==0)
{
break;
}
else
{
if(err==4 || err==137 ||err==146 || err==136) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
Print("Error opening BUY order : ", ErrorDescription(err));
break;
}
}
}
}
if(type==OP_SELL)
{
for(c = 0 ; c < NumberOfTries ; c++)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippag e,Bid+StopLoss*Point,Bid-TakeProfit*Point,ExpertComment,MagicNumber,0 ,Red);
err=GetLastError();
if(err==0)
{
break;
}
else
{
if(err==4 || err==137 ||err==146 || err==136) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
Print("Error opening SELL order : ", ErrorDescription(err));
break;
}
}
}
}
return(ticket);
}
bool CloseOrder(int type)
{
Print("Asked to close!");
if(OrderMagicNumber() == MagicNumber)
{
if(type==OP_BUY)
return (OrderClose(OrderTicket(),OrderLots(),Bid,Slippage ,Violet));
if(type==OP_SELL)
return (OrderClose(OrderTicket(),OrderLots(),Ask,Slippage ,Violet));
}
}
double USDINDEX(int bar,int MA_Period,int MA_Shift,int Price,int Mode)
{
double USD_Index=
(iMA("EURUSD",0,MA_Period,0,Mode,Price,bar+MA_Shif t)-
iMA("EURUSD",0,MA_Period,0,Mode,Price,bar))*10000
+
(iMA("GBPUSD",0,MA_Period,0,Mode,Price,bar+MA_Shif t)-
iMA("GBPUSD",0,MA_Period,0,Mode,Price,bar))*10000
+
(iMA("USDCHF",0,MA_Period,0,Mode,Price,bar+MA_Shif t)-
iMA("USDCHF",0,MA_Period,0,Mode,Price,bar))*10000
+
(iMA("USDJPY",0,MA_Period,0,Mode,Price,bar+MA_Shif t)-
iMA("USDJPY",0,MA_Period,0,Mode,Price,bar))*100
;
return (USD_Index);
}
__________________
You need proffesional mql coder? Contact me! I will help you!
........................................ http://www.fxservice.eu/
........................................
__________________
You need proffesional mql coder? Contact me! I will help you!
........................................ http://www.fxservice.eu/
........................................
__________________
You need proffesional mql coder? Contact me! I will help you!
........................................ http://www.fxservice.eu/
........................................