Chiedete! - pagina 63

 

Ok, ho capito il calcolo del pivot. Grazie per la vostra assistenza.

Il problema che devo affrontare ora è che quando apre correttamente l'ordine pendente nelle posizioni di prezzo corrette, continua ad aprire ordini pendenti più e più volte ogni volta che l'azione del prezzo si muove di 1 pip.

Ho cercato e continuerò a cercare il motivo per cui questo accade, ma volevo vedere se potevi darmi un suggerimento o un aiuto se vedi un errore logico che sto facendo.

Come sempre grazie per il vostro tempo.

extern int look_price_hour = 1; // Change for your time zone (my is +1 Hour). Should be 9AM London time.

extern int look_price_min = 35; // Offset in minutes when to look on price.

extern int close_hour = 12; // Close all orders after this hour

bool use_close_hour = true; // set it to false to ignore close_hour

int take_profit = 20;

extern int Currency_Spread = 4;

int open_long = 21;

int open_short = 21;

int stop_long = 30;

int stop_short = 30;

extern int slippage = 0;// Put what your brooker requires

extern double lots = 0.20; // Position size

extern int magic = 123;

bool clear_to_send = true;

void ReportStrategy()

{

int totalorders = HistoryTotal();

double StrategyProfit = 0.0;

double StrategyProfitOpen = 0.0;

int StrategyOrders = 0;

int StrategyOrdersOpen = 0;

for(int j=0; j<totalorders;j++)

{ if(OrderSelect(j, SELECT_BY_POS, MODE_HISTORY) &&

(OrderMagicNumber() == magic))

{

if((OrderType() == OP_BUY) ||

(OrderType() == OP_SELL))

{

StrategyOrders++;

StrategyProfit += OrderProfit();

}

}

}

totalorders = OrdersTotal();

for(j=0; j<totalorders;j++)

{ if(OrderSelect(j, SELECT_BY_POS, MODE_TRADES) &&

(OrderMagicNumber() == magic))

{

if((OrderType() == OP_BUY) ||

(OrderType() == OP_SELL))

{

StrategyOrdersOpen++;

StrategyProfitOpen += OrderProfit();

}

}

}

Comment("Daily20Pip EA Executed ", StrategyOrders,"+",StrategyOrdersOpen, " trades with ", StrategyProfit,"+",

StrategyProfitOpen," = ",StrategyProfit+StrategyProfitOpen," of profit\n",

"Server hour: ", TimeHour(CurTime()), " Local hour: ", TimeHour(LocalTime()));

return;

}

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

ReportStrategy();

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

ReportStrategy();

if(Hour() >= close_hour &&

use_close_hour){

// we are after closing time

int totalorders = OrdersTotal();

for(int j=0;j<totalorders;j++){

OrderSelect(j, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol()==Symbol() &&

OrderMagicNumber() == magic){

if(OrderType() == OP_BUY)

OrderClose(OrderTicket(), OrderLots(), Bid, 0, Red);

if(OrderType() == OP_SELL)

OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red);

if(OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP)

OrderDelete(OrderTicket());

}

}

return(0);

}

if(Hour() == look_price_hour &&

Minute() >= look_price_min &&

clear_to_send){

// Probably I need to close any old positions first:

totalorders = OrdersTotal();

for(j=0;j<totalorders;j++){

OrderSelect(j, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol()==Symbol() &&

OrderMagicNumber() == magic){

if(OrderType() == OP_BUY)

OrderClose(OrderTicket(), OrderLots(), Bid, 0, Red);

if(OrderType() == OP_SELL)

OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red);

if(OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP)

OrderDelete(OrderTicket());

}

}

}

double PIVOT;

PIVOT = (iHigh(NULL,PERIOD_D1,1) + iLow(NULL,PERIOD_D1,1) + iClose(NULL,PERIOD_D1,1))/3;

// Send orders:

OrderSend(Symbol(),

OP_BUYSTOP,

lots,

PIVOT+(open_long+Currency_Spread)*Point, // Spread included

slippage,

PIVOT+((open_long+Currency_Spread)-stop_long)*Point,

PIVOT+((open_long+Currency_Spread)+take_profit)*Point,

NULL,

magic,

0,

FireBrick);

OrderSend(Symbol(),

OP_SELLSTOP,

lots,

PIVOT-open_short*Point,

slippage,

PIVOT-(open_short-stop_short)*Point,

PIVOT-(open_short+take_profit)*Point,

NULL,

magic,

0,

FireBrick);

clear_to_send = false; // mark that orders are sent

if(!clear_to_send){ // there are active orders

int long_ticket = -1;

int short_ticket = -1;

bool no_active_order = true;

totalorders = OrdersTotal();

for(j=0;j<totalorders;j++){

OrderSelect(j, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol()==Symbol() &&

OrderMagicNumber() == magic){

if(OrderType() == OP_BUYSTOP)

long_ticket = OrderTicket();

if(OrderType() == OP_SELLSTOP)

short_ticket = OrderTicket();

if(OrderType() == OP_BUY ||

OrderType() == OP_SELL) // Active order

no_active_order = false; }

}

if(short_ticket == -1 && long_ticket != -1)

OrderDelete(long_ticket);

if(long_ticket == -1 && short_ticket != -1)

OrderDelete(short_ticket);

if(long_ticket == -1 && short_ticket == -1 && no_active_order &&

Hour() != look_price_hour && Minute() >= look_price_min)

clear_to_send = true;

if(Hour() == (look_price_hour-1) &&

MathAbs(Minute() - look_price_min) < 10)

clear_to_send = true;

}

//----

return(0);

}

 

Per quanto riguarda il mio post precedente,

Sembra che il "clear_to_send = false;" non stia passando dopo l'ordine pendente. Qualche idea?

Questo è successo una volta che ho reso il pivot il mio punto di riferimento per gli ordini in sospeso. Se non riesco a risolvere questa logica allora credo che cercherò di capire come fare riferimento a un piviot da un indicatore e chiamarlo dall'EA.

Qualsiasi consiglio o assistenza è apprezzato.

 

extern int look_price_hour = 1; // Change for your time zone (my is +1 Hour). Should be 9AM London time.

extern int look_price_min = 35; // Offset in minutes when to look on price.

extern int close_hour = 12; // Close all orders after this hour

bool use_close_hour = true; // set it to false to ignore close_hour

int take_profit = 20;

extern int Currency_Spread = 4;

int open_long = 21;

int open_short = 21;

int stop_long = 30;

int stop_short = 30;

extern int slippage = 0;// Put what your brooker requires

extern double lots = 0.20; // Position size

extern int magic = 123;

bool clear_to_send = true;

void ReportStrategy()

{

int totalorders = HistoryTotal();

double StrategyProfit = 0.0;

double StrategyProfitOpen = 0.0;

int StrategyOrders = 0;

int StrategyOrdersOpen = 0;

for(int j=0; j<totalorders;j++)

{ if(OrderSelect(j, SELECT_BY_POS, MODE_HISTORY) &&

(OrderMagicNumber() == magic))

{

if((OrderType() == OP_BUY) ||

(OrderType() == OP_SELL))

{

StrategyOrders++;

StrategyProfit += OrderProfit();

}

}

}

totalorders = OrdersTotal();

for(j=0; j<totalorders;j++)

{ if(OrderSelect(j, SELECT_BY_POS, MODE_TRADES) &&

(OrderMagicNumber() == magic))

{

if((OrderType() == OP_BUY) ||

(OrderType() == OP_SELL))

{

StrategyOrdersOpen++;

StrategyProfitOpen += OrderProfit();

}

}

}

Comment("Daily20Pip EA Executed ", StrategyOrders,"+",StrategyOrdersOpen, " trades with ", StrategyProfit,"+",

StrategyProfitOpen," = ",StrategyProfit+StrategyProfitOpen," of profit\n",

"Server hour: ", TimeHour(CurTime()), " Local hour: ", TimeHour(LocalTime()));

return;

}

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

ReportStrategy();

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

ReportStrategy();

if(Hour() >= close_hour &&

use_close_hour){

// we are after closing time

int totalorders = OrdersTotal();

for(int j=0;j<totalorders;j++){

OrderSelect(j, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol()==Symbol() &&

OrderMagicNumber() == magic){

if(OrderType() == OP_BUY)

OrderClose(OrderTicket(), OrderLots(), Bid, 0, Red);

if(OrderType() == OP_SELL)

OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red);

if(OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP)

OrderDelete(OrderTicket());

}

}

return(0);

}

if(Hour() == look_price_hour &&

Minute() >= look_price_min &&

clear_to_send){

// Probably I need to close any old positions first:

totalorders = OrdersTotal();

for(j=0;j<totalorders;j++){

OrderSelect(j, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol()==Symbol() &&

OrderMagicNumber() == magic){

if(OrderType() == OP_BUY)

OrderClose(OrderTicket(), OrderLots(), Bid, 0, Red);

if(OrderType() == OP_SELL)

OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red);

if(OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP)

OrderDelete(OrderTicket());

}

}

}

double PIVOT;

PIVOT = (iHigh(NULL,PERIOD_D1,1) + iLow(NULL,PERIOD_D1,1) + iClose(NULL,PERIOD_D1,1))/3;

// Send orders:

