[Qualsiasi domanda da principiante, per non ingombrare il forum. Professionisti, non passate oltre. Da nessuna parte senza di te - 4. - pagina 469

 

Ciao a tutti.

Ho una domanda dal tutorial MQL4.

Quando si passa la MA dall'alto o dal basso non dà nessun messaggio?

Per favore, scrivi cosa c'è che non va.

bool Fact_Up= true;
bool Fact_Dn = true;
//-----------------------------------------------------------------
int start()
   {
   double MA;
//-----------------------------------------------------------------
   MA= iMA(NULL,0,Period_MA,0,MODE_SMA,PRICE_CLOSE,0);
//-----------------------------------------------------------------
   if(Bid > MA && Fact_Up == true)
      {
      Fact_Dn = true;
      Fact_Up = false;
      Alert("Цена находится выше МА(",Period_MA,").");
      }
//------------------------------------------------------------------
   if(Bid < MA && Fact_Dn == true)
      {
      Fact_Up = true;
      Fact_Dn = false;
      Alert("Цена находится ниже МА(",Period_MA,").");
      }
//------------------------------------------------------------------
   return;
}
 
Pacman:

Ciao a tutti.

Ho una domanda dal tutorial MQL4.

Quando si passa la MA dall'alto o dal basso non dà nessun messaggio?

Per favore, scrivi cosa c'è che non va.


Nel tester?
 
PapaYozh:

Nel tester?
No, su un conto demo.
 

Buon pomeriggio,
Sto facendo un EA che sposta lo stop a pareggio dopo l'apertura. Cioè, modifica l'ordine, ma il problema è che modifica costantemente quello che sembra un trailing stop. Come farlo modificare una volta e poi solo una volta. Ho anche inserito una variabile nel codice che mod1=1 ma poi mod1 deve essere più grande, ma il linguaggio per qualche motivo non lo nota.

Grazie!

while(true)
{
if (tip==0 && open_b==true && mod1<=1 && Bid>ma+15*Point)
{
Alert("popitkaa perenesti stop v b/u" ,ticket);
RefreshRates();
modify=OrderModify(ticket,Ask,Bid-mod*Point,0,0);
if(modify==true)
{
Alert("zakrit modificirovanij order",ticket);
mod1++;
return;
}
return;
}
if (tip==1 && open_s==true && mod1<=1 && Bid<ma+15*Point)
{
Alert("popitkaa perenesti stop ",ticket, "v b/u");
RefreshRates();
modify=OrderModify(ticket,Bid,Ask+mod*Point,0,0);
if(modify==true)
{
Alert("zakrit modificirovanij order",ticket);
mod1++;
return;
}
return;
}
break;
}

 
'00FF33' - numero non valido C:\Alpari\experts\customer.mq4 (66, 173) ??? Come faccio a inserire correttamente il colore?
 
kostikk:

Salve,
Sto facendo un consulente che sposta lo stop al pareggio dopo l'apertura. Cioè, modifica l'ordine, ma il problema è che lo modifica costantemente, qualcosa come un trailing stop. Come farlo modificare una volta e poi solo una volta. Ho anche aggiunto una variabile nel codice, mod1=1 ma mod1 deve essere più grande, ma il linguaggio non sa quale sia il problema.

Grazie!

Già fatto per te e funziona bene

KimIV01.11.2006 18:49

Raccomando il mio codice testato
extern int    LevelProfit  = 30;            // Уровень профита
extern int    LevelWLoss   = 2;             // Уровень безубытка
extern color  clModifyBuy  = Aqua;          // Цвет модификации покупки
extern color  clModifySell = Tomato;        // Цвет модификации продажи
 
 
//+----------------------------------------------------------------------------+
//|  Перенос уровня StopLoss                                                   |
//|  Параметры:                                                                |
//|    ldStop  - уровень StopLoss                                              |
//|    lcColor - цвет модификации                                              |
//+----------------------------------------------------------------------------+
void ModifyStopLoss(double ldStop, color lcColor=CLR_NONE) {
  double ldOpen=OrderOpenPrice();
  double ldTake=OrderTakeProfit();
 
  OrderModify(OrderTicket(), ldOpen, ldStop, ldTake, 0, lcColor);
}
 
//+----------------------------------------------------------------------------+
//|  Перенос стопа в безубыток                                                 |
//+----------------------------------------------------------------------------+
void MovingInWL() {
  int i, k=OrdersTotal();
 
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Symbol()) {
        if (OrderType()==OP_BUY) {
          if (OrderStopLoss()-OrderOpenPrice()<LevelWLoss*Point) {
            if (Bid-OrderOpenPrice()>LevelProfit*Point) {
              ModifyStopLoss(OrderOpenPrice()+LevelWLoss*Point, clModifyBuy);
            }
          }
        }
        if (OrderType()==OP_SELL) {
          if (OrderStopLoss()==0 || OrderOpenPrice()-OrderStopLoss()<LevelWLoss*Point) {
            if (OrderOpenPrice()-Ask>LevelProfit*Point) {
              ModifyStopLoss(OrderOpenPrice()-LevelWLoss*Point, clModifySell);
            }
          }
        }
      }
    }
  }
}
//+----------------------------------------------------------------------------+



