Борис, здравствуйте. Уточните о чем это Вы.
Я не понял вопроса.
//+------------------------------------------------------------------+
//| RSI_2_Seve.mq4 |
//| Copyright © 2016, Татьяна |
//| sekrenovtnr@yandex.ru |
//+------------------------------------------------------------------+
#property strict
//--------------------------------------------------------------------
extern int period_RSI_1 = 5; // RSI сигнал
extern int buy_level_1 = 2; // Buy
extern int sel_level_1 = 89; // Sell
extern int period_RSI_2 = 28; // RSI фильтр
extern int buy_level_2 = 4; // Dn
extern int sel_level_2 = 65; // Up
extern int StopLoss = 213; // Stop Loss
extern int TakeProfit = 319; // TakeProfit
extern double Lots = 0.01; // Start Lot
extern bool History = false; // Старый рассчет // Я думаю, false правильнее. Ваш вариант true.
extern double Math_Lot = 0.01; // Добавка к лоту // Так проще в настройках. Каждый следующий лот увеличится на эту величину, как и у Вас.
extern bool Save = true; // Включение Save // При проходе в "+" расстояния равного SL закрывается часть ордера.
extern double PartCloseLots = 0.5; // Часть закрываемого ордера по Save
extern int Magic = 777;
extern int slippage = 30;
//---
double SL = 0,TP =0;
int posType = -1;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//-------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
double New_RSI_1 = iRSI(NULL,0,period_RSI_1,PRICE_OPEN,0);
double Old_RSI_1 = iRSI(NULL,0,period_RSI_1,PRICE_OPEN,1);
double RSI_Filter = iRSI(NULL,0,period_RSI_2,PRICE_OPEN,0);
if (New_RSI_1 > buy_level_1 && Old_RSI_1 < buy_level_1)
if (RSI_Filter < buy_level_2)
{
if (TakeProfit!=0)
TP = NormalizeDouble(Ask + TakeProfit*Point,Digits);
if (StopLoss!=0)
SL = NormalizeDouble(Ask - StopLoss* Point,Digits);
if (OrderSend(Symbol(),OP_BUY, LastLot(),NormalizeDouble(Ask,Digits),slippage,SL,TP,NULL,Magic)==-1) Print(GetLastError());
}
if (New_RSI_1 < sel_level_1 && Old_RSI_1 > sel_level_1)
if (RSI_Filter > sel_level_2)
{
if (TakeProfit!=0) TP = NormalizeDouble(Bid - TakeProfit*Point,Digits);
if (StopLoss!=0) SL = NormalizeDouble(Bid + StopLoss* Point,Digits);
if (OrderSend(Symbol(),OP_SELL,LastLot(),NormalizeDouble(Bid,Digits),slippage,SL,TP,NULL,Magic)==-1) Print(GetLastError());
}
if(Save) CloseOrder();
}
//+------------------------------------------------------------------+
double LastLot()
{
int loss = 0, count;
double lot = 0;
if(History)
count = OrdersHistoryTotal(); // Все свои уже закрытые ордера.
else // Со временем закрытых будет много и ордера буду max. Реально получается по другому???
count = MathMin(OrdersTotal(),OrdersHistoryTotal()); // Все свои открытые ордера.
for(int i=count-1; i>=0; i--)
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
if(OrderType()==OP_BUY || OrderType()==OP_SELL)
if(OrderClosePrice()-OrderOpenPrice()<0)
loss++;
lot = Lots + Math_Lot*loss;
return(NormalizeDouble(lot,2));
}
//+------------------------------------------------------------------+
void CloseOrder()
{
int ticket;
double lot = 0;
for(int i=0; i<OrdersTotal(); i++)
{
ticket = OrderTicket();
if(!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)))
{
if(OrderType() == OP_BUY)
{
if(Bid >= OrderOpenPrice()*2 - OrderStopLoss()) //часть ордера при TP=SL
{
lot = Lots;
if(Lots==0)
lot = NormalizeDouble(MathCeil(OrderLots()*100*PartCloseLots)/100,2);
ClosePosition(ticket,lot);
}
if(Bid - OrderOpenPrice() >= TakeProfit*Point && TakeProfit!=0) // весь ордер по ТР
ClosePosition(ticket,OrderLots());
if(OrderOpenPrice() - Bid >= StopLoss*Point && StopLoss!=0) // весь ордер по SL
ClosePosition(ticket,OrderLots());
}
if(OrderType() == OP_SELL)
{
if(Ask <= OrderOpenPrice()*2 - OrderStopLoss()) //часть ордера при TP=SL
{
lot = Lots;
if(Lots==0)
lot = NormalizeDouble(MathCeil(OrderLots()*100*PartCloseLots)/100,2);
ClosePosition(ticket,lot);
}
if(OrderOpenPrice() - Ask >= TakeProfit*Point && TakeProfit!=0) // весь ордер по ТР
ClosePosition(ticket,OrderLots());
if( Ask - OrderOpenPrice() >= StopLoss*Point && StopLoss!=0) // весь ордер по SL
ClosePosition(ticket,OrderLots());
}
}
}
}
//+------------------------------------------------------------------+
//| Функция закрытия позиций |
//+------------------------------------------------------------------+
void ClosePosition(int tic, double lot)
{
bool closed;
int lastError=0;
for(int i=0; i<5; i++)
{
double price=MarketInfo(Symbol(),posType==OP_BUY ? MODE_BID : MODE_ASK);
closed=OrderClose(tic,lot,price,slippage,clrYellow);
if(!closed)
lastError=GetLastError();
if(closed) // Позиция закрыта
break; // Выходим из цикла
if(lastError==4108) // Не верный номер тикета
break; // Выходим из цикла
Sleep(100);
Print("Close Position retry no: "+IntegerToString(i+2));
}
}
//+------------------------------------------------------------------+
<code>//+------------------------------------------------------------------+ //| RSI_2.mq4 | //| Copyright © 2016, Татьяна | //| sekrenovtnr@yandex.ru | //+------------------------------------------------------------------+ #property strict //-------------------------------------------------------------------- extern int period_RSI_1 = 3; // RSI сигнал extern int buy_level_1 = 28; // Buy extern int sel_level_1 = 96; // Sell extern int period_RSI_2 = 14; // RSI фильтр extern int buy_level_2 = 26; // Dn extern int sel_level_2 = 70; // Up extern int StopLoss = 349; // Stop Loss extern int TakeProfit = 341; // TakeProfit extern double Lots = 0.01; // Start Lot extern bool History = true; // Старый рассчет // Я думаю, false правильнее extern double Math_Lot = 0.01; // Добавка к лоту // Так проще в настройках. Каждый следующий лот увеличится на эту величину, как и у Вас. extern int Magic = 777; extern int slippage = 30; //--- double SL = 0,TP =0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //-------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { double New_RSI_1 = iRSI(NULL,0,period_RSI_1,PRICE_OPEN,0); double Old_RSI_1 = iRSI(NULL,0,period_RSI_1,PRICE_OPEN,1); double RSI_Filter = iRSI(NULL,0,period_RSI_2,PRICE_OPEN,0); if (New_RSI_1 > buy_level_1 && Old_RSI_1 < buy_level_1) if (RSI_Filter < buy_level_2) { if (TakeProfit!=0) TP = NormalizeDouble(Ask + TakeProfit*Point,Digits); if (StopLoss!=0) SL = NormalizeDouble(Ask - StopLoss* Point,Digits); if (OrderSend(Symbol(),OP_BUY, LastLot(),NormalizeDouble(Ask,Digits),slippage,SL,TP,NULL,Magic)==-1) Print(GetLastError()); } if (New_RSI_1 < sel_level_1 && Old_RSI_1 > sel_level_1) if (RSI_Filter > sel_level_2) { if (TakeProfit!=0) TP = NormalizeDouble(Bid - TakeProfit*Point,Digits); if (StopLoss!=0) SL = NormalizeDouble(Bid + StopLoss* Point,Digits); if (OrderSend(Symbol(),OP_SELL,LastLot(),NormalizeDouble(Bid,Digits),slippage,SL,TP,NULL,Magic)==-1) Print(GetLastError()); } } //+------------------------------------------------------------------+ double LastLot() { int loss = 0, count; double lot = 0; if(History) count = OrdersHistoryTotal(); // Все свои уже закрытые ордера. else // Со временем закрытых будет много и ордера буду max. Реально получается по другому??? count = MathMin(OrdersTotal(),OrdersHistoryTotal()); // Все свои открытые ордера. for(int i=count-1; i>=0; i--) if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) if(OrderType()==OP_BUY || OrderType()==OP_SELL) if(OrderClosePrice()-OrderOpenPrice()<0) loss++; lot = Lots + Math_Lot*loss; return(NormalizeDouble(lot,2)); } //+------------------------------------------------------------------+ </code>
//+------------------------------------------------------------------+
//| RSI_3.mq4 |
//| Copyright © 2016, Татьяна |
//| sekrenovtnr@yandex.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2022, Татьяна"
#property link "sekrenovtnr@yandex.ru"
#property strict
#property description "советник по 3-м RSI"
#property description "sell при пересечение сверху вниз 70 и на buy снизу вверх 30"
#property description "стопы и тейки можно выстовить в настройках советника"
//--------------------------------------------------------------------
// Богиня, я исправил Ваши ошибки. Советник сам по себе работать не может. Нет в нем ничего, кроме возможной идеи.
// Похвально вообще его наличие.
// Маленький совет: всякие переменные пишите подлиннее и понятнее дальше. Level_for_first_RSI ну и т.д.
// На счет идеи увеличить как-то лот в зависимости от всех закрытых в убыток ордеров, сама по себе нонсенс.
// Я бы проверял последний закрытый, если в "+", то стартовым лотом, в "-" лот последнего бы увеличивал.
// Да я не крут, а только учусь. Но Вы всегда можете обращаться. если смогу помогу, отвечу.
extern int period_RSI_1 = 2;
extern int buy_level_1 = 11;
extern int sel_level_1 = 65;
extern int period_RSI_2 = 20;
extern int buy_level_2 = 29;
extern int sel_level_2 = 71;
extern int period_RSI_3 = 33;
extern int buy_level_3 = 31;
extern int sel_level_3 = 65;
extern int StopLoss = 193;
extern int TakeProfit = 352;
extern double Lots = 0.01;
extern double Lot1 = 0.02;
extern double Lot2 = 0.03;
extern double Lot3 = 0.04;
extern double Lot4 = 0.05;
extern double Lot5 = 0.06;
extern double Lot6 = 0.07;
extern double Lot7 = 0.08;
extern double Lot8 = 0.09;
extern double Lot9 = 0.1;
extern double Lot10 = 0.11;
extern int Magic = 777;
extern int slippage = 30;
double SL = 0,TP =0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//--------------------------------------------------------------------
//| |
//+------------------------------------------------------------------+
void OnTick()
{
double New_RSI_1 = iRSI(NULL,0,period_RSI_1,PRICE_OPEN,0);
double Old_RSI_1 = iRSI(NULL,0,period_RSI_1,PRICE_OPEN,1);
double New_RSI_2 = iRSI(NULL,0,period_RSI_2,PRICE_OPEN,0);
double Old_RSI_2 = iRSI(NULL,0,period_RSI_2,PRICE_OPEN,1);
double New_RSI_3 = iRSI(NULL,0,period_RSI_3,PRICE_OPEN,0);
double Old_RSI_3 = iRSI(NULL,0,period_RSI_3,PRICE_OPEN,1);
if (New_RSI_1 < sel_level_1 && Old_RSI_1 > sel_level_1)
if (New_RSI_2 < sel_level_2 && Old_RSI_2 > sel_level_2)
if (New_RSI_3 < sel_level_3 && Old_RSI_3 > sel_level_3)
{
if (TakeProfit!=0) TP = NormalizeDouble(Bid - TakeProfit*Point,Digits);
if (StopLoss!=0) SL = NormalizeDouble(Bid + StopLoss* Point,Digits);
if (OrderSend(Symbol(),OP_SELL,Lot(),NormalizeDouble(Bid,Digits),slippage,SL,TP,NULL,Magic)==-1) Print(GetLastError());
}
if (New_RSI_1 > buy_level_1 && Old_RSI_1 < buy_level_1)
if (New_RSI_2 > buy_level_2 && Old_RSI_2 < buy_level_2)
if (New_RSI_3 > buy_level_3 && Old_RSI_3 < buy_level_3)
{
if (TakeProfit!=0)
TP = NormalizeDouble(Ask + TakeProfit*Point,Digits);
if (StopLoss!=0)
SL = NormalizeDouble(Ask - StopLoss* Point,Digits);
if (OrderSend(Symbol(),OP_BUY, Lot(),NormalizeDouble(Ask,Digits),slippage,SL,TP,NULL,Magic)==-1) Print(GetLastError());
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int Loss()
{
int loss=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
if(OrderType()==OP_BUY || OrderType()==OP_SELL)
if(OrderClosePrice()-OrderOpenPrice()<0)
loss++;
return(loss);
}
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
switch(Loss())
{
case 0:lot=Lots;break;
case 1:lot=Lot1;break;
case 2:lot=Lot2;break;
case 3:lot=Lot3;break;
case 4:lot=Lot4;break;
case 5:lot=Lot5;break;
case 6:lot=Lot6;break;
case 7:lot=Lot7;break;
case 8:lot=Lot8;break;
case 9:lot=Lot9;break;
case 10:lot=Lot10;break;
default:lot=Lots;
}
return(lot);
}
//--------------------------------------------------------------------
Этот вопрос под вопросом. Классно высказался. А?
Тут варианты, да и еще каждый может свой придумать.
Я пока предполагал стопы ордеров выносить за БУ (около 2-х ширин шага).
Ну и прет с утра. Цена выходит в БУ с плюсом, закрываем все противоположные и включаем трал прибыли.
Как то так.
Удачи.
kvashnin007