Come faccio a far filtrare l'indicatore al posto dell'avviso? - pagina 8

 

U da man!

quindi.... vediamo se ho capito bene...

se volessi chiudere delle posizioni basate sull'incrocio posteriore di una media mobile tutto quello che dovrei codificare è questo....

if(currentlong>minorts) {CloseOrder(OP_SELL); // Chiudi tutti gli ordini di vendita}

dove currentlong è la 20ema e minorts è la 150ema quindi la posizione aperta sarebbe stata o è una posizione corta che ha fatto il suo corso e ora la 20ema si sta muovendo sopra la 150ema che è il segnale di chiusura per il trade corto.

e...

if (currentlong<minorts) {CloseOrder(OP_BUY); // Chiudi tutti gli ordini di acquisto}

dove currentlong è la 20ema e minorts è la 150ema quindi la posizione aperta sarebbe stata o è una long che ha fatto il suo corso e ora la 20ema si sta muovendo sotto la 150ema che è il segnale di chiusura dell'operazione long.

Quindi potrei mettere queste due linee

if (currentlong<minorts) {CloseOrder(OP_BUY); // Chiudi tutti gli ordini di acquisto}

if(currentlong>minorts) {CloseOrder(OP_SELL); // Chiudi tutti gli ordini di vendita}

subito dopo il codice di entrata e prima di tutte le altre cose di chiusura e trailing stop come questa? e funzionerà?

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES )) Print("SELL order opened : ",OrderOpenPrice());

}

else Print("Error opening SELL order : ",GetLastError());

return(0);

}

}

//+---------end of order entry-------------------------+

//+------close on moving average cross-----------------+

if(currentlong<minorts) {CloseOrder(OP_BUY);} // Close all buy orders}

if(currentlong>minorts) {CloseOrder(OP_SELL);} // Close all sell orders}

//+--------end of close on moving average cross--------+

//+-------------------------Trailing Stop Code------------------------------------+

for(cnt=0;cnt<total;cnt++) {

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()) {

if(OrderType()==OP_BUY){

il compilatore dice questo:

')' - errato conteggio dei parametri C:\File di programma\Interbank FX Trader 4-live mini\experts\whatever.mq4 (85, 43)

')' - numero di parametri errato C:\Program Files\Interbank FX Trader 4-live mini-experts\whatever.mq4 (86, 44)

non gli piacciono quelle linee. Non mi sembra di comunicare molto bene.

 

questo è interessante improvvisamente la mia funzione di ricerca sul metaeditor funziona?

bool OrderCloseBy( int ticket, int opposite, color Color=CLR_NONE)

Chiude un ordine aperto da un altro ordine aperto opposto. Se la funzione ha successo, il valore di ritorno è true. Se la funzione fallisce, il valore di ritorno è false. Per ottenere informazioni dettagliate sull'errore, chiama GetLastError().

Parametri:

ticket - Numero unico del biglietto dell'ordine.

opposto - Numero unico del biglietto d'ordine opposto.

Colore - Colore della freccia di chiusura sul grafico. Se il parametro manca o ha il valore CLR_NONE la freccia di chiusura non sarà disegnata sul grafico.

Esempio:

if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)

{

OrderCloseBy(order_id,opposite_id);

return(0);

}

quindi sto visualizzando qualcosa del genere...

if(currentlong<minorts)

{

OrderCloseBy(order_id,opposite_id);

return(0);

}[/PHP]

thing is this doesn't distinguish what kind of position I'm into first, long or short. So if I put the opposite side of this with it...like this...

[PHP] if(currentlong>minorts)

{

OrderCloseBy(order_id,opposite_id);

return(0);

}

insieme chiuderebbero tutto, no? ci deve essere di più... mi sento frustrato come un bambino che non può ancora parlare per comunicare frasi complete, quando ho idee complete dentro di me che non posso far uscire.

 
elihayun:
Ho dimenticato questo
void CloseOrder(int ticket,double numLots,double close_price)

{

int CloseCnt, err;

// try to close 3 Times

CloseCnt = 0;

color clr = Violet;

if (OrderType() == OP_SELL)

clr = Orange;

while (CloseCnt < 3)

{

if (OrderClose(ticket,numLots,close_price,Slippage,clr))

{

CloseCnt = 3;

}

else

{

err=GetLastError();

Print(CloseCnt," Error closing order : (", err , ") " + ErrorDescription(err));

if (err > 0) CloseCnt++;

}

}

}

[/PHP]

and dont forget to add this line after #property link

[PHP]#property link "http://www.elihayun.com"

#include

cosa fa questo? è qualcos'altro che devo scaricare per averlo a disposizione per essere chiamato? Voglio capire come questo fa quello che fa, come distingue le posizioni lunghe da quelle corte. Voglio imparare.

 
Aaragorn:
Sei un grande!

so.... vediamo se ho capito bene...

Quindi potrei semplicemente mettere queste due linee

if (currentlong<minorts) {CloseOrder(OP_BUY); // Chiudi tutti gli ordini di acquisto}

if(currentlong>minorts) {CloseOrder(OP_SELL); // Chiudi tutti gli ordini di vendita}

//+------chiudere su incrocio media mobile-----------------+

if(currentlong<minorts) {CloseOrder(OP_BUY);} // Chiudere tutti gli ordini di acquisto}

if(currentlong>minorts) {CloseOrder(OP_SELL);} // Chiudere tutti gli ordini di vendita}

if(OrderType()==OP_BUY){[/PHP]

il compilatore dice questo:

')' - conteggio parametri errato C:\File di programma\Interbank FX Trader 4-live mini\experts\whatever.mq4 (85, 43)

')' - numero di parametri errato C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (86, 44)

Non gli piacciono queste linee. Non mi sembra di comunicare molto bene.

Devi chiamare CloseOrders con s alla fine non CloseOrder (che chiude solo un ordine)

 
Aaragorn:
cosa fa questo? è qualcos'altro che devo scaricare per averlo a disposizione per essere chiamato? Voglio capire come questo fa quello che fa, come distingue le posizioni lunghe da quelle corte. Voglio imparare.

Fa parte di MQL4 e contiene la funzione ErrorDescription

 
elihayun:
Fa parte di MQL4 e contiene la funzione ErrorDescription

ok Ho ancora bisogno di un po' di codice che mi permetta di chiudere in base all'incrocio della media mobile.

 

Questo pezzo di codice dovrebbe farvi partire...

Naturalmente dovrete modificarlo per adattarlo alle vostre esigenze. Tuttavia, questo dovrebbe fornirvi un punto di partenza. Questa routine usa la linea SMA1 come trailing stop. Quindi prendete questa idea e vedete cosa ne potete fare.

//these two lines within start()

SMA1 = iMA(NULL,TimePeriod,SlowPeriod,0,SlowMode,SlowPrice,1);

TrailingAlls(TrailStart, SMA1);

// trailing routine using the value of SMA1

void TrailingAlls(int start, double currvalue)

{

int profit;

double stoptrade;

double stopcal;

// if(stop==0) return;

int trade;

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

{

if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))

continue;

if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)

continue;

if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)

{

if(OrderType()==OP_BUY)

{

profit=NormalizeDouble((Bid-OrderOpenPrice())/Point,0);

if(profit<start)

continue;

stoptrade=OrderStopLoss();

// stopcal=Bid-(stop*Point);

stopcal=NormalizeDouble(currvalue, Digits);

if(stoptrade==0||(stoptrade!=0&&stopcal>stoptrade))

OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);

}//Long

if(OrderType()==OP_SELL)

{

profit=NormalizeDouble((OrderOpenPrice()-Ask)/Point,0);

if(profit<start)

continue;

stoptrade=OrderStopLoss();

// stopcal=Ask+(stop*Point);

stopcal=NormalizeDouble(currvalue, Digits);

if(stoptrade==0||(stoptrade!=0&&stopcal<stoptrade))

OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);

}//Shrt

}

}//for

}

 

un trailing stop close è forse utile se riesco a capirlo prima....

Questo snippet che mi ha dato elihayun penso che potrebbe funzionare se qualcuno riesce a capire come farlo rispondere al ma backcross e nella giusta direzione. Sono confuso con l'op_buy e l'op_sell quali sono e quali usare per chiudere posizioni lunghe e quali per chiudere posizioni corte.

//+------close on moving average cross-----------------+

void CloseOrders(int op)

{

int tik[30], t = 0;

for(int i =0;i<OrdersTotal();i++){

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){

if(OrderSymbol()==Symbol() && MagicNum==OrderMagicNumber() && OrderType() == op){

tik[t] = OrderTicket(); t++;

}

}

}

for (i = 0; i<t; i++)

{

if(OrderSelect(tik,SELECT_BY_TICKET)){

double prc = Bid;

if (op == OP_SELL) prc = Ask;

CloseOrder(tik, OrderLots(), prc);

}

}

}

//+--------end of close on moving average cross--------+[/PHP]

I think I see that at this point in the code it has selected the orders by ticket and it's figuring out to set the close price based on the bid or the ask. So I'm not sure which is which for long or short positions. If the ticket is a long position that means it was opened at the ask price right? so it should close on the bid price? so this snippet is saying use the bid price to close so I assume that's for a long position. THEN it asks the

if (op == OP_SELL) prc = Ask;

so I assume this is the first place in this code where we now know if we are looking at a long or a short position ticket.

Then it moves immediately to close. But if I can put my closing criteria in here BEFORE it does that???

here it is as I received it...

for (i = 0; i<t; i++)

{

if(OrderSelect(tik,SELECT_BY_TICKET)){

double prc = Bid;

if (op == OP_SELL) prc = Ask;

CloseOrder(tik, OrderLots(), prc);

}[/PHP]

so what I'm thinking is that this is the place in the code where I should insert the moving average criteria to trigger the close for long or short positions. Something like this...

[PHP]for (i = 0; i<t; i++)

{

if(OrderSelect(tik,SELECT_BY_TICKET)){

double prc = Bid;

if (op == OP_SELL) prc = Ask;

if (prc == Bid && currentlong minorts);

CloseOrder(tik, OrderLots(), prc);

}

Will this do it? I think it might if I understand correctly..

Please tell me coders if this is correct??

I think this connects the direction of the moving average cross to the type of position that the ticket is identifed as being.

if the bid is to close long positions so we know the ticket is for a long position then it can close long positions if the currentlongema < minortsEMA because it knows that the ticket is for a long position and the 20ema has moved below the 150ema.

If the ask is for closing short positions and the ticket is identified as a short position because it wants to close at the ask price and the currentlongEMA has moved above the minortsEMA because it knows the ticket is for a short position and the 20ema has moved above the 150ema.

if that is correct will adding this line to the code,

if (prc == Bid && currentlong minorts)

stop it from closing UNLESS each ticket fits this criteria?

...that for the long position the 20ema150ema?

if that is ok then the logic for deciding to close long or short based on the emacrossback is ok and it's worth fixing these errors

I get these errors from the compiler...

[PHP]Compiling 'whatever.mq4'...

'(' - function definition unexpected C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (85, 17)

'MagicNum' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (90, 40)

'op' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (90, 87)

'tik' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (91, 13)

't' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (91, 17)

't' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (91, 37)

't' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (96, 18)

'tik' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (98, 22)

'op' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (100, 14)

'tik' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (102, 21)

'cnt' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 5)

'cnt' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 5)

'cnt' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 11)

'cnt' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 11)

'total' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 15)

'total' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 15)

'cnt' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 21)

'cnt' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 21)

'{' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 28)

'i' - variable is already defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (135, 11)

'}' - unbalanced parentheses C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (165, 1)

16 error(s), 5 warning(s)

 

Un suggerimento a tutti i membri, non usate routine di "count up" per chiudere i trade. Per esempio, non usate qualcosa come questo

for (i = 0; i<t; i++)

{

if(OrderSelect(tik,SELECT_BY_TICKET)){

double prc = Bid;

if (op == OP_SELL) prc = Ask;

CloseOrder(tik, OrderLots(), prc);

}

Se stai usando ordini multipli, non chiuderà l'ultimo ordine. Usa una routine di "conto alla rovescia". Ecco la mia discussione con gli sviluppatori di Metaquotes quando mi sono imbattuto per la prima volta in questo irritante "bug".

http://www.metaquotes.net/forum/2018/

 
Maji:
Questo pezzo di codice dovrebbe farti andare avanti...

Naturalmente dovrete modificarlo per adattarlo alle vostre esigenze. Tuttavia, questo dovrebbe fornirvi un punto di partenza. Questa routine usa la linea SMA1 come trailing stop. Quindi prendete questa idea e vedete cosa potete ricavarne.

//these two lines within start()

SMA1 = iMA(NULL,TimePeriod,SlowPeriod,0,SlowMode,SlowPrice,1);

TrailingAlls(TrailStart, SMA1);

// trailing routine using the value of SMA1

void TrailingAlls(int start, double currvalue)

{

int profit;

double stoptrade;

double stopcal;

// if(stop==0) return;

int trade;

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

{

if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))

continue;

if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)

continue;

if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)

{

if(OrderType()==OP_BUY)

{

profit=NormalizeDouble((Bid-OrderOpenPrice())/Point,0);

if(profit<start)

continue;

stoptrade=OrderStopLoss();

// stopcal=Bid-(stop*Point);

stopcal=NormalizeDouble(currvalue, Digits);

if(stoptrade==0||(stoptrade!=0&&stopcal>stoptrade))

OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);

}//Long

if(OrderType()==OP_SELL)

{

profit=NormalizeDouble((OrderOpenPrice()-Ask)/Point,0);

if(profit<start)

continue;

stoptrade=OrderStopLoss();

// stopcal=Ask+(stop*Point);

stopcal=NormalizeDouble(currvalue, Digits);

if(stoptrade==0||(stoptrade!=0&&stopcal<stoptrade))

OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);

}//Shrt

}

}//for

}

Grazie mille. Non vedo l'ora di sezionare questo e vedere cosa posso farne...

Il motivo per cui voglio far funzionare prima l'emacrossback è che sarà fondamentalmente il mio stoploss e la mia strategia di uscita predefinita.

Una volta che funziona, aggiungerò cose come questa per aumentare la redditività. Ma dato che non posso avere uno stop loss senza incasinarlo e dato che non sono disposto a permettere enormi parametri di stop loss, voglio prima far funzionare la chiusura della media mobile crossback. Se hai la possibilità di verificare quello che ho fatto finora con la chiusura crossback te ne sarei grato.

Motivazione: