Например
стоит сделка EURUSD BUY и USDCHF SELL если общая просадка счета достигла 45 пунктов, то сделки закрываются и открываются заново, но наоборот
теперь EURUSD SELL а USDCHF BUY
//+------------------------------------------------------------------+
//| TFChange.mq4 |
//| Copyright 2020, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
#property indicator_chart_window
input int sec=20;
input ENUM_TIMEFRAMES tf1=PERIOD_H4; // период куда переключаем
input ENUM_TIMEFRAMES tf=PERIOD_H1; // текуший период
int i=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
Comment("");
//--- создадим таймер с периодом в 1 секунду
EventSetTimer(1);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- уничтожим таймер при завершении работы
EventKillTimer();
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
i++;
if(i>sec)
{
if(Period()!=tf1)
{
ChartSetSymbolPeriod(0,NULL,tf1);
ChartSetSymbolPeriod(0,NULL,tf);
i=0;
return;
}
}
Comment("\n Sec: ",i);
}
//+------------------------------------------------------------------+
AM2