#property version "1.00"
#property strict
extern bool Use_TP_In_Money=false;
extern double TP_In_Money=10;
extern bool Use_TP_In_percent=false;
extern double TP_In_Percent=10;
input string txt32 = "------------[Money Trailing Stop]---------------"; //———————————————————————————————————————————
input bool Enable_Trailing = true; //Enable_Trailing
input double Take_Profit_Money = 40.0; //Take Profit In Money (in current currency)
input double Stop_Loss_Money = 10; //Stop Loss In Money(in current currency)
extern bool Exit=false;//Enable Exit strategy
extern double IncreaseFactor=0.001; //IncreaseFactor
extern int CandlesToRetrace=10; //Num.Of Candles For Divergence
extern double Lots=0.01; //Lots size
extern double Stop_Loss=20; //Stop Loss
extern double LotExponent = 1.44; //Lots size Exponent
extern int MagicNumber=1234; //MagicNumber
input double Take_Profit=50; //TakeProfit
extern int FastMA=6; //FastMA
extern int SlowMA=85; //SlowMA
extern double Mom_Sell=0.3; //Momentum_Sell
extern double Mom_Buy=0.3; //Momentum_Buy
input bool UseEquityStop = true; //Use Equity Stop
input double TotalEquityRisk = 1.0; //Total Equity Risk
input int Max_Trades=10;
extern double TrailingStop=40; //TrailingStop
input bool USEMOVETOBREAKEVEN=true;//Enable "no loss"
input double WHENTOMOVETOBE=30; //When to move break even
input double PIPSTOMOVESL=30; //How much pips to move sl
int err;
int total=0;
double
Lot,Dmax,Dmin,// Amount of lots in a selected order
Lts, // Amount of lots in an opened order
Min_Lot, // Minimal amount of lots
Step, // Step of lot size change
Free, // Current free margin
One_Lot, // Price of one lot
Price, // Price of a selected order,
pips,
MA_1,MA_2,MACD_SIGNAL;
int Type,freeze_level,Spread;
double priceopen,stoploss,takeprofit;
int orderticket;
int
Period_MA_2, Period_MA_3, // Calculation periods of MA for other timefr.
Period_MA_02, Period_MA_03, // Calculation periods of supp. MAs
K2,K3,T,L;
int INDEX2=0;
double PROFIT_SUM1=0;
double PROFIT_SUM2=0;
double AccountEquityHighAmt,PrevEquity;
int OnInit()
{
// код доступен только после оплаты
}
void OnDeinit(const int reason)
{
}
void OnTick(void)
{
// код доступен только после оплаты
}
void Trail1()
{
total=OrdersTotal();
for(int cnt=0; cnt<total; cnt++)
{
if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderMagicNumber()!=MagicNumber)
continue;
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>pips*TrailingStop)
{
if(OrderStopLoss()<Bid-pips*TrailingStop)
{
RefreshRates();
stoploss=Bid-(pips*TrailingStop);
takeprofit=OrderTakeProfit();
double StopLevel=MarketInfo(Symbol(),MODE_STOPLEVEL)+MarketInfo(Symbol(),MODE_SPREAD);
if(stoploss<StopLevel*pips)
stoploss=StopLevel*pips;
string symbol=OrderSymbol();
double point=SymbolInfoDouble(symbol,SYMBOL_POINT);
if(MathAbs(OrderStopLoss()-stoploss)>point)
if((pips*TrailingStop)>(int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_FREEZE_LEVEL)*pips)
if(CheckStopLoss_Takeprofit(OP_BUY,stoploss,takeprofit))
if(OrderModifyCheck(OrderTicket(),OrderOpenPrice(),stoploss,takeprofit))
if(!OrderModify(OrderTicket(),OrderOpenPrice(),stoploss,takeprofit,0,Green))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
else // go to short position
{
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(pips*TrailingStop))
{
if((OrderStopLoss()>(Ask+pips*TrailingStop)) || (OrderStopLoss()==0))
{
RefreshRates();
stoploss=Ask+(pips*TrailingStop);
takeprofit=OrderTakeProfit();
double StopLevel=MarketInfo(Symbol(),MODE_STOPLEVEL)+MarketInfo(Symbol(),MODE_SPREAD);
if(stoploss<StopLevel*pips)
stoploss=StopLevel*pips;
if(takeprofit<StopLevel*pips)
takeprofit=StopLevel*pips;
string symbol=OrderSymbol();
double point=SymbolInfoDouble(symbol,SYMBOL_POINT);
if(MathAbs(OrderStopLoss()-stoploss)>point)
if((pips*TrailingStop)>(int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_FREEZE_LEVEL)*pips)
if(CheckStopLoss_Takeprofit(OP_SELL,stoploss,takeprofit))
if(OrderModifyCheck(OrderTicket(),OrderOpenPrice(),stoploss,takeprofit))
if(!OrderModify(OrderTicket(),OrderOpenPrice(),stoploss,takeprofit,0,Red))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
}
}
}
void MOVETOBREAKEVEN()
{
for(int b=OrdersTotal()-1; b>=0; b--)
{
if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
if(OrderMagicNumber()!=MagicNumber)
continue;
if(OrderSymbol()==Symbol())
if(OrderType()==OP_BUY)
if(Bid-OrderOpenPrice()>WHENTOMOVETOBE*pips)
if(OrderOpenPrice()>OrderStopLoss())
if(CheckStopLoss_Takeprofit(OP_SELL,OrderOpenPrice()+(PIPSTOMOVESL*pips),OrderTakeProfit()))
if(OrderModifyCheck(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+(PIPSTOMOVESL*pips),OrderTakeProfit()))
if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+(PIPSTOMOVESL*pips),OrderTakeProfit(),0,CLR_NONE))
Print("eror");
}
for(int s=OrdersTotal()-1; s>=0; s--)
{
if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES))
if(OrderMagicNumber()!=MagicNumber)
continue;
if(OrderSymbol()==Symbol())
if(OrderType()==OP_SELL)
if(OrderOpenPrice()-Ask>WHENTOMOVETOBE*pips)
if(OrderOpenPrice()<OrderStopLoss())
if(CheckStopLoss_Takeprofit(OP_SELL,OrderOpenPrice()-(PIPSTOMOVESL*pips),OrderTakeProfit()))
if(OrderModifyCheck(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-(PIPSTOMOVESL*pips),OrderTakeProfit()))
if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-(PIPSTOMOVESL*pips),OrderTakeProfit(),0,CLR_NONE))
Print("eror");
}
}
double NDTP(double val)
{
RefreshRates();
double SPREAD=MarketInfo(Symbol(),MODE_SPREAD);
double StopLevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
if(val<StopLevel*pips+SPREAD*pips)
val=StopLevel*pips+SPREAD*pips;
return(NormalizeDouble(val, Digits));
}
double ND(double val)
{
return(NormalizeDouble(val, Digits));
}
bool OrderModifyCheck(int ticket,double price,double sl,double tp)
{
if(OrderSelect(ticket,SELECT_BY_TICKET))
{
string symbol=OrderSymbol();
double point=SymbolInfoDouble(symbol,SYMBOL_POINT);
bool PriceOpenChanged=true;
int type=OrderType();
if(!(type==OP_BUY || type==OP_SELL))
{
PriceOpenChanged=(MathAbs(OrderOpenPrice()-price)>point);
}
bool StopLossChanged=(MathAbs(OrderStopLoss()-sl)>point);
bool TakeProfitChanged=(MathAbs(OrderTakeProfit()-tp)>point);
if(PriceOpenChanged || StopLossChanged || TakeProfitChanged)
return(true); // order can be modified
else
PrintFormat("Order #%d already has levels of Open=%.5f SL=%.5f TP=%.5f",
ticket,OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit());
}
return(false); // no point in modifying
}
bool CheckStopLoss_Takeprofit(ENUM_ORDER_TYPE type,double SL,double TP)
{
int stops_level=(int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
if(stops_level!=0)
{
PrintFormat("SYMBOL_TRADE_STOPS_LEVEL=%d: StopLoss and TakeProfit must"+Показано первые 50% кода (символов: 20816)
Введите ваш email и нажмите кнопку, чтобы перейти к оплате.