В настройках стоит начало в 10:00. В это время открывается бар и советник должен сохранить эту цену как уровень (в данном случае 13000)
добавьте в буфер индикатора и на график только стрелки, которые указывают момент входа в рынок и направление, которое рекомендует индикатор.
//+------------------------------------------------------------------+
//| MACDMA2.mq4 |
//| Copyright 2021, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
input double Lots = 0.01; // лот
input double KLot = 2; // увеличение лота
input double MaxLot = 10; // максимальный лот
input int StopLoss = 200; // стоплосс
input int TakeProfit = 300; // тейкпрофит
input int CloseSig = 0; // 1-закрытие по сигналу
input int Shift = 1; // бар индикатора
input int Slip = 100; // проскальзывание
input int Magic = 123; // магик
input int Fast = 12; // Fast EMA period
input int Slow = 26; // Slow EMA period
input int Signal = 9; // Signal SMA period
input int MAPeriod = 8; // период МА
input int MAShift = 0; // сдвиг МА
input ENUM_MA_METHOD MAMethod = 0; // метод МА
input ENUM_APPLIED_PRICE MAPrice = 0; // цены МА
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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),0,sl,tp,"",Magic,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)
{
if(OrderType()<2)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()>0)
break;
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
break;
}
}
}
}
if(lot>MaxLot)
lot=Lots;
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);
}
}
}
}
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
double macd1=iMACD(NULL,0,Fast,Slow,Signal,0,0,Shift);
double macd2=iMACD(NULL,0,Fast,Slow,Signal,0,0,Shift+1);
double ma=iMA(NULL,0,MAPeriod,MAShift,MAMethod,MAPrice,Shift);
if(t!=Time[0])
{
if(CloseSig>0)
{
if(macd1>0 && macd2<0 && Close[1]>ma)
{
CloseAll(1);
}
if(macd1<0 && macd2>0 && Close[1]<ma)
{
CloseAll(0);
}
}
if(CountTrades()<1)
{
if(macd1>0 && macd2<0 && Close[1]>ma)
{
PutOrder(0,Ask);
}
if(macd1<0 && macd2>0 && Close[1]<ma)
{
PutOrder(1,Bid);
}
}
if(CountTrades()>0)
{
if(macd1>0 && Close[1]>ma && Open[1]<ma)
{
PutOrder(0,Ask);
}
if(macd1<0 && Close[1]<ma && Open[1]>ma)
{
PutOrder(1,Bid);
}
}
t=Time[0];
}
Comment("\n ma: ",ma,
"\n macd: ",macd1,
"\n Lot: ",Lot(),
"\n Trades: ",CountTrades());
}
//+------------------------------------------------------------------+
омогите написать, пожалуйста, функцию открытия ордеров по тренду или киньте ссылку на советник(не могу найти)!
//+------------------------------------------------------------------+
//| Mashtab.mq4 |
//| Copyright 2021, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
#include <WinUser32.mqh>
int hwnd=0;
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- переменные для идентификаторов графиков
int i=0;
long currChart,prevChart=ChartFirst();
Print("ChartFirst = ",ChartSymbol(prevChart)," ID = ",prevChart);
while(i<100)// у нас наверняка не больше 100 открытых графиков
{
currChart=ChartNext(prevChart); // на основании предыдущего получим новый график
if(currChart<0)
break; // достигли конца списка графиков
Print(i,ChartSymbol(currChart)," ID =",currChart);
hwnd = WindowHandle(ChartSymbol(currChart),ChartPeriod());
PostMessageA(hwnd, WM_KEYDOWN, 0x6D, 0); // уменьшение масштаба
prevChart=currChart;// запомним идентификатор текущего графика для ChartNext()
i++;// не забудем увеличить счетчик
}
}
//+------------------------------------------------------------------+
AM2