[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 520

 
Roger:

In general, I added two variables - one for the deposit level to be reached and the second for the number of files to be deleted. It will work only once, then it is necessary to correct the level for another value or restart the Expert Advisor.
Thanks - now I will run the test. Or it is not suitable for running in the tester ?
 
alex12:
Thanks - I'll run the test now. Or is it not suitable for the tester run?

How would I test it?
 
demlin:

Greetings all!

Please advise a normal indicator for determining a flat, thanks in advance ))))


I'm testing this one myself.

Can be easily added (plugged) into an Expert Advisor through iCustom().

 
A simple system for crossing 2 wagons.
Buy - the fast one crosses the slow one upwards.
Sell - fast one crosses slow one downwards.

Close - opposite signal or trawl. Can you please tell me what I should change in the code to set stop = 50 pips on every position opening?

extern double Lots           =   0; // лот, если 0, то динамический
extern double RiskPercentage =  70; // % от депо на лот, если динамический
extern int    FastPer        =   4;
extern int    SlowPer        =  18;
extern int    magicnumber    = 777;
extern int    TrailingStop   =  20; 
extern bool   PolLots        = true;



int prevtime;
int ticket=0;
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----




   if (!IsDemo())
    {
//     Print ("Эта версия только для демо-счетов");
//     return(0);
    }   


   if(Time[0] == prevtime)
   { 

       return(0);
   }
   prevtime = Time[0];
   if(!IsTradeAllowed()) 
     {
       prevtime = Time[1];
       return(0);
     }




 int Ord=0;
 double ClLot=0;
int LotsCount=0;
   int i=0;  
   int total = OrdersTotal();   
   for(i = 0; i <= total; i++) 
     {
      if(TrailingStop>0)  
       {                 
       OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
       if(OrderMagicNumber() == magicnumber) 
         {
         ticket=OrderTicket(); 
         ClLot=OrderLots();
         if (OrderType()==OP_BUY)
          {
           Ord=1;
          }
         else
          {
           Ord=2;
          }         
          LotsCount ++;
          TrailingStairs(OrderTicket(),TrailingStop);
         }
       }
      }
/*
 
     for(i = 0; i <= OrdersTotal(); i++) 
      {
       OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
       if(OrderMagicNumber() == magicnumber) 
         {
         ticket=OrderTicket(); 
         ClLot=OrderLots();
         if (OrderType()==OP_BUY)
          {
           Ord=1;
          }
         else
          {
           Ord=2;
          }
         }
      } 
*/    
bool SellOp=false;
bool BuyOp=false;

double MAFast1=NormalizeDouble(iMA(NULL,0,FastPer,0,MODE_SMA,PRICE_CLOSE,2),Digits);
double MAFast2=NormalizeDouble(iMA(NULL,0,FastPer,0,MODE_SMA,PRICE_CLOSE,1),Digits);
double MAFast3=NormalizeDouble(iMA(NULL,0,FastPer,0,MODE_SMA,PRICE_CLOSE,0),Digits);
double MASlow1=NormalizeDouble(iMA(NULL,0,SlowPer,0,MODE_SMA,PRICE_CLOSE,2),Digits);
double MASlow2=NormalizeDouble(iMA(NULL,0,SlowPer,0,MODE_SMA,PRICE_CLOSE,1),Digits);
double MASlow3=NormalizeDouble(iMA(NULL,0,SlowPer,0,MODE_SMA,PRICE_CLOSE,0),Digits);


      
if ((MAFast1<MASlow1)&&
    (MAFast2==MASlow2)&&
    (MAFast3>MASlow3))
{
 BuyOp=true;
}

if ((MAFast1>MASlow1)&&
    (MAFast2==MASlow2)&&
    (MAFast3<MASlow3))
{
 SellOp=true;
}



if (BuyOp)
 {
  if (Ord==2)
   {
    OrderClose(ticket,ClLot,Ask,3,Red);
   }
  if (Ord!=1)
   {
    OrderSend(Symbol(),OP_BUY,Lot(),Ask,3,0,0,"MA_Buy",magicnumber,0,Green);
   }
 }

if (SellOp)
 {
  if (Ord==1)
   {
    OrderClose(ticket,ClLot,Bid,3,Green);
   }
  if (Ord!=2)
   {
    OrderSend(Symbol(),OP_SELL,Lot(),Bid,3,0,0,"MA_Sell",magicnumber,0,Red);
   }
 }



   
//----
   return(0);
  }
//+------------------------------------------------------------------+
void TrailingStairs(int ticket,int trldistance)
   { 
    int Spred=Ask - Bid;
    if (OrderType()==OP_BUY)
      {
       if((Bid-OrderOpenPrice())>(Point*trldistance))
         {
          if(OrderStopLoss()<Bid-Point*trldistance || (OrderStopLoss()==0))
            {
             OrderModify(ticket,OrderOpenPrice(),Bid-Point*trldistance,OrderTakeProfit(),0,Green);
             if (PolLots)
             if (NormalizeDouble(OrderLots()/2,1)>MarketInfo(Symbol(), MODE_MINLOT))
               {
               OrderClose(ticket,NormalizeDouble(OrderLots()/2,1),Bid,3,Green);
               }
             else
               {
               OrderClose(ticket,OrderLots(),Bid,3,Green);
               }
            }
         }
       }
     else
       {
        if((OrderOpenPrice()-Ask)>(Point*trldistance))
          {
           if((OrderStopLoss()>(Ask+Point*trldistance)) || (OrderStopLoss()==0))
             {
              OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*trldistance,OrderTakeProfit(),0,Red);
             if (PolLots)
             if (NormalizeDouble(OrderLots()/2,1)>MarketInfo(Symbol(), MODE_MINLOT))
               {
               OrderClose(ticket,NormalizeDouble(OrderLots()/2,1),Ask,3,Green);
               }
             else
               {
               OrderClose(ticket,OrderLots(),Ask,3,Green);
               }
             }
          }
        }
    }
    
double Lot()
{
 double LotQ = Lots;

 if (Lots==0)
  {
   double margin = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
   double minLot = MarketInfo(Symbol(), MODE_MINLOT);
   double maxLot = MarketInfo(Symbol(), MODE_MAXLOT);
   double step =   MarketInfo(Symbol(), MODE_LOTSTEP);
   double account = AccountFreeMargin();
   
   double percentage = account*RiskPercentage/100;
   
   LotQ = MathRound(percentage/margin/step)*step;
   
   if(LotQ < minLot)
   {
      LotQ = minLot;
   }
   
   if(LotQ > maxLot)
   {
      LotQ = maxLot;
   }
  } 
  return (LotQ);
  }

 
Roman.:


I am testing this one myself.

It is easily added (connected) to the Expert Advisor via iCustom().

I wonder, how do you define its extreme low and extreme high values in an EA? After all, in one local area of the chart 0.3800 (the blue line) was an extreme value and corresponded to a temporary correction, while in the next local area 0.3041 (the green line) became its extreme value and marked a reversal...

What about the extremum low value 0.4596 at the first long (red line), which said nothing?

And how do you determine whether the indicator extremally low value indicates a correction or reversal? In fact, the value of 0.3800 in the first case indicated a correction (the green vertical line), and in the second case - the end of the trend (the red vertical line)

And finally - there are a lot of such local extremes on the chart. After all, for a 3-5 hour period, there will certainly be the lowest value, and it will be an extreme low value for that time interval. If we specify a certain time interval for finding indicator extreme values, they will be found, but... However, on subsequent bars, beyond the specified timeframe, it may happen that the indicator value will become even lower (higher) and then this value will be extremally low (high) - but what to do with the previously found one? The more so that the Expert Advisor will make a decision based on it.

However...


 
artmedia70:

I wonder, how do you define extreme low and extreme high values in your Expert Advisor? After all, in one local sector of the chart 0.3800 (blue line) was an extreme value and corresponded to a temporary correction, while in the next local sector 0.3041 (green line) became its extreme value and marked a reversal...

What about the extremum low value 0.4596 at the first long (red line), which said nothing?

And how do you determine whether the indicator extremally low value indicates a correction or reversal? In fact, the value of 0.3800 in the first case indicated a correction (the green vertical line), and in the second case - the end of the trend (the red vertical line)

And finally - there are a lot of such local extremes on the chart. If we set a 3-5 hour interval, it will certainly be the lowest value, and it will be an extreme low value for that time interval. If we specify a certain time interval for finding indicator extreme values, it will be found, but... However, on subsequent bars, beyond the specified timeframe, it may happen that the indicator value will become even lower (higher) and then this value will be extremally low (high) - but what to do with the previously found one? The more so that the Expert Advisor will make a decision based on it...

However...





I look at this indicator as a filter for entering the market of either trend or flat strategy, i.e., the following interpretation of its reading appears:

double iVAR_1 = iCustom (Symbol(),trend_period, "iVAR", n, nBars, 0, 1);                    // расчет индикатора iVAR
   

Indicator's value below 0.5 means that the market is in a trend.

iVAR_1 < 0.5 &&                                                            // тренд на основном ТФ   

Extremely low values often precede the end (correction) of the current trend - it is already on the figure - here trawl works (when in the market).


Indicator value above 0.5 means a flat market condition

iVAR_1 > 0.5 && 

The extremely high value often precedes the beginning of a significant trend - see the previous interpretation.

Indicator's value around 0.5 means an uncertain market situation - here it is possible to use some "level" of indentation (I do not exclude that it is redundant, i.e. take value 0.5 and all), both below - x, and above - y value 0.5 (base level), enter them into external variables and optimize with step 0.02, let's say, the same as variable n - start:2 step:1 stop:7 - it is not superfluous, I do it - soon I will post results in Avalanche branch (it is trend system...:-)), only with MM by Martin... and all... :-)))).

 
Roman.:


I look at this indicator as a filter for entering the market either to a trend or flat strategy, i.e. I get the following interpretation of its reading:

An indicator value below 0.5 indicates a trending market condition -

Extremely low values often precede the end (correction) of the current trend - this already suits the figure - here trawl works (when in the market).


The indicator value above 0.5 means the flat market condition

Extremely high value often precedes the beginning of a significant trend - see the previous interpretation.

Indicator's value around 0.5 means an uncertain market condition - here it is possible to use some "level" of indentation (I don't exclude that it is redundant, i.e. take value 0.5 and all), both below - x, and above - y value 0.5 (base level), enter them into external variables and optimize with step 0.02, let's say, the same as variable n - start:2 step:1 stop:7 - this is not excessive, I do it - soon I will post results in Lavina branch (it is trend system...:-)), only with MM by Martin... and all... :-)))).

I don't like optimisation: the essence is a fit... And I never optimize the parameters of my babies... I try to choose necessary parameters for different market conditions.

Thanks for the clarification, though... :) Honestly - catch the post above was a pebble in the direction of the turkey... :)

 

Good afternoon!

I have such a question. The Expert Advisor has a function that writes trades into a csv file, but I have discovered a problem that occurs when I enable/disable(TRUE/FALSE) the money management system option in the Expert Advisor parameters. For example, right after compiling the source file everything works correctly and trades are written to the file as intended. The figure below illustrates correctly written data:

Then in the tester, I enable the money management system option in the Expert Advisor parameters, run the test, but the data is not written to the file correctly. The figure below shows two variants for comparison. The one on the left is correct (as above) and the one on the right is not correct:

I haven't been able to figure out on my own what this might be about, but I found the following. If I also enable/disable the money management system option and compile the source file again before starting the test, everything is written correctly.

Can you tell me what the problem could be?

 
artmedia70:

I don't like optimisation: the essence is fitting... And I never optimize the parameters of my products... I try to let them choose the necessary parameters for different market conditions.

Although, thanks for the clarification... :) Honestly - go with the post above was a pebble in the direction of a turkey... :)


I see... If you're interested, here's a similar thing (in the trailer). See also here (entire thread)-there'sa treatment above/below 0.6 and here(selective pages).

Files:
 
Roman.:


I'm testing this one myself.

Easily added (plugged in) to the EA via iCustom().

Thanks, I downloaded it, I will test it in my Expert Advisor