А то что я сверху сегодня написала это не подходит?
Тут просто слов нет


А то что я сверху сегодня написала это не подходит?
//+------------------------------------------------------------------+
//| BuySell.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern int StopLoss = 500; // лось
extern int TakeProfit = 500; // язь
extern int StopLoss2 = 1500; // лось
extern int TakeProfit2 = 1500; // язь
extern int BuySell = 0; // 1-buy 2-sell 0-off
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
extern int Magic2 = 321; // магик доп ордера
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,double stop,double take,int mag)
{
int r=0;
color clr=Green;
double sl=0,tp=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(StopLoss>0) sl=NormalizeDouble(price+stop*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price-take*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(StopLoss>0) sl=NormalizeDouble(price-stop*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price+take*Point,Digits);
}
r=OrderSend(NULL,type,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",mag,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades()
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && (OrderMagicNumber()==Magic || OrderMagicNumber()==Magic2))
{
if(OrderType()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Результат последней сделки |
//+------------------------------------------------------------------+
int LastRes()
{
int result=0;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()>0)
{
result=1;//tp
}
if(OrderProfit()<0)
{
result=2;//sl
}
}
}
return(result);
}
//+------------------------------------------------------------------+
//| Результат последней сделки |
//+------------------------------------------------------------------+
int LastType()
{
int type=0;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
type=OrderType();
}
}
return(type);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountTrades()<1)
{
if(LastRes()==2 && LastType()==0) PutOrder(1,Bid,StopLoss2,TakeProfit2,Magic2);
if(LastRes()==2 && LastType()==1) PutOrder(0,Ask,StopLoss2,TakeProfit2,Magic2);
}
if(CountTrades()<1)
{
if(BuySell==1) PutOrder(0,Ask,StopLoss,TakeProfit,Magic);
if(BuySell==2) PutOrder(1,Bid,StopLoss,TakeProfit,Magic);
}
}
//+------------------------------------------------------------------+
нарисовала и описала вам прямо на скрине как нужно. не думаю, что это сложно написать советника. в направляющей бай брать брать только ордера на бай и закрывать на сигнале в сел от этой направляющей и аналогично на сел, если в направляющей сел, закрываем ордер при сигнале на бай от любых МА. ПОЭТОМУ я вам и написала, что тут важно вписать сразу 3 пары МА, потому что тут работают все
не понял твой совет
if(Point*(n1-n2)>0)...
сделал (подсмотрел у кого то такой финт) — добавляем малое число, оно ни на что не влияет, зато 0 не будет
//+------------------------------------------------------------------+
//| 3MA.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property description "Simple expert advisor"
//--- Inputs
extern int MA1Period = 50;
extern int MA1Shift = 0;
extern int MA1Method = 0;
extern int MA1ApPrice = 0;
extern int MA2Period = 100;
extern int MA2Shift = 0;
extern int MA2Method = 0;
extern int MA2ApPrice = 0;
extern int MA3Period = 200;
extern int MA3Shift = 0;
extern int MA3Method = 0;
extern int MA3ApPrice = 0;
extern int StopLoss = 500;
extern int TakeProfit = 500;
extern int TrailingStop = 0;
extern double Lots = 0.1;
extern double Risk = 10;
extern int Slip = 30;
extern int Magic = 123;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades()
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
double sl=0,tp=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(StopLoss>0) sl=NormalizeDouble(price+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(StopLoss>0) sl=NormalizeDouble(price-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
}
r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| Calculate optimal lot size |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
if(Lots==0)
{
if(StopLoss>0 && Risk>0) lot=NormalizeDouble(AccountEquity()/Risk/100/StopLoss,2); // 10000/1/100/1000=1
}
if(lot<MarketInfo(NULL,MODE_MINLOT)) lot=MarketInfo(NULL,MODE_MINLOT);
if(lot>MarketInfo(NULL,MODE_MAXLOT)) lot=MarketInfo(NULL,MODE_MAXLOT);
return(lot);
}
//+------------------------------------------------------------------+
//| Закрытие позиции по типу ордера |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
{
bool cl;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0 && (ot==0 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenPos()
{
double MA1=iMA(NULL,0,MA1Period,MA1Shift,MA1Method,MA2ApPrice,1);
double MA2=iMA(NULL,0,MA2Period,MA1Shift,MA1Method,MA2ApPrice,1);
double MA3=iMA(NULL,0,MA3Period,MA1Shift,MA1Method,MA2ApPrice,1);
double MA12=iMA(NULL,0,MA1Period,MA1Shift,MA1Method,MA2ApPrice,2);
double MA22=iMA(NULL,0,MA2Period,MA1Shift,MA1Method,MA2ApPrice,2);
double MA32=iMA(NULL,0,MA3Period,MA1Shift,MA1Method,MA2ApPrice,2);
bool buy=MA1>MA2 && MA12<MA22;
bool sell=MA1<MA2 && MA12>MA22;
//--- sell
if(sell)
{
PutOrder(1,Bid);
}
//--- buy
if(buy)
{
PutOrder(0,Ask);
}
//---
}
//+------------------------------------------------------------------+
void ClosePos()
{
double MA1=iMA(NULL,0,MA1Period,MA1Shift,MA1Method,MA2ApPrice,1);
double MA2=iMA(NULL,0,MA2Period,MA1Shift,MA1Method,MA2ApPrice,1);
double MA3=iMA(NULL,0,MA3Period,MA1Shift,MA1Method,MA2ApPrice,1);
double MA12=iMA(NULL,0,MA1Period,MA1Shift,MA1Method,MA2ApPrice,2);
double MA22=iMA(NULL,0,MA2Period,MA1Shift,MA1Method,MA2ApPrice,2);
double MA32=iMA(NULL,0,MA3Period,MA1Shift,MA1Method,MA2ApPrice,2);
bool buy=MA1>MA2 && MA12<MA22;
bool sell=MA1<MA2 && MA12>MA22;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderMagicNumber()==Magic || OrderSymbol()==Symbol())
{
//--- check order type
if(OrderType()==OP_BUY)
if(sell) CloseAll(0);
if(OrderType()==OP_SELL)
if(buy)CloseAll(1);
}
}
}
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Trailing()
{
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol() || OrderMagicNumber()==Magic)
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
double BID=MarketInfo(Symbol(),MODE_BID);
if(BID-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<BID-Point*TrailingStop)
{
bool m=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(BID-Point*TrailingStop,Digits),OrderTakeProfit(),0,Yellow);
}
}
}
}
if(OrderType()==OP_SELL)
{
if(TrailingStop>0)
{
double ASK=MarketInfo(Symbol(),MODE_ASK);
if((OrderOpenPrice()-ASK)>(Point*TrailingStop))
{
if((OrderStopLoss()>(ASK+Point*TrailingStop)) || (OrderStopLoss()==0))
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(ASK+Point*TrailingStop,Digits),OrderTakeProfit(),0,Yellow);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountTrades()<1) OpenPos();
if(CountTrades()>0) ClosePos();
if(TrailingStop>0) Trailing();
}
//+------------------------------------------------------------------+
сегодня во вкладке эксперты заметил —
2016.07.03 07:07:48.232 Trend Speed EURUSD,H4: zero divide in 'TrendSpeed.mq4' (74,46)
Point*(n1-n2))
ноль вернуло, сделайте проверку, если вас это смущает.
void DisplayAlert(string message, int shift)
{
if(shift <= 2 && Time[shift] != lastAlertTime)
{
lastAlertTime = Time[shift];
Alert(message, Symbol(), " , ", Period(), " minutes chart");
SendMail("MACD Divergence Indicator signal: ", message + Symbol()+" , " + Period() + " minutes chart");
}
}
AM2