проверьте пожалуйста советник

 

Закрывает все открытые ордера при изменении эквити на заданное значение.

Отображает стартовое эквити на графике. Автор утверждает что всё работает как было задумано. У меня почему то после закрытия всех ордеров с прибылью стартовое эквити не меняется .Может кто нибудь подскажет почему так работает?Очень нужен именно такой советник.

extern string rem0 = "- в валюте депозита -";
extern double Profit = 30;
extern double Loss = 1000;
double Last_Equity,
Equity,
Diff_Profit,
Diff_Loss;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
Last_Equity = AccountEquity( );
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
Equity = AccountEquity( );
Diff_Profit = Equity - Last_Equity;
Diff_Loss = Last_Equity - Equity;
if(Diff_Profit > Profit || Diff_Loss > Loss)
{
while(OrdersTotal()>0)
{
for (int i=0; i < OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
switch(OrderType())
{
case 0 : OrderClose(OrderTicket(),OrderLots(),Bid,5); break;
case 1 : OrderClose(OrderTicket(),OrderLots(),Ask,5); break;
}
}
}
}
Last_Equity = Equity;
}
Comment("Начальное Эквити = ", DoubleToStr(Last_Equity,2));
//----
return(0);
}
//+------------------------------------------------------------------+

Файлы:
 

Закрывает ордера он конечно через ж.., отсюда, пока они закрываются, весь профит (всего 10) и ускользает.

 

Вы же сами сказали, что ничего не меняется.

 
Roger:

Вы же сами сказали, что ничего не меняется.


не меняется показание эквити после закрытия ордеров в плюс.

 

А, это легко. Замените

Last_Equity = Equity;
на

Last_Equity = AccountEquity( );

 
Roger:

А, это легко. Замените

Last_Equity = Equity;
на

Last_Equity = AccountEquity( );


спасибо попробую.
 
Roger:

А, это легко. Замените

Last_Equity = Equity;
на

Last_Equity = AccountEquity( );


не меняется что ещё можно исправить?
 
rusa:

не меняется что ещё можно исправить?

Должно!
 
Roger:

Должно!

Last_Equity = AccountEquity( );

это строка внизу?я отметила синим цветом

 

Да, другой такой строки вроде нет.

 

Воопщем проходил я Теорию вероятности и по статистике если отложение ордера будут в радиусе 50пунктов от цены, то при открытии ордера с профитом в10 пунктов легче досягаем - если будет ещё и стоп лос в 10 пунктов (даже спред непомеха) движения тренда великая вещь...

Добавьте стоп лос независимо от StepStop

//+------------------------------------------------------------------+
//| Volfram.mq4 |
//| Vova-x@list.ru |
//| |
//+------------------------------------------------------------------+
#property copyright "Vova-x@list.ru"
#property link ""
//-----------------------------------------
extern int TakeProfit=10;
extern int StepStop=45;
extern double Lots=0.01;
extern bool MoneyManagement=true;
extern int MarginPercent=10;
//-------------------------------------------
int level_sell_stop;
int level_buy_stop;

//----------------------------------------------------------
void init()
{
// int minstop=MarketInfo(Symbol(),MODE_STOPLEVEL);
//Print("Уровень стопов: "+minstop);
}
//-----------------------------------------------------------
void start()
{
if (!IsTradeAllowed()) return;
level_buy_stop=0;
level_sell_stop=0;
StepingStop();
StepingPendings();
if (TotalBuy ()==0 && TotalBuyStop ()==0) SetBuyStop ();
if (TotalSell()==0 && TotalSellStop()==0) SetSellStop();
Comment("Level Buy Stop=",level_buy_stop*Point,
"\n","Level Sell Stop=",level_sell_stop*Point);
}
//---------------------------------------------------------------------------------------------
void StepingStop()
{
if (StepStop<1) return;
int ask, bid, open, stop, x;
double loss;
for (int i=0; i<OrdersTotal(); i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderSymbol()!=Symbol())
if (OrderType()==OP_BUY)
{
bid=MathRound(Bid/Point);
open=MathRound(OrderOpenPrice()/Point);
stop=MathRound(OrderStopLoss()/Point);
x=(bid-open)/StepStop; x--; x*=StepStop;
level_sell_stop=open+x;
if (stop>=open+x)
loss=(open+x)*Point;
OrderModify(OrderTicket(),OrderOpenPrice(),loss,OrderTakeProfit(),0,CLR_NONE);
}
if (OrderType()==OP_SELL)
{
ask=MathRound(Ask/Point);
open=MathRound(OrderOpenPrice()/Point);
stop=MathRound(OrderStopLoss()/Point);
x=(open-ask)/StepStop; x--; x*=StepStop;
level_buy_stop=open-x;
if (stop>0 && stop<=open-x)
loss=(open-x)*Point;
OrderModify(OrderTicket(),OrderOpenPrice(),loss,OrderTakeProfit(),0,CLR_NONE);
}
}
}
//----------------------------------------------------------------------------
void StepingPendings()
{
int ask, bid, open;
double price, loss, profit;
for (int i=0; i<OrdersTotal(); i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderSymbol()!=Symbol())
if (OrderType()==OP_BUYSTOP)
{
if (level_buy_stop==0)
open=MathRound(OrderOpenPrice()/Point);
if (open<=level_buy_stop)
price=level_buy_stop*Point;
loss=price-StepStop*Point;
profit=0; if (TakeProfit>0) profit=price+TakeProfit*Point;
OrderModify(OrderTicket(),price,loss,profit,0,CLR_NONE);
}
if (OrderType()==OP_SELLSTOP)
{
if (level_sell_stop==0)
open=MathRound(OrderOpenPrice()/Point);
if (open>=level_sell_stop)
price=level_sell_stop*Point;
loss=price+StepStop*Point;
profit=0; if (TakeProfit>0) profit=price-TakeProfit*Point;
OrderModify(OrderTicket(),price,loss,profit,0,CLR_NONE);
}
}
}
//-------------------------------------------------------------------
void SetBuyStop()
{
double lots=LotsCounting();
double price=Bid+StepStop*Point;
double loss=price-StepStop*Point;
double profit=0; if (TakeProfit>0) profit=price+TakeProfit*Point;
int ticket=OrderSend(Symbol(),OP_BUYSTOP,lots,price,0,loss,profit,"",0,0,CLR_NONE);
if (ticket<1) Print("Set a pending order failed with error #",GetLastError()," ",(GetLastError()));
}

void SetSellStop()
{
double lots=LotsCounting();
double price=Ask-StepStop*Point;
double loss=price+StepStop*Point;
double profit=0; if (TakeProfit>0) profit=price-TakeProfit*Point;
int ticket=OrderSend(Symbol(),OP_SELLSTOP,lots,price,0,loss,profit,"",0,0,CLR_NONE);
if (ticket<1) Print("Set a pending order failed with error #",GetLastError()," ",(GetLastError()));
}


int TotalBuy()
{
int count=0;
for (int i=0; i<OrdersTotal(); i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()==OP_BUY) count++;
}
return (count);
}

int TotalBuyStop()
{
int count=0;
for (int i=0; i<OrdersTotal(); i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()==OP_BUYSTOP) count++;
}
return (count);
}

int TotalSell()
{
int count=0;
for (int i=0; i<OrdersTotal(); i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()==OP_SELL) count++;
}
return (count);
}

int TotalSellStop()
{
int count=0;
for (int i=0; i<OrdersTotal(); i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()==OP_SELLSTOP) count++;
}
return (count);
}

double LotsCounting()
{
double lots=Lots;
if (MoneyManagement)
{
double lotsize=MarketInfo(Symbol(),MODE_LOTSIZE);
double freemargin=AccountFreeMargin();
lots=0; if (lotsize>0) lots=NormalizeDouble((MarginPercent*freemargin/lotsize),1);
}
if (lots>10) lots=NormalizeDouble(lots,0);
if (lots<0.01) lots=0.01;
return (lots);
}


// End

Причина обращения: