[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 291

 
Thank you all! I figured it out... I first did it without IndicatorBuffers(2); and it didn't work...
 

Help please have an advisor to break through fractals. I picked up good parameters only need to add that it sets a lot of martingale (2 more when you lose).Or give me a clue about the advisor which will only double the lot without waiting for a draw to 2 run (if available).Here is an advisor:

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

|| Fractals.mq4 |

//| TO |

//| http://www.forex-tradexperts-to.narod.ru |

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

#property copyright "TO"

#property link "http://www.forex-tradexperts-to.narod.ru"





#include <WinUser32.mqh>.


extern int TP_Fract_3=300;

extern int SL_Fract_3=200;

extern int TP_Fract_11=500;

extern int SL_Fract_11=300;

extern bool buy_Fract_3=true;

extern bool sell_Fract_3=true;

extern bool buy_Fract_11=true;

extern bool sell_Fract_11=true;

extern bool podtvergdenie=false;

extern int tofract=10;

extern double lots=0.1;

extern int ID = 5452;


string com;

double spread;


int init()

{

com=DoubleToStr(ID,0);

spread=MarketInfo(Symbol(),MODE_SPREAD)*Point;

return(0);

}


int deinit()

{

return(0);

}


datetime t1,t2=0;


bool order(double price,int type,string c,int m)

{

int i;

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

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderComment()==c && OrderMagicNumber()==m && OrderOpenPrice()==price && OrderType()==type)return(false);

if(i==0)return(true);

}

if(OrdersTotal()==0)return(true);

}


int start()

{

int i,ret;

t1=Time[0];

if(t1!=t2)

{

int fract_buy_3=iHighest(Symbol(),Period(),MODE_HIGH,5,1);

int fract_sell_3=iLowest(Symbol(),Period(),MODE_LOW,5,1);

int fract_buy_11=iHighest(Symbol(),Period(),MODE_HIGH,21,1);

int fract_sell_11=iLowest(Symbol(),Period(),MODE_LOW,21,1);

if( fract_buy_3==3 && buy_Fract_3==true)

{

if(OrdersTotal()==0)if(order(High[fract_buy_3]+tofract*Point+spread,4,com,5))OrderSend(Symbol(),OP_BUYSTOP,lots,High[fract_buy_3]+tofract*Point+spread,10,High[fract_buy_3]+tofract*Point-SL_Fract_3*Point,High[fract_buy_3]+tofract*Point+spread+TP_Fract_3*Point,5);

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

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderComment()==com && OrderMagicNumber()==5 && OrderType()==4)

{

OrderModify(OrderTicket(),High[fract_buy_3]+tofract*Point+spread, High[fract_buy_3]+tofract*Point-SL_Fract_3*Point, High[fract_buy_3]+tofract*Point+spread+TP_Fract_3*Point,0,Blue);

break;

}

if(i==0)if(order(High[fract_buy_3]+tofract*Point+spread,4,com,5))

{

if(podtvergdenie)

{

ret=MessageBox("Signal at "+Symbol()+" H1 BUYSTOP "+"{Set Order?", "Signal", MB_YESNO|MB_ICONQUESTION);

if(ret==IDYES)OrderSend(Symbol(),OP_BUYSTOP,lots,High[fract_buy_3]+tofract*Point+spread,10,High[fract_buy_3]+tofract*Point-SL_Fract_3*Point,High[fract_buy_3]+tofract*Point+spread+TP_Fract_3*Point,5);

}

if(!podtvergdenie)OrderSend(Symbol(),OP_BUYSTOP,lots,High[fract_buy_3]+tofract*Point+spread,10,High[fract_buy_3]+tofract*Point-SL_Fract_3*Point,High[fract_buy_3]+tofract*Point+spread+TP_Fract_3*Point,com,5);

}

}

}

if( fract_sell_3==3 && sell_Fract_3==true)

{

if(OrdersTotal()==0)if(order(Low[fract_sell_3]-tofract*Point,5,com,5))OrderSend(Symbol(),OP_SELLSTOP,lots,Low[fract_sell_3]-tofract*Point,10,Low[fract_sell_3]+spread-tofract*Point+SL_Fract_3*Point,Low[fract_sell_3]-tofract*Point-TP_Fract_3*Point,com,5);

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

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderComment()==com && OrderMagicNumber()==5 && OrderType()==5)

{

OrderModify(OrderTicket(),Low[fract_sell_3]-tofract*Point,Low[fract_sell_3]+spread-tofract*Point+SL_Fract_3*Point,Low[fract_sell_3]-tofract*Point-TP_Fract_3*Point,0,Red);

break;

}

if(i==0)if(order(Low[fract_sell_3]-tofract*Point,5,com,5))

