ээ уважаемый , дай полный код - вставлю как положено.
//+------------------------------------------------------------------+
//
//+------------------------------------------------------------------+
#property link "http://www.forexfactory.com/"
#property version "1.00"
#property description "Programmer Voldemar227"
#property strict
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
enum Trade
{
Only_BUY, // Only BUY
Only_SELL, // Only SELL
Only_All // BUY and SELL
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
enum ma
{
BUY_MA = 0,
SELL_MA = 1,
OFF = 2
};
extern int OpenHour = 0;
extern int EndHour = 6;
input Trade TypeOrders = Only_SELL;
input double Lot = 0.01; // Lot
input double Risk = 1.01; // Risk percent if Lot=0;
input int MinStep = 400; // Step order
input int MinStepPlus = 0; // Add minimal step
input double MinProfit = 10.00; // Minimal Profit Close
input int Magic = 227;
input int Slippage = 30;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if (TimeHour(TimeCurrent()) < OpenHour || TimeHour(TimeCurrent()) > EndHour) return;
int b=0,s=0;
double
BuyProfit = 0,
SellProfit = 0,
BuyMin = 0,
SellMax = 0,
BuyMinLot = 0,
SellMaxLot = 0,
BuyLot = 0,
SellLot = 0,
BuyMax = 0,
SellMin = 0,
SellTicProfit = 0,
BuyTicProfit = 0;
int
BuyMaxTic = 0,
SellMinTic = 0;
for(int i=OrdersTotal()-1; i>=0; i--)
if(OrderSelect(i,SELECT_BY_POS))
if(OrderSymbol()==Symbol())
if(OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
b++;
if(OrderOpenPrice()<BuyMin || BuyMin==0)
{
BuyMin=OrderOpenPrice();
BuyMinLot=OrderLots();
}
if(OrderOpenPrice()>BuyMax || BuyMin==0)
{
BuyMax=OrderOpenPrice();
BuyMaxTic=OrderTicket();
BuyTicProfit=OrderProfit();
}
if(OrderProfit()>0)BuyProfit+=OrderProfit()+OrderCommission()+OrderSwap();
}
if(OrderType()==OP_SELL)
{
s++;
if(OrderOpenPrice()>SellMax || SellMax==0)
{
SellMax=OrderOpenPrice();
SellMaxLot=OrderLots();
}
if(OrderOpenPrice()<SellMin || SellMin==0)
{
SellMin=OrderOpenPrice();
SellMinTic=OrderTicket();
SellTicProfit=OrderProfit();
}
if(OrderProfit()>0)SellProfit+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
// Summ profit final
double ProfitBuy=BuyTicProfit+BuyProfit;
double ProfitSel=SellTicProfit+SellProfit;
double lot=NormalizeDouble(AccountBalance()*Risk/100/MarketInfo(Symbol(),MODE_MARGINREQUIRED),2);
if(b==0)
BuyLot=(Lot>0)?Lot:lot;
else
BuyLot=BuyMinLot+Lot;
if(s==0)
SellLot=(Lot>0)?Lot:lot;
else
SellLot=SellMaxLot+Lot;
double BuyDist = NormalizeDouble(MinStep*Point()+MinStepPlus*Point()*b,Digits());
double SellDist = NormalizeDouble(MinStep*Point()+MinStepPlus*Point()*s,Digits());
if(TypeOrders==Only_BUY ||TypeOrders==Only_All)
if((b==0) || (b>0 && (BuyMin-Ask)>=BuyDist))
if(OrderSend(Symbol(),OP_BUY,NormalizeDouble(BuyLot,2),NormalizeDouble(Ask,Digits()),Slippage,0,0,"My order",Magic,0,clrGreen)<0)
Print(" Error open Buy N ",GetLastError());
if(TypeOrders==Only_SELL ||TypeOrders==Only_All)
if((s==0) || (s>0 && (Bid-SellMax)>=SellDist))
if(OrderSend(Symbol(),OP_SELL,NormalizeDouble(SellLot,2),NormalizeDouble(Bid,Digits()),Slippage,0,0,"My order",Magic,0,clrGreen)<0)
Print(" Error open Sell N ",GetLastError());
if(ProfitBuy>=MinProfit && b>=2)
CloseAll(OP_BUY,BuyMaxTic);
if(ProfitSel>=MinProfit && s>=2)
CloseAll(OP_SELL,SellMinTic);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
void CloseAll(int aType,int ticket)
{
for(int i=OrdersTotal()-1; i>=0; i--)
if(OrderSelect(i,SELECT_BY_POS))
if(OrderSymbol()==Symbol())
if(OrderMagicNumber()==Magic)
{
if(OrderType()==aType && OrderType()==OP_BUY)
if(OrderProfit()>0 || OrderTicket()==ticket)
if(!OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits()),Slippage,clrRed))
Print(" OrderClose OP_BUY Error N",GetLastError());
if(OrderType()==aType && OrderType()==OP_SELL)
if(OrderProfit()>0 || OrderTicket()==ticket)
if(!OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits()),Slippage,clrRed))
Print(" OrderClose OP_SELL Error N",GetLastError());
}
}
//+------------------------------------------------------------------+
между этими часами открывает сделки, за ними нема.
Да, но он же будет открывать сделки в течения дня. Мне нужно чтобы с определенного времени сов начал работать и больше уже не останавливался, до конца теста
Спасибо, в справочник я заглянул )// не работает в выходные дни.
if(DayOfWeek()==0 || DayOfWeek()==6) return(0);
Порядковый номер дня недели (воскресенье-0,1,2,3,4,5,6).
А в чём тогда сложности?Спасибо, в справочник я заглянул )
Мне нужно, чтобы код как раз выполнялся в определенные дни недели.А в чём тогда сложности?
Можно вот так
if(DayOfWeek()!=0 && DayOfWeek()!=6)
{
//Внутри этих скобок код не будет выполняться в субботу и воскресенье.
}
if(DayOfWeek()==1 || DayOfWeek()==3)Мне нужно, чтобы код как раз выполнялся в определенные дни недели.
//+------------------------------------------------------------------+
//| ULTRON-3.1.mq4 |
//| Copyright 2018, Pawel.Gawron |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, Pawel.Gawron"
#property version "3.1"
#property strict
static input string Input_Section_1 = ">>>>>>>>>> Magic Number <<<<<<<<<<"; // ------ Input Section 1 ------
input int MAGICMA = 20131111;
static input string Input_Section_2 = ">>>>>>>>>> Magic Number <<<<<<<<<<"; // ------ Input Section 2 ------
input double lots =0.01;
static input string Input_Section_3 = ">>>>>>>>>> Trading Hours <<<<<<<<<<"; // ------ Input Section 3 ------
input int hour1 = 6;
input int hour2 = 21;
static input string Input_Section_4 = ">>>>>>>>>> MA Periods <<<<<<<<<<"; // ------ Input Section 4 ------
input int PeriodMA1 = 9;
input int PeriodMA2 = 9;
input int PeriodMA3 = 50;
input int PeriodMA4 = 1;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CheckForSell(double dStopLoss, double dTakeProfit)
{
if(Volume[0]>25) return;
int res=OrderSend(Symbol(),OP_SELL,lots,Bid,20 /*slippage*/,dStopLoss,dTakeProfit,"",MAGICMA,0,Red);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CheckForBuy(double dStopLoss, double dTakeProfit)
{
if(Volume[0]>25) return;
int res=OrderSend(Symbol(),OP_BUY,lots,Ask,20 /*slippage*/,dStopLoss,dTakeProfit,"",MAGICMA,0,Blue);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
double ma1 = iMA(NULL,PERIOD_CURRENT,PeriodMA1,0,MODE_LWMA,PRICE_OPEN, 0);
double ma2 = iMA(NULL,PERIOD_CURRENT,PeriodMA2,0,MODE_LWMA,PRICE_CLOSE,0);
double ma3 = iMA(NULL,PERIOD_CURRENT,PeriodMA3,0,MODE_SMA, PRICE_CLOSE,0);
double ma4 = iMA(NULL,PERIOD_CURRENT,PeriodMA4,0,MODE_SMA, PRICE_CLOSE,0);
double ma1ma2 = ma1-ma2;
double ma2ma1 = ma2-ma1;
double ma3ma4 = ma3-ma4;
double ma4ma3 = ma4-ma3;
int CountSymbolPositions=0;
for(int trade=OrdersTotal()-1;trade>=0;trade--)
{
if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderSymbol()==Symbol())
{
if((OrderType()==OP_SELL||OrderType()==OP_BUY) && OrderMagicNumber()==MAGICMA)
CountSymbolPositions++;
}
}
if ((ma3ma4<0.0048) &&
(ma3>ma1) &&
(ma3>ma2) &&
(Close[1]<Close[2]) &&
(Close[2]<Open[2]) &&
(CountSymbolPositions<1) &&
(Hour()>hour1) &&
(Hour()<hour2) &&
(ma1ma2<0.0013) &&
(ma1ma2>0.0004) )
{
double dTakeProfit = Bid - (680*Point);
double dStopLoss = Ask + (550*Point);
CheckForSell(dStopLoss, dTakeProfit);
}
if ((ma4ma3<0.0048) &&
(ma3<ma1) &&
(ma3<ma2) &&
(Close[1]>Close[2]) &&
(Close[2]>Open[2]) &&
(CountSymbolPositions<1) &&
(Hour()>hour1) &&
(Hour()<hour2) &&
(ma2ma1<0.0013) &&
(ma2ma1>0.0004) )
{
double dTakeProfit = Ask + (680*Point);
double dStopLoss = Bid - (550*Point);
CheckForBuy(dStopLoss, dTakeProfit);
}
return;
}
Всем привет. Помогите исправить код:
Сова работает, если hour1 < hour2.
Если, например, выставляем hour1 = 23, hour2 = 6, то сова не работает - не понимает переход на следующий день (через 00:00)
Как это исправить?
Код://+------------------------------------------------------------------+ //| ULTRON-3.1.mq4 | //| Copyright 2018, Pawel.Gawron | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, Pawel.Gawron" #property version "3.1" #property strict static input string Input_Section_1 = ">>>>>>>>>> Magic Number <<<<<<<<<<"; // ------ Input Section 1 ------ input int MAGICMA = 20131111; static input string Input_Section_2 = ">>>>>>>>>> Magic Number <<<<<<<<<<"; // ------ Input Section 2 ------ input double lots =0.01; static input string Input_Section_3 = ">>>>>>>>>> Trading Hours <<<<<<<<<<"; // ------ Input Section 3 ------ input int hour1 = 6; input int hour2 = 21; static input string Input_Section_4 = ">>>>>>>>>> MA Periods <<<<<<<<<<"; // ------ Input Section 4 ------ input int PeriodMA1 = 9; input int PeriodMA2 = 9; input int PeriodMA3 = 50; input int PeriodMA4 = 1; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CheckForSell(double dStopLoss, double dTakeProfit) { if(Volume[0]>25) return; int res=OrderSend(Symbol(),OP_SELL,lots,Bid,20 /*slippage*/,dStopLoss,dTakeProfit,"",MAGICMA,0,Red); return; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CheckForBuy(double dStopLoss, double dTakeProfit) { if(Volume[0]>25) return; int res=OrderSend(Symbol(),OP_BUY,lots,Ask,20 /*slippage*/,dStopLoss,dTakeProfit,"",MAGICMA,0,Blue); return; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { double ma1 = iMA(NULL,PERIOD_CURRENT,PeriodMA1,0,MODE_LWMA,PRICE_OPEN, 0); double ma2 = iMA(NULL,PERIOD_CURRENT,PeriodMA2,0,MODE_LWMA,PRICE_CLOSE,0); double ma3 = iMA(NULL,PERIOD_CURRENT,PeriodMA3,0,MODE_SMA, PRICE_CLOSE,0); double ma4 = iMA(NULL,PERIOD_CURRENT,PeriodMA4,0,MODE_SMA, PRICE_CLOSE,0); double ma1ma2 = ma1-ma2; double ma2ma1 = ma2-ma1; double ma3ma4 = ma3-ma4; double ma4ma3 = ma4-ma3; int CountSymbolPositions=0; for(int trade=OrdersTotal()-1;trade>=0;trade--) { if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderSymbol()==Symbol()) { if((OrderType()==OP_SELL||OrderType()==OP_BUY) && OrderMagicNumber()==MAGICMA) CountSymbolPositions++; } } if ((ma3ma4<0.0048) && (ma3>ma1) && (ma3>ma2) && (Close[1]<Close[2]) && (Close[2]<Open[2]) && (CountSymbolPositions<1) && (Hour()>hour1) && (Hour()<hour2) && (ma1ma2<0.0013) && (ma1ma2>0.0004) ) { double dTakeProfit = Bid - (680*Point); double dStopLoss = Ask + (550*Point); CheckForSell(dStopLoss, dTakeProfit); } if ((ma4ma3<0.0048) && (ma3<ma1) && (ma3<ma2) && (Close[1]>Close[2]) && (Close[2]>Open[2]) && (CountSymbolPositions<1) && (Hour()>hour1) && (Hour()<hour2) && (ma2ma1<0.0013) && (ma2ma1>0.0004) ) { double dTakeProfit = Ask + (680*Point); double dStopLoss = Bid - (550*Point); CheckForBuy(dStopLoss, dTakeProfit); } return; }
if (hour1>=6&&hour2<=23) ... go
Не могли бы вы внедрить это в представленный код и выделить вашу вставку?