Tutte le domande dei nuovi arrivati su MQL4 e MQL5, aiuto e discussione su algoritmi e codici - pagina 63
Ti stai perdendo delle opportunità di trading:
- App di trading gratuite
- Oltre 8.000 segnali per il copy trading
- Notizie economiche per esplorare i mercati finanziari
Registrazione
Accedi
Accetti la politica del sito e le condizioni d’uso
Se non hai un account, registrati
Si controlla su una barra esistente double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
Il prezzo sale, c'è un crossover del livello 70 e l'entrata nel commercio. Sul fatto di chiudere la barra, si vede già che l'RSI è più basso, ma prima era più alto, e poi è tornato sotto il livello.
Fai il controllo su una barra chiusa, allora questo non accadrà, e le entrate saranno su un segnale confermato:
double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,2);
L'ho scritto così: (probabilmente sbagliato).
double slSell,slBuy,tpSell,tpBuy,TotalBiu,TotalSell;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
OrderBuy=0; OrderSell=0;
for(int i=OrdersTotal()-1; i>=0; i--) //Цикл по всем ордерам
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) //Выбрали ордер
{
if(OrderType()==OP_BUY)
{
OrderBuy++; //Кол. покупок
}
if(OrderType()==OP_SELL)
{
OrderSell++; //Кол. продаж
}
}
}
double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
double rsi2=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,2);
//+------------------------------------------------------------------+
double StopLossLevel;
double TakeProfitLevel;
if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0;
if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0;
tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits);
slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits);
tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits);
slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);
///---
if(OrderBuy==0 && rsi>Urov_70 && rsi1<Urov_70 && rsi2<Urov_70)
{
tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);
if(tiket<0)Print("Ошибка открытия ордера № - ",GetLastError());
}
if(OrderSell==0 && rsi<Urov_30 && rsi1>Urov_30 && rsi2>Urov_30)
{
tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);
if(tiket<0)Print("Ошибка открытия ордера № - ",GetLastError());
}
}
//+------------------------------------------------------------------+
Risultato: gli ordini si aprono quando non c'è crossover...
L'ho scritto così: (probabilmente sbagliato).
}
double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
double rsi2=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,2);
//+------------------------------------------------------------------+
double StopLossLevel;
Il risultato è il seguente: gli ordini si aprono quando non c'è crossover...
Perché avete bisogno della barra correntedouble rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);??
Il tuo codice riscritto soddisfa esattamente la stessa condizione di prima - sulla barra zero il prezzo ha attraversato il livello ed è stato aperto un trade, più tardi il prezzo è tornato indietro e l'RSI è tornato sotto il livello, di conseguenza, dopo la chiusura della barra non c'è alcun segnale.
Non usare la barra zero nel calcolo.
Perché avete bisogno della barra correntedouble rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);??
Il tuo codice riscritto soddisfa esattamente la stessa condizione di prima, sulla barra zero il prezzo ha attraversato il livello ed è stato aperto un trade, più tardi il prezzo è tornato indietro e l'RSI è tornato sotto il livello, di conseguenza, dopo la chiusura della barra non c'è nessun segnale.
Non usare la barra zero nel calcolo.
Puoi dirmi perché dà un errore?
double slSell,slBuy,tpSell,tpBuy,TotalBiu,TotalSell;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
OrderBuy=0; OrderSell=0;
for(int i=OrdersTotal()-1; i>=0; i--) //Цикл по всем ордерам
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) //Выбрали ордер
{
if(OrderType()==OP_BUY)
{
OrderBuy++; //Кол. покупок
}
if(OrderType()==OP_SELL)
{
OrderSell++; //Кол. продаж
}
}
}
//double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
double rsi2=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,2);
//+------------------------------------------------------------------+
double StopLossLevel;
double TakeProfitLevel;
if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0;
if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0;
tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits);
slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits);
tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits);
slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);
///---
if(CountBuy()+CountSell()==0 && rsi1>Urov_70 && rsi2<Urov_70)
{
tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);
if(tiket<0)Print("Ошибка открытия ордера № - ",GetLastError());
}
if(CountBuy()+CountSell()==0 && rsi1<Urov_30 && rsi2>Urov_30)
{
tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);
if(tiket<0)Print("Ошибка открытия ордера № - ",GetLastError());
}
}
//+------------------------------------------------------------------+
int CountBuy()
{
int count=0;
for(int trade=OrdersTotal()-1; trade>0; trade--);
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_BUY)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
int CountSell()
{
int count=0;
for(int trade=OrdersTotal()-1; trade>0; trade--);
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_SELL)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
Puoi dirmi perché dà un errore?
double slSell,slBuy,tpSell,tpBuy,TotalBiu,TotalSell;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
OrderBuy=0; OrderSell=0;
for(int i=OrdersTotal()-1; i>=0; i--) //Цикл по всем ордерам
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) //Выбрали ордер
{
if(OrderType()==OP_BUY)
{
OrderBuy++; //Кол. покупок
}
if(OrderType()==OP_SELL)
{
OrderSell++; //Кол. продаж
}
}
}
//double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
double rsi2=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,2);
//+------------------------------------------------------------------+
double StopLossLevel;
double TakeProfitLevel;
if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0;
if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0;
tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits);
slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits);
tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits);
slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);
///---
if(CountBuy()+CountSell()==0 && rsi1>Urov_70 && rsi2<Urov_70)
{
tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);
if(tiket<0)Print("Ошибка открытия ордера № - ",GetLastError());
}
if(CountBuy()+CountSell()==0 && rsi1<Urov_30 && rsi2>Urov_30)
{
tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);
if(tiket<0)Print("Ошибка открытия ордера № - ",GetLastError());
}
}
//+------------------------------------------------------------------+
int CountBuy()
{
int count=0;
for(int trade=OrdersTotal()-1; trade>0; trade--);
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_BUY)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
int CountSell()
{
int count=0;
for(int trade=OrdersTotal()-1; trade>0; trade--);
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_SELL)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
Potete dirmi perché viene visualizzato un errore?
for(int trade=OrdersTotal()-1; trade>0; trade--);
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_SELL)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
extra " ; "
{
int count=0;
for(int trade=OrdersTotal()-1; trade>0; trade--); <<<
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_BUY)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
int CountSell()
{
int count=0;
for(int trade=OrdersTotal()-1; trade>0; trade--); <<<
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_SELL)
count++;
}
}
return(count);
}
E sarebbe meglio, in questo caso:
A proposito.
superfluo " ; "
{
int count=0;
for(int trade=OrdersTotal()-1; trade>0; trade--); <<<
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_BUY)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
int CountSell()
{
int count=0;
for(int trade=OrdersTotal()-1; trade>0; trade--); <<<
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_SELL)
count++;
}
}
return(count);
}
E sarebbe meglio, in questo caso:
Ciao a tutti, come faccio a scrivere l'espressione
il quinto lotto è uguale alla somma dei lotti 1 e 4
per trovare il primo o l'ultimo di tutti può essere trovato tramite la definizione del biglietto
Ma come trovare una qualsiasi intermedia considerando i continui cambiamenti nella griglia attuale?
Voglio dire che ogni ordine dovrebbe essere memorizzato da qualche parte o in qualche altro modo
e c'è una differenza?
tra
{
if uslovie1==true {...}
if uslovie2==true {...}
if uslovie3==true {...}
}
И
void OnTick()
{
{
if uslovie1==true
{...}
else if {...}
else if {...}
}
}