Coding help - page 658

 

Dear mladen

If I want to know the last closed order type and if it made profit in an EA, can the following function do the job:

int OrdersProfit()
  {
   int Profit;
   for (int i=OrdersHistoryTotal(); i>=0; i--)
     {
      if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
      if (OrderType()==OP_BUY  && OrderProfit()> 0) Profit ="1" ;
      if (OrderType()==OP_SELL && OrderProfit()> 0) Profit ="2" ;
     }    
   return(Profit);
  }


Best,

 
IXI:

Dear mladen

If I want to know the last closed order type and if it made profit in an EA, can the following function do the job:


Best,

No, it is not (simply because the closed orders are not ordered by closing time - at least that is what the manual tells us : no guarantee that the orders are ordered by closing time). It has to be done something like this :

int OrdersProfit()
{
   int      profit    = 0;
   datetime CloseTime = 0;
       for(int i=OrdersHistoryTotal()-1;i>=0;i--)
       {
           if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
           if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderCloseTime()>CloseTime)
           {
              CloseTime = OrderCloseTime();
              if (OrderType()==OP_BUY  && OrderProfit()> 0) Profit =1 ;
              if (OrderType()==OP_SELL && OrderProfit()> 0) Profit =2 ;
           } 
       }
       return(Profit);
}  
 

Dear mladen

Many thanks for your perfect answer.

Best,

 

Dear friends,

Can you updated attached indicators for latest build mt4 please?

Especially, "123PatternsV6" is freezes mt4 and not working! 

 

 
oguz:

Dear friends,

Can you updated attached indicators for latest build mt4 please?

Especially, "123PatternsV6" is freezes mt4 and not working! 

 

I think 123 needs zigzag indicator for to work with out freezing terminal.
 
mntiwana:
I think 123 needs zigzag indicator for to work with out freezing terminal.

Zigzag indicator is already available in mt4.

 
oguz:

Zigzag indicator is already available in mt4.

The new zigzag does not work as the previous versions. It will hang the terminal if some parameters are used from iCustom() calls
 

Hi.

 

lately I started to program MQL4 to gain experience so I can be able to code my own ideas to test them out beforehand.

 

Now im struggeling with the timing of the painting.

 

Lets say i have an if statment for some stochastics and want to wait until the MA goes above or below price before painting, how can i do that?

 

What i tried and the only thing that came to my mind:

 

if(iStochastic(NULL, PERIOD_CURRENT, _K_period, _D_period, Slowing, MODE_SMA, 0, MODE_MAIN, i) > 80
      && iStochastic(NULL, PERIOD_CURRENT, _K_period, _D_period, Slowing, MODE_SMA, 0, MODE_MAIN, i+1) < 80

 while High[i] > iMA(NULL, PERIOD_CURRENT, MAfilter, 0, MODE_EMA, PRICE_CLOSE, i+1) //Candlestick High < Moving Average
            (
               1+1
            )
       
      )

{
         Buffer1[i] = High[i]; //Set indicator value at Candlestick High
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Selling opportunity"); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      else
        {
         Buffer1[i] = 0;

 the 1+1 just to fill the while loop, what i am trying to do is to wait to paint the arrow until the high of the price is below the MA, but yet i dont want this to be and statement since the cross happend i just want to wait util i paint .

 

however this was not sucsessful, hence i ask the professional coders in the community 

 
NWFstudent:

Hi.

 

lately I started to program MQL4 to gain experience so I can be able to code my own ideas to test them out beforehand.

 

Now im struggeling with the timing of the painting.

 

Lets say i have an if statment for some stochastics and want to wait until the MA goes above or below price before painting, how can i do that?

 

What i tried and the only thing that came to my mind:

 

 the 1+1 just to fill the while loop, what i am trying to do is to wait to paint the arrow until the high of the price is below the MA, but yet i dont want this to be and statement since the cross happend i just want to wait util i paint .

 

however this was not sucsessful, hence i ask the professional coders in the community 

Try like this :

Buffer1[i] = 0;
if(   iStochastic(NULL, PERIOD_CURRENT, _K_period, _D_period, Slowing, MODE_SMA, 0, MODE_MAIN, i)   > 80
   && iStochastic(NULL, PERIOD_CURRENT, _K_period, _D_period, Slowing, MODE_SMA, 0, MODE_MAIN, i+1) < 80 
   && High[i] > iMA(NULL, PERIOD_CURRENT, MAfilter, 0, MODE_EMA, PRICE_CLOSE, i+1)) //Candlestick High < Moving Average
         Buffer1[i] = High[i]; //Set indicator value at Candlestick High

if(i == 0 && Time[0] != time_alert && Buffer1[i]!=0) { myAlert("indicator", "Selling opportunity"); time_alert = Time[0]; } //Instant alert, only once per bar
 
mladen:

Try like this :

This will give me the "signal  only when the crossover occure over the MA, I want it under the MA, but i also want the signal if i have an crossover above the MA and a few bars later the price moves below the MA.

 

Thats what i tried with the while loop, so the code would loop until the argument turns false and proceeed to paint the signal. 

 

I Made a schematic drawing, maybe you will understand better.

 

Thank you for your reply anyway 

Files:
illust.png  24 kb