OrderClose come si usa?

Sezione dedicata a metatrader (ed altre piattaforme) ed al suo linguaggio di programmazione per il trading automatico
faustf
Messaggi: 32
Iscritto il: 08/09/2015, 22:06

OrderClose come si usa?

Messaggio da faustf »

ciao a tutti
sto cercando di modificare , uno script , priceallert , il funzionamento di price allert è:
imposti una soglia di prezzo , quando la trova suona , (cè anche le due opzioni al superamento sopra o sotto)
io volevo modificarlo in modo tale che anziche suonare chiuda un ordine che ho gia aperto lo script l ho modificato come segue

Codice: Seleziona tutto

//+------------------------------------------------------------------+
//|                                                   PriceAlert.mq4 |
//|                         Copyright © 2009-2011, www.earnforex.com |
//|           Issues sound alerts when price reaches certain levels. |
//|             			modded by Mn ------------------------    |
//+------------------------------------------------------------------+
#include <WinUser32.mqh>

#property copyright "EarnForex.com"
#property link      "http://www.earnforex.com"

#property indicator_chart_window

extern int    e_MagicID               = 23456;
extern int    ticket_order            = 0;
extern double lotto_size              = 0.01;
extern double SoundWhenPriceGoesAbove = 0;
extern double SoundWhenPriceGoesBelow = 0;
extern double SoundWhenPriceIsExactly = 0;
extern bool   SendEmail = false; //If true e-mail is sent to the e-mail address set in your MT4. E-mail SMTP Server settings should also be configured in your MT4

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() 
{
   if (SoundWhenPriceIsExactly > 0)
   {
      ObjectCreate("SoundWhenPriceIsExactly", OBJ_HLINE, 0, Time[0], SoundWhenPriceIsExactly);
      ObjectSet("SoundWhenPriceIsExactly", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("SoundWhenPriceIsExactly", OBJPROP_COLOR, Yellow);
      ObjectSet("SoundWhenPriceIsExactly", OBJPROP_WIDTH, 1);
   }
   if (SoundWhenPriceGoesAbove > 0)
   {
      ObjectCreate("SoundWhenPriceGoesAbove", OBJ_HLINE, 0, Time[0], SoundWhenPriceGoesAbove);
      ObjectSet("SoundWhenPriceGoesAbove", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("SoundWhenPriceGoesAbove", OBJPROP_COLOR, Green);
      ObjectSet("SoundWhenPriceGoesAbove", OBJPROP_WIDTH, 1);
   }
   if (SoundWhenPriceGoesBelow > 0)
   {
      ObjectCreate("SoundWhenPriceGoesBelow", OBJ_HLINE, 0, Time[0], SoundWhenPriceGoesBelow);
      ObjectSet("SoundWhenPriceGoesBelow", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("SoundWhenPriceGoesBelow", OBJPROP_COLOR, Red);
      ObjectSet("SoundWhenPriceGoesBelow", OBJPROP_WIDTH, 1);
   }
   return(0);
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   ObjectDelete("SoundWhenPriceIsExactly");
   ObjectDelete("SoundWhenPriceGoesAbove");
   ObjectDelete("SoundWhenPriceGoesBelow");
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
 // added by Mn -----------------------------------------------------------
   if (ObjectGet("SoundWhenPriceGoesAbove", 1) != SoundWhenPriceGoesAbove)
     SoundWhenPriceGoesAbove = ObjectGet("SoundWhenPriceGoesAbove", 1);
   if (ObjectGet("SoundWhenPriceGoesBelow", 1) != SoundWhenPriceGoesBelow)
     SoundWhenPriceGoesBelow = ObjectGet("SoundWhenPriceGoesBelow", 1);
   if (ObjectGet("SoundWhenPriceIsExactly", 1) != SoundWhenPriceIsExactly)
     SoundWhenPriceIsExactly = ObjectGet("SoundWhenPriceIsExactly", 1);
 // added by Mn -----------------------------------------------------------

   if ((Ask > SoundWhenPriceGoesAbove) && (SoundWhenPriceGoesAbove > 0))
   {
      Alert("Price above the alert level.");
      PlaySound("alert.wav");
      SendMail("Price for " + Symbol() +  " above the alert level " + Ask, "Price for " + Symbol() +  " reached " + Ask + " level, which is above your alert level of " + SoundWhenPriceGoesAbove);
      ObjectDelete("SoundWhenPriceGoesAbove");
      SoundWhenPriceGoesAbove = 0;
   }
   if ((Bid < SoundWhenPriceGoesBelow) && (SoundWhenPriceGoesBelow > 0))
   {
      Alert("Price below the alert level.");
      PlaySound("alert.wav");
      SendMail("Price for " + Symbol() +  " below the alert level " + Bid, "Price for " + Symbol() +  " reached " + Bid + " level, which is below your alert level of " + SoundWhenPriceGoesBelow);
      ObjectDelete("SoundWhenPriceGoesBelow");
      SoundWhenPriceGoesBelow = 0;
   }
   if ((Bid == SoundWhenPriceIsExactly) || (Ask == SoundWhenPriceIsExactly))
   {
      OrderClose(ticket_order,lotto_size,SoundWhenPriceIsExactly,0.0,Red);
      Alert("Price exactly the alert level.");
      PlaySound("alert.wav");
      SendMail("Price for " + Symbol() +  " exactly at the alert level " + Ask, "Price for " + Symbol() +  " reached " + Ask + "/" + Bid + " level, which is exactly your alert level of " + SoundWhenPriceIsExactly);
      ObjectDelete("SoundWhenPriceIsExactly");
      SoundWhenPriceIsExactly = 0;
   }
   return(0);
}
//+------------------------------------------------------------------+
ma non chiude l ordine , sicuramente sbaglio qualcosa su orderclose

vi ringrazio ancora se mi date una mano grazie :)
Avatar utente
carlo10
Messaggi: 4259
Iscritto il: 08/05/2014, 21:17

Re: OrderClose come si usa?

Messaggio da carlo10 »

Dovresti cercare l'errore nei log di metatrader, sicuramente avrà scritto qualcosa.

Ad occhio sostituirei ad esempio:

Codice: Seleziona tutto

OrderClose(ticket_order,lotto_size,SoundWhenPriceIsExactly,0.0,Red);
con:

Codice: Seleziona tutto

OrderClose(ticket_order,lotto_size,Ask,3,Red);
Inoltre è buona norma controllare l'esito restituito dalla funzione ed in caso stampare in modo dettagliato l'errore restituito.

http://docs.mql4.com/trading/orderclose
faustf
Messaggi: 32
Iscritto il: 08/09/2015, 22:06

Re: OrderClose come si usa?

Messaggio da faustf »

dove lo trovo il log ???
Avatar utente
carlo10
Messaggi: 4259
Iscritto il: 08/05/2014, 21:17

Re: OrderClose come si usa?

Messaggio da carlo10 »

In metatrader prova a scorrere i tab Consiglieri o Diario nell'orario in cui avrebbe dovuto chiudere il tuo ordine.
faustf
Messaggi: 32
Iscritto il: 08/09/2015, 22:06

Re: OrderClose come si usa?

Messaggio da faustf »

non funziona con
OrderClose(ticket_order,lotto_size,Ask,3,Red);
Avatar utente
carlo10
Messaggi: 4259
Iscritto il: 08/05/2014, 21:17

Re: OrderClose come si usa?

Messaggio da carlo10 »

Sei riuscito a vedere l'errore?
faustf
Messaggi: 32
Iscritto il: 08/09/2015, 22:06

Re: OrderClose come si usa?

Messaggio da faustf »

con la modifica che mi hai detto nel log dell editor , mi dice return value orderclose should be checked ?? ma cosa vuol dire???
che devo mettere il risultato in una variabile e vederlo ???
faustf
Messaggi: 32
Iscritto il: 08/09/2015, 22:06

Re: OrderClose come si usa?

Messaggio da faustf »

o guardato nell log metatrader e mi dice orderclosed function cannot be called in custom indicator
quindi suppongo che la funzione orderclosed non gira negli indicatori giusto?
Avatar utente
carlo10
Messaggi: 4259
Iscritto il: 08/05/2014, 21:17

Re: OrderClose come si usa?

Messaggio da carlo10 »

return value orderclose should be checked -> indica che non stai verificando il valore restituito dalla OrderClose per capire se va a buon fine o meno la chiusura. E' un warning in compilazione e non un errore bloccante.

orderclose function cannot be called in custom indicator -> non puoi utilizzare funzioni per gestire ordini negli indicatori, per farlo devi creare un expert advisor.
faustf
Messaggi: 32
Iscritto il: 08/09/2015, 22:06

Re: OrderClose come si usa?

Messaggio da faustf »

si infatti mi pareva :lol:
e ho creato un expert , ma non mi va anzi fa una serie di cose strane

allora quando era un indicatore lo mettevo su mettevo il prezzo e lui subito mi faceva apparire la linea , se inserisco priceexactly
ora s provo a fare lo stesso sta li ci pensa un po poi quando passa da exactly (e avrebbe docuto mettere la linea ) allora la mette , in piu non chiude ovviamente niente
:D

Codice: Seleziona tutto

//+------------------------------------------------------------------+
//|                                                      HideDog.mq4 |
//|                                           Copyright 2015, FaustF |
//|                                          https://www.FaustFX.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, FaustF"
#property link      "https://www.FaustFX.com"
#property version   "1.00"
#property strict

extern int    magik_number = 1234656;
extern int    number_order = 0;
extern double lotto_size =0.1;
extern double WhenPriceGoesAbove = 0;
extern double WhenPriceGoesBelow = 0;
extern double WhenPriceIsExactly = 0;
extern bool SendEmail = false; //If true e-mail is sent to the e-mail address set in your MT4. E-mail SMTP Server settings should also be configured in your MT4

int start()
  {
  {
   if (WhenPriceIsExactly > 0)
   {
      ObjectCreate("WhenPriceIsExactly", OBJ_HLINE, 0, Time[0], WhenPriceIsExactly);
      ObjectSet("WhenPriceIsExactly", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("WhenPriceIsExactly", OBJPROP_COLOR, Yellow);
      ObjectSet("WhenPriceIsExactly", OBJPROP_WIDTH, 1);
   }
   if (WhenPriceGoesAbove > 0)
   {
      ObjectCreate("WhenPriceGoesAbove", OBJ_HLINE, 0, Time[0], WhenPriceGoesAbove);
      ObjectSet("WhenPriceGoesAbove", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("WhenPriceGoesAbove", OBJPROP_COLOR, Green);
      ObjectSet("WhenPriceGoesAbove", OBJPROP_WIDTH, 1);
   }
   if (WhenPriceGoesBelow > 0)
   {
      ObjectCreate("WhenPriceGoesBelow", OBJ_HLINE, 0, Time[0], WhenPriceGoesBelow);
      ObjectSet("WhenPriceGoesBelow", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("WhenPriceGoesBelow", OBJPROP_COLOR, Red);
      ObjectSet("WhenPriceGoesBelow", OBJPROP_WIDTH, 1);
   }
   return(0);
}
 {
 ObjectDelete("WhenPriceIsExactly");
   ObjectDelete("WhenPriceGoesAbove");
   ObjectDelete("WhenPriceGoesBelow");
   return(0);
} 
   
// added by Mn -----------------------------------------------------------
   if (ObjectGet("WhenPriceGoesAbove", 1) != WhenPriceGoesAbove)
     WhenPriceGoesAbove = ObjectGet("WhenPriceGoesAbove", 1);
   if (ObjectGet("WhenPriceGoesBelow", 1) != WhenPriceGoesBelow)
     WhenPriceGoesBelow = ObjectGet("WhenPriceGoesBelow", 1);
   if (ObjectGet("WhenPriceIsExactly", 1) != WhenPriceIsExactly)
     WhenPriceIsExactly = ObjectGet("WhenPriceIsExactly", 1);
 // added by Mn -----------------------------------------------------------

   if ((Ask > WhenPriceGoesAbove) && (WhenPriceGoesAbove > 0))
   {
      Alert("Price above the alert level.");
      PlaySound("alert.wav");
   //   SendMail("Price for " + Symbol() +  " above the alert level " + Ask, "Price for " + Symbol() +  " reached " + Ask + " level, which is above your alert level of " + WhenPriceGoesAbove);
      ObjectDelete("WhenPriceGoesAbove");
      WhenPriceGoesAbove = 0;
   }
   if ((Bid < WhenPriceGoesBelow) && (WhenPriceGoesBelow > 0))
   {
      Alert("Price below the alert level.");
      PlaySound("alert.wav");
   //   SendMail("Price for " + Symbol() +  " below the alert level " + Bid, "Price for " + Symbol() +  " reached " + Bid + " level, which is below your alert level of " + WhenPriceGoesBelow);
      ObjectDelete("WhenPriceGoesBelow");
      WhenPriceGoesBelow = 0;
   }
   if ((Bid == WhenPriceIsExactly) || (Ask == WhenPriceIsExactly))
   {
   bool result=false;
     result= OrderClose(number_order,lotto_size,Bid,30,Red);
       
      Alert("Price is exactly at the alert level.");
      PlaySound("alert.wav");
 //     SendMail("Price for " + Symbol() +  " exactly at the alert level " + Ask, "Price for " + Symbol() +  " reached " + Ask + "/" + Bid + " level, which is exactly your alert level of " + WhenPriceIsExactly);
      ObjectDelete("WhenPriceIsExactly");
      WhenPriceIsExactly = 0;
   }
   return(0);
}
un anim pia per qualche dritta lo ringrazio anticipatamente :D
Rispondi

Chi c’è in linea

Visitano il forum: Nessuno e 0 ospiti