Sorry.. hier nochmal der gleiche Code, mit einer Klammersetzung die übersichtlicher ist.
Code:
#property strict
input int SLPoints = 500;
input int TPPoints = 500;
input int TSLPoints = 500;
input double Lots = 0.1;
input double MaximumRisk =0.02;
input ENUM_TIMEFRAMES Timeframe = PERIOD_H1;
input int PeriodsMAFast = 50;
input int PeriodsMASlow = 200;
input ENUM_MA_METHOD MethodMAFast = MODE_SMA;
input ENUM_MA_METHOD MethodMASlow = MODE_SMA;
input ENUM_TIMEFRAMES TimeframeCCI = PERIOD_H1;
input string Commentary = "jhjgh";
input int Magic = 111;
//globale Variable
datetime timestamp;
int OnInit()
{
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
trailingStop();
if(timestamp == iTime(Symbol(),Timeframe,0)) return;
timestamp = iTime(Symbol(),Timeframe,0);
double maFast = iMA(Symbol(),Timeframe,PeriodsMAFast,0,MethodMAFast,PRICE_CLOSE,0);
double maSlow = iMA(Symbol(),Timeframe,PeriodsMASlow,0,MethodMASlow,PRICE_CLOSE,0);
double maFastLast = iMA(Symbol(),Timeframe,PeriodsMAFast,0,MethodMAFast,PRICE_CLOSE,1);
double maSlowLast = iMA(Symbol(),Timeframe,PeriodsMASlow,0,MethodMASlow,PRICE_CLOSE,1);
double CCI = iCCI(NULL,TimeframeCCI,14,PRICE_CLOSE,1);
int total = OrdersTotal();
if (total <50)
if(maFast > maSlow && maFastLast < maSlowLast &&CCI >=100)
{
Print("Long");
int ticket = executeLong();
Print(IntegerToString(ticket));
}
else if(maFast < maSlow && maFastLast > maSlowLast && CCI <=-100)
{
Print("Short");
int ticket = executeShort();
Print(IntegerToString(ticket));
}
}
double LotsOptimized()
{
double lot=Lots;
//--- select lot size
lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);
if(lot<0.1) lot=0.1;
return(lot);
}
int executeLong ()
{
double entry = Ask;
entry = NormalizeDouble(entry,Digits);
double sl = entry - SLPoints * Point;
sl = NormalizeDouble(sl,Digits);
double tp = entry + TPPoints * Point;
tp = NormalizeDouble(tp,Digits);
int ticket = OrderSend(Symbol(),OP_BUY,LotsOptimized,entry,1000,sl,tp,Commentary,Magic);
return ticket;
}
int executeShort ()
{
double entry = Bid;
entry = NormalizeDouble(entry,Digits);
double sl = entry + SLPoints * Point;
sl = NormalizeDouble(sl,Digits);
double tp = entry - TPPoints * Point;
tp = NormalizeDouble(tp,Digits);
int ticket = OrderSend(Symbol(),OP_SELL,LotsOptimized,entry,1000,sl,tp,Commentary,Magic);
return ticket;
}
void trailingStop()
{
for(int i = 0; i < OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
if(OrderType() == OP_BUY){
double sl = Bid - TSLPoints * Point;
sl = NormalizeDouble(sl,Digits);
if(sl > OrderStopLoss()){
bool res = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration());
}
}
if(OrderType() == OP_SELL){
double sl = Ask + TSLPoints * Point;
sl = NormalizeDouble(sl,Digits);
if(sl < OrderStopLoss() || OrderStopLoss() == 0){
bool res = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration());
}
}
}
}
}