int f=FileOpen("file.csv",FILE_READ|FILE_WRITE|FILE_CSV);
int f=FileOpen("\\https://api.beget.com/api/ftp/login=login&passwd\\pipe\\file.csv",FILE_READ|FILE_WRITE|FILE_CSV);
//+------------------------------------------------------------------+
//| Monson3.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
extern double Lots = 0.1; // лот
extern double Profit = 0; // язь в рублях
extern int StopLoss = 0; // лось
extern int TakeProfit = 0; // язь
extern int Delta = 111; // пункты от цены
extern int TrailingStop = 111; // трал
extern int TrailingStep = 20; // шаг трала
extern int Count = 25; // число поз
extern int Slip = 30; // реквот
extern int Magic = 0; // магик
int trades=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,Lots,NormalizeDouble(price,_Digits),Slip,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);
}
//+------------------------------------------------------------------+
//| Ступенчатый трал if(TrailingStop>0) Trailing(); |
//+------------------------------------------------------------------+
void Trailing()
{
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+TrailingStep-1)*_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+TrailingStep-1)*_Point || OrderStopLoss()==0)
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*_Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
int CountOrders(int type=-1)
{
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 || type==-1)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Профит всех ордеров по типу ордера |
//+------------------------------------------------------------------+
double AllProfit(int ot=-1)
{
double pr=0;
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))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
}
return(pr);
}
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров |
//+------------------------------------------------------------------+
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()
{
if(TrailingStop>0)
Trailing();
if(CountOrders()<1)
DelOrder();
if(Profit>0 && AllProfit()>Profit)
CloseAll();
if((trades!=CountOrders()) || (CountOrders()<1))
{
DelOrder();
if((trades!=CountTrades() && CountTrades()>0 && CountTrades()<Count) || (CountTrades()<1))
{
PutOrder(4,Bid+Delta*_Point);
PutOrder(5,Bid-Delta*_Point);
}
trades=CountOrders();
}
Comment("\n Trades: ",CountTrades(),
"\n Profit: ",AllProfit(),
"\n Buy Profit: ",AllProfit(0),
"\n Sell Profit: ",AllProfit(1));
}
//+------------------------------------------------------------------+
<code>//+------------------------------------------------------------------+ //| Monson3.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 extern double Lots = 0.1; // лот extern double Profit = 0; // язь в рублях extern int StopLoss = 0; // лось extern int TakeProfit = 0; // язь extern int Delta = 111; // пункты от цены extern int TrailingStop = 111; // трал extern int TrailingStep = 20; // шаг трала extern int CountOrd =5; // кол-во однонаправленных ордеров extern int Slip = 30; // реквот extern int Magic = 0; // магик int trades=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,Lots,NormalizeDouble(price,_Digits),Slip,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); } //+------------------------------------------------------------------+ //| Ступенчатый трал if(TrailingStop>0) Trailing(); | //+------------------------------------------------------------------+ void Trailing() { 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+TrailingStep-1)*_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+TrailingStep-1)*_Point || OrderStopLoss()==0) { mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*_Point,OrderTakeProfit(),0,Yellow); return; } } } } } } } //+------------------------------------------------------------------+ //| Подсчет ордеров по типу | //+------------------------------------------------------------------+ int CountOrders(int type=-1) { 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 || type==-1) count++; } } } return(count); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 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); } } } } } //+------------------------------------------------------------------+ //| Профит всех ордеров по типу ордера | //+------------------------------------------------------------------+ double AllProfit(int ot=-1) { double pr=0; 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)) { pr+=OrderProfit()+OrderCommission()+OrderSwap(); } if(OrderType()==1 && (ot==1 || ot==-1)) { pr+=OrderProfit()+OrderCommission()+OrderSwap(); } } } } return(pr); } //+------------------------------------------------------------------+ //| Удаление отложенных ордеров | //+------------------------------------------------------------------+ 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() { if(TrailingStop>0) Trailing(); if(CountOrders()<1) DelOrder(); if(Profit>0 && AllProfit()>Profit) CloseAll(); if((trades!=CountOrders()) || (CountOrders()<1)) { DelOrder(); if(CountTrades()<CountOrd*2) { if(CountOrders(4)<CountOrd) { PutOrder(4,Bid+Delta*_Point); } if(CountOrders(5)<CountOrd) { PutOrder(5,Bid-Delta*_Point); } } trades=CountOrders(); } Comment("\n Trades: ",CountTrades(), "\n Profit: ",AllProfit(), "\n Buy Profit: ",AllProfit(0), "\n Sell Profit: ",AllProfit(1)); } //+------------------------------------------------------------------+ </code>
double LOT()
{
if(CountTrades()>0)
{
LOT=NormalizeDouble(LOT*MathPow(KLot,CountTrades()),2);
}
if (LOTS!=0) return(LOTS);
double LOT = NormalizeDouble(AccountBalance()*RiskPercent/100/MarketInfo(Symbol(),MODE_MARGINREQUIRED),DigitsLot);
if (LOT>MAXLOT) LOT = MAXLOT;
if (LOT<MINLOT) LOT = MINLOT;
return(LOT);
}
//--- Inputs
extern ENUM_TIMEFRAMES timeframe_RSI = 60;
extern int period_RSI = 14;
extern int level_buy = 30;
extern int level_sell = 70;
extern double Lots = 0.1; // торговый объем ордера
extern double Risk = 1; // 1-риск
extern double MaxLot = 5; // максимальный торговый объем
extern double KLot = 1.3; // увеличение лота
extern double KStep = 1.3; // увеличение шага
extern double Pro = 200; // язь в рублях
extern int StopLoss = 5000; // лось
extern int TakeProfit = 200; // язь
extern int TrailingStop = 200; // трал
extern int Step = 200; // шаг усреднения
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
extern double KCandle = 3; // k для свечи
extern ENUM_TIMEFRAMES TF = PERIOD_H1; // тф
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
..............
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(TrailingStop>0)
Trailing();
if(AllProfit()>Pro && Pro>0)
CloseAll();
if(t!=Time[0])
{
double cl1=iClose(NULL,TF,1);
double cl2=iClose(NULL,TF,2);
double op1=iOpen(NULL,TF,1);
double op2=iOpen(NULL,TF,2);
double RSI0= iRSI (NULL,timeframe_RSI,period_RSI,PRICE_CLOSE,0);
// первый ордер
if(cl1-op1>0 && (op2-cl2)/(cl1-op1)>KCandle && CountTrades()<1)
{
if (RSI0<level_buy)
{
PutOrder(0,Ask);
ModifyOrders();
}
}
if(op1-cl1>0 && (cl2-op2)/(op1-cl1)>KCandle && CountTrades()<1)
{
if (RSI0>level_sell)
{
PutOrder(1,Bid);
ModifyOrders();
}
}
t=Time[0];
}
// усреднение
if(CountTrades()>0 && FindOrderType()==0 && (FindLastBuyPrice()-Ask)/_Point>=Steps())
{
PutOrder(0,Ask);
ModifyOrders();
}
if(CountTrades()>0 && FindOrderType()==1 && (Bid-FindLastSellPrice())/_Point>=Steps())
{
PutOrder(1,Bid);
ModifyOrders();
}
Comment("\n Lot: ",Lot(),
"\n Trades: ",CountTrades(),
"\n Profit: ",AllProfit());
}
//+------------------------------------------------------------------+
www.opentraders.ru/downloads/3037/
В настройках:
— магик первого ордера — магик открываемых ордеров в ручню или другим советником.
— магик эксперта — думаю это понятно
— увеличение лота — коофициент умножения лота
— профит всех ордеров в валюте — если =0 то отключен.
Сов написан в выходные и не тестировался. проверяйте на демо.
verta81