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
Periodo di tempo del grafico
Qual è il codice per scoprire a quale periodo di tempo sta funzionando il grafico? Così posso cambiare le impostazioni delle variabili per ogni periodo di tempo.
if(?????) . . .
Dave
Qual è il codice per scoprire a quale periodo di tempo sta funzionando il grafico? Così posso cambiare le impostazioni delle variabili per ogni periodo di tempo.
if(?????) . . .
Dave[/PHP]
or:
switch(Period())
{
case PERIOD_M1:
...
break;
case PERIOD_M5:
...
break;
...
}
[/PHP]
Sometime it maybe easier to work with indices:[PHP]
int tfIndex = ArrayBsearch({PERIOD_M1, PERIOD_M5, PERIOD_M15, ...}, Period());
Example : how to display the period by the string you want:[PHP]
int Periods[] = {PERIOD_M1, PERIOD_M5, PERIOD_M15, ...};
string sPeriods[] = {" M1", " M5", " M15", " M30", " Hourly", " 4 hours", " Daily", " Weekly"...};
int tfIndex = ArrayBsearch(Periods, Period());
comment(Symbol() + sPeriods[tfIndex]);
Grazie Michel!
Spero che questo EA che sto creando sia quello giusto! Il tuo aiuto è molto apprezzato!
Dave
ciao a tutti!
qualcuno può aiutarmi ad aggiungere questa funzione. Farla chiudere quando la barra è completata o in un'altra parola farla chiudere quando appare la prossima barra (non importa se il commercio è in profitto o in perdita)
extern int SystemMagicNumber=197;
extern double TakeProfit = 100;
extern double StopLoss = 500;
extern double Lots=0.1;
extern double TrailingStop = 0;
extern int MaxBuyTrades=5;
extern int MaxSellTrades=5;
int start()
{
if( HavePosThisBar(SystemMagicNumber)==false
&&iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,1)<iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,1)
&& iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,2)>iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,2)
&& SellPositionsCount()<MaxSellTrades
)
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,0,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",SystemMagicNumber,0,Red);
return(0);
}
if( HavePosThisBar(SystemMagicNumber)==false
&& iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,1)>iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,1)
&& iMA(NULL,0,5,0,MODE_SMA, PRICE_CLOSE,2)<iMA(NULL,0,15,0,MODE_EMA, PRICE_CLOSE,2)
&& BuyPositionsCount()<MaxBuyTrades
)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",SystemMagicNumber,0,Blue);
return(0);
}
for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol())
{
se (OrderType()==OP_SELL)
{
se (TrailingStop>0){
if (OrderOpenPrice()-Ask>TrailingStop*Point)
{
if (OrderStopLoss() == 0 || OrderStopLoss()>(Ask+Point*TrailingStop))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Purple);
return(0);
}
}
}
}
if (OrderType()==OP_BUY)
{
se (TrailingStop>0){
if (Bid-OrderOpenPrice()>TrailingStop*Point)
{
se (OrderStopLoss()<(Bid-Point*TrailingStop))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Yellow);
return(0);
}
}
}
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
bool HavePosThisBar(int magic)
{
int cnt;
bool Result=false;
for(cnt=0; cnt<=OrdersHistoryTotal()-1; cnt++)
if(OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY))
if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == magic) && Time[0]<=OrderOpenTime())
{
Risultato=vero;
break;
}
for(cnt=0; cnt<=OrdiniTotali()-1; cnt++)
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == magic) && Time[0]<=OrderOpenTime())
{
Risultato=vero;
break;
}
return(Result);
}
int BuyPositionsCount()
{
int Result=0;
for(int cnt=0; cnt<=OrdersTotal()-1; cnt++)
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == SystemMagicNumber) &&
(OrderType()==OP_BUY)
)
{
Risultato++;
}
return(Result);
}
int SellPositionsCount()
{
int Result=0;
for(int cnt=0; cnt<=OrdersTotal()-1; cnt++)
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
if((OrderSymbol() == Symbol()) &&(OrderMagicNumber() == SystemMagicNumber) &&
(OrderType()==OP_SELL)
)
{
Risultato++;
}
return(Risultato);
}
Ciao a tutti!
qualcuno può aiutarmi ad aggiungere questa funzione. Fare in modo che chiuda il trade quando la barra è completata o in un'altra parola fare in modo che chiuda il trade quando appare la prossima barra (non importa se il trade è in profitto o in perdita).
Per rilevare una nuova barra ci sono diverse soluzioni:
1)
2)
3)
Better, but again, restarting the terminal may produce wrong behaviors.
So my opinion is that the best is to write the lifetime max of each order into the order itself, using the "Comment" field :[PHP]OrderSend(..., ""+(Time[0] + Period()*60), ..);. Questa è una buona soluzione perché se hai diversi ordini da chiudere, hai tutto il tempo necessario per farlo.
Grazie Michel per la risposta.
Ci proverò. Ma cosa dovrei mettere nel commento? Qualcosa che mi piace?
grazie michel per la risposta. proverò. ma cosa devo mettere nel commento? qualcosa che mi piace?
Metti l'ora in cui vuoi chiudere l'ordine. Il campo Commento deve essere una stringa, ecco perché c'è ""+ davanti al valore. per esempio:
""+(Time[0] + Period()*60) // begin of the next bar on the current timeframe
""+(TimeCurrent() + 2*360 + 30*60) // 2 hours 30 minutes after the openning
""+(iTime(NULL,PERIOD_D1,0) + 23*360 + 45*60) // today at 23:45 (server time)
""+(iTime(NULL,PERIOD_W1,0) + (PERIOD_W1 - 10)*60) // next friday at 23:50Grazie
Se necessario, controlla prima che tu sia più tardi delle 8 del mattino:
Then, find the max and min of the current day. (if its ok for you, its easier than from 8 am): [PHP]double Max = iHigh(Symbol(), PERIOD_D1, 0);
double Min = iLow(Symbol(), PERIOD_D1, 0);
int Range = (Max - Min) / Point;
if(Range > 90) return;
...
Ciao,
Mi scuso per averci messo così tanto tempo a dire "grazie".
Apprezzo il vostro aiuto.
Grazie ancora.
Shek
Per rilevare una nuova barra ci sono diverse soluzioni:
1)
2)
3)
So my opinion is that the best is to write the lifetime max of each order into the order itself, using the "Comment" field :
i got the error below.what does ot mean?
[PHP]'>' - different types in comparison F:\Program Files\MetaTrader - FXOpen\experts\EMA_10.mq4 (88, 22)
I make it like this
for the send order
[PHP]OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask-25*Point,Ask+TakeProfit*Point, ""+(Time[0] + Period()*60),SystemMagicNumber,0,Blue);e per l'ordine di chiusura
[PHP]se(TimeCurrent() > OrderComment())
{
OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, CLR_NONE);
}e ho ottenuto l'errore mostrato sopra.
È giusto?
il mio errore, scusate.
Questo dovrebbe funzionare: