Hello,
i need a TrailingStop and a Break even in this Template.
both can be simple. and please dont touch the other code (buy and sell strategy) to much
that i could work easly with it in future
Thanks for Help
++++++++++++++++++++++++++++++++++++++++++
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Sebastian Meissner"
extern string Expert_Name = "Trading Basti";
extern double iLots=0.1;
extern double iMaximumRisk= 0.02;
extern int iStopLoss=650;
extern int iTakeProfit=50;
extern int iSlippage=3;
extern int iMaxTrades=1;
extern int iMagicNumber=336699;
double stochg,stochr;
int iTotalTrades;
int iOrderOpenStatus;
int iErrorNumber;
string strErrorMessage;
double LotsOptimized()
{
double lot=iLots;
//---- select lot size
lot=NormalizeDouble(AccountFreeMargin()*iMaximumRisk/1000.0,1);
//---- return lot size
if(lot<0.1) lot=0.1;
if(lot>50.0) lot=50.0;
return(lot);
}
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| The functions from this point to the start function are where |
//| changes are made to test other systems or strategies. |
//|+-----------------------------------------------------------------+
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
stochg = iCustom (NULL,0,"Stochastic",8,3,3,MODE_SMA,0,MODE_MAIN,0);
stochr = iCustom (NULL,0,"Stochastic",8,3,3,MODE_SMA,0,MODE_SIGNAL,0);
double willd = 81;
double willu = 19;
double will1 = 80;
double will2 = 20;
//Buy-Logik
//Sell-Logik
// Buy-Order ausführen
iTotalTrades=OrdersTotal();
if (( stochg > will2) && (stochg > stochr) && (stochr < will2) && (stochr > willu) && (iTotalTrades < iMaxTrades))
{
double dBuyStopLoss=Ask-(iStopLoss*Point);
double dBuyTakeProfit=Ask+(iTakeProfit*Point);
iOrderOpenStatus=OrderSend (Symbol(), OP_BUY,LotsOptimized(), Ask, iSlippage, dBuyStopLoss, dBuyTakeProfit, "Trading Basti",iMagicNumber,0,Green);
if (iOrderOpenStatus<0)
{
iErrorNumber=GetLastError();
Print ("Order fehlgeschlagen!: ", iErrorNumber);
return;
}
}
// Sell-Order ausführen
iTotalTrades=OrdersTotal();
if (( stochg < will1) && (stochg < stochr) && (stochr > will1) && (stochr < willd) && (iTotalTrades < iMaxTrades))
{
double dSellStopLoss=Bid+(iStopLoss*Point);
double dSellTakeProfit=Bid-(iTakeProfit*Point);
iOrderOpenStatus=OrderSend (Symbol(), OP_SELL,LotsOptimized(), Bid, iSlippage, dSellStopLoss, dSellTakeProfit, "Trading Basti",iMagicNumber,0,Red);
if (iOrderOpenStatus<0)
{
iErrorNumber=GetLastError();
Print ("Order fehlgeschlagen!: ", iErrorNumber);
return;
}
}
return(0);
}
//----
i need a TrailingStop and a Break even in this Template.
both can be simple. and please dont touch the other code (buy and sell strategy) to much
that i could work easly with it in future
Thanks for Help
++++++++++++++++++++++++++++++++++++++++++
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Sebastian Meissner"
extern string Expert_Name = "Trading Basti";
extern double iLots=0.1;
extern double iMaximumRisk= 0.02;
extern int iStopLoss=650;
extern int iTakeProfit=50;
extern int iSlippage=3;
extern int iMaxTrades=1;
extern int iMagicNumber=336699;
double stochg,stochr;
int iTotalTrades;
int iOrderOpenStatus;
int iErrorNumber;
string strErrorMessage;
double LotsOptimized()
{
double lot=iLots;
//---- select lot size
lot=NormalizeDouble(AccountFreeMargin()*iMaximumRisk/1000.0,1);
//---- return lot size
if(lot<0.1) lot=0.1;
if(lot>50.0) lot=50.0;
return(lot);
}
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| The functions from this point to the start function are where |
//| changes are made to test other systems or strategies. |
//|+-----------------------------------------------------------------+
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
stochg = iCustom (NULL,0,"Stochastic",8,3,3,MODE_SMA,0,MODE_MAIN,0);
stochr = iCustom (NULL,0,"Stochastic",8,3,3,MODE_SMA,0,MODE_SIGNAL,0);
double willd = 81;
double willu = 19;
double will1 = 80;
double will2 = 20;
//Buy-Logik
//Sell-Logik
// Buy-Order ausführen
iTotalTrades=OrdersTotal();
if (( stochg > will2) && (stochg > stochr) && (stochr < will2) && (stochr > willu) && (iTotalTrades < iMaxTrades))
{
double dBuyStopLoss=Ask-(iStopLoss*Point);
double dBuyTakeProfit=Ask+(iTakeProfit*Point);
iOrderOpenStatus=OrderSend (Symbol(), OP_BUY,LotsOptimized(), Ask, iSlippage, dBuyStopLoss, dBuyTakeProfit, "Trading Basti",iMagicNumber,0,Green);
if (iOrderOpenStatus<0)
{
iErrorNumber=GetLastError();
Print ("Order fehlgeschlagen!: ", iErrorNumber);
return;
}
}
// Sell-Order ausführen
iTotalTrades=OrdersTotal();
if (( stochg < will1) && (stochg < stochr) && (stochr > will1) && (stochr < willd) && (iTotalTrades < iMaxTrades))
{
double dSellStopLoss=Bid+(iStopLoss*Point);
double dSellTakeProfit=Bid-(iTakeProfit*Point);
iOrderOpenStatus=OrderSend (Symbol(), OP_SELL,LotsOptimized(), Bid, iSlippage, dSellStopLoss, dSellTakeProfit, "Trading Basti",iMagicNumber,0,Red);
if (iOrderOpenStatus<0)
{
iErrorNumber=GetLastError();
Print ("Order fehlgeschlagen!: ", iErrorNumber);
return;
}
}
return(0);
}
//----