Как кодировать? - страница 207

 

Уменьшить открытую позицию

Кто-нибудь знает, как закрыть / уменьшить половину позиции. Какую функцию мы вызываем?

Пример: Уменьшить открытую позицию с 10 лотов до 5 лотов без открытия другой сделки в противоположном направлении?

 

Это называется "частичное закрытие";

bool OrderClose( int ticket, double lots, double price, int slippage, color Color=CLR_NONE)

Просто укажите, сколько лотов нужно закрыть.

 
ljuba973:
Привет,

Попробуйте этот способ

for (int i=OrdersTotal()-1;i>=0 i--) {

if (OrderSelect(i, SELECT_BY_POS)) {

if (OrderSymbol()==Symbol()&&OrderType()==0) {

Ans=OrderClose(OrderTicket(),alLots,Bid,2);// Order closing

}

if (OrderSymbol()==Symbol()&&OrderType()==1) {

Ans=OrderClose(OrderTicket(),alLots,Ask,2);// Order closing

}

}

 
username1:
Кто-нибудь знает, как закрыть / уменьшить половину позиции. Какую функцию мы вызываем? Пример: Уменьшить открытую позицию с 10 лотов до 5 лотов без открытия другой сделки в противоположном направлении?

Просто закройте ордер на 5 лотов, вот так:

OrderClose(OrderTicket(),5.0,........

 

Привет, Роджер,

Большое спасибо за помощь. За это время мне удалось исправить его, чтобы он работал:

OrderSend(Symbol(),OP_BUY,alLots,Ask,3,0,0,EA_Tester,Magic);

if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS)==true) {

alTicker = OrderTicket();

Alert("Bought! ", alTicker);

} else Print("OrderSelect failed error code is ",GetLastError());

[/CODE]

Like that I found alTicker (after opening position) which I close later on.

But your code I will use to optimize my Closing function. Sorry for maybe "beginner's code", I am into mq4 just 2 days ... will improve - I promise

Thanks again

Roger09:
Try this way

[CODE]

for (int i=OrdersTotal()-1;i>=0 i--) {

if (OrderSelect(i, SELECT_BY_POS)) {

if (OrderSymbol()==Symbol()&&OrderType()==0) {

Ans=OrderClose(OrderTicket(),alLots,Bid,2);// Order closing

}

if (OrderSymbol()==Symbol()&&OrderType()==1) {

Ans=OrderClose(OrderTicket(),alLots,Ask,2);// Order closing

}

}

 

Как я могу установить фиксированный StopLoss?

Здравствуйте,

Не мог бы кто-нибудь сообщить мне, как я могу разместить фиксированный StopLoss в этом коде?

//+------------------------------------------------------------------+

//| Daydream by Cothool |

//| Recommended: USD/JPY 1H |

//+------------------------------------------------------------------+

#define MAGIC_NUM 48213657

//+------------------------------------------------------------------+

extern double Lots = 0.1;

extern int ChannelPeriod = 25;

extern int Slippage = 3;

extern int TakeProfit = 15;

//+------------------------------------------------------------------+

double LastOrderTime = 0;

double CurrentDirection = 0;

double CurrentTakeProfitPrice = 0;

//+------------------------------------------------------------------+

void OpenLong()

{

if (Time[0] == LastOrderTime)

return;

if (CurrentDirection != 0)

return;

OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0,

"Daydream", MAGIC_NUM, 0, Blue);

LastOrderTime = Time[0];

CurrentDirection = 1;

}

//+------------------------------------------------------------------+

void OpenShort()

{

if (Time[0] == LastOrderTime)

return;

if (CurrentDirection != 0)

return;

OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0,

"Daydream", MAGIC_NUM, 0, Red);

LastOrderTime = Time[0];

CurrentDirection = -1;

}

//+------------------------------------------------------------------+

void CloseLong()

