Я отредактировал твой код.Основная проблема в вашем коде - это прибыль!В функциях GetBuy () и GetSell () вы написали:
Ask+(TakeProfit*Point)
Возвращает Ask!потому что ваш TakeProfit был установлен на ноль.Если вы не хотите устанавливать Takeprofit, вы должны написать:
int ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-(StopLoss*Point),0,"Buy",MagicNumber,0,Blue);
Это новый код:
#property copyright "Copyright 2018"
#property link "https://www.mql4.com"
#property version "1.00"
#property strict
input int Ema_Fast_Period = 62;
input int Ema_Slow_Period = 30;
input int MagicNumber = 1982;
input double Lots = 0.01;
input int StopLoss = 100;
input int TakeProfit = 1000;
double FastMACurrent ,SlowMACurrent ,FastMAPrevious ,SlowMAPrevious;
bool BuyCondition = False, SellCondition = False, CrossPriseWithFastMAUpShado = False, CrossPriseWithFastMADownShado = False;
//---
int Slippage=5;
double OpenPosition = 0;
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| expert OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(Volume[0]<=1)
{
FastMACurrent = iMA(Symbol() ,PERIOD_CURRENT ,Ema_Fast_Period ,0 ,MODE_EMA ,PRICE_CLOSE ,1 );
SlowMACurrent = iMA(Symbol() ,PERIOD_CURRENT ,Ema_Slow_Period ,0 ,MODE_EMA ,PRICE_CLOSE ,1 );
FastMAPrevious = iMA(Symbol() ,PERIOD_CURRENT ,Ema_Fast_Period ,0 ,MODE_EMA ,PRICE_CLOSE ,2 );
SlowMAPrevious = iMA(Symbol() ,PERIOD_CURRENT ,Ema_Slow_Period ,0 ,MODE_EMA ,PRICE_CLOSE ,2 );
//----------------------- BUY CONDITION
BuyCondition = (FastMAPrevious<SlowMAPrevious && FastMACurrent>SlowMACurrent);
//----------------------- SELL CONDITION
SellCondition = (FastMAPrevious>SlowMAPrevious && FastMACurrent<SlowMACurrent);
CrossPriseWithFastMADownShado = ( Low[1]<FastMACurrent && FastMACurrent<Open[1] );
if( BuyCondition )
{
//If we have open trade before get another trade close perivios trade and save money
if( OrderSelect(0, SELECT_BY_POS,MODE_TRADES) )
{
int a = OrderClose( OrderTicket(),OrderLots(),OrderType()==OP_SELL ? Ask : Bid, Slippage, clrWhite );
}
if(GetBuy()) BuyCondition = False;
}
if( SellCondition )
{
//If we have open trade before get another trade close perivios trade and save money
if( OrderSelect(0, SELECT_BY_POS,MODE_TRADES) )
{
int a = OrderClose( OrderTicket(),OrderLots(),OrderType()==OP_BUY ? Bid : Ask, Slippage, clrWhite );
}
if(GetSell()) SellCondition = False;
}
}
}
//+------------------------------------------------------------------+
//| expert Buy Or Sell function |
//+------------------------------------------------------------------+
bool GetBuy(){
int ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-(StopLoss*Point),Ask+ (TakeProfit*Point),"Buy",MagicNumber,0,Blue);
if(ticket > 0) return true;
return false;
}
bool GetSell(){
int ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+(StopLoss*Point),Bid- (TakeProfit*Point),"Sell",MagicNumber,0,Red);
if(ticket > 0) return true;
return false;
}