Tutte le domande dei nuovi arrivati su MQL4 e MQL5, aiuto e discussione su algoritmi e codici - pagina 629

 
Chi altro può aiutare?).
 
Rustam Bikbulatov:
Chi altro può aiutare?).

Sembra che ti siano state date risposte ed esempi esaurienti, ma hai ancora bisogno di leggere l'aiuto per capire come vengono chiamate le funzioni e perché viene usato il modificatore statico.

Ecco un altro modo, forse ti sarà più facile da capire:

int N(bool reset=false) // если вызываем N() то возвращает следующее значение n++, при первом вызове n=0, но вернет 1, т.к. n=0, а затем n++, если нужно 0 то 
			// или  static int n=-1; или вызывайте сначала N(true)
  {                     // если вызываем N(true), то сбрасываем n=0 и возвращзаем 0
   static int n=0;
   if(reset) n=0; else n++;
   return n;
  }
 
Igor Makanu:

Sembra che ti siano state date risposte ed esempi esaurienti, ma hai ancora bisogno di leggere l'aiuto per capire come vengono chiamate le funzioni e perché viene usato il modificatore statico.

Ecco un'altra variante, forse questo vi renderà più facile la comprensione:

Il primo esempio mostra una chiamata di funzione quando non viene presa nessuna posizione e il risultato restituito viene confrontato.

if( ((OpenB-Ask)/ma+TimeB/60) > N() )

Ecco perché probabilmente vale la pena di fare solo il ritorno senza azzerare e aggiungere. Che ho implementato in 2 varianti

 
//+------------------------------------------------------------------+
//|                                                 elliotbutton.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
  ButtonCreate();
  ButtonCreate(0,"ButtonMinor",0,10,60,50,50,CORNER_LEFT_UPPER,"(i)","Arial",12,clrBlack, C'236,233,216',clrNONE,false,false,false,false,0);
  
  
     return(INIT_SUCCEEDED);
  }

void OnTick()
  {
  }

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
         if (ObjectGetInteger(0,"Button",OBJPROP_STATE,0)==true) 
          {
               int      x     =(int)lparam;
               int      y     =(int)dparam;
               datetime dt    =0;
               double   price =0;
               int      window=0;
                        if(ChartXYToTimePrice(0,x,y,window,dt,price))  
                         {
                         PrintFormat("Window=%d X=%d  Y=%d  =>  Time=%s  Price=%G",window,x,y,TimeToString(dt),price);
                                 if(ChartTimePriceToXY(0,window,dt,price,x,y))
                                     PrintFormat("Time=%s  Price=%G  =>  X=%d  Y=%d",TimeToString(dt),price,x,y);
                                 ChartRedraw(0);
                         }
               TextCreate(0,"Text "+string(MathRand()),0,dt,price,"i","Arial",10,clrBlack,0.0,ANCHOR_LEFT_UPPER,false,true,false,0); 
            
               TextCreate(0,"Text "+string(MathRand()),0,dt,price,"ii","Arial",10,clrBlack,0.0,ANCHOR_LEFT_UPPER,false,true,false,0); 
          
               TextCreate(0,"Text "+string(MathRand()),0,dt,price,"iii","Arial",10,clrBlack,0.0,ANCHOR_LEFT_UPPER,false,true,false,0);
           
               TextCreate(0,"Text "+string(MathRand()),0,dt,price,"iv","Arial",10,clrBlack,0.0,ANCHOR_LEFT_UPPER,false,true,false,0); 
             
               TextCreate(0,"Text "+string(MathRand()),0,dt,price,"v","Arial",10,clrBlack,0.0,ANCHOR_LEFT_UPPER,false,true,false,0); 
               
               ObjectSetInteger(0,"Button",OBJPROP_STATE,False);
             }
                        
               
          if (ObjectGetInteger(0,"ButtonMinor",OBJPROP_STATE,0)==true) 
          {
               int      x     =(int)lparam;
               int      y     =(int)dparam;
               datetime dt    =0;
               double   price =0;
               int      window=0;
                        if(ChartXYToTimePrice(0,x,y,window,dt,price))  
                         {
                         PrintFormat("Window=%d X=%d  Y=%d  =>  Time=%s  Price=%G",window,x,y,TimeToString(dt),price);
                                 if(ChartTimePriceToXY(0,window,dt,price,x,y))
                                     PrintFormat("Time=%s  Price=%G  =>  X=%d  Y=%d",TimeToString(dt),price,x,y);
                                 ChartRedraw(0);
                         }
               TextCreate(0,"Text "+string(MathRand()),0,dt,price,"(i)","Arial",10,clrBlack,0.0,ANCHOR_LEFT_UPPER,false,true,false,0); 
            
               TextCreate(0,"Text "+string(MathRand()),0,dt,price,"(ii)","Arial",10,clrBlack,0.0,ANCHOR_LEFT_UPPER,false,true,false,0); 
          
               TextCreate(0,"Text "+string(MathRand()),0,dt,price,"(iii)","Arial",10,clrBlack,0.0,ANCHOR_LEFT_UPPER,false,true,false,0);
           
               TextCreate(0,"Text "+string(MathRand()),0,dt,price,"(iv)","Arial",10,clrBlack,0.0,ANCHOR_LEFT_UPPER,false,true,false,0); 
             
               TextCreate(0,"Text "+string(MathRand()),0,dt,price,"(v)","Arial",10,clrBlack,0.0,ANCHOR_LEFT_UPPER,false,true,false,0); 
               
               ObjectSetInteger(0,"ButtonMinor",OBJPROP_STATE,False);
               
            
           }
 }
            
  
  

