Salve a tutti, ho creato la seguente funzione che mi modifica il tp a secondo il valore di una media:
A volte mi da questo errore "2020.11.20 15:26:29.154 2019.08.20 02:00:00 Moving Averages Levels EURUSDc,H1: Order failed to update with error - buy 1" ho pensato che è il fatto che la media modifica il Take meno del minimo spostamento che è consentito su quel determinato cross e l'ho modificata nel seguente modo:
[PHP]
..............
dStopLevel = MarketInfo(Symbol(),MODE_STOPLEVEL);
if (p != Point) dStopLevel = dStopLevel/10;
dStopLevel *= p;
...................................
void TPMedia(int MediaTrandPeriod, int MediaTrandMethod,int nMagic)
{
for (int i=OrdersTotal()-1; i>=0; i--)
{
if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ) {
Print("ERROR - Unable to select the order - ",GetLastError());
continue;}
if(OrderSymbol()!=Symbol())continue;
if(OrderMagicNumber()!= nMagic)continue;
//Prepare the prices
double TakeProfitPrice=OrderTakeProfit();
double OpenPrice=OrderOpenPrice();
double NewTakeProfitPrice=TakeProfitPrice;
double MAValue=iMA(NULL,0,MediaTrandPeriod,0,MediaTrandMe thod,0,1);
if (NewTakeProfitPrice>dStopLevel)
{
RefreshRates();
if(OrderType()==OP_BUY)
{
NewTakeProfitPrice=NormalizeDouble(MAValue,Digits) ;
if(OrderModify(OrderTicket(),OrderOpenPrice(),0,Ne wTakeProfitPrice,0,Yellow))
Print("Order modified");
else
Print("Order failed to update with error - buy ",GetLastError());
}
if(OrderType()==OP_SELL)
{
NewTakeProfitPrice=NormalizeDouble(MAValue,Digits) ;
if(OrderModify(OrderTicket(),OrderOpenPrice(),0,Ne wTakeProfitPrice,0,Yellow))
Print("Order modified");
else
Print("Order failed to update with error - sell ",GetLastError());
}
else
Print("TP troppo stretto ",GetLastError());
}
//Wait a delay
Sleep(5);
}
}
[PHP]
In modo che prima di modificare il tp mi faccia il controllo di qual'è il minimo tp impostabile però invece di risolvere la cosa oltre a quell'errore mi si aggiunge pure questo:
"2020.11.20 15:45:40.806 2018.01.05 17:00:00 Moving Averages Levels Temp EURUSDc,H1: invalid lots amount for OrderSend function""2020.11.20 15:46:05.691 2018.01.19 23:00:00 Moving Averages Levels Temp EURUSDc,H1: OrderSend error 4051"
Ma non capisco il motivo perche non tocco i lotti di entrata;
Avete idee su come sistemare il problema?
PHP Code:
void TPMedia(int MediaTrandPeriod, int MediaTrandMethod,int nMagic){
for (int i=OrdersTotal()-1; i>=0; i--)
{
if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ) {
Print("ERROR - Unable to select the order - ",GetLastError());
continue;}
if(OrderSymbol()!=Symbol())continue;
if(OrderMagicNumber()!= nMagic)continue;
//Prepare the prices
double TakeProfitPrice=OrderTakeProfit();
double OpenPrice=OrderOpenPrice();
double NewTakeProfitPrice=TakeProfitPrice;
double MAValue=iMA(NULL,0,MediaTrandPeriod,0,MediaTrandMe thod,0,1);
RefreshRates();
if(OrderType()==OP_BUY)
{
NewTakeProfitPrice=NormalizeDouble(MAValue,Digits) ;
if(OrderModify(OrderTicket(),OrderOpenPrice(),0,Ne wTakeProfitPrice,0,Yellow))
Print("Order modified");
else
Print("Order failed to update with error - buy ",GetLastError());
}
if(OrderType()==OP_SELL)
{
NewTakeProfitPrice=NormalizeDouble(MAValue,Digits) ;
if(OrderModify(OrderTicket(),OrderOpenPrice(),0,Ne wTakeProfitPrice,0,Yellow))
Print("Order modified");
else
Print("Order failed to update with error - sell ",GetLastError());
}
}
//Wait a delay
Sleep(5);
}
[PHP]
..............
dStopLevel = MarketInfo(Symbol(),MODE_STOPLEVEL);
if (p != Point) dStopLevel = dStopLevel/10;
dStopLevel *= p;
...................................
void TPMedia(int MediaTrandPeriod, int MediaTrandMethod,int nMagic)
{
for (int i=OrdersTotal()-1; i>=0; i--)
{
if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ) {
Print("ERROR - Unable to select the order - ",GetLastError());
continue;}
if(OrderSymbol()!=Symbol())continue;
if(OrderMagicNumber()!= nMagic)continue;
//Prepare the prices
double TakeProfitPrice=OrderTakeProfit();
double OpenPrice=OrderOpenPrice();
double NewTakeProfitPrice=TakeProfitPrice;
double MAValue=iMA(NULL,0,MediaTrandPeriod,0,MediaTrandMe thod,0,1);
if (NewTakeProfitPrice>dStopLevel)
{
RefreshRates();
if(OrderType()==OP_BUY)
{
NewTakeProfitPrice=NormalizeDouble(MAValue,Digits) ;
if(OrderModify(OrderTicket(),OrderOpenPrice(),0,Ne wTakeProfitPrice,0,Yellow))
Print("Order modified");
else
Print("Order failed to update with error - buy ",GetLastError());
}
if(OrderType()==OP_SELL)
{
NewTakeProfitPrice=NormalizeDouble(MAValue,Digits) ;
if(OrderModify(OrderTicket(),OrderOpenPrice(),0,Ne wTakeProfitPrice,0,Yellow))
Print("Order modified");
else
Print("Order failed to update with error - sell ",GetLastError());
}
else
Print("TP troppo stretto ",GetLastError());
}
//Wait a delay
Sleep(5);
}
}
[PHP]
In modo che prima di modificare il tp mi faccia il controllo di qual'è il minimo tp impostabile però invece di risolvere la cosa oltre a quell'errore mi si aggiunge pure questo:
"2020.11.20 15:45:40.806 2018.01.05 17:00:00 Moving Averages Levels Temp EURUSDc,H1: invalid lots amount for OrderSend function""2020.11.20 15:46:05.691 2018.01.19 23:00:00 Moving Averages Levels Temp EURUSDc,H1: OrderSend error 4051"
Ma non capisco il motivo perche non tocco i lotti di entrata;
Avete idee su come sistemare il problema?
Comment