{

if(podtvergdenie)

{

ret=MessageBox("Signal on "+Symbol()+"H1 SELLSTOP "+"{Set Order?", "Signal", MB_YESNO|MB_ICONQUESTION);

if(ret==IDYES)OrderSend(Symbol(),OP_SELLSTOP,lots,Low[fract_sell_3]-tofract*Point,10,Low[fract_sell_3]+spread-tofract*Point+SL_Fract_3*Point,Low[fract_sell_3]-tofract*Point-TP_Fract_3*Point,5);

}

if(!podtvergdenie)OrderSend(Symbol(),OP_SELLSTOP,lots,Low[fract_sell_3]-tofract*Point,10,Low[fract_sell_3]+spread-tofract*Point+SL_Fract_3*Point,Low[fract_sell_3]-tofract*Point*Point,com,5);

}

}

}

if( fract_buy_11==11 && buy_Fract_11==true)

{

if(OrdersTotal()==0)if(order(High[fract_buy_11]+tofract*Point+spread,4,com,21))orderSend(Symbol(),OP_BUYSTOP,lots,High[fract_buy_11]+tofract*Point+spread,10,High[fract_buy_11]+tofract*Point-SL_Fract_11*Point,High[fract_buy_11]+tofract*Point+spread+TP_Fract_11*Point,21);

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

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderComment()==com && OrderMagicNumber()==21 && OrderType()==4)

{

OrderModify(OrderTicket(),High[fract_buy_11]+tofract*Point+spread, High[fract_buy_11]+tofract*Point-SL_Fract_11*Point, High[fract_buy_11]+tofract*Point+spread+TP_Fract_11*Point,0,Blue);

break;

}

if(i==0)if(order(High[fract_buy_11]+tofract*Point+spread,4,com,21))

{

if(podtvergdenie)

{

ret=MessageBox("Signal on "+Symbol()+"H4 BUYSTOP "+"{Set Order?", "Signal", MB_YESNO|MB_ICONQUESTION);

if(ret==IDYES)OrderSend(Symbol(),OP_BUYSTOP,High[fract_buy_11]+tofract*Point+spread,10,High[fract_buy_11]+tofract*Point-SL_Fract_11*Point,High[fract_buy_11]+tofract*Point+spread+TP_Fract_11*Point,21);

}

if(!podtvergdenie)OrderSend(Symbol(),OP_BUYSTOP,lots,High[fract_buy_11]+tofract*Point+spread,10,High[fract_buy_11]+tofract*Point-SL_Fract_11*Point,High[fract_buy_11]+tofract*Point+spread+TP_Fract_11*Point,com,21);

}

}

}

if( fract_sell_11==11 && sell_Fract_11==true)

{

if(OrdersTotal()==0)if(order(Low[fract_sell_11]-tofract*Point,5,com,21))orderSend(Symbol(),OP_SELLSTOP,lots,Low[fract_sell_11]-tofract*Point,10,Low[fract_sell_11]+spread-tofract*Point+SL_Fract_11*Point,Low[fract_sell_11]-tofract*Point-TP_Fract_11*Point,com,21);

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

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderComment()==com && OrderMagicNumber()==21 && OrderType()==5)

{

OrderModify(OrderTicket(),Low[fract_sell_11]-tofract*Point,Low[fract_sell_11]+spread-tofract*Point+SL_Fract_11*Point,Low[fract_sell_11]-tofract*Point-TP_Fract_11*Point,0,Red);

break;

}

if(i==0)if(order(Low[fract_sell_11]-tofract*Point,5,com,21))

{

if(podtvergdenie)

{

ret=MessageBox("Signal on "+Symbol()+"H4 BUYSTOP "+"{Set Order?", "Signal", MB_YESNO|MB_ICONQUESTION);

if(ret==IDYES)OrderSend(Symbol(),OP_SELLSTOP,lots,Low[fract_sell_11]-tofract*Point,10,Low[fract_sell_11]+spread-tofract*Point+SL_Fract_11*Point,Low[fract_sell_11]-tofract*Point-TP_Fract_11*Point,21);

}

if(!podtvergdenie)OrderSend(Symbol(),OP_SELLSTOP,lots,Low[fract_sell_11]-tofract*Point,10,Low[fract_sell_11]+spread-tofract*Point+SL_Fract_11*Point,Low[fract_sell_11]-tofract*Point*Point,com,21);

}

}

}

t2=Time[0];

}

return(0);

}

I'm bad at writing Russian, sorry!

 
AppaRat:

I'm not good at writing Russian, sorry!

You don't even know how to insert code. I don't want to read this.
 

Tell me who can help with the Klimov block, the problem is that it does not return the value of the last closed, but the value of the last closed by the condition

so at 2 conditions

bool BuystopLotA=isCloseLastPosByStop(NULL,OP_BUY,MagBuy,LotA);
и
bool BuyTakeLotB=isCloseLastPosByTake(NULL,OP_BUY,MagBuy,LotB);

it returns both values True,

how to make it return only last closed order and not last one by a conditional,

i added a lot check to the code for my convenience

//+----------------------------------------------------------------------------+
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.05.2008                                                     |
//|  Описание : Возвращает флаг закрытия последней позиции по стопу.           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
bool isCloseLastPosByStop(string sy="", int op=-1, int mn=-1, int ll=-1) {
  datetime t;
  double   ocp, osl;
  int      dg, i, j=-1, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
             if (ll<0 || OrderLots()==ll) {
              if (t<OrderCloseTime()) {
                t=OrderCloseTime();
                j=i;
              }
            }
          }
        }
      }
    }
  }
} 
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
    dg=MarketInfo(sy, MODE_DIGITS);
    if (dg==0) if (StringFind(OrderSymbol(), "JPY")<0) dg=4; else dg=2;
    ocp=NormalizeDouble(OrderClosePrice(), dg);
    osl=NormalizeDouble(OrderStopLoss(), dg);
    if (ocp==osl) return(True);
  }
  return(False);
}



//+----------------------------------------------------------------------------+
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.05.2008                                                     |
//|  Описание : Возвращает флаг закрытия последней позиции по тейку.           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
bool isCloseLastPosByTake(string sy="", int op=-1, int mn=-1, int ll=-1) {
  datetime t;
  double   ocp, otp;
  int      dg, i, j=-1, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
             if (ll<0 || OrderLots()==ll) {
              if (t<OrderCloseTime()) {
                t=OrderCloseTime();
                j=i;
              }
            }
          }
        }
      }
    }
  }
} 
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
    dg=MarketInfo(sy, MODE_DIGITS);
    if (dg==0) if (StringFind(OrderSymbol(), "JPY")<0) dg=4; else dg=2;
    ocp=NormalizeDouble(OrderClosePrice(), dg);
    otp=NormalizeDouble(OrderTakeProfit(), dg);
    if (ocp==otp) return(True);
  }
  return(False);
}
 
FoxUA:

Tell me who can help with the Klimov block, the problem is that it does not return the value of the last closed, but the value of the last closed by the condition

so at 2 conditions

it returns both values True,

how to make it return only last closed order and not last one by a conditional,

i've added a lot check to the code for my convenience


Did you add the check of lots to this function? Now they check the last closed positions with the passed lot, and the lot is probably always equal to zero, or an integer. The variable ll must be of type double. Why do we need lot checking here anyway?

You write down what you want to achieve, and they will tell you :)

 

Yes, and why is the lot an int? The lot has always been double.

You could do this, when you have one order left, determine which order is left and search for the opposite one.

 
FoxUA:

Tell me who can help with the Klimov block...

Don't duplicate posts in different threads, it's bad form.
 
artmedia70:

Check lots in the function added by yourself? Now they check the last closed positions with the passed lot, and the lot is probably always equal to zero, or an integer. The variable ll must be of type double. Why do we need lot checking here anyway?

You write down what you want to achieve, and they will tell you :)

I have already achieved everything, but there is one bug, it is at a certain moment an order I don't need pops up,

I tried to change it to int, originally it was double but I forgot to return it, and if I use a separate function without lot check, the result does not change, so maybe I did not check it correctly, help me to understand what is wrong with this bug

this is what the request looks like

вот так работает без проблем 
bool BuystopLotA=isCloseLastPosByStop(NULL,OP_BUY,MagBuy,LotA);
bool BuyTakeLotA=isCloseLastPosByTake(NULL,OP_BUY,MagBuy,LotA);
bool SellstopLotC=isCloseLastPosByStop(NULL,OP_SELL,MagBuy,LotC);
bool SellTakeLotC=isCloseLastPosByTake(NULL,OP_SELL,MagBuy,LotC);

при добовлении вот этих запросов
bool BuystopLotB=isCloseLastPosByStop(NULL,OP_BUY,MagBuy,LotB);
bool BuyTakeLotB=isCloseLastPosByTake(NULL,OP_BUY,MagBuy,LotB);

начинает возвращять True не по одному а по двум запросам 
BuyTakeLotB и BuystopLotA



 
Roger:

Yes, and why is the lot an int? The lot has always been double.

You could do this, when you have one order left, determine which order is left and search for the opposite one.


it is not so simple because the conditions for opening may be 2 on the sell, and then this search will not find anything
 
granit77:
Don't duplicate posts in different threads, it's bad form.

I'm sorry, I'll try harder to remember to delete identical posts from different threads,