void OnDeinit(const int reason)
  {
   ObjectDelete(0,"Button");
   ObjectDelete(0,"ButtonMinor");
  }
  
bool ButtonCreate(const long              chart_ID=0,               // ID графика 
                  const string            name="Button",            // имя кнопки 
                  const int               sub_window=0,             // номер подокна 
                  const int               x=10,                      // координата по оси X 
                  const int               y=10,                      // координата по оси Y 
                  const int               width=50,                 // ширина кнопки 
                  const int               height=50,                // высота кнопки 
                  const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // угол графика для привязки 
                  const string            text="i",                 // текст 
                  const string            font="Arial",             // шрифт 
                  const int               font_size=10,             // размер шрифта 
                  const color             clr=clrBlack,             // цвет текста 
                  const color             back_clr=C'236,233,216',  // цвет фона 
                  const color             border_clr=clrNONE,       // цвет границы 
                  const bool              state=false,              // нажата/отжата 
                  const bool              back=false,               // на заднем плане 
                  const bool              selection=false,          // выделить для перемещений 
                  const bool              hidden=false,              // скрыт в списке объектов 
                  const long              z_order=0)                // приоритет на нажатие мышью 
  { 

   ResetLastError(); 

   if(ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0)) 
     { 
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); 
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); 
   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width); 
   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height); 
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); 
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); 
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font); 
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr); 
   ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr); 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
   ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
      }
  return(true); 
 }
 
 bool TextCreate(const long              chart_ID=0,              // ID графика 
                const string            name="Text",              // имя объекта 
                const int               sub_window=0,             // номер подокна 
                datetime                time=0,                   // время точки привязки 
                double                  price=0,                  // цена точки привязки 
                const string            text="Text",              // сам текст 
                const string            font="Arial",             // шрифт 
                const int               font_size=10,             // размер шрифта 
                const color             clr=clrBlack,             // цвет 
                const double            angle=0.0,                // наклон текста 
                const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // способ привязки 
                const bool              back=false,               // на заднем плане 
                const bool              selection=true,           // выделить для перемещений 
                const bool              hidden=true,              // скрыт в списке объектов 
                const long              z_order=0)                // приоритет на нажатие мышью 
  { 

   ResetLastError(); 

   if(ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price)) 
     { 
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); 
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font); 
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); 
   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle); 
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor); 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
     }
   return(true); 
 } 



  
  

scrivere un EA che quando clicco sul pulsante, crea un testo nel posto del grafico, come mostrato dal mouse. Ora il mio Expert Advisor crea solo il testo al posto del pulsante.

 

Ciao, come faccio a fare in modo che quando trascino manualmente un ordine pendente buystop, l'altro ordine pendente sellstop si sposti con esso?

Come posso legare uno all'altro, in modo che quando ne muovo uno, li muova entrambi contemporaneamente?

 


Здравствуйте. У меня алгоритм такой 
//----------------------------------------------------------------------------
if (CountBuy() == 0)
{

BuySignal = h1; tttp=1; 
if (BuySignal > 0 && tttp==1 && h2>0)
{
CloseSell();
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, comment, Magic, 0, Blue);

if (ticket > 0)
{

if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
{

SL = NormalizeDouble(Ask-StopLoss*Point, Digits);

TP = NormalizeDouble(Ask+TakeProfit*Point, Digits);

res = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0);
if (!res)

Print("Ошибка модификации ордера на покупку, ASK=" + DoubleToStr(Ask) + ", SL=" + DoubleToStr(SL) + ", TP=" + DoubleToStr(TP)); 
}
}
}
}
if (CountSell() == 0)
{
SellSignal= l1; tttp=-1;
if (SellSignal > 0 && tttp==-1 && l2>0)
{
CloseBuy();
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, comment, Magic, 0, Red);
if (ticket > 0)
{
if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
{
SL = NormalizeDouble(Bid+StopLoss*Point, Digits);
TP = NormalizeDouble(Bid-TakeProfit*Point, Digits);
res = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0);
if (!res)
Print("Ошибка модификации ордера на продажу, BID=" + DoubleToStr(Bid) + ", SL=" + DoubleToStr(SL) + ", TP=" + DoubleToStr(TP)); 
}
}
}
}
} 
//------------------------------------------------------------------------------------------
Пытаюсь сделать, чтоб условия на открытие ордера проверялось бы через какое-то кол-во баров, а так сразу открывается другой ордер
 
Carcass77:

Perché lo spam?

 
Konstantin Nikitin:

Perché lo spam?

Quello che hai scritto in diversi thread? Posso tirarlo giù.
 
Ihor Herasko:

Scrivete i vostri zecchini e metteteli nel tester di strategia.

Saluti. Puoi dirmi qual è il problema e come risolverlo?

Ho cambiato alcuni candelieri nella storia per i test, per il 1°, 2°, 3° e 6°.

Durante il test, il secondo viene elaborato, il terzo viene disegnato (senza elaborazione), e si ferma dando un errore fermato a causa di Stop Out



 

Buon pomeriggio

Ho una situazione molto semplice ma ho problemi a risolverla.

Per favore, ditemi cosa sto sbagliando:

problema: non riesco a legare l'indicatore personalizzato(i-DRP...) all'Expert Advisor (DR Test) tramite iCustom

grazie in anticipo