Averaging function

To add comments, please log in or register
David Diez
1207
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.


Marius Ovidiu Sunzuiana
1301
Marius Ovidiu Sunzuiana  
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 ?
David Diez
1207
David Diez  
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.
William Roeder
18893
William Roeder  
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.
iRick
203
iRick  
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

David Diez
1207
David Diez  
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 😁
David Diez
1207
David Diez  
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;
                           }
                        }
                     }
                  }
               }
William Roeder
18893
William Roeder  
  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.
David Diez
1207
David Diez  
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.
ffoorr
1342
ffoorr  
David Diez:
i is last order, but probably meaningless.
last order is OrdersTotal()-1


You better use a loop for your orders

William Roeder
18893
William Roeder  
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
12
To add comments, please log in or register