{

int i;

if (Time[0] == LastOrderTime)

return;

if (CurrentDirection != 1)

return;

for (i = 0; i < OrdersTotal(); i++)

{

if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() &&

OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_BUY)

{

OrderClose(OrderTicket(), OrderLots(), Bid, 3, White);

LastOrderTime = Time[0];

CurrentDirection = 0;

}

}

}

//+------------------------------------------------------------------+

void CloseShort()

{

int i;

if (Time[0] == LastOrderTime)

return;

if (CurrentDirection != -1)

return;

for (i = 0; i < OrdersTotal(); i++)

{

if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() &&

OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_SELL)

{

OrderClose(OrderTicket(), OrderLots(), Ask, 3, White);

LastOrderTime = Time[0];

CurrentDirection = 0;

}

}

}

//+------------------------------------------------------------------+

void start()

{

double HighestValue;

double LowestValue;

HighestValue = High;

LowestValue = Low[Lowest(NULL, 0, MODE_LOW, ChannelPeriod, 1)];

// BUY

if (Close[0] < LowestValue)

{

CloseShort();

OpenLong();

CurrentTakeProfitPrice = Bid + TakeProfit * Point;

}

// SELL

if (Close[0] > HighestValue)

{

CloseLong();

OpenShort();

CurrentTakeProfitPrice = Ask - TakeProfit * Point;

}

// Trailing Profit Taking for Long Position

if (CurrentDirection == 1)

{

if (CurrentTakeProfitPrice > Bid + TakeProfit * Point)

CurrentTakeProfitPrice = Bid + TakeProfit * Point;

if (Bid >= CurrentTakeProfitPrice)

CloseLong();

}

// Trailing Profit Taking for Short Position

if (CurrentDirection == -1)

{

if (CurrentTakeProfitPrice < Ask - TakeProfit * Point)

CurrentTakeProfitPrice = Ask - TakeProfit * Point;

if (Ask <= CurrentTakeProfitPrice)

CloseShort();

}

}

//+------------------------------------------------------------------+

С уважением!

 
fxbg:
Привет,

Не мог бы кто-нибудь сообщить мне, как я могу разместить фиксированный StopLoss в этом коде?

Заменить

extern double Lots = 0.1;

extern int ChannelPeriod = 25;

extern int Slippage = 3;

extern int TakeProfit = 15;

//+------------------------------------------------------------------+

double LastOrderTime = 0;

double CurrentDirection = 0;

double CurrentTakeProfitPrice = 0;

//+------------------------------------------------------------------+

void OpenLong()

{

if (Time[0] == LastOrderTime)

return;

if (CurrentDirection != 0)

return;

OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0,

"Daydream", MAGIC_NUM, 0, Blue);

LastOrderTime = Time[0];

CurrentDirection = 1;

}

//+------------------------------------------------------------------+

void OpenShort()

{

if (Time[0] == LastOrderTime)

return;

if (CurrentDirection != 0)

return;

OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0,

"Daydream", MAGIC_NUM, 0, Red);

LastOrderTime = Time[0];

CurrentDirection = -1;

} [/CODE]

to

[CODE]extern double Lots = 0.1;

extern int ChannelPeriod = 25;

extern int Slippage = 3;

extern int TakeProfit = 15;

extern int StopLoss = 15;

//+------------------------------------------------------------------+

double LastOrderTime = 0;

double CurrentDirection = 0;

double CurrentTakeProfitPrice = 0;

//+------------------------------------------------------------------+

void OpenLong()

{

if (Time[0] == LastOrderTime)

return;

if (CurrentDirection != 0)

return;

OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, Ask-StopLoss*Point, 0,

"Daydream", MAGIC_NUM, 0, Blue);

LastOrderTime = Time[0];

CurrentDirection = 1;

}

//+------------------------------------------------------------------+

void OpenShort()

{

if (Time[0] == LastOrderTime)

return;

if (CurrentDirection != 0)

return;

OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, Bid+StopLoss*Point, 0,

"Daydream", MAGIC_NUM, 0, Red);

LastOrderTime = Time[0];

CurrentDirection = -1;

}
 

Нужна помощь в модификации индикатора

Привет всем программистам,

Я нашел на форуме индикатор (валютные позиции), который показывает текущие позиции, которыми я торгую. Теперь я хочу найти кого-то, кто поможет мне сделать этот индикатор, чтобы использовать внешнее окно в нижней части графика, также шрифты и цвет могут быть изменены. Я не силен в программировании. Спасибо большое.

Асам

Файлы:
 

Не работает в тестере

Я запускаю этот советник в тестере. Когда он достигает первого стоплосса, тестер останавливается и не продолжает тест. Можно ли исправить эту проблему. Спасибо, Роджер.

//+------------------------------------------------------------------+

//| Daydream by Cothool |

//| Recommended: USD/JPY 1H |

//+------------------------------------------------------------------+

#define MAGIC_NUM 48213657

//+------------------------------------------------------------------+

extern double Lots = 0.1;

extern int ChannelPeriod = 25;

extern int Slippage = 3;

extern int TakeProfit = 0;

extern int StopLoss = 15;

//+------------------------------------------------------------------+

double LastOrderTime = 0;

double CurrentDirection = 0;

double CurrentTakeProfitPrice = 0;

//+------------------------------------------------------------------+

void OpenLong()

{

if (Time[0] == LastOrderTime)

return;

if (CurrentDirection != 0)

return;

OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage,Ask-StopLoss*Point, 0,

"Daydream", MAGIC_NUM, 0, Blue);

LastOrderTime = Time[0];

CurrentDirection = 1;

}

//+------------------------------------------------------------------+

void OpenShort()

{

if (Time[0] == LastOrderTime)

return;

if (CurrentDirection != 0)

return;

OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage,Bid+StopLoss*Point, 0,

"Daydream", MAGIC_NUM, 0, Red);

LastOrderTime = Time[0];

CurrentDirection = -1;

}

//+------------------------------------------------------------------+

void CloseLong()

{

int i;

if (Time[0] == LastOrderTime)

return;

if (CurrentDirection != 1)

return;

for (i = 0; i < OrdersTotal(); i++)

{

if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() &&

OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_BUY)

{

OrderClose(OrderTicket(), OrderLots(), Bid, 3, White);

LastOrderTime = Time[0];

CurrentDirection = 0;

}

}

}

//+------------------------------------------------------------------+

void CloseShort()

{

int i;

if (Time[0] == LastOrderTime)

return;

if (CurrentDirection != -1)

return;

for (i = 0; i < OrdersTotal(); i++)

{

if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() &&

OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_SELL)

{

OrderClose(OrderTicket(), OrderLots(), Ask, 3, White);

LastOrderTime = Time[0];

CurrentDirection = 0;

}

}

}

//+------------------------------------------------------------------+

void start()

{

double HighestValue;

double LowestValue;

HighestValue = High;

LowestValue = Low[Lowest(NULL, 0, MODE_LOW, ChannelPeriod, 1)];

// BUY

if (Close[0] < LowestValue)

{

CloseShort();

OpenLong();

CurrentTakeProfitPrice = Bid + TakeProfit * Point;

}

// SELL

if (Close[0] > HighestValue)

{

CloseLong();

OpenShort();

CurrentTakeProfitPrice = Ask - TakeProfit * Point;

}

// Trailing Profit Taking for Long Position

if (CurrentDirection == 1)

{

if (CurrentTakeProfitPrice > Bid + TakeProfit * Point)

CurrentTakeProfitPrice = Bid + TakeProfit * Point;

if (Bid >= CurrentTakeProfitPrice)

CloseLong();

}

// Trailing Profit Taking for Short Position

if (CurrentDirection == -1)

{

if (CurrentTakeProfitPrice < Ask - TakeProfit * Point)

CurrentTakeProfitPrice = Ask - TakeProfit * Point;

if (Ask <= CurrentTakeProfitPrice)

CloseShort();

}

}

//+------------------------------------------------------------------+

 

Код потрясающий, спасибо.

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