
По телу свечи по Н1 за предыдущий день самой верхней и самой нижней свечи.формулировка интересная. еще попробуй это машине объяснить
//+------------------------------------------------------------------+
//| ProWeak.mq4 |
//| Copyright 2021, AM2 |
//| https://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, AM2"
#property link "https://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 2; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int StopLoss = 333; // лось
extern int TakeProfit = 4444; // язь
extern int TrailingStop = 25; // трал
extern int Delta = 100; // расстояние от цены
extern int Shift = 1; // сдвиг
extern int Slip = 30; // реквот
extern int Magic = 0; // магик
extern ENUM_TIMEFRAMES TF = PERIOD_W1; // период свечи
//+------------------------------------------------------------------+
//| 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),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderProfit()>0)
break;
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
break;
}
}
}
if(lot>MaxLot)
lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
int CountOrders(int type)
{
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()==type)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Простой трал |
//+------------------------------------------------------------------+
void Trail()
{
bool mod;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(Bid-OrderOpenPrice()>TrailingStop*_Point)
{
if(OrderStopLoss()<Bid-TrailingStop*_Point)
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*_Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
if(OrderType()==OP_SELL)
{
if((OrderOpenPrice()-Ask)>TrailingStop*_Point)
{
if((OrderStopLoss()>(Ask+TrailingStop*_Point)) || (OrderStopLoss()==0))
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*_Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров |
//+------------------------------------------------------------------+
void DelOrder()
{
bool del;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()>1)
del=OrderDelete(OrderTicket());
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double lo=iLow(NULL,TF,Shift);
double hi=iHigh(NULL,TF,Shift);
if(TrailingStop>0)
Trail();
if(CountTrades()>0)
DelOrder();
if(CountTrades()<1)
{
if(CountOrders(4)<1 && Bid<hi)
{
PutOrder(4,hi+Delta*_Point);
}
if(CountOrders(5)<1 && Bid>lo)
{
PutOrder(5,lo-Delta*_Point);
}
}
Comment("\n Lot: ",Lot());
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| MultiMeter.mq4 |
//| Copyright 2021, AM2 |
//| https://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, AM2"
#property link "https://www.forexsystems.biz"
#property version "1.00"
#property strict
#property indicator_chart_window
#property strict
#property indicator_chart_window
#property indicator_plots 0
input ENUM_TIMEFRAMES i_eOlderTF = PERIOD_D1; // Older TF
input ENUM_TIMEFRAMES i_eYoungerTF = PERIOD_H1; // Younger TF
input uint i_uMinutes = 30; // Minutes from the opening
enum ENUM_BAR_TYPE
{
BAR_TYPE_DODG,
BAR_TYPE_BULL,
BAR_TYPE_BEAR
};
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if(i_uMinutes > uint(Period()))
{
Alert("Wrong value of parameter \"Minutes from the opening\". Indicator is turned off.");
return INIT_FAILED;
}
return(INIT_SUCCEEDED);
}
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Expert deinitialization function |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Custom indicator iteration function |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
if(!IsTesting())
if(!IsTFDataReady(i_eOlderTF) || !IsTFDataReady(i_eYoungerTF))
return rates_total;
datetime dtYoungerTFTime = iTime(NULL, i_eYoungerTF, 0);
if(TimeCurrent() - dtYoungerTFTime < i_uMinutes * 60)
return rates_total;
static datetime dtPrevBar = 0;
if(dtPrevBar == dtYoungerTFTime)
return rates_total;
dtPrevBar = dtYoungerTFTime;
ENUM_BAR_TYPE eOlderBar = GetBarType(0, i_eOlderTF);
ENUM_BAR_TYPE eYoungerBar = GetBarType(0, i_eYoungerTF);
if(eOlderBar == BAR_TYPE_DODG || eYoungerBar == BAR_TYPE_DODG || eOlderBar != eYoungerBar)
return rates_total;
Alert(_Symbol+" Coincidence of readings for ", (eOlderBar == BAR_TYPE_BEAR)? "sell.": "buy.");
return rates_total;
}
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Определение типа свечи |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
ENUM_BAR_TYPE GetBarType(const int nBar, const ENUM_TIMEFRAMES eTF)
{
double fWholeHeight = iHigh(NULL, eTF, nBar) - iLow(NULL, eTF, nBar);
if(fWholeHeight <= 0.0)
return BAR_TYPE_DODG;
if(fabs(iOpen(NULL, eTF, nBar) - iClose(NULL, eTF, nBar)) / fWholeHeight < 2 * DBL_EPSILON)
return BAR_TYPE_DODG;
if(iOpen(NULL, eTF, nBar) > iClose(NULL, eTF, nBar))
return BAR_TYPE_BEAR;
return BAR_TYPE_BULL;
}
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Проверка обновления данных указанного ТФ |
//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
bool IsTFDataReady(ENUM_TIMEFRAMES eTF)
{
ResetLastError();
iTime(NULL, eTF, 1);
return GetLastError() == ERR_NO_ERROR;
}
//+------------------------------------------------------------------+
... код ...
максимальная просадка текущего дня в валюте и в процентах
ТЗ сводится к двум пунктам:
1. В соответствии с настройками сделать сетку.
2. Если есть ТП, то ставится новая сетка с предварительным удалением существующих отложек.
//+------------------------------------------------------------------+
//| Limit.mq5 |
//| Copyright 2021, AM2 |
//| https://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, AM2"
#property link "https://www.forexsystems.biz"
#property version "1.00"
#include <Trade\Trade.mqh>
CTrade trade;
input double Lots = 0.1; // лот
input double KLot = 2; // увеличение лота
input double MaxLot = 5; // максимальный лот
input int StopLoss = 0; // лось
input int TakeProfit = 300; // язь
input int Count = 3; // число ордеров
input int Step = 100; // шаг
input int Type = 2; // 1-BuyLimit 2-SellLimit
input int Slip = 5; // реквот
int pos=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool Take()
{
HistorySelect(0,TimeCurrent());
ulong ticket=0;
for(int i=HistoryDealsTotal()-1; i>=0; i--)
{
if((ticket=HistoryDealGetTicket(i))>0)
{
if(HistoryDealGetInteger(ticket,DEAL_REASON)==DEAL_REASON_TP)
return(true);
}
break;
}
return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DelOrder()
{
for(int i=OrdersTotal()-1; i>=0; i--)
{
ulong ticket=OrderGetTicket(i);
trade.OrderDelete(ticket);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountOrders(ENUM_ORDER_TYPE type)
{
int count=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(OrderGetTicket(i)))
{
if(OrderGetInteger(ORDER_TYPE)==type)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Лот |
//+------------------------------------------------------------------+
double Lot(ENUM_ORDER_TYPE type)
{
double lots=Lots;
lots=NormalizeDouble(Lots*MathPow(KLot,CountOrders(type)),2);
if(lots>MaxLot)
lots=Lots;
if(lots<0.1)
lots=0.1;
return(lots);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double pr=0,sl=0,tp=0;
double Bid = SymbolInfoDouble(NULL,SYMBOL_BID);
if(Take())
{
DelOrder();
}
if(OrdersTotal()<1 && PositionsTotal()<1)
{
if(Type==1)
for(int i=1; i<=Count; i++)
{
pr=NormalizeDouble(Bid-Step*_Point*i,_Digits);
if(StopLoss>0)
sl=NormalizeDouble(Bid-StopLoss*_Point,_Digits);
if(TakeProfit>0)
tp=NormalizeDouble(Bid+TakeProfit*_Point,_Digits);
trade.BuyLimit(Lot(ORDER_TYPE_BUY_LIMIT),pr,NULL,sl,tp,0,0,"");
}
if(Type==2)
for(int i=1; i<=Count; i++)
{
pr=NormalizeDouble(Bid+Step*_Point*i,_Digits);
if(StopLoss>0)
sl=NormalizeDouble(Bid+StopLoss*_Point,_Digits);
if(TakeProfit>0)
tp=NormalizeDouble(Bid-TakeProfit*_Point,_Digits);
trade.SellLimit(Lot(ORDER_TYPE_SELL_LIMIT),pr,NULL,sl,tp,0,0,"");
}
}
Comment("\n Profit: ",AccountInfoDouble(ACCOUNT_BALANCE)-AccountInfoDouble(ACCOUNT_EQUITY),
"\n Take: ",Take());
}
//+------------------------------------------------------------------+
находим свечи с максимальным и минимальным уровнями закрытия за предыдущий день и выставляем ордера.
AM2