Yoursin
забанен

 
Уровень 2


Группа "Стол заказов MQL"

Рейтинг 2081



РЕКОМЕНДУЮ




Лучшее от Yoursin



Доработать советника Комментариев 17
2017-09-10 12:28:24Рейтинг 0

Скрипт

Здравствуйте! ВЫ МОГЛИ БЫ ИЗ СОВЕТНИКА ВЗЯТЬ ФУНКЦИИ И СОЗДАТЬ НА ИХ ОСНОВЕ СКРИПТ ЗАКРЫТИЯ ОДРЕРОВ В ПРОФИТ?

СОВЕТНИК SIGMA:

//+------------------------------------------------------------------+
//| Sigma.mq4 |
//| Copyright 2017, AM2 |
//| www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright «Copyright 2017, AM2»
#property link «www.forexsystems.biz»
#property version «1.00»
#property strict

//--- Inputs
extern double Lots = 0.1; // лот
extern double Risk = 3; // риск
extern double KLot = 2; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern double Profit = 5; // общий язь в валюте
extern double BuyProfit = 20; // язь по баям
extern double SellProfit = 20; // язь по селам
extern int StopLoss = 0; // лось
extern int TakeProfit = 0; // язь
extern int CandleProfit = 0; // 1-кроем профит в конце свечи
extern int Slip = 30; // реквот
extern int Magic = 123; // магик

datetime t=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,Lot(type),NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| Лот для усреднителя |
//+------------------------------------------------------------------+
double Lot(int type)
{
double lot=Lots;
if(Lots==0) lot=AccountBalance()*Risk/100000;
double MinimumLot = MarketInfo(NULL,MODE_MINLOT);
double MaximumLot = MarketInfo(NULL,MODE_MAXLOT);

lot=NormalizeDouble(lot*MathPow(KLot,CountTrades(type)),2);

if(lot>MaxLot)lot=Lots;
if(lot<MinimumLot) lot=MinimumLot;
if(lot>MaximumLot) lot=MaximumLot;
return(lot);
}
//+------------------------------------------------------------------+
//| Подсчет позиций |
//+------------------------------------------------------------------+
int CountTrades(int ot=-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()==0 && (ot==0 || ot==-1)) count++;
if(OrderType()==1 && (ot==1 || ot==-1)) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseType(int type)
{
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()==OP_BUY && type==0)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==OP_SELL && type==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 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);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(t!=Time[1])
{
if(Close[1]>Open[1])
{
PutOrder(0,Ask);
}
if(Close[1]<Open[1])
{
PutOrder(1,Bid);
}
// кроем профит в конце свечи
if(CandleProfit>0 && AllProfit()>0) CloseAll();
t=Time[1];
}

//кроем все
if(Profit>0 && AllProfit()>Profit)
{
CloseAll();
}

//кроем баи
if(BuyProfit>0 && AllProfit(0)>BuyProfit) CloseAll(0);

//кроем селы
if(SellProfit>0 && AllProfit(1)>SellProfit) CloseAll(1);

Comment("\n All Profit: ",AllProfit(),
"\n Buy Profit: ",AllProfit(0),
"\n Sell Profit: ",AllProfit(1));
}
//+------------------------------------------------------------------+

ВОТ ФУНКЦИИ КОТОРЫЕ НУЖНЫ В СКРИПТЕ:

extern double Profit = 5; // общий язь в валюте
extern double BuyProfit = 20; // язь по баям
extern double SellProfit = 20; // язь по селам
extern int StopLoss = 0; // лось
extern int TakeProfit = 0; // язь
extern int CandleProfit = 0; // 1-кроем профит в конце свечи

P.S.
ДАННЫЙ СКРИПТ НУЖНО ВЕШАТЬ НА ГРАФИК К СОВЕТНИКУ
  • 0
  • Просмотров: 1446
  • 15 сентября 2017, 11:59
  • Yoursin
Понравилcя материал? Не забудьте поставить плюс и поделиться в социальной сети!

Вступите в группу "Стол заказов MQL", чтобы следить за обновлениями
ПРИСОЕДИНИТЬСЯ К ГРУППЕ
присоединиться
  Предыдущая запись в группе
Поправить советник
Следующая запись в группе  
советник
15 сентября 2017
15 сентября 2017

Комментарии (1)

+
0


#property copyright "Copyright © 2008, PRMQuotes Software Corp."
#property link      ""
//+------------------------------------------------------------------+
//| EX4 imports                                                      |
//+------------------------------------------------------------------+
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| global variables to program:                                     |
//+------------------------------------------------------------------+
double Price[2];
int    giSlippage;
bool   CloseOrdersWithPlusProfit = true;
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
void start() {
  int iOrders=OrdersTotal()-1, i;
  
  if(CloseOrdersWithPlusProfit) {
    for(i=iOrders; i>=0; i--) {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderProfit() >= 0)) {
        if((OrderType()<=OP_SELL) && GetMarketInfo()) {
          if(!OrderClose(OrderTicket(),OrderLots(),Price[1-OrderType()],giSlippage)) Print(OrderError());
        }
      }
    }
  }
}
//+------------------------------------------------------------------+
//| Function..: OrderError                                           |
//+------------------------------------------------------------------+
string OrderError() {
  int iError=GetLastError();
  return(StringConcatenate("Order:",OrderTicket()," GetLastError()=",iError," ",ErrorDescription(iError)));
}
//+------------------------------------------------------------------+
//| Function..: GetMarketInfo                                        |
//+------------------------------------------------------------------+
bool GetMarketInfo() {
  RefreshRates();
  Price[0]=MarketInfo(OrderSymbol(),MODE_ASK);
  Price[1]=MarketInfo(OrderSymbol(),MODE_BID);
  double dPoint=MarketInfo(OrderSymbol(),MODE_POINT);
  if(dPoint==0) return(false);
  giSlippage=(Price[0]-Price[1])/dPoint;
  return(Price[0]>0.0 && Price[1]>0.0);
}
//+------------------------------------------------------------------+
avatar

  14  Syte Сообщений: 399

  • 16 октября 2017, 16:36

Зарегистрируйтесь или авторизуйтесь, чтобы оставить комментарий
Начать торговлю с Альпари