if (clear_to_send){

OrderSend(Symbol(),

OP_BUYSTOP,

lots,

PIVOT+(open_long+Currency_Spread)*Point, // Spread included

slippage,

PIVOT+((open_long+Currency_Spread)-stop_long)*Point,

PIVOT+((open_long+Currency_Spread)+take_profit)*Point,

NULL,

magic,

0,

FireBrick);

OrderSend(Symbol(),

OP_SELLSTOP,

lots,

PIVOT-open_short*Point,

slippage,

PIVOT-(open_short-stop_short)*Point,

PIVOT-(open_short+take_profit)*Point,

NULL,

magic,

0,

FireBrick);

clear_to_send = false; // mark that orders are sent

}

if(!clear_to_send){ // there are active orders

int long_ticket = -1;

int short_ticket = -1;

bool no_active_order = true;

totalorders = OrdersTotal();

for(j=0;j<totalorders;j++){

OrderSelect(j, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol()==Symbol() &&

OrderMagicNumber() == magic){

if(OrderType() == OP_BUYSTOP)

long_ticket = OrderTicket();

if(OrderType() == OP_SELLSTOP)

short_ticket = OrderTicket();

if(OrderType() == OP_BUY ||

OrderType() == OP_SELL) // Active order

no_active_order = false; }

}

if(short_ticket == -1 && long_ticket != -1)

OrderDelete(long_ticket);

if(long_ticket == -1 && short_ticket != -1)

OrderDelete(short_ticket);

if(long_ticket == -1 && short_ticket == -1 && no_active_order &&

Hour() != look_price_hour && Minute() >= look_price_min)

clear_to_send = true;

if(Hour() == (look_price_hour-1) &&

MathAbs(Minute() - look_price_min) < 10)

clear_to_send = true;

}

//----

return(0);

}

Prova questo codice.

 

Ryanklefas ,

Sei brillante, semplicemente brillante in questo settore.

Il test che ho fatto dalla tua modifica ha funzionato.

Non sono sicuro del perché l'aggiunta della logica pivot abbia interferito con l'attuale logica "If". Probabilmente avevo bisogno di stabilire il codice pivot in una posizione diversa. Tuttavia, vedo come hai isolato il codice dell'ordine pendente e per ora funziona.

Grazie per l'URL che mi ha indicato gli esempi di codice. Sarà una grande risorsa per migliorare le mie capacità di programmazione.

Trovo interessante/frustrante come la soluzione di un problema a volte ne causi un altro.

Problema attuale: Ora ho bisogno di scoprire perché questo codice permette solo ordini in sospeso per prezzi con 5 cifre e non 3.

Esempio: 1.1234 funziona bene ma 1.12 dà un errore che 1.123333 non è un prezzo valido per OrderSend.

Quindi funziona su GBP/USD ma non su USD/JPY.

Ancora grazie per il vostro tempo.

 
proverbs:
Ryanklefas ,

Lei è brillante, semplicemente brillante in questo campo.

Grazie.

Per quanto riguarda il tuo problema:

Assicurati, prima di inviare i valori pivot alla funzione orderSend, di averli normalizzati con la funzione NormalizeDouble; usa il valore predefinito "Digits" come secondo parametro per arrotondare il doppio al numero appropriato di cifre per la tua valuta.

 
waaustin:
Il mio problema è stato come arrotondare il valore calcolato al decimale più vicino.

Penso che la funzione normalizeDouble funzionerebbe anche per te. Ho anche visto del codice che usa le funzioni MathFloor e MathCeiling per ottenere la stessa cosa.

 

Un altro aiuto

Qualcuno può dirmi come fare questo?

File:
chart.gif  18 kb
 
hellkas:
Qualcuno può dirmi come fare?

Penso che sia collegato a questo thread https://www.mql5.com/en/forum/176969

 

Impostare il colore del livello nel codice

Qualcuno può mostrarmi come posso impostare il livello1 30 in verde e il livello2 70 in rosso?

#proprietà indicator_separate_window

#proprietà indicator_buffers 1

#proprietà indicator_color1 DodgerBlue

#property indicator_level1 30

#property indicator_level2 70

#property indicator_minimum 0

#property indicator_maximum 100

Grazie in anticipo

 
highway3000:
Qualcuno può mostrarmi come posso impostare il livello1 30 su Green e il livello2 70 su Red ?

#proprietà indicator_separate_window

#proprietà indicatore_buffer 1

#property indicator_color1 DodgerBlue

#Proprietà indicatore_livello1 30

#proprietà indicatore_livello2 70

#property indicator_minimum 0

#proprietà indicatore_massimo 100

Grazie in anticipo

Penso che questa sezione del MetaEditor sarà quello che stai cercando:

MQL4 Reference - Basics - Preprocessore - Controllo della compilazione