[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 131

 
smshev:
When closing trades in the tester is written as you have listed, it is most likely the result of the orderclose function (TP and SL have nothing to do with it)

Thanks, but there seems to be no errors in the code:

int CloseOrder(int ticket, double lots)
              {
               int err,i1;
               double price;
               OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
               if (lots<MarketInfo(Symbol(),MODE_MINLOT))lots=MarketInfo(Symbol(),MODE_MINLOT);
               while(i1<10)
                   {
                    RefreshRates();
                    if (OrderType()==0)price=Bid;
                    if (OrderType()==1)price=Ask;
                    if (OrderType()>1){OrderDelete(ticket);return(0);}
                    OrderClose(ticket,lots,NormalizeDouble(price,Digits),Slippage,Goldenrod);
                    err = GetLastError();
                    if (err == 0) break;
                    Print(WindowExpertName(),Symbol(),Error(err),"  при закрытии ордера");
                    Sleep(100);
                    i1++;
                   }
               return(0);
              }
 

but there is another code in the EA:

int CloseMarket()
   {
    for (int j=0; j<OrdersTotal(); j++)
      {
       OrderSelect(j,SELECT_BY_POS,MODE_TRADES);
       if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType()<2)
         {
          CloseOrder(OrderTicket(),OrderLots());
          j--;
         }
      }
   } 
 
alex12:

But there is another code in the EA:

put for example Print("close by CloseMarket " , j); in this function and something similar in the previous one you posted . run it and look through the logs to see which of these prints appears to analyse which one triggers. then similarly log the values of the variables checked in the close execution conditions and find the reasons for their triggering...

 
alsu:
And what prevents you from putting the EA on the exact window where you want to draw?


My EA works better on M1, because it is better at M1 and opens 1 trade on M5 bar opening, it also refills if conditions allow. I also use indicators on M5 and other TFs. And it is better to test on M1 at bar opening, while on other TFs with all ticks it tests bad.

I don't draw, I just see the results of the calculations made by the EA and displayed in somments to make sure everything is in order. Thank you for your attention and help!

 
borilunad:


My EA works better on M1, as it trawls better on M1 and opens 1 trade on M5 bar opening, also refills if conditions allow. And I use indicators on M5 and other TFs. And it is better to test on M1 at bar opening, while on other TFs with all ticks it tests bad.

I don't draw, I just see the results of the calculations made by the EA and displayed in somments to make sure everything is OK. Thank you for your attention and help!

On M1, and on M5 ticks are taken from the same source, and you can use any timeframe from any chart, just replace Close[] by iClose, etc. In order to test it better, you have to make better fxt-files from ticks, here is an example, but in general google, there is a lot of information on this subject.
 
alsu:
Both on M1 and M5 the ticks are taken from the same source, and you can use any timeframe from any chart, just replace Close[] with iClose, etc. In order to test it better, you have to make better fxt-files from ticks, here is an example, but in general google, there is a lot of information on this subject.

The practice has shown, that it is better to open on Op and test also better, than on ticks. I am not keen on ticks at all. When depo allows, I may move to higher TF, which will show better results in a day. I do not leave deals for the night to sleep well. Thanks again!
 
smshev:

Print("Close by CloseMarket " , j); in this function and something similar in the previous one you posted. Run it and look through the log for the results of these printers to analyse which one triggers. Then similarly log the values of the variables checked in the close conditions and find the reasons for their triggering...

Thank you.
 
borilunad:

Practice has shown that it's better to open on Orep and test better, too, than on ticks. And I'm not into ticks at all. When depo allows, I may switch to higher TF, which will show better results within a day. I do not leave deals for the night to sleep well. Thanks again!
I'm not saying that, I'm saying what difference does it make where the EA is attached? If it is properly written, it does not matter where it is located: even if it is on the chart of Mongolian exchange, but if it is set to operate on EURUSD 1 minute, it will do so. And it is not difficult to program it, just change a couple of lines as a rule.
 

Dear Mr. Programmers! I can't draw a horizontal line by the maximum numerical value of the MACD indicator window.

Code


#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Red
//--- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double topBuffer[];


bool initFinished=false; // add a variable that will remember the state of initialization.
// false - initialization has not yet happened.
// true - was initialized
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_NONE);
SetIndexBuffer(2,topBuffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted(),
limit;

if(counted_bars>0)
counted_bars--;

limit=Bars-counted_bars;
//----
for(int i=0;i<limit;i++)

{
ExtMapBuffer1[i]=iMACD(0,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i);
ExtMapBuffer2[i]=iMACD(0,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,i);

if(initFinished==false)
{
IndicatorShortName("MACD_max-min");

int win_idx=WindowFind("MACD_max-min");
// find the number of our indicator subwindow

if(win_idx<0)
{
// if the subwindow number is -1, there is an error
Print("Window not found");
return(0);
}

double top=WindowPriceMax(win_idx);
//find the maximum value of the vertical scale of the specified sub-window of the current chart


ObjectCreate("max",OBJ_HLINE,win_idx,0,top);
// draw a horizontal line in a subwindow of our indicator

ObjectSet("max",OBJPROP_COLOR,Yellow);
ObjectSet("max",OBJPROP_WIDTH,0);

WindowRedraw();
// redraw the window to see the line

initFinished=true;
// drawing is finished

}

topBuffer[i]=top;


}

//----
return(0);
}

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


It looks like in the line

double top=WindowPriceMax(win_idx);

top variable does not get any value and in the

ObjectCreate("max",OBJ_HLINE,win_idx,0,top);

instead of it (i.e. instead of top variable) I automatically get 0 (zero). So, I get a zero line in the required window and in the required colour. topBuffer[] is also empty. If in this line instead of the variable top put a numeric value, the line takes this fixed value.Somewhere I have a clinical error.Help to understand! Thank you in advance.

Files:
 
IndicatorShortName would be better moved to init()
Reason: