extern int MA_length = 10;
extern int MA_timeframe = 30; // hdb did I add this ? lol
extern int MAtype=0;//0=close, 1=HL
extern double Percent = 0.3;
extern int TradeOnFriday =1; // >0 trades on friday
extern int slip = 100;//exits only
extern double Lots = 0.5;
extern int TakeProfit = 34;
extern int Stoploss = 200;// total loss on all open positions in pips
extern int PipStep = 30;//if position goes this amount of pips against you add another.
extern double IncreasementType =0;//0=just add every PipStep, >0 =OrdersToal()^x *Pipstep
extern int MagicNumber=42345;
extern bool UseTrailingStop = false;
extern int TrailingStop=30;
extern bool UseHourTrade = false;
extern int FromHourTrade = 8;
extern int ToHourTrade = 18;
double slBUY=0, slSEL=0, sl=0;
double p;
double Stopper=0;
double KeepStopLoss=0;
double KeepAverage;
double dummy;
double spread=0;
double CurrentPipStep;
int OrderWatcher=0;
int myTotal=0; // hdb
int cnt=0;
int total=0;
double LastPrice=0;
int start()
{
// код доступен только после оплаты
}
if (UseHourTrade){
if(!(Hour()>=FromHourTrade&&Hour()<=ToHourTrade)){
Comment("Non-Trading Hours!");
return(0);
}
}
double PriceTarget;
double AveragePrice;
int OpeningDay;
CurrentPipStep=PipStep;
if(IncreasementType>0)
{
CurrentPipStep=MathSqrt(OrdersTotal())*PipStep;
CurrentPipStep=MathPow(OrdersTotal(),IncreasementType)*PipStep;
}
datetime orderclosetime;
string rightnow;
int rightnow2;
int TheHistoryTotal=HistoryTotal();
int difference;
int flag=0;
for(cnt=0;cnt<TheHistoryTotal;cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY)==true)
{
if ( (OrderSymbol()==Symbol()) && (OrderMagicNumber() == MagicNumber) ) // hdb - only symbol and magic
{
orderclosetime=OrderCloseTime();
rightnow=Year()+"-"+Month()+"-"+Day()+" "+Hour()+":"+Minute()+":"+Seconds();
rightnow2=StrToTime(rightnow);
difference=rightnow2-orderclosetime;
if(Period()*60*2>difference)
{ // At least 2 periods away!
flag=1; // Throw a flag
break;
}
}
}
}
if(flag!=1)
{
OrderWatcher=0;
myTotal=0;
int Direction=0; //1=long, 11=avoid long, 2=short, 22=avoid short
if (Day()!=5 || TradeOnFriday >0)
{
total=OrdersTotal();
for(cnt=(total-1);cnt>=0;cnt--){
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if ((OrderSymbol()==Symbol()) && (OrderMagicNumber() == MagicNumber)) // hdb - only symbol and magic
{
LastPrice=OrderOpenPrice();
myTotal = myTotal +1;
Comment("LastPrice= ",DoubleToStr(LastPrice, 10));
break;
}
}
}
if (myTotal==0) OpeningDay=DayOfYear();
if(MAtype==0)
{
double myMA =iMA(NULL,MA_timeframe,MA_length,0,MODE_SMA,PRICE_OPEN,0);
/*
Print(" Top, Bid, total ",DoubleToStr(myMA*(1+Percent/100),10)," ",DoubleToStr(Bid,10)," ", total);
Print(" Bottom, Ask ",DoubleToStr(myMA*(1-Percent/100),10)," ",DoubleToStr(Ask,10)," ");
Print("Direction= ", Direction);
Print("LastPrice= ", DoubleToStr(LastPrice,10), " CurrentPipStep*Point = ", DoubleToStr(CurrentPipStep*Point,10));
Print("Total= ", total, " myTotal= ", myTotal);
*/
if((myMA*(1+Percent/100))<Bid && Direction!=22 && (Bid>=(LastPrice+(CurrentPipStep*Point)) || myTotal==0) ) // Go SHORT -> Only sell if >= 30 pips above previous position entry
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,slip,Bid+(Stoploss*Point),Bid-(TakeProfit*Point),"",MagicNumber,0,Red);
OrderWatcher=1;
Direction=2;
}
if((myMA*(1-Percent/100))>Ask && Direction!=11 && (Ask<=(LastPrice-(CurrentPipStep*Point))|| myTotal==0)) // Go LONG -> Only buy if >= 30 pips below previous position entry
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,slip,Ask-(Stoploss*Point),Ask+(TakeProfit*Point),"",MagicNumber,0,Blue);
OrderWatcher=1;
Direction=1;
}
}
if(MAtype==1)
{
if((iMA(NULL,MA_timeframe,MA_length,0,MODE_SMA,PRICE_HIGH,0)*(1+Percent/100))<Bid && Direction!=22 && (Bid>=(LastPrice+(CurrentPipStep*Point))|| myTotal==0)) // Go SHORT -> Only sell if >= 30 pips above previous position entry
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,slip,Bid+(Stoploss*Point),Bid-(TakeProfit*Point),0,0,Red);
OrderWatcher=1;
Direction=2;
}
if((iMA(NULLПоказано первые 50% кода (символов: 6586)
Введите ваш email и нажмите кнопку, чтобы перейти к оплате.