https://forum.mql4.com/ru/4689

 
Dimka-novitsek:
'00FF33' - numero non valido C:\Alpari\experts\customer.mq4 (66, 173) ??? Come faccio a inserire correttamente il colore?


In realtà c'è un tipo speciale di variabili nel linguaggio - il colore è chiamato. Per esempio:

doppio Velichina;

MyLine;

Velichina=2,569;

MyLine=Rosso;

 

Come posso cambiare il nome della finestra del grafico?

 

Aiuto! Per qualche motivo non apre posizioni SELL, ma solo BUY?



#property copyright "eevviill"
#property link "itisallillusion@gmail.com"


extern string os = "Настройки лота и стопов";
extern double Lot = 0.1;
extern bool use_percent_of_deposit = false;
extern double Risk = 1;
extern int StopLoss = 0;
extern int TakeProfit = 0;

extern string slug = "Дополнительные настройки";
extern string pus1 = "";
extern bool use_exit = true;
extern int slippage = 2;
extern int magic = 4335;
extern string comment = "HA nonlag";
extern int MaxAttempts = 4;

extern string pus2 = "";
extern string V_R = "Время работы";
extern bool use_work_time = true;
extern int Start = 0;
extern int Stop = 24;

extern string pus3 = "";
extern string mar = "Мартингейл";
extern bool use_martini = false;
extern int CloseProfit_pips = 22;
extern double Lot_koef = 1.6;
extern int step = 40;

extern string pus4 = "";
extern string bez_ub = "Безубыток";
extern bool use_bezubitok = false;
extern int Bez_Ub_Level = 8;
extern int Bez_Ub_Size = 1;

extern string pus5 = "";
extern string tre_st = "Трейлинг стоп";
extern bool use_traling_stop = false;
extern int Trailing_Stop = 10;

extern string pus6 = "";
extern string ATR_p = "ATR";
extern bool use_ATR = false;
extern int ATR_period = 14;
extern double ATR_min_level = 0.0004;

extern string pus7 = "";
extern string ind1 = "HA nonlagma v4";
extern int Price = 0;
extern int Length = 21;
extern int Displace = 0;
extern int Filter = 0;
extern int Color = 1;
extern int ColorBarBack = 0;
extern double Deviation = 0;

extern double Cycle = 4;






double SLbuy=0, SLsell=0, TPbuy=0, TPsell=0;
int buy,sell,Sig_p,Sig_ex_p;
static int prevtime = 0;





//////////////////////////////////////////////////////////////
int init()
{
prevtime = iTime(Symbol(),0,0);


//ATR_level(4) && JPY_Point
if (StringFind(Symbol(), "JPY", 0) != -1) ATR_min_level *=100;


return;
}





////////////////////////////////////////////////////////////
int start(){
if (iTime(Symbol(), 0, 0) == prevtime) {Sleep(50);return(0);}
prevtime = iTime(Symbol(),0,0);

//проверка на разрешение торговли от брокера
while(!IsTradeAllowed()) Sleep(2000);

//фильтр ATR
if(use_ATR)
{
double ATR = iATR(Symbol(),0,ATR_period,1);
if(ATR<ATR_min_level) return;
}

//фильтр время
if(use_work_time)
{
if(Hour()<Start || Hour()>=Stop) return;
}

//мартингейл
if(use_martini) {use_bezubitok=false;use_traling_stop=false;use_percent_of_deposit=false;use_exit=false;}
if(use_martini) martini_f();

//закрытие всех ордеров при общем профите(пункты)- для мартини
if(use_martini)
{
if(Profit_f()>=CloseProfit_pips) Close_f();
}

//трейлинг стоп
if((Bez_Ub_Level>Trailing_Stop) && use_traling_stop) use_bezubitok=false;
if(use_traling_stop) Traling_Stop_f();

//безубыток
if(use_bezubitok) BezUb();

//SL && TP
if(!use_martini)
{
if(StopLoss>0) {SLbuy=NormalizeDouble(Ask-StopLoss*Point,Digits); SLsell=NormalizeDouble(Bid+StopLoss*Point,Digits);}
if(TakeProfit>0) {TPbuy=NormalizeDouble(Ask+TakeProfit*Point,Digits);TPsell=NormalizeDouble(Bid-TakeProfit*Point,Digits);}
}

//расчёт лота от % депозита
if(use_percent_of_deposit) Lot=GetLot();

//Сигнал на вход
Sig_p =Sig_f();
//Сигнал на выход
Sig_ex_p = Sig_ex_f();


//Выход
for(int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS);
{
if(OrderMagicNumber()==magic)
{
bool ticket_ex;
for (int j_ex = 0;j_ex < MaxAttempts; j_ex++)
{
while(IsTradeContextBusy()) Sleep(2000);

if(OrderType()==OP_BUY && ((use_exit && Sig_p<0))) ticket_ex=OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Yellow);
if(OrderType()==OP_SELL && ((use_exit && Sig_p>0))) ticket_ex=OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Yellow);
if(ticket_ex==true)break;
}
}
}
}


//подсчёт открытых позиций
CountOpenPositions();

//Вход
int ticket_op=0;
for (int j_op = 0; j_op < MaxAttempts; j_op++)
{
while(IsTradeContextBusy()) Sleep(2000);

if(Sig_p>0 && buy==0&& sell==0) ticket_op=OrderSend(Symbol(),OP_BUY,Lot,Ask,slippage,SLbuy,TPbuy,comment,magic,0,Green);
if(Sig_p<0 && sell==0&& buy==0) ticket_op=OrderSend(Symbol(),OP_SELL,Lot,Bid,slippage,SLsell,TPsell,comment,magic,0,OrangeRed);
if(ticket_op>-1)break;
}





return(0);
}








//расчёт функций
/////////////////////////////////////////////////////////////////////////////////////////////
int Sig_f()
{
//объявление индикаторов
double ind1 = iCustom(Symbol(),0,"Heiken_ashi_nonlagma_v4",Price,Length,Displace,Filter,Color,ColorBarBack,Deviation,1,1); //buy
double ind2 = iCustom(Symbol(),0,"Heiken_ashi_nonlagma_v4",Price,Length,Displace,Filter,Color,ColorBarBack,Deviation,2,1); //sell


//сигнал для бай
if(ind1<50000) return(1);

//сигнал для сел
if(ind2<50000) return(-1);


return(0);
}

/////////////////////////////////////////////////////////////////////////////////////////////
int Sig_ex_f()
{
//объявление индикаторов
double ind1 = iCustom(Symbol(),0,"Heiken_ashi_nonlagma_v4",Price,Length,Displace,Filter,Color,ColorBarBack,Deviation,1,1); //exit sell
double ind2 = iCustom(Symbol(),0,"Heiken_ashi_nonlagma_v4",Price,Length,Displace,Filter,Color,ColorBarBack,Deviation,2,1); //exit buy


//сигнал для выход селл
if(ind1<50000) return(1);

//сигнал для выход бай
if(ind2<50000) return(-1);



return(0);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double GetLot()
{
double Free =AccountFreeMargin();
double One_Lot =MarketInfo(Symbol(),MODE_MARGINREQUIRED);
double Min_Lot =MarketInfo(Symbol(),MODE_MINLOT);
double Max_Lot =MarketInfo(Symbol(),MODE_MAXLOT);
double Step =MarketInfo(Symbol(),MODE_LOTSTEP);
double Lot =MathFloor(Free*Risk/100/One_Lot/Step)*Step;
if(Lot<Min_Lot) Lot=Min_Lot;
if(Lot>Max_Lot) Lot=Max_Lot;
if(Lot*One_Lot>Free) return(0.0);

return(Lot);
}

////////////////////////////////////////////////////////////////
void BezUb()
{
for (int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS);
{
if (OrderMagicNumber()==magic)
{
if (OrderType()==OP_BUY)
{
if(OrderStopLoss()!=OrderOpenPrice()+NormalizeDouble(Bez_Ub_Size*Point,Digits))
{
if (Bid>OrderOpenPrice()+Bez_Ub_Level*Point && (OrderStopLoss()<OrderOpenPrice() || OrderStopLoss()==0))
{
OrderModify(OrderTicket(),0,OrderOpenPrice()+NormalizeDouble(Bez_Ub_Size*Point,Digits),OrderTakeProfit(),0,Blue);
}
}
}


if (OrderType()==OP_SELL)
{
if(OrderStopLoss()!=OrderOpenPrice()-NormalizeDouble(Bez_Ub_Size*Point,Digits))
{
if (Ask<OrderOpenPrice()-Bez_Ub_Level*Point && (OrderStopLoss()>OrderOpenPrice() || OrderStopLoss()==0))
{
OrderModify(OrderTicket(),0,OrderOpenPrice()-NormalizeDouble(Bez_Ub_Size*Point,Digits),OrderTakeProfit(),0,Blue);
}
}
}
}
}
}
}

///////////////////////////////////////////////////////////////////////////
void Traling_Stop_f()
{
for (int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS);
{
if (OrderMagicNumber()==magic)
{
double Or_St_Lo = OrderStopLoss();
double Or_Op_Pr = OrderOpenPrice();
if(Or_St_Lo==0) Or_St_Lo=Or_Op_Pr;
if((OrderStopLoss()!=Or_St_Lo+NormalizeDouble(Trailing_Stop*Point,Digits)) || (OrderStopLoss()!=Or_St_Lo-NormalizeDouble(Trailing_Stop*Point,Digits)))
{
if (OrderType()==OP_BUY && Bid-Or_St_Lo>=Trailing_Stop*Point && Bid>Or_St_Lo && ((Bid-Or_St_Lo+Trailing_Stop*Point)/Point>MarketInfo(Symbol(),MODE_STOPLEVEL))) OrderModify(OrderTicket(),0,Or_St_Lo+NormalizeDouble(Trailing_Stop*Point,Digits),OrderTakeProfit(),0,LightBlue);
if(OrderType()==OP_SELL && Or_St_Lo-Ask>=Trailing_Stop*Point && Ask<Or_St_Lo && ((Or_St_Lo-Trailing_Stop*Point-Ask)/Point>MarketInfo(Symbol(),MODE_STOPLEVEL))) OrderModify(OrderTicket(),0,Or_St_Lo-NormalizeDouble(Trailing_Stop*Point,Digits),OrderTakeProfit(),0,OrangeRed);
}
}
}
}

}

///////////////////////////////////////////////////////////////////////////////////
void martini_f()
{
int nor_lot;
if(MarketInfo(Symbol(),MODE_LOTSTEP)==0.1) nor_lot=1;
if(MarketInfo(Symbol(),MODE_LOTSTEP)==0.01) nor_lot=2;

CountOpenPositions();

double Mar_Lot_b=Lot*buy*Lot_koef;
double Mar_Lot_s=Lot*sell*Lot_koef;

for(int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS);
{
if(OrderMagicNumber()==magic)
{
if(OrderSymbol()==Symbol())
{
break;
}
}
}
}



if(OrderType()==OP_BUY)
{
//
if(Bid<=OrderOpenPrice()-step*Point) OrderSend(Symbol(),OP_BUY,NormalizeDouble(Mar_Lot_b,nor_lot),Ask,slippage,0,0,comment,magic,0,Green);
}


if(OrderType()==OP_SELL)
{
//
if(Ask>=OrderOpenPrice()+step*Point) OrderSend(Symbol(),OP_SELL,NormalizeDouble(Mar_Lot_s,nor_lot),Bid,slippage,0,0,comment,magic,0,OrangeRed);
}



}

///////////////////////////////////////////////////////////////////////////////////
int Profit_f()
{
int prof;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS)==true)
{
if(OrderMagicNumber()==magic)
{
if (OrderType()==OP_BUY) prof+=(Bid - OrderOpenPrice())/Point;
if (OrderType()==OP_SELL) prof+=(OrderOpenPrice()-Ask) /Point;
}
}
}

return(prof);
}

////////////////////////////////////////////////////////////////////////////////////
void CountOpenPositions()
{
buy=0;
sell=0;

for (int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS);
{
if(OrderMagicNumber()==magic)
{
if(OrderType()==OP_BUY) buy++;
if(OrderType()==OP_SELL) sell++;
}
}
}

}

////////////////////////////////////////////////////////////////////////////////
void Close_f()
{
for(int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS);
{
if(OrderMagicNumber()==magic)
{
if(OrderSymbol()==Symbol())
{
bool ticket_ex;
for (int j_ex = 0;j_ex < MaxAttempts; j_ex++)
{
while(IsTradeContextBusy()) Sleep(2000);

if(OrderType()==OP_BUY ) ticket_ex=OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Yellow);
if(OrderType()==OP_SELL) ticket_ex=OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Yellow);
if(OrderType()==OP_SELLSTOP || OrderType()==OP_BUYSTOP || OrderType()==OP_SELLLIMIT || OrderType()==OP_BUYLIMIT) ticket_ex=OrderDelete(OrderTicket(),CLR_NONE);
if(ticket_ex==true)break;
}
}
}
}
}

}

Grazie in anticipo!
 

La documentazione dice che la funzione SetIndexEmptyValue è usata per specificare un valore "vuoto". Cioè, specifichiamo a quale valore non abbiamo bisogno di disegnare nulla. È molto conveniente nel nostro caso in quanto i segnali non si verificano su ogni barra. Funziona come segue. Quando non avete bisogno di disegnare la freccia sulla barra corrente, assegnate un valore "vuoto" alla voce appropriata del buffer di dati, nel nostro caso 0.

Qualcosa che non capisco. Se qualcosa è disegnato dal segnale, non sarà disegnato senza il segnale. Allora qual è lo scopo di questa funzione in generale?