Averaging function

 

Have written averaging function to my new expert but for some reason does not make sense at Strategy Tester. I hope someone could help with this.


 
David Diez:

Have written averaging function to my new expert but for some reason does not make sense at Strategy Tester. I hope someone could help with this.


What do you mean does not make sense? Can you put the code ?
 
Marius Ovidiu Sunzuiana:
What do you mean does not make sense? Can you put the code ?
In the image you can see that result is the same despite the parameters.
 
David Diez: In the image you can see that result is the same despite the parameters.
Do you really expect an answer? We can't see your broken code. There are no mind readers here and our crystal balls are cracked.
 
William Roeder:
Do you really expect an answer? We can't see your broken code. There are no mind readers here and our crystal balls are cracked.

Just mix mugwort and rain water in a vile on the first Sunday after a full moon, pour it over your computer and re-run the EA

 
iRick:

Just mix mugwort and rain water in a vile on the first Sunday after a full moon, pour it over your computer and re-run the EA

This will help 😁
 
William Roeder:
Do you really expect an answer? We can't see your broken code. There are no mind readers here and our crystal balls are cracked.
            if(AvDistance>0){
               //--------------------------- Averaging LONG deal ---!
               double AveragingLong=NormalizeDouble(OpenPriceLong-(AvDistance*10)*Point,Digits); // PRICE TO START AVERAGING
               Print("OpenPrice LONG is ",OpenPriceLong);Print("Averaging LONG is ",AveragingLong);
               if(Ask<=AveragingLong){
                  Print("Averaging LONG under ",AveragingLong);
                  Comment("Averaging LONG under ",AveragingLong);
                  int FirstBuy=0,LastBuy=0;
                  double FirstProfit=0,LastProfit=0;
                  if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)){ // FIRST ORDER
                     if(OrderType()==OP_BUY){
                        FirstBuy=OrderTicket();
                        FirstProfit=OrderProfit()+OrderSwap()+OrderCommission();
                        }
                     }
                  if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){ // LAST ORDER
                     if(OrderType()==OP_BUY){
                        LastBuy=OrderTicket();
                        LastProfit=OrderProfit()+OrderSwap()+OrderCommission();
                        }
                     }
                  if(LastProfit>=MathAbs(FirstProfit)*(1+AvOverlapping/100)){ // CONDITION CLOSE
                     Print("FirstBuy profit is ",FirstProfit,", ticket ",FirstBuy);
                     Print("LastBuy profit is ",LastProfit,", ticket ",LastBuy);
                     if(OrderSelect(FirstBuy,SELECT_BY_TICKET,MODE_TRADES)){
                        if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,clrNONE)){
                           Print("OrderClose error ",GetLastError());
                           RefreshRates();
                           return;
                           }
                        }
                     if(OrderSelect(LastBuy,SELECT_BY_TICKET,MODE_TRADES)){
                        if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,clrSilver)){
                           Print("OrderClose error ",GetLastError());
                           RefreshRates();
                           return;
                           }
                        }
                     }
                  }
               }
 
  1.                   if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)){ // FIRST ORDER
                         if(OrderType()==OP_BUY){
                            FirstBuy=OrderTicket();
                            FirstProfit=OrderProfit()+OrderSwap()+OrderCommission();
                            }
                         }
    
    Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles

  2. What if there is no open orders?
  3.                   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){ // LAST ORDER
    
    No value given to i.
  4. "Doesn't make sense" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. We can't see your broken code. There are no mind readers here and our crystal balls are cracked.
 
William Roeder:
  1. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles

  2. What if there is no open orders?
  3. No value given to i.
  4. "Doesn't make sense" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. We can't see your broken code. There are no mind readers here and our crystal balls are cracked.
i is last order, but probably meaningless.
 
David Diez:
i is last order, but probably meaningless.
last order is OrdersTotal()-1


You better use a loop for your orders

 
ffoorr: last order is OrdersTotal()-1
Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
          Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum
          MagicNumber: "Magic" Identifier of the Order - MQL4 Articles